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" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 34 | #include "netlink.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 35 | #include "linux_defines.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 36 | #include "linux_ioctl.h" |
| 37 | #include "radiotap.h" |
| 38 | #include "radiotap_iter.h" |
| 39 | #include "rfkill.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 40 | #include "driver_nl80211.h" |
Ajay Davanageri | b921bb8 | 2020-09-16 12:49:08 +0530 | [diff] [blame] | 41 | #ifdef CONFIG_DRIVER_NL80211_BRCM |
| 42 | #include "common/brcm_vendor.h" |
| 43 | #endif /* CONFIG_DRIVER_NL80211_BRCM */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 44 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 45 | #ifndef NETLINK_CAP_ACK |
| 46 | #define NETLINK_CAP_ACK 10 |
| 47 | #endif /* NETLINK_CAP_ACK */ |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 48 | /* support for extack if compilation headers are too old */ |
| 49 | #ifndef NETLINK_EXT_ACK |
| 50 | #define NETLINK_EXT_ACK 11 |
| 51 | enum nlmsgerr_attrs { |
| 52 | NLMSGERR_ATTR_UNUSED, |
| 53 | NLMSGERR_ATTR_MSG, |
| 54 | NLMSGERR_ATTR_OFFS, |
| 55 | NLMSGERR_ATTR_COOKIE, |
| 56 | |
| 57 | __NLMSGERR_ATTR_MAX, |
| 58 | NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1 |
| 59 | }; |
| 60 | #endif |
| 61 | #ifndef NLM_F_CAPPED |
| 62 | #define NLM_F_CAPPED 0x100 |
| 63 | #endif |
| 64 | #ifndef NLM_F_ACK_TLVS |
| 65 | #define NLM_F_ACK_TLVS 0x200 |
| 66 | #endif |
| 67 | #ifndef SOL_NETLINK |
| 68 | #define SOL_NETLINK 270 |
| 69 | #endif |
| 70 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 71 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 72 | #ifdef ANDROID |
| 73 | /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */ |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 74 | #undef nl_socket_set_nonblocking |
| 75 | #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 76 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 77 | #endif /* ANDROID */ |
| 78 | |
| 79 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 80 | 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] | 81 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 82 | struct nl_sock *handle; |
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 | handle = nl_socket_alloc_cb(cb); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 85 | if (handle == NULL) { |
| 86 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 87 | "callbacks (%s)", dbg); |
| 88 | return NULL; |
| 89 | } |
| 90 | |
| 91 | if (genl_connect(handle)) { |
| 92 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " |
| 93 | "netlink (%s)", dbg); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 94 | nl_socket_free(handle); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 95 | return NULL; |
| 96 | } |
| 97 | |
| 98 | return handle; |
| 99 | } |
| 100 | |
| 101 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 102 | static void nl_destroy_handles(struct nl_sock **handle) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 103 | { |
| 104 | if (*handle == NULL) |
| 105 | return; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 106 | nl_socket_free(*handle); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 107 | *handle = NULL; |
| 108 | } |
| 109 | |
| 110 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 111 | #if __WORDSIZE == 64 |
| 112 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL |
| 113 | #else |
| 114 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL |
| 115 | #endif |
| 116 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 117 | static void nl80211_register_eloop_read(struct nl_sock **handle, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 118 | eloop_sock_handler handler, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 119 | void *eloop_data, int persist) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 120 | { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 121 | /* |
| 122 | * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB) |
| 123 | * by default. It is possible to hit that limit in some cases where |
| 124 | * operations are blocked, e.g., with a burst of Deauthentication frames |
| 125 | * to hostapd and STA entry deletion. Try to increase the buffer to make |
| 126 | * this less likely to occur. |
| 127 | */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 128 | int err; |
| 129 | |
| 130 | err = nl_socket_set_buffer_size(*handle, 262144, 0); |
| 131 | if (err < 0) { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 132 | wpa_printf(MSG_DEBUG, |
| 133 | "nl80211: Could not set nl_socket RX buffer size: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 134 | nl_geterror(err)); |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 135 | /* continue anyway with the default (smaller) buffer */ |
| 136 | } |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 137 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 138 | nl_socket_set_nonblocking(*handle); |
| 139 | eloop_register_read_sock(nl_socket_get_fd(*handle), handler, |
| 140 | eloop_data, *handle); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 141 | if (!persist) |
| 142 | *handle = (void *) (((intptr_t) *handle) ^ |
| 143 | ELOOP_SOCKET_INVALID); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 147 | static void nl80211_destroy_eloop_handle(struct nl_sock **handle, int persist) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 148 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 149 | if (!persist) |
| 150 | *handle = (void *) (((intptr_t) *handle) ^ |
| 151 | ELOOP_SOCKET_INVALID); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 152 | eloop_unregister_read_sock(nl_socket_get_fd(*handle)); |
| 153 | nl_destroy_handles(handle); |
| 154 | } |
| 155 | |
| 156 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 157 | static void nl80211_global_deinit(void *priv); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 158 | static void nl80211_check_global(struct nl80211_global *global); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 159 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 160 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 161 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 162 | struct hostapd_freq_params *freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 163 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 164 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 165 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 166 | const u8 *set_addr, int first, |
| 167 | const char *driver_params); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 168 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 169 | unsigned int freq, unsigned int wait, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 170 | const u8 *buf, size_t buf_len, |
| 171 | int save_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 172 | int no_cck, int no_ack, int offchanok, |
| 173 | const u16 *csa_offs, size_t csa_offs_len); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 174 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, |
| 175 | int report); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 176 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 177 | #define IFIDX_ANY -1 |
| 178 | |
| 179 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 180 | int ifidx_reason); |
| 181 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 182 | int ifidx_reason); |
| 183 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 184 | int ifidx_reason); |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 185 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 186 | static int nl80211_set_channel(struct i802_bss *bss, |
| 187 | struct hostapd_freq_params *freq, int set_chan); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 188 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 189 | int ifindex, int disabled); |
| 190 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 191 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 192 | int reset_mode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 193 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 194 | static int i802_set_iface_flags(struct i802_bss *bss, int up); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 195 | static int nl80211_set_param(void *priv, const char *param); |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 196 | #ifdef CONFIG_MESH |
| 197 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
| 198 | struct wpa_driver_mesh_bss_params *params); |
| 199 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 200 | 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] | 201 | u16 reason); |
Vinayak Yadawad | e62409f | 2022-01-20 12:32:07 +0530 | [diff] [blame^] | 202 | #ifdef CONFIG_DRIVER_NL80211_BRCM |
| 203 | static int nl80211_set_td_policy(void *priv, u32 td_policy); |
| 204 | #endif /* CONFIG_DRIVER_NL80211_BRCM */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 205 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 206 | /* Converts nl80211_chan_width to a common format */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 207 | enum chan_width convert2width(int width) |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 208 | { |
| 209 | switch (width) { |
| 210 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 211 | return CHAN_WIDTH_20_NOHT; |
| 212 | case NL80211_CHAN_WIDTH_20: |
| 213 | return CHAN_WIDTH_20; |
| 214 | case NL80211_CHAN_WIDTH_40: |
| 215 | return CHAN_WIDTH_40; |
| 216 | case NL80211_CHAN_WIDTH_80: |
| 217 | return CHAN_WIDTH_80; |
| 218 | case NL80211_CHAN_WIDTH_80P80: |
| 219 | return CHAN_WIDTH_80P80; |
| 220 | case NL80211_CHAN_WIDTH_160: |
| 221 | return CHAN_WIDTH_160; |
| 222 | } |
| 223 | return CHAN_WIDTH_UNKNOWN; |
| 224 | } |
| 225 | |
| 226 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 227 | int is_ap_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 228 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 229 | return nlmode == NL80211_IFTYPE_AP || |
| 230 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 234 | int is_sta_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 235 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 236 | return nlmode == NL80211_IFTYPE_STATION || |
| 237 | nlmode == NL80211_IFTYPE_P2P_CLIENT; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 241 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 242 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 243 | return nlmode == NL80211_IFTYPE_P2P_CLIENT || |
| 244 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 245 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 246 | |
| 247 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 248 | struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, |
| 249 | int ifindex) |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 250 | { |
| 251 | struct i802_bss *bss; |
| 252 | |
| 253 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 254 | if (bss->ifindex == ifindex) |
| 255 | return bss; |
| 256 | } |
| 257 | |
| 258 | return NULL; |
| 259 | } |
| 260 | |
| 261 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 262 | static int is_mesh_interface(enum nl80211_iftype nlmode) |
| 263 | { |
| 264 | return nlmode == NL80211_IFTYPE_MESH_POINT; |
| 265 | } |
| 266 | |
| 267 | |
| 268 | void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 269 | { |
| 270 | if (drv->associated) |
| 271 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); |
| 272 | drv->associated = 0; |
| 273 | os_memset(drv->bssid, 0, ETH_ALEN); |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 274 | drv->first_bss->freq = 0; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 278 | /* nl80211 code */ |
| 279 | static int ack_handler(struct nl_msg *msg, void *arg) |
| 280 | { |
| 281 | int *err = arg; |
| 282 | *err = 0; |
| 283 | return NL_STOP; |
| 284 | } |
| 285 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 286 | |
| 287 | struct nl80211_ack_ext_arg { |
| 288 | int *err; |
| 289 | void *ext_data; |
| 290 | }; |
| 291 | |
| 292 | |
| 293 | static int ack_handler_cookie(struct nl_msg *msg, void *arg) |
| 294 | { |
| 295 | struct nl80211_ack_ext_arg *ext_arg = arg; |
| 296 | struct nlattr *tb[NLMSGERR_ATTR_MAX + 1]; |
| 297 | u64 *cookie = ext_arg->ext_data; |
| 298 | struct nlattr *attrs; |
| 299 | size_t ack_len, attr_len; |
| 300 | |
| 301 | *ext_arg->err = 0; |
| 302 | ack_len = sizeof(struct nlmsghdr) + sizeof(int) + |
| 303 | sizeof(struct nlmsghdr); |
| 304 | attrs = (struct nlattr *) |
| 305 | ((u8 *) nlmsg_data(nlmsg_hdr(msg)) + sizeof(struct nlmsghdr) + |
| 306 | sizeof(int)); |
| 307 | if (nlmsg_hdr(msg)->nlmsg_len <= ack_len) |
| 308 | return NL_STOP; |
| 309 | |
| 310 | attr_len = nlmsg_hdr(msg)->nlmsg_len - ack_len; |
| 311 | |
| 312 | if(!(nlmsg_hdr(msg)->nlmsg_flags & NLM_F_ACK_TLVS)) |
| 313 | return NL_STOP; |
| 314 | |
| 315 | nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, attr_len, NULL); |
| 316 | if (tb[NLMSGERR_ATTR_COOKIE]) |
| 317 | *cookie = nla_get_u64(tb[NLMSGERR_ATTR_COOKIE]); |
| 318 | |
| 319 | return NL_STOP; |
| 320 | } |
| 321 | |
| 322 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 323 | static int finish_handler(struct nl_msg *msg, void *arg) |
| 324 | { |
| 325 | int *ret = arg; |
| 326 | *ret = 0; |
| 327 | return NL_SKIP; |
| 328 | } |
| 329 | |
| 330 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, |
| 331 | void *arg) |
| 332 | { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 333 | struct nlmsghdr *nlh = (struct nlmsghdr *) err - 1; |
| 334 | int len = nlh->nlmsg_len; |
| 335 | struct nlattr *attrs; |
| 336 | struct nlattr *tb[NLMSGERR_ATTR_MAX + 1]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 337 | int *ret = arg; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 338 | int ack_len = sizeof(*nlh) + sizeof(int) + sizeof(*nlh); |
| 339 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 340 | *ret = err->error; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 341 | |
| 342 | if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS)) |
| 343 | return NL_SKIP; |
| 344 | |
| 345 | if (!(nlh->nlmsg_flags & NLM_F_CAPPED)) |
| 346 | ack_len += err->msg.nlmsg_len - sizeof(*nlh); |
| 347 | |
| 348 | if (len <= ack_len) |
| 349 | return NL_STOP; |
| 350 | |
| 351 | attrs = (void *) ((unsigned char *) nlh + ack_len); |
| 352 | len -= ack_len; |
| 353 | |
| 354 | nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, len, NULL); |
| 355 | if (tb[NLMSGERR_ATTR_MSG]) { |
| 356 | len = strnlen((char *) nla_data(tb[NLMSGERR_ATTR_MSG]), |
| 357 | nla_len(tb[NLMSGERR_ATTR_MSG])); |
| 358 | wpa_printf(MSG_ERROR, "nl80211: kernel reports: %*s", |
| 359 | len, (char *) nla_data(tb[NLMSGERR_ATTR_MSG])); |
| 360 | } |
| 361 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 362 | return NL_SKIP; |
| 363 | } |
| 364 | |
| 365 | |
| 366 | static int no_seq_check(struct nl_msg *msg, void *arg) |
| 367 | { |
| 368 | return NL_OK; |
| 369 | } |
| 370 | |
| 371 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 372 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
| 373 | { |
| 374 | /* |
| 375 | * Clear nlmsg data, e.g., to make sure key material is not left in |
| 376 | * heap memory for unnecessarily long time. |
| 377 | */ |
| 378 | if (msg) { |
| 379 | struct nlmsghdr *hdr = nlmsg_hdr(msg); |
| 380 | void *data = nlmsg_data(hdr); |
| 381 | /* |
| 382 | * This would use nlmsg_datalen() or the older nlmsg_len() if |
| 383 | * only libnl were to maintain a stable API.. Neither will work |
| 384 | * with all released versions, so just calculate the length |
| 385 | * here. |
| 386 | */ |
| 387 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; |
| 388 | |
| 389 | os_memset(data, 0, len); |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 394 | static int send_and_recv(struct nl80211_global *global, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 395 | struct nl_sock *nl_handle, struct nl_msg *msg, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 396 | int (*valid_handler)(struct nl_msg *, void *), |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 397 | void *valid_data, |
| 398 | int (*ack_handler_custom)(struct nl_msg *, void *), |
| 399 | void *ack_data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 400 | { |
| 401 | struct nl_cb *cb; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 402 | int err = -ENOMEM, opt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 403 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 404 | if (!msg) |
| 405 | return -ENOMEM; |
| 406 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 407 | cb = nl_cb_clone(global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 408 | if (!cb) |
| 409 | goto out; |
| 410 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 411 | /* try to set NETLINK_EXT_ACK to 1, ignoring errors */ |
| 412 | opt = 1; |
| 413 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, |
| 414 | NETLINK_EXT_ACK, &opt, sizeof(opt)); |
| 415 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 416 | /* try to set NETLINK_CAP_ACK to 1, ignoring errors */ |
| 417 | opt = 1; |
| 418 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, |
| 419 | NETLINK_CAP_ACK, &opt, sizeof(opt)); |
| 420 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 421 | err = nl_send_auto_complete(nl_handle, msg); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 422 | if (err < 0) { |
| 423 | wpa_printf(MSG_INFO, |
| 424 | "nl80211: nl_send_auto_complete() failed: %s", |
| 425 | nl_geterror(err)); |
| 426 | /* Need to convert libnl error code to an errno value. For now, |
| 427 | * just hardcode this to EBADF; the real error reason is shown |
| 428 | * in that error print above. */ |
| 429 | err = -EBADF; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 430 | goto out; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 431 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 432 | |
| 433 | err = 1; |
| 434 | |
| 435 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); |
| 436 | 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] | 437 | if (ack_handler_custom) { |
| 438 | struct nl80211_ack_ext_arg *ext_arg = ack_data; |
| 439 | |
| 440 | ext_arg->err = &err; |
| 441 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, |
| 442 | ack_handler_custom, ack_data); |
| 443 | } else { |
| 444 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
| 445 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 446 | |
| 447 | if (valid_handler) |
| 448 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 449 | valid_handler, valid_data); |
| 450 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 451 | while (err > 0) { |
| 452 | int res = nl_recvmsgs(nl_handle, cb); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 453 | |
| 454 | if (res == -NLE_DUMP_INTR) { |
| 455 | /* Most likely one of the nl80211 dump routines hit a |
| 456 | * case where internal results changed while the dump |
| 457 | * was being sent. The most common known case for this |
| 458 | * is scan results fetching while associated were every |
| 459 | * received Beacon frame from the AP may end up |
| 460 | * incrementing bss_generation. This |
| 461 | * NL80211_CMD_GET_SCAN case tries again in the caller; |
| 462 | * other cases (of which there are no known common ones) |
| 463 | * will stop and return an error. */ |
| 464 | wpa_printf(MSG_DEBUG, "nl80211: %s; convert to -EAGAIN", |
| 465 | nl_geterror(res)); |
| 466 | err = -EAGAIN; |
| 467 | } else if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 468 | wpa_printf(MSG_INFO, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 469 | "nl80211: %s->nl_recvmsgs failed: %d (%s)", |
| 470 | __func__, res, nl_geterror(res)); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 471 | } |
| 472 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 473 | out: |
| 474 | nl_cb_put(cb); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 475 | /* Always clear the message as it can potentially contain keys */ |
| 476 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 477 | nlmsg_free(msg); |
| 478 | return err; |
| 479 | } |
| 480 | |
| 481 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 482 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
| 483 | struct nl_msg *msg, |
| 484 | int (*valid_handler)(struct nl_msg *, void *), |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 485 | void *valid_data, |
| 486 | int (*ack_handler_custom)(struct nl_msg *, void *), |
| 487 | void *ack_data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 488 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 489 | return send_and_recv(drv->global, drv->global->nl, msg, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 490 | valid_handler, valid_data, |
| 491 | ack_handler_custom, ack_data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 492 | } |
| 493 | |
| 494 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 495 | /* Use this method to mark that it is necessary to own the connection/interface |
| 496 | * for this operation. |
| 497 | * handle may be set to NULL, to get the same behavior as send_and_recv_msgs(). |
| 498 | * set_owner can be used to mark this socket for receiving control port frames. |
| 499 | */ |
| 500 | static int send_and_recv_msgs_owner(struct wpa_driver_nl80211_data *drv, |
| 501 | struct nl_msg *msg, |
| 502 | struct nl_sock *handle, int set_owner, |
| 503 | int (*valid_handler)(struct nl_msg *, |
| 504 | void *), |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 505 | void *valid_data, |
| 506 | int (*ack_handler_custom)(struct nl_msg *, |
| 507 | void *), |
| 508 | void *ack_data) |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 509 | { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 510 | if (!msg) |
| 511 | return -ENOMEM; |
| 512 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 513 | /* Control port over nl80211 needs the flags and attributes below. |
| 514 | * |
| 515 | * The Linux kernel has initial checks for them (in nl80211.c) like: |
| 516 | * validate_pae_over_nl80211(...) |
| 517 | * or final checks like: |
| 518 | * dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid |
| 519 | * |
| 520 | * Final operations (e.g., disassociate) don't need to set these |
| 521 | * attributes, but they have to be performed on the socket, which has |
| 522 | * the connection owner property set in the kernel. |
| 523 | */ |
| 524 | if ((drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) && |
| 525 | handle && set_owner && |
| 526 | (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_OVER_NL80211) || |
| 527 | nla_put_flag(msg, NL80211_ATTR_SOCKET_OWNER) || |
| 528 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 529 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_PREAUTH))) |
| 530 | return -1; |
| 531 | |
| 532 | return send_and_recv(drv->global, handle ? handle : drv->global->nl, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 533 | msg, valid_handler, valid_data, |
| 534 | ack_handler_custom, ack_data); |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 538 | static int |
| 539 | send_and_recv_msgs_connect_handle(struct wpa_driver_nl80211_data *drv, |
| 540 | struct nl_msg *msg, struct i802_bss *bss, |
| 541 | int set_owner) |
| 542 | { |
| 543 | struct nl_sock *nl_connect = get_connect_handle(bss); |
| 544 | |
| 545 | if (nl_connect) |
| 546 | return send_and_recv_msgs_owner(drv, msg, nl_connect, set_owner, |
| 547 | process_bss_event, bss, NULL, |
| 548 | NULL); |
| 549 | else |
| 550 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
| 551 | } |
| 552 | |
| 553 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 554 | struct nl_sock * get_connect_handle(struct i802_bss *bss) |
| 555 | { |
| 556 | if ((bss->drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) || |
| 557 | bss->use_nl_connect) |
| 558 | return bss->nl_connect; |
| 559 | |
| 560 | return NULL; |
| 561 | } |
| 562 | |
| 563 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 564 | struct family_data { |
| 565 | const char *group; |
| 566 | int id; |
| 567 | }; |
| 568 | |
| 569 | |
| 570 | static int family_handler(struct nl_msg *msg, void *arg) |
| 571 | { |
| 572 | struct family_data *res = arg; |
| 573 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; |
| 574 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 575 | struct nlattr *mcgrp; |
| 576 | int i; |
| 577 | |
| 578 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 579 | genlmsg_attrlen(gnlh, 0), NULL); |
| 580 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) |
| 581 | return NL_SKIP; |
| 582 | |
| 583 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { |
| 584 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; |
| 585 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), |
| 586 | nla_len(mcgrp), NULL); |
| 587 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || |
| 588 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || |
| 589 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), |
| 590 | res->group, |
| 591 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) |
| 592 | continue; |
| 593 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); |
| 594 | break; |
| 595 | }; |
| 596 | |
| 597 | return NL_SKIP; |
| 598 | } |
| 599 | |
| 600 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 601 | static int nl_get_multicast_id(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 602 | const char *family, const char *group) |
| 603 | { |
| 604 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 605 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 606 | struct family_data res = { group, -ENOENT }; |
| 607 | |
| 608 | msg = nlmsg_alloc(); |
| 609 | if (!msg) |
| 610 | return -ENOMEM; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 611 | if (!genlmsg_put(msg, 0, 0, global->nlctrl_id, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 612 | 0, 0, CTRL_CMD_GETFAMILY, 0) || |
| 613 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { |
| 614 | nlmsg_free(msg); |
| 615 | return -1; |
| 616 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 617 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 618 | ret = send_and_recv(global, global->nl, msg, family_handler, &res, |
| 619 | NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 620 | if (ret == 0) |
| 621 | ret = res.id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 622 | return ret; |
| 623 | } |
| 624 | |
| 625 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 626 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
| 627 | struct nl_msg *msg, int flags, uint8_t cmd) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 628 | { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 629 | if (TEST_FAIL()) |
| 630 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 631 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
| 632 | 0, flags, cmd, 0); |
| 633 | } |
| 634 | |
| 635 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 636 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
| 637 | { |
| 638 | if (bss->wdev_id_set) |
| 639 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); |
| 640 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 641 | } |
| 642 | |
| 643 | |
| 644 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 645 | { |
| 646 | struct nl_msg *msg; |
| 647 | |
| 648 | msg = nlmsg_alloc(); |
| 649 | if (!msg) |
| 650 | return NULL; |
| 651 | |
| 652 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || |
| 653 | nl80211_set_iface_id(msg, bss) < 0) { |
| 654 | nlmsg_free(msg); |
| 655 | return NULL; |
| 656 | } |
| 657 | |
| 658 | return msg; |
| 659 | } |
| 660 | |
| 661 | |
| 662 | static struct nl_msg * |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 663 | nl80211_ifindex_msg_build(struct wpa_driver_nl80211_data *drv, |
| 664 | struct nl_msg *msg, int ifindex, int flags, |
| 665 | uint8_t cmd) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 666 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 667 | if (!msg) |
| 668 | return NULL; |
| 669 | |
| 670 | if (!nl80211_cmd(drv, msg, flags, cmd) || |
| 671 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { |
| 672 | nlmsg_free(msg); |
| 673 | return NULL; |
| 674 | } |
| 675 | |
| 676 | return msg; |
| 677 | } |
| 678 | |
| 679 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 680 | static struct nl_msg * |
| 681 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, |
| 682 | int flags, uint8_t cmd) |
| 683 | { |
| 684 | return nl80211_ifindex_msg_build(drv, nlmsg_alloc(), ifindex, flags, |
| 685 | cmd); |
| 686 | } |
| 687 | |
| 688 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 689 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, |
| 690 | uint8_t cmd) |
| 691 | { |
| 692 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); |
| 693 | } |
| 694 | |
| 695 | |
| 696 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 697 | { |
| 698 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); |
| 699 | } |
| 700 | |
| 701 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 702 | struct wiphy_idx_data { |
| 703 | int wiphy_idx; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 704 | enum nl80211_iftype nlmode; |
| 705 | u8 *macaddr; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 706 | u8 use_4addr; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 707 | }; |
| 708 | |
| 709 | |
| 710 | static int netdev_info_handler(struct nl_msg *msg, void *arg) |
| 711 | { |
| 712 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 713 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 714 | struct wiphy_idx_data *info = arg; |
| 715 | |
| 716 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 717 | genlmsg_attrlen(gnlh, 0), NULL); |
| 718 | |
| 719 | if (tb[NL80211_ATTR_WIPHY]) |
| 720 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 721 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 722 | if (tb[NL80211_ATTR_IFTYPE]) |
| 723 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); |
| 724 | |
| 725 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
| 726 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 727 | ETH_ALEN); |
| 728 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 729 | if (tb[NL80211_ATTR_4ADDR]) |
| 730 | info->use_4addr = nla_get_u8(tb[NL80211_ATTR_4ADDR]); |
| 731 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 732 | return NL_SKIP; |
| 733 | } |
| 734 | |
| 735 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 736 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 737 | { |
| 738 | struct nl_msg *msg; |
| 739 | struct wiphy_idx_data data = { |
| 740 | .wiphy_idx = -1, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 741 | .macaddr = NULL, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 742 | }; |
| 743 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 744 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 745 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 746 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 747 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data, |
| 748 | NULL, NULL) == 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 749 | return data.wiphy_idx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 750 | return -1; |
| 751 | } |
| 752 | |
| 753 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 754 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
| 755 | { |
| 756 | struct nl_msg *msg; |
| 757 | struct wiphy_idx_data data = { |
| 758 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
| 759 | .macaddr = NULL, |
| 760 | }; |
| 761 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 762 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 763 | return NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 764 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 765 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data, |
| 766 | NULL, NULL) == 0) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 767 | return data.nlmode; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 768 | return NL80211_IFTYPE_UNSPECIFIED; |
| 769 | } |
| 770 | |
| 771 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 772 | static int nl80211_get_macaddr(struct i802_bss *bss) |
| 773 | { |
| 774 | struct nl_msg *msg; |
| 775 | struct wiphy_idx_data data = { |
| 776 | .macaddr = bss->addr, |
| 777 | }; |
| 778 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 779 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 780 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 781 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 782 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data, |
| 783 | NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 784 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 785 | |
| 786 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 787 | static int nl80211_get_4addr(struct i802_bss *bss) |
| 788 | { |
| 789 | struct nl_msg *msg; |
| 790 | struct wiphy_idx_data data = { |
| 791 | .use_4addr = 0, |
| 792 | }; |
| 793 | |
| 794 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)) || |
| 795 | send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data, |
| 796 | NULL, NULL)) |
| 797 | return -1; |
| 798 | return data.use_4addr; |
| 799 | } |
| 800 | |
| 801 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 802 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
| 803 | struct nl80211_wiphy_data *w) |
| 804 | { |
| 805 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 806 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 807 | |
| 808 | msg = nlmsg_alloc(); |
| 809 | if (!msg) |
| 810 | return -1; |
| 811 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 812 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
| 813 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { |
| 814 | nlmsg_free(msg); |
| 815 | return -1; |
| 816 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 817 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 818 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL, |
| 819 | NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 820 | if (ret) { |
| 821 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " |
| 822 | "failed: ret=%d (%s)", |
| 823 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 824 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 825 | return ret; |
| 826 | } |
| 827 | |
| 828 | |
| 829 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) |
| 830 | { |
| 831 | struct nl80211_wiphy_data *w = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 832 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 833 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 834 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 835 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 836 | res = nl_recvmsgs(handle, w->nl_cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 837 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 838 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 839 | __func__, res); |
| 840 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | |
| 844 | static int process_beacon_event(struct nl_msg *msg, void *arg) |
| 845 | { |
| 846 | struct nl80211_wiphy_data *w = arg; |
| 847 | struct wpa_driver_nl80211_data *drv; |
| 848 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 849 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 850 | union wpa_event_data event; |
| 851 | |
| 852 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 853 | genlmsg_attrlen(gnlh, 0), NULL); |
| 854 | |
| 855 | if (gnlh->cmd != NL80211_CMD_FRAME) { |
| 856 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", |
| 857 | gnlh->cmd); |
| 858 | return NL_SKIP; |
| 859 | } |
| 860 | |
| 861 | if (!tb[NL80211_ATTR_FRAME]) |
| 862 | return NL_SKIP; |
| 863 | |
| 864 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, |
| 865 | wiphy_list) { |
| 866 | os_memset(&event, 0, sizeof(event)); |
| 867 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); |
| 868 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); |
| 869 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
| 870 | } |
| 871 | |
| 872 | return NL_SKIP; |
| 873 | } |
| 874 | |
| 875 | |
| 876 | static struct nl80211_wiphy_data * |
| 877 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) |
| 878 | { |
| 879 | static DEFINE_DL_LIST(nl80211_wiphys); |
| 880 | struct nl80211_wiphy_data *w; |
| 881 | int wiphy_idx, found = 0; |
| 882 | struct i802_bss *tmp_bss; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 883 | u8 channel; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 884 | |
| 885 | if (bss->wiphy_data != NULL) |
| 886 | return bss->wiphy_data; |
| 887 | |
| 888 | wiphy_idx = nl80211_get_wiphy_index(bss); |
| 889 | |
| 890 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { |
| 891 | if (w->wiphy_idx == wiphy_idx) |
| 892 | goto add; |
| 893 | } |
| 894 | |
| 895 | /* alloc new one */ |
| 896 | w = os_zalloc(sizeof(*w)); |
| 897 | if (w == NULL) |
| 898 | return NULL; |
| 899 | w->wiphy_idx = wiphy_idx; |
| 900 | dl_list_init(&w->bsss); |
| 901 | dl_list_init(&w->drvs); |
| 902 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 903 | /* Beacon frames not supported in IEEE 802.11ad */ |
| 904 | if (ieee80211_freq_to_chan(bss->freq, &channel) != |
| 905 | HOSTAPD_MODE_IEEE80211AD) { |
| 906 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 907 | if (!w->nl_cb) { |
| 908 | os_free(w); |
| 909 | return NULL; |
| 910 | } |
| 911 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 912 | no_seq_check, NULL); |
| 913 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 914 | process_beacon_event, w); |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 915 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 916 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, |
| 917 | "wiphy beacons"); |
| 918 | if (w->nl_beacons == NULL) { |
| 919 | os_free(w); |
| 920 | return NULL; |
| 921 | } |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 922 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 923 | if (nl80211_register_beacons(bss->drv, w)) { |
| 924 | nl_destroy_handles(&w->nl_beacons); |
| 925 | os_free(w); |
| 926 | return NULL; |
| 927 | } |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 928 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 929 | nl80211_register_eloop_read(&w->nl_beacons, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 930 | nl80211_recv_beacons, w, 0); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 931 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 932 | |
| 933 | dl_list_add(&nl80211_wiphys, &w->list); |
| 934 | |
| 935 | add: |
| 936 | /* drv entry for this bss already there? */ |
| 937 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 938 | if (tmp_bss->drv == bss->drv) { |
| 939 | found = 1; |
| 940 | break; |
| 941 | } |
| 942 | } |
| 943 | /* if not add it */ |
| 944 | if (!found) |
| 945 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); |
| 946 | |
| 947 | dl_list_add(&w->bsss, &bss->wiphy_list); |
| 948 | bss->wiphy_data = w; |
| 949 | return w; |
| 950 | } |
| 951 | |
| 952 | |
| 953 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) |
| 954 | { |
| 955 | struct nl80211_wiphy_data *w = bss->wiphy_data; |
| 956 | struct i802_bss *tmp_bss; |
| 957 | int found = 0; |
| 958 | |
| 959 | if (w == NULL) |
| 960 | return; |
| 961 | bss->wiphy_data = NULL; |
| 962 | dl_list_del(&bss->wiphy_list); |
| 963 | |
| 964 | /* still any for this drv present? */ |
| 965 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 966 | if (tmp_bss->drv == bss->drv) { |
| 967 | found = 1; |
| 968 | break; |
| 969 | } |
| 970 | } |
| 971 | /* if not remove it */ |
| 972 | if (!found) |
| 973 | dl_list_del(&bss->drv->wiphy_list); |
| 974 | |
| 975 | if (!dl_list_empty(&w->bsss)) |
| 976 | return; |
| 977 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 978 | if (w->nl_beacons) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 979 | nl80211_destroy_eloop_handle(&w->nl_beacons, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 980 | |
| 981 | nl_cb_put(w->nl_cb); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 982 | dl_list_del(&w->list); |
| 983 | os_free(w); |
| 984 | } |
| 985 | |
| 986 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 987 | static unsigned int nl80211_get_ifindex(void *priv) |
| 988 | { |
| 989 | struct i802_bss *bss = priv; |
| 990 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 991 | |
| 992 | return drv->ifindex; |
| 993 | } |
| 994 | |
| 995 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 996 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
| 997 | { |
| 998 | struct i802_bss *bss = priv; |
| 999 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1000 | if (!drv->associated) |
| 1001 | return -1; |
| 1002 | os_memcpy(bssid, drv->bssid, ETH_ALEN); |
| 1003 | return 0; |
| 1004 | } |
| 1005 | |
| 1006 | |
| 1007 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
| 1008 | { |
| 1009 | struct i802_bss *bss = priv; |
| 1010 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1011 | if (!drv->associated) |
| 1012 | return -1; |
| 1013 | os_memcpy(ssid, drv->ssid, drv->ssid_len); |
| 1014 | return drv->ssid_len; |
| 1015 | } |
| 1016 | |
| 1017 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1018 | static void wpa_driver_nl80211_event_newlink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1019 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 1020 | int ifindex, const char *ifname) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1021 | { |
| 1022 | union wpa_event_data event; |
| 1023 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1024 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1025 | if (if_nametoindex(drv->first_bss->ifname) == 0) { |
| 1026 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", |
| 1027 | drv->first_bss->ifname); |
| 1028 | return; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1029 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1030 | if (!drv->if_removed) |
| 1031 | return; |
| 1032 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", |
| 1033 | drv->first_bss->ifname); |
| 1034 | drv->if_removed = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1035 | } |
| 1036 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1037 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1038 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1039 | os_strlcpy(event.interface_status.ifname, ifname, |
| 1040 | sizeof(event.interface_status.ifname)); |
| 1041 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1042 | if (drv) |
| 1043 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 1044 | else |
| 1045 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 1046 | &event); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | |
| 1050 | static void wpa_driver_nl80211_event_dellink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1051 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 1052 | int ifindex, const char *ifname) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1053 | { |
| 1054 | union wpa_event_data event; |
| 1055 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1056 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1057 | if (drv->if_removed) { |
| 1058 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", |
| 1059 | ifname); |
| 1060 | return; |
| 1061 | } |
| 1062 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
| 1063 | ifname); |
| 1064 | drv->if_removed = 1; |
| 1065 | } else { |
| 1066 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", |
| 1067 | ifname); |
| 1068 | } |
| 1069 | |
| 1070 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1071 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1072 | os_strlcpy(event.interface_status.ifname, ifname, |
| 1073 | sizeof(event.interface_status.ifname)); |
| 1074 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1075 | if (drv) |
| 1076 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 1077 | else |
| 1078 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 1079 | &event); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | |
| 1083 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
| 1084 | u8 *buf, size_t len) |
| 1085 | { |
| 1086 | int attrlen, rta_len; |
| 1087 | struct rtattr *attr; |
| 1088 | |
| 1089 | attrlen = len; |
| 1090 | attr = (struct rtattr *) buf; |
| 1091 | |
| 1092 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
| 1093 | while (RTA_OK(attr, attrlen)) { |
| 1094 | if (attr->rta_type == IFLA_IFNAME) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1095 | if (os_strcmp(((char *) attr) + rta_len, |
| 1096 | drv->first_bss->ifname) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1097 | return 1; |
| 1098 | else |
| 1099 | break; |
| 1100 | } |
| 1101 | attr = RTA_NEXT(attr, attrlen); |
| 1102 | } |
| 1103 | |
| 1104 | return 0; |
| 1105 | } |
| 1106 | |
| 1107 | |
| 1108 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, |
| 1109 | int ifindex, u8 *buf, size_t len) |
| 1110 | { |
| 1111 | if (drv->ifindex == ifindex) |
| 1112 | return 1; |
| 1113 | |
| 1114 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1115 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1116 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
| 1117 | "interface"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1118 | if (wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL) < 0) |
| 1119 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1120 | return 1; |
| 1121 | } |
| 1122 | |
| 1123 | return 0; |
| 1124 | } |
| 1125 | |
| 1126 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1127 | static struct wpa_driver_nl80211_data * |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1128 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len, |
| 1129 | int *init_failed) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1130 | { |
| 1131 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1132 | int res; |
| 1133 | |
| 1134 | if (init_failed) |
| 1135 | *init_failed = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1136 | dl_list_for_each(drv, &global->interfaces, |
| 1137 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1138 | res = wpa_driver_nl80211_own_ifindex(drv, idx, buf, len); |
| 1139 | if (res < 0) { |
| 1140 | wpa_printf(MSG_DEBUG, |
| 1141 | "nl80211: Found matching own interface, but failed to complete reinitialization"); |
| 1142 | if (init_failed) |
| 1143 | *init_failed = 1; |
| 1144 | return drv; |
| 1145 | } |
| 1146 | if (res > 0 || have_ifidx(drv, idx, IFIDX_ANY)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1147 | return drv; |
| 1148 | } |
| 1149 | return NULL; |
| 1150 | } |
| 1151 | |
| 1152 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1153 | static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1154 | int ifindex, int notify) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1155 | { |
| 1156 | struct i802_bss *bss; |
| 1157 | u8 addr[ETH_ALEN]; |
| 1158 | |
| 1159 | bss = get_bss_ifindex(drv, ifindex); |
| 1160 | if (bss && |
| 1161 | linux_get_ifhwaddr(drv->global->ioctl_sock, |
| 1162 | bss->ifname, addr) < 0) { |
| 1163 | wpa_printf(MSG_DEBUG, |
| 1164 | "nl80211: %s: failed to re-read MAC address", |
| 1165 | bss->ifname); |
| 1166 | } else if (bss && os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { |
| 1167 | wpa_printf(MSG_DEBUG, |
| 1168 | "nl80211: Own MAC address on ifindex %d (%s) changed from " |
| 1169 | MACSTR " to " MACSTR, |
| 1170 | ifindex, bss->ifname, |
| 1171 | MAC2STR(bss->addr), MAC2STR(addr)); |
| 1172 | os_memcpy(bss->addr, addr, ETH_ALEN); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1173 | if (notify) |
| 1174 | wpa_supplicant_event(drv->ctx, |
| 1175 | EVENT_INTERFACE_MAC_CHANGED, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1180 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
| 1181 | struct ifinfomsg *ifi, |
| 1182 | u8 *buf, size_t len) |
| 1183 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1184 | struct nl80211_global *global = ctx; |
| 1185 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1186 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1187 | struct rtattr *attr; |
| 1188 | u32 brid = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1189 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1190 | char ifname[IFNAMSIZ + 1]; |
| 1191 | char extra[100], *pos, *end; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1192 | int init_failed; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1193 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1194 | extra[0] = '\0'; |
| 1195 | pos = extra; |
| 1196 | end = pos + sizeof(extra); |
| 1197 | ifname[0] = '\0'; |
| 1198 | |
| 1199 | attrlen = len; |
| 1200 | attr = (struct rtattr *) buf; |
| 1201 | while (RTA_OK(attr, attrlen)) { |
| 1202 | switch (attr->rta_type) { |
| 1203 | case IFLA_IFNAME: |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1204 | if (RTA_PAYLOAD(attr) > IFNAMSIZ) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1205 | break; |
| 1206 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1207 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1208 | break; |
| 1209 | case IFLA_MASTER: |
| 1210 | brid = nla_get_u32((struct nlattr *) attr); |
| 1211 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1212 | break; |
| 1213 | case IFLA_WIRELESS: |
| 1214 | pos += os_snprintf(pos, end - pos, " wext"); |
| 1215 | break; |
| 1216 | case IFLA_OPERSTATE: |
| 1217 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1218 | nla_get_u32((struct nlattr *) attr)); |
| 1219 | break; |
| 1220 | case IFLA_LINKMODE: |
| 1221 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1222 | nla_get_u32((struct nlattr *) attr)); |
| 1223 | break; |
| 1224 | } |
| 1225 | attr = RTA_NEXT(attr, attrlen); |
| 1226 | } |
| 1227 | extra[sizeof(extra) - 1] = '\0'; |
| 1228 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1229 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1230 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1231 | ifi->ifi_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1232 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1233 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1234 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1235 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1236 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1237 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, &init_failed); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1238 | if (!drv) |
| 1239 | goto event_newlink; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1240 | if (init_failed) |
| 1241 | return; /* do not update interface state */ |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1242 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1243 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1244 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1245 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1246 | linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1247 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1248 | "event since interface %s is up", namebuf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1249 | drv->ignore_if_down_event = 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1250 | /* Re-read MAC address as it may have changed */ |
| 1251 | nl80211_refresh_mac(drv, ifi->ifi_index, 1); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1252 | return; |
| 1253 | } |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1254 | wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", |
| 1255 | namebuf, ifname); |
| 1256 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 1257 | wpa_printf(MSG_DEBUG, |
| 1258 | "nl80211: Not the main interface (%s) - do not indicate interface down", |
| 1259 | drv->first_bss->ifname); |
| 1260 | } else if (drv->ignore_if_down_event) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1261 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1262 | "event generated by mode change"); |
| 1263 | drv->ignore_if_down_event = 0; |
| 1264 | } else { |
| 1265 | drv->if_disabled = 1; |
| 1266 | wpa_supplicant_event(drv->ctx, |
| 1267 | EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1268 | |
| 1269 | /* |
| 1270 | * Try to get drv again, since it may be removed as |
| 1271 | * part of the EVENT_INTERFACE_DISABLED handling for |
| 1272 | * dynamic interfaces |
| 1273 | */ |
| 1274 | drv = nl80211_find_drv(global, ifi->ifi_index, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1275 | buf, len, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1276 | if (!drv) |
| 1277 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1278 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1279 | } |
| 1280 | |
| 1281 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 1282 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1283 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1284 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1285 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1286 | "event since interface %s is down", |
| 1287 | namebuf); |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 1288 | return; |
| 1289 | } |
| 1290 | wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)", |
| 1291 | namebuf, ifname); |
| 1292 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 1293 | wpa_printf(MSG_DEBUG, |
| 1294 | "nl80211: Not the main interface (%s) - do not indicate interface up", |
| 1295 | drv->first_bss->ifname); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1296 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1297 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1298 | "event since interface %s does not exist", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1299 | drv->first_bss->ifname); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1300 | } else if (drv->if_removed) { |
| 1301 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1302 | "event since interface %s is marked " |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1303 | "removed", drv->first_bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1304 | } else { |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1305 | /* Re-read MAC address as it may have changed */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1306 | nl80211_refresh_mac(drv, ifi->ifi_index, 0); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1307 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1308 | drv->if_disabled = 0; |
| 1309 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, |
| 1310 | NULL); |
| 1311 | } |
Sunil Ravi | 9077544 | 2020-09-24 11:53:19 -0700 | [diff] [blame] | 1312 | } else if (ifi->ifi_flags & IFF_UP) { |
| 1313 | /* Re-read MAC address as it may have changed */ |
| 1314 | nl80211_refresh_mac(drv, ifi->ifi_index, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1315 | } |
| 1316 | |
| 1317 | /* |
| 1318 | * Some drivers send the association event before the operup event--in |
| 1319 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() |
| 1320 | * fails. This will hit us when wpa_supplicant does not need to do |
| 1321 | * IEEE 802.1X authentication |
| 1322 | */ |
| 1323 | if (drv->operstate == 1 && |
| 1324 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1325 | !(ifi->ifi_flags & IFF_RUNNING)) { |
| 1326 | 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] | 1327 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1328 | -1, IF_OPER_UP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1329 | } |
| 1330 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1331 | event_newlink: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1332 | if (ifname[0]) |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1333 | wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index, |
| 1334 | ifname); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1335 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1336 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1337 | struct i802_bss *bss; |
| 1338 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1339 | /* device has been added to bridge */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1340 | if (!if_indextoname(brid, namebuf)) { |
| 1341 | wpa_printf(MSG_DEBUG, |
| 1342 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1343 | brid); |
| 1344 | return; |
| 1345 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1346 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
| 1347 | brid, namebuf); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1348 | add_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1349 | |
| 1350 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 1351 | if (os_strcmp(ifname, bss->ifname) == 0) { |
| 1352 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); |
| 1353 | break; |
| 1354 | } |
| 1355 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1356 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1357 | } |
| 1358 | |
| 1359 | |
| 1360 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
| 1361 | struct ifinfomsg *ifi, |
| 1362 | u8 *buf, size_t len) |
| 1363 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1364 | struct nl80211_global *global = ctx; |
| 1365 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1366 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1367 | struct rtattr *attr; |
| 1368 | u32 brid = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1369 | char ifname[IFNAMSIZ + 1]; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1370 | char extra[100], *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1371 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1372 | extra[0] = '\0'; |
| 1373 | pos = extra; |
| 1374 | end = pos + sizeof(extra); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1375 | ifname[0] = '\0'; |
| 1376 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1377 | attrlen = len; |
| 1378 | attr = (struct rtattr *) buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1379 | while (RTA_OK(attr, attrlen)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1380 | switch (attr->rta_type) { |
| 1381 | case IFLA_IFNAME: |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1382 | if (RTA_PAYLOAD(attr) > IFNAMSIZ) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1383 | break; |
| 1384 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1385 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1386 | break; |
| 1387 | case IFLA_MASTER: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1388 | brid = nla_get_u32((struct nlattr *) attr); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1389 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1390 | break; |
| 1391 | case IFLA_OPERSTATE: |
| 1392 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1393 | nla_get_u32((struct nlattr *) attr)); |
| 1394 | break; |
| 1395 | case IFLA_LINKMODE: |
| 1396 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1397 | nla_get_u32((struct nlattr *) attr)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1398 | break; |
| 1399 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1400 | attr = RTA_NEXT(attr, attrlen); |
| 1401 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1402 | extra[sizeof(extra) - 1] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1403 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1404 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1405 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1406 | ifi->ifi_flags, |
| 1407 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1408 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1409 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1410 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1411 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1412 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1413 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1414 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1415 | /* device has been removed from bridge */ |
| 1416 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1417 | |
| 1418 | if (!if_indextoname(brid, namebuf)) { |
| 1419 | wpa_printf(MSG_DEBUG, |
| 1420 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1421 | brid); |
| 1422 | } else { |
| 1423 | wpa_printf(MSG_DEBUG, |
| 1424 | "nl80211: Remove ifindex %u for bridge %s", |
| 1425 | brid, namebuf); |
| 1426 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1427 | del_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1428 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1429 | |
| 1430 | if (ifi->ifi_family != AF_BRIDGE || !brid) |
| 1431 | wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index, |
| 1432 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1433 | } |
| 1434 | |
| 1435 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1436 | struct nl80211_get_assoc_freq_arg { |
| 1437 | struct wpa_driver_nl80211_data *drv; |
| 1438 | unsigned int assoc_freq; |
| 1439 | unsigned int ibss_freq; |
| 1440 | u8 assoc_bssid[ETH_ALEN]; |
| 1441 | u8 assoc_ssid[SSID_MAX_LEN]; |
| 1442 | u8 assoc_ssid_len; |
| 1443 | }; |
| 1444 | |
| 1445 | static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg) |
| 1446 | { |
| 1447 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1448 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1449 | struct nlattr *bss[NL80211_BSS_MAX + 1]; |
| 1450 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { |
| 1451 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, |
| 1452 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, |
| 1453 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, |
| 1454 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
| 1455 | }; |
| 1456 | struct nl80211_get_assoc_freq_arg *ctx = arg; |
| 1457 | enum nl80211_bss_status status; |
| 1458 | |
| 1459 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1460 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1461 | if (!tb[NL80211_ATTR_BSS] || |
| 1462 | nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], |
| 1463 | bss_policy) || |
| 1464 | !bss[NL80211_BSS_STATUS]) |
| 1465 | return NL_SKIP; |
| 1466 | |
| 1467 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); |
| 1468 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1469 | bss[NL80211_BSS_FREQUENCY]) { |
| 1470 | ctx->assoc_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1471 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", |
| 1472 | ctx->assoc_freq); |
| 1473 | } |
| 1474 | if (status == NL80211_BSS_STATUS_IBSS_JOINED && |
| 1475 | bss[NL80211_BSS_FREQUENCY]) { |
| 1476 | ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1477 | wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz", |
| 1478 | ctx->ibss_freq); |
| 1479 | } |
| 1480 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1481 | bss[NL80211_BSS_BSSID]) { |
| 1482 | os_memcpy(ctx->assoc_bssid, |
| 1483 | nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN); |
| 1484 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " |
| 1485 | MACSTR, MAC2STR(ctx->assoc_bssid)); |
| 1486 | } |
| 1487 | |
| 1488 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1489 | bss[NL80211_BSS_INFORMATION_ELEMENTS]) { |
| 1490 | const u8 *ie, *ssid; |
| 1491 | size_t ie_len; |
| 1492 | |
| 1493 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1494 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1495 | ssid = get_ie(ie, ie_len, WLAN_EID_SSID); |
| 1496 | if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) { |
| 1497 | ctx->assoc_ssid_len = ssid[1]; |
| 1498 | os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]); |
| 1499 | } |
| 1500 | } |
| 1501 | |
| 1502 | return NL_SKIP; |
| 1503 | } |
| 1504 | |
| 1505 | |
| 1506 | 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] | 1507 | { |
| 1508 | struct nl_msg *msg; |
| 1509 | int ret; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1510 | struct nl80211_get_assoc_freq_arg arg; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1511 | int count = 0; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1512 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1513 | try_again: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1514 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1515 | os_memset(&arg, 0, sizeof(arg)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1516 | arg.drv = drv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1517 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1518 | &arg, NULL, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1519 | if (ret == -EAGAIN) { |
| 1520 | count++; |
| 1521 | if (count >= 10) { |
| 1522 | wpa_printf(MSG_INFO, |
| 1523 | "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid"); |
| 1524 | } else { |
| 1525 | wpa_printf(MSG_DEBUG, |
| 1526 | "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid - try again"); |
| 1527 | goto try_again; |
| 1528 | } |
| 1529 | } |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1530 | if (ret == 0) { |
| 1531 | os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len); |
| 1532 | return arg.assoc_ssid_len; |
| 1533 | } |
| 1534 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)", |
| 1535 | ret, strerror(-ret)); |
| 1536 | return ret; |
| 1537 | } |
| 1538 | |
| 1539 | |
| 1540 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
| 1541 | { |
| 1542 | struct nl_msg *msg; |
| 1543 | int ret; |
| 1544 | struct nl80211_get_assoc_freq_arg arg; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1545 | int count = 0; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1546 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1547 | try_again: |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1548 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
| 1549 | os_memset(&arg, 0, sizeof(arg)); |
| 1550 | arg.drv = drv; |
| 1551 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1552 | &arg, NULL, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1553 | if (ret == -EAGAIN) { |
| 1554 | count++; |
| 1555 | if (count >= 10) { |
| 1556 | wpa_printf(MSG_INFO, |
| 1557 | "nl80211: Failed to receive consistent scan result dump for get_assoc_freq"); |
| 1558 | } else { |
| 1559 | wpa_printf(MSG_DEBUG, |
| 1560 | "nl80211: Failed to receive consistent scan result dump for get_assoc_freq - try again"); |
| 1561 | goto try_again; |
| 1562 | } |
| 1563 | } |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1564 | if (ret == 0) { |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1565 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
| 1566 | arg.ibss_freq : arg.assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1567 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1568 | "associated BSS from scan results: %u MHz", freq); |
| 1569 | if (freq) |
| 1570 | drv->assoc_freq = freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1571 | return drv->assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1572 | } |
| 1573 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
| 1574 | "(%s)", ret, strerror(-ret)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1575 | return drv->assoc_freq; |
| 1576 | } |
| 1577 | |
| 1578 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1579 | static int get_link_signal(struct nl_msg *msg, void *arg) |
| 1580 | { |
| 1581 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1582 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1583 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; |
| 1584 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { |
| 1585 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1586 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1587 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1588 | }; |
| 1589 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
| 1590 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 1591 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 1592 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 1593 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, |
| 1594 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 1595 | }; |
| 1596 | struct wpa_signal_info *sig_change = arg; |
| 1597 | |
| 1598 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1599 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1600 | if (!tb[NL80211_ATTR_STA_INFO] || |
| 1601 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, |
| 1602 | tb[NL80211_ATTR_STA_INFO], policy)) |
| 1603 | return NL_SKIP; |
| 1604 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) |
| 1605 | return NL_SKIP; |
| 1606 | |
| 1607 | sig_change->current_signal = |
| 1608 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); |
| 1609 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1610 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
| 1611 | sig_change->avg_signal = |
| 1612 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); |
| 1613 | else |
| 1614 | sig_change->avg_signal = 0; |
| 1615 | |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1616 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
| 1617 | sig_change->avg_beacon_signal = |
| 1618 | (s8) |
| 1619 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); |
| 1620 | else |
| 1621 | sig_change->avg_beacon_signal = 0; |
| 1622 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1623 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
| 1624 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, |
| 1625 | sinfo[NL80211_STA_INFO_TX_BITRATE], |
| 1626 | rate_policy)) { |
| 1627 | sig_change->current_txrate = 0; |
| 1628 | } else { |
| 1629 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { |
| 1630 | sig_change->current_txrate = |
| 1631 | nla_get_u16(rinfo[ |
| 1632 | NL80211_RATE_INFO_BITRATE]) * 100; |
| 1633 | } |
| 1634 | } |
| 1635 | } |
| 1636 | |
| 1637 | return NL_SKIP; |
| 1638 | } |
| 1639 | |
| 1640 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1641 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
| 1642 | struct wpa_signal_info *sig) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1643 | { |
| 1644 | struct nl_msg *msg; |
| 1645 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1646 | sig->current_signal = -WPA_INVALID_NOISE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1647 | sig->current_txrate = 0; |
| 1648 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1649 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
| 1650 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) { |
| 1651 | nlmsg_free(msg); |
| 1652 | return -ENOBUFS; |
| 1653 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1654 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1655 | 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] | 1656 | } |
| 1657 | |
| 1658 | |
| 1659 | static int get_link_noise(struct nl_msg *msg, void *arg) |
| 1660 | { |
| 1661 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1662 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1663 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 1664 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 1665 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 1666 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 1667 | }; |
| 1668 | struct wpa_signal_info *sig_change = arg; |
| 1669 | |
| 1670 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1671 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1672 | |
| 1673 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 1674 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); |
| 1675 | return NL_SKIP; |
| 1676 | } |
| 1677 | |
| 1678 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 1679 | tb[NL80211_ATTR_SURVEY_INFO], |
| 1680 | survey_policy)) { |
| 1681 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " |
| 1682 | "attributes!"); |
| 1683 | return NL_SKIP; |
| 1684 | } |
| 1685 | |
| 1686 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 1687 | return NL_SKIP; |
| 1688 | |
| 1689 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 1690 | sig_change->frequency) |
| 1691 | return NL_SKIP; |
| 1692 | |
| 1693 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 1694 | return NL_SKIP; |
| 1695 | |
| 1696 | sig_change->current_noise = |
| 1697 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 1698 | |
| 1699 | return NL_SKIP; |
| 1700 | } |
| 1701 | |
| 1702 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1703 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
| 1704 | struct wpa_signal_info *sig_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1705 | { |
| 1706 | struct nl_msg *msg; |
| 1707 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1708 | sig_change->current_noise = WPA_INVALID_NOISE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1709 | sig_change->frequency = drv->assoc_freq; |
| 1710 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1711 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1712 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change, |
| 1713 | NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1714 | } |
| 1715 | |
| 1716 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1717 | static int get_channel_info(struct nl_msg *msg, void *arg) |
| 1718 | { |
| 1719 | struct nlattr *tb[NL80211_ATTR_MAX + 1] = { 0 }; |
| 1720 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1721 | struct wpa_channel_info *chan_info = arg; |
| 1722 | |
| 1723 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1724 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1725 | |
| 1726 | os_memset(chan_info, 0, sizeof(struct wpa_channel_info)); |
| 1727 | chan_info->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 1728 | |
| 1729 | if (tb[NL80211_ATTR_WIPHY_FREQ]) |
| 1730 | chan_info->frequency = |
| 1731 | nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]); |
| 1732 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) |
| 1733 | chan_info->chanwidth = convert2width( |
| 1734 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 1735 | if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1736 | enum nl80211_channel_type ct = |
| 1737 | nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1738 | |
| 1739 | switch (ct) { |
| 1740 | case NL80211_CHAN_HT40MINUS: |
| 1741 | chan_info->sec_channel = -1; |
| 1742 | break; |
| 1743 | case NL80211_CHAN_HT40PLUS: |
| 1744 | chan_info->sec_channel = 1; |
| 1745 | break; |
| 1746 | default: |
| 1747 | chan_info->sec_channel = 0; |
| 1748 | break; |
| 1749 | } |
| 1750 | } |
| 1751 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 1752 | chan_info->center_frq1 = |
| 1753 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 1754 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 1755 | chan_info->center_frq2 = |
| 1756 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 1757 | |
| 1758 | if (chan_info->center_frq2) { |
| 1759 | u8 seg1_idx = 0; |
| 1760 | |
| 1761 | if (ieee80211_freq_to_chan(chan_info->center_frq2, &seg1_idx) != |
| 1762 | NUM_HOSTAPD_MODES) |
| 1763 | chan_info->seg1_idx = seg1_idx; |
| 1764 | } |
| 1765 | |
| 1766 | return NL_SKIP; |
| 1767 | } |
| 1768 | |
| 1769 | |
| 1770 | static int nl80211_channel_info(void *priv, struct wpa_channel_info *ci) |
| 1771 | { |
| 1772 | struct i802_bss *bss = priv; |
| 1773 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1774 | struct nl_msg *msg; |
| 1775 | |
| 1776 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1777 | 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] | 1778 | } |
| 1779 | |
| 1780 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1781 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
| 1782 | void *handle) |
| 1783 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1784 | struct nl_cb *cb = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1785 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1786 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1787 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1788 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1789 | res = nl_recvmsgs(handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 1790 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1791 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 1792 | __func__, res); |
| 1793 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1794 | } |
| 1795 | |
| 1796 | |
| 1797 | /** |
| 1798 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain |
| 1799 | * @priv: driver_nl80211 private data |
| 1800 | * @alpha2_arg: country to which to switch to |
| 1801 | * Returns: 0 on success, -1 on failure |
| 1802 | * |
| 1803 | * This asks nl80211 to set the regulatory domain for given |
| 1804 | * country ISO / IEC alpha2. |
| 1805 | */ |
| 1806 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) |
| 1807 | { |
| 1808 | struct i802_bss *bss = priv; |
| 1809 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1810 | char alpha2[3]; |
| 1811 | struct nl_msg *msg; |
| 1812 | |
| 1813 | msg = nlmsg_alloc(); |
| 1814 | if (!msg) |
| 1815 | return -ENOMEM; |
| 1816 | |
| 1817 | alpha2[0] = alpha2_arg[0]; |
| 1818 | alpha2[1] = alpha2_arg[1]; |
| 1819 | alpha2[2] = '\0'; |
| 1820 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1821 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
| 1822 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { |
| 1823 | nlmsg_free(msg); |
| 1824 | return -EINVAL; |
| 1825 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1826 | if (send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1827 | return -EINVAL; |
| 1828 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1832 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
| 1833 | { |
| 1834 | char *alpha2 = arg; |
| 1835 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 1836 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1837 | |
| 1838 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1839 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1840 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { |
| 1841 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); |
| 1842 | return NL_SKIP; |
| 1843 | } |
| 1844 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); |
| 1845 | return NL_SKIP; |
| 1846 | } |
| 1847 | |
| 1848 | |
| 1849 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) |
| 1850 | { |
| 1851 | struct i802_bss *bss = priv; |
| 1852 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1853 | struct nl_msg *msg; |
| 1854 | int ret; |
| 1855 | |
| 1856 | msg = nlmsg_alloc(); |
| 1857 | if (!msg) |
| 1858 | return -ENOMEM; |
| 1859 | |
| 1860 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
| 1861 | alpha2[0] = '\0'; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1862 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2, |
| 1863 | NULL, NULL); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1864 | if (!alpha2[0]) |
| 1865 | ret = -1; |
| 1866 | |
| 1867 | return ret; |
| 1868 | } |
| 1869 | |
| 1870 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1871 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1872 | { |
| 1873 | int ret; |
| 1874 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1875 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1876 | if (global->nl_cb == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1877 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 1878 | "callbacks"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1879 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1880 | } |
| 1881 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1882 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
| 1883 | if (global->nl == NULL) |
| 1884 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1885 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1886 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
| 1887 | if (global->nl80211_id < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1888 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
| 1889 | "found"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1890 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1891 | } |
| 1892 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 1893 | global->nlctrl_id = genl_ctrl_resolve(global->nl, "nlctrl"); |
| 1894 | if (global->nlctrl_id < 0) { |
| 1895 | wpa_printf(MSG_ERROR, |
| 1896 | "nl80211: 'nlctrl' generic netlink not found"); |
| 1897 | goto err; |
| 1898 | } |
| 1899 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1900 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
| 1901 | if (global->nl_event == NULL) |
| 1902 | goto err; |
| 1903 | |
| 1904 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1905 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1906 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1907 | if (ret < 0) { |
| 1908 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1909 | "membership for scan events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1910 | ret, nl_geterror(ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1911 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1912 | } |
| 1913 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1914 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1915 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1916 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1917 | if (ret < 0) { |
| 1918 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1919 | "membership for mlme events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1920 | ret, nl_geterror(ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1921 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1922 | } |
| 1923 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1924 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1925 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1926 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1927 | if (ret < 0) { |
| 1928 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1929 | "membership for regulatory events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1930 | ret, nl_geterror(ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1931 | /* Continue without regulatory events */ |
| 1932 | } |
| 1933 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1934 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
| 1935 | if (ret >= 0) |
| 1936 | ret = nl_socket_add_membership(global->nl_event, ret); |
| 1937 | if (ret < 0) { |
| 1938 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1939 | "membership for vendor events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1940 | ret, nl_geterror(ret)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1941 | /* Continue without vendor events */ |
| 1942 | } |
| 1943 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1944 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1945 | no_seq_check, NULL); |
| 1946 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1947 | process_global_event, global); |
| 1948 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1949 | nl80211_register_eloop_read(&global->nl_event, |
| 1950 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1951 | global->nl_cb, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1952 | |
| 1953 | return 0; |
| 1954 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1955 | err: |
| 1956 | nl_destroy_handles(&global->nl_event); |
| 1957 | nl_destroy_handles(&global->nl); |
| 1958 | nl_cb_put(global->nl_cb); |
| 1959 | global->nl_cb = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1960 | return -1; |
| 1961 | } |
| 1962 | |
| 1963 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1964 | static void nl80211_check_global(struct nl80211_global *global) |
| 1965 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1966 | struct nl_sock *handle; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1967 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; |
| 1968 | int ret; |
| 1969 | unsigned int i; |
| 1970 | |
| 1971 | /* |
| 1972 | * Try to re-add memberships to handle case of cfg80211 getting reloaded |
| 1973 | * and all registration having been cleared. |
| 1974 | */ |
| 1975 | handle = (void *) (((intptr_t) global->nl_event) ^ |
| 1976 | ELOOP_SOCKET_INVALID); |
| 1977 | |
| 1978 | for (i = 0; groups[i]; i++) { |
| 1979 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); |
| 1980 | if (ret >= 0) |
| 1981 | ret = nl_socket_add_membership(handle, ret); |
| 1982 | if (ret < 0) { |
| 1983 | wpa_printf(MSG_INFO, |
| 1984 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1985 | groups[i], ret, nl_geterror(ret)); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1986 | } |
| 1987 | } |
| 1988 | } |
| 1989 | |
| 1990 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1991 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
| 1992 | { |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1993 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1994 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1995 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1996 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1997 | /* |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1998 | * rtnetlink ifdown handler will report interfaces other than the P2P |
| 1999 | * Device interface as disabled. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2000 | */ |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2001 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2002 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | |
| 2006 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) |
| 2007 | { |
| 2008 | struct wpa_driver_nl80211_data *drv = ctx; |
| 2009 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2010 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2011 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
| 2012 | "after rfkill unblock"); |
| 2013 | return; |
| 2014 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2015 | |
| 2016 | if (is_p2p_net_interface(drv->nlmode)) |
| 2017 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
| 2018 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2019 | /* |
| 2020 | * rtnetlink ifup handler will report interfaces other than the P2P |
| 2021 | * Device interface as enabled. |
| 2022 | */ |
| 2023 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2024 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2025 | } |
| 2026 | |
| 2027 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2028 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
| 2029 | void *eloop_ctx, |
| 2030 | void *handle) |
| 2031 | { |
| 2032 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 2033 | u8 data[2048]; |
| 2034 | struct msghdr msg; |
| 2035 | struct iovec entry; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2036 | u8 control[512]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2037 | struct cmsghdr *cmsg; |
| 2038 | int res, found_ee = 0, found_wifi = 0, acked = 0; |
| 2039 | union wpa_event_data event; |
| 2040 | |
| 2041 | memset(&msg, 0, sizeof(msg)); |
| 2042 | msg.msg_iov = &entry; |
| 2043 | msg.msg_iovlen = 1; |
| 2044 | entry.iov_base = data; |
| 2045 | entry.iov_len = sizeof(data); |
| 2046 | msg.msg_control = &control; |
| 2047 | msg.msg_controllen = sizeof(control); |
| 2048 | |
| 2049 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); |
| 2050 | /* if error or not fitting 802.3 header, return */ |
| 2051 | if (res < 14) |
| 2052 | return; |
| 2053 | |
| 2054 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
| 2055 | { |
| 2056 | if (cmsg->cmsg_level == SOL_SOCKET && |
| 2057 | cmsg->cmsg_type == SCM_WIFI_STATUS) { |
| 2058 | int *ack; |
| 2059 | |
| 2060 | found_wifi = 1; |
| 2061 | ack = (void *)CMSG_DATA(cmsg); |
| 2062 | acked = *ack; |
| 2063 | } |
| 2064 | |
| 2065 | if (cmsg->cmsg_level == SOL_PACKET && |
| 2066 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { |
| 2067 | struct sock_extended_err *err = |
| 2068 | (struct sock_extended_err *)CMSG_DATA(cmsg); |
| 2069 | |
| 2070 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) |
| 2071 | found_ee = 1; |
| 2072 | } |
| 2073 | } |
| 2074 | |
| 2075 | if (!found_ee || !found_wifi) |
| 2076 | return; |
| 2077 | |
| 2078 | memset(&event, 0, sizeof(event)); |
| 2079 | event.eapol_tx_status.dst = data; |
| 2080 | event.eapol_tx_status.data = data + 14; |
| 2081 | event.eapol_tx_status.data_len = res - 14; |
| 2082 | event.eapol_tx_status.ack = acked; |
| 2083 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); |
| 2084 | } |
| 2085 | |
| 2086 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 2087 | static int nl80211_init_connect_handle(struct i802_bss *bss) |
| 2088 | { |
| 2089 | if (bss->nl_connect) { |
| 2090 | wpa_printf(MSG_DEBUG, |
| 2091 | "nl80211: Connect handle already created (nl_connect=%p)", |
| 2092 | bss->nl_connect); |
| 2093 | return -1; |
| 2094 | } |
| 2095 | |
| 2096 | bss->nl_connect = nl_create_handle(bss->nl_cb, "connect"); |
| 2097 | if (!bss->nl_connect) |
| 2098 | return -1; |
| 2099 | nl80211_register_eloop_read(&bss->nl_connect, |
| 2100 | wpa_driver_nl80211_event_receive, |
| 2101 | bss->nl_cb, 1); |
| 2102 | return 0; |
| 2103 | } |
| 2104 | |
| 2105 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2106 | static int nl80211_init_bss(struct i802_bss *bss) |
| 2107 | { |
| 2108 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 2109 | if (!bss->nl_cb) |
| 2110 | return -1; |
| 2111 | |
| 2112 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 2113 | no_seq_check, NULL); |
| 2114 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 2115 | process_bss_event, bss); |
| 2116 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 2117 | nl80211_init_connect_handle(bss); |
| 2118 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2119 | return 0; |
| 2120 | } |
| 2121 | |
| 2122 | |
| 2123 | static void nl80211_destroy_bss(struct i802_bss *bss) |
| 2124 | { |
| 2125 | nl_cb_put(bss->nl_cb); |
| 2126 | bss->nl_cb = NULL; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 2127 | |
| 2128 | if (bss->nl_connect) |
| 2129 | nl80211_destroy_eloop_handle(&bss->nl_connect, 1); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2130 | } |
| 2131 | |
| 2132 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2133 | static void |
| 2134 | wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv) |
| 2135 | { |
| 2136 | struct rfkill_config *rcfg; |
| 2137 | |
| 2138 | if (drv->rfkill) |
| 2139 | return; |
| 2140 | |
| 2141 | rcfg = os_zalloc(sizeof(*rcfg)); |
| 2142 | if (!rcfg) |
| 2143 | return; |
| 2144 | |
| 2145 | rcfg->ctx = drv; |
| 2146 | |
| 2147 | /* rfkill uses netdev sysfs for initialization. However, P2P Device is |
| 2148 | * not associated with a netdev, so use the name of some other interface |
| 2149 | * sharing the same wiphy as the P2P Device interface. |
| 2150 | * |
| 2151 | * Note: This is valid, as a P2P Device interface is always dynamically |
| 2152 | * created and is created only once another wpa_s interface was added. |
| 2153 | */ |
| 2154 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 2155 | struct nl80211_global *global = drv->global; |
| 2156 | struct wpa_driver_nl80211_data *tmp1; |
| 2157 | |
| 2158 | dl_list_for_each(tmp1, &global->interfaces, |
| 2159 | struct wpa_driver_nl80211_data, list) { |
| 2160 | if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx || |
| 2161 | !tmp1->rfkill) |
| 2162 | continue; |
| 2163 | |
| 2164 | wpa_printf(MSG_DEBUG, |
| 2165 | "nl80211: Use (%s) to initialize P2P Device rfkill", |
| 2166 | tmp1->first_bss->ifname); |
| 2167 | os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname, |
| 2168 | sizeof(rcfg->ifname)); |
| 2169 | break; |
| 2170 | } |
| 2171 | } else { |
| 2172 | os_strlcpy(rcfg->ifname, drv->first_bss->ifname, |
| 2173 | sizeof(rcfg->ifname)); |
| 2174 | } |
| 2175 | |
| 2176 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; |
| 2177 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; |
| 2178 | drv->rfkill = rfkill_init(rcfg); |
| 2179 | if (!drv->rfkill) { |
| 2180 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
| 2181 | os_free(rcfg); |
| 2182 | } |
| 2183 | } |
| 2184 | |
| 2185 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2186 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
| 2187 | void *global_priv, int hostapd, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2188 | const u8 *set_addr, |
| 2189 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2190 | { |
| 2191 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2192 | struct i802_bss *bss; |
| 2193 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2194 | if (global_priv == NULL) |
| 2195 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2196 | drv = os_zalloc(sizeof(*drv)); |
| 2197 | if (drv == NULL) |
| 2198 | return NULL; |
| 2199 | drv->global = global_priv; |
| 2200 | drv->ctx = ctx; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2201 | drv->hostapd = !!hostapd; |
| 2202 | drv->eapol_sock = -1; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 2203 | |
| 2204 | /* |
| 2205 | * There is no driver capability flag for this, so assume it is |
| 2206 | * supported and disable this on first attempt to use if the driver |
| 2207 | * rejects the command due to missing support. |
| 2208 | */ |
| 2209 | drv->set_rekey_offload = 1; |
| 2210 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2211 | drv->num_if_indices = ARRAY_SIZE(drv->default_if_indices); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2212 | drv->if_indices = drv->default_if_indices; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2213 | |
| 2214 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); |
| 2215 | if (!drv->first_bss) { |
| 2216 | os_free(drv); |
| 2217 | return NULL; |
| 2218 | } |
| 2219 | bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2220 | bss->drv = drv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2221 | bss->ctx = ctx; |
| 2222 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2223 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
| 2224 | drv->monitor_ifidx = -1; |
| 2225 | drv->monitor_sock = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2226 | drv->eapol_tx_sock = -1; |
| 2227 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2228 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2229 | if (nl80211_init_bss(bss)) |
| 2230 | goto failed; |
| 2231 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2232 | 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] | 2233 | goto failed; |
| 2234 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2235 | if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_TX_STATUS) { |
| 2236 | drv->control_port_ap = 1; |
| 2237 | goto skip_wifi_status; |
| 2238 | } |
| 2239 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2240 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
| 2241 | if (drv->eapol_tx_sock < 0) |
| 2242 | goto failed; |
| 2243 | |
| 2244 | if (drv->data_tx_status) { |
| 2245 | int enabled = 1; |
| 2246 | |
| 2247 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, |
| 2248 | &enabled, sizeof(enabled)) < 0) { |
| 2249 | wpa_printf(MSG_DEBUG, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2250 | "nl80211: wifi status sockopt failed: %s", |
| 2251 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2252 | drv->data_tx_status = 0; |
| 2253 | if (!drv->use_monitor) |
| 2254 | drv->capa.flags &= |
| 2255 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
| 2256 | } else { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2257 | eloop_register_read_sock( |
| 2258 | drv->eapol_tx_sock, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2259 | wpa_driver_nl80211_handle_eapol_tx_status, |
| 2260 | drv, NULL); |
| 2261 | } |
| 2262 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2263 | skip_wifi_status: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2264 | |
| 2265 | if (drv->global) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2266 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2267 | dl_list_add(&drv->global->interfaces, &drv->list); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2268 | drv->in_interface_list = 1; |
| 2269 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2270 | |
| 2271 | return bss; |
| 2272 | |
| 2273 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2274 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2275 | return NULL; |
| 2276 | } |
| 2277 | |
| 2278 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2279 | /** |
| 2280 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface |
| 2281 | * @ctx: context to be used when calling wpa_supplicant functions, |
| 2282 | * e.g., wpa_supplicant_event() |
| 2283 | * @ifname: interface name, e.g., wlan0 |
| 2284 | * @global_priv: private driver global data from global_init() |
| 2285 | * Returns: Pointer to private data, %NULL on failure |
| 2286 | */ |
| 2287 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
| 2288 | void *global_priv) |
| 2289 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2290 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
| 2291 | NULL); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2292 | } |
| 2293 | |
| 2294 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2295 | static int nl80211_register_frame(struct i802_bss *bss, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2296 | struct nl_sock *nl_handle, |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2297 | u16 type, const u8 *match, size_t match_len, |
| 2298 | bool multicast) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2299 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2300 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2301 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2302 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2303 | char buf[30]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2304 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2305 | buf[0] = '\0'; |
| 2306 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2307 | wpa_printf(MSG_DEBUG, |
| 2308 | "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s multicast=%d", |
| 2309 | type, fc2str(type), nl_handle, buf, multicast); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2310 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2311 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_FRAME)) || |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2312 | (multicast && nla_put_flag(msg, NL80211_ATTR_RECEIVE_MULTICAST)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2313 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
| 2314 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { |
| 2315 | nlmsg_free(msg); |
| 2316 | return -1; |
| 2317 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2318 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2319 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL, |
| 2320 | NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2321 | if (ret) { |
| 2322 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
| 2323 | "failed (type=%u): ret=%d (%s)", |
| 2324 | type, ret, strerror(-ret)); |
| 2325 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", |
| 2326 | match, match_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2327 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2328 | return ret; |
| 2329 | } |
| 2330 | |
| 2331 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2332 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
| 2333 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2334 | if (bss->nl_mgmt) { |
| 2335 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
| 2336 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
| 2337 | return -1; |
| 2338 | } |
| 2339 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2340 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2341 | if (bss->nl_mgmt == NULL) |
| 2342 | return -1; |
| 2343 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2344 | return 0; |
| 2345 | } |
| 2346 | |
| 2347 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2348 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
| 2349 | { |
| 2350 | nl80211_register_eloop_read(&bss->nl_mgmt, |
| 2351 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2352 | bss->nl_cb, 0); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2356 | static int nl80211_register_action_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2357 | const u8 *match, size_t match_len) |
| 2358 | { |
| 2359 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2360 | return nl80211_register_frame(bss, bss->nl_mgmt, |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2361 | type, match, match_len, false); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2362 | } |
| 2363 | |
| 2364 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2365 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2366 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2367 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2368 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2369 | int ret = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2370 | |
| 2371 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2372 | return -1; |
| 2373 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
| 2374 | "handle %p", bss->nl_mgmt); |
| 2375 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2376 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2377 | /* register for any AUTH message */ |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2378 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0, false); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2379 | } else if ((drv->capa.flags & WPA_DRIVER_FLAGS_SAE) && |
| 2380 | !(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
| 2381 | /* register for SAE Authentication frames */ |
| 2382 | nl80211_register_frame(bss, bss->nl_mgmt, type, |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2383 | (u8 *) "\x03\x00", 2, false); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2384 | } |
| 2385 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 2386 | #ifdef CONFIG_PASN |
| 2387 | /* register for PASN Authentication frames */ |
| 2388 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_SME) && |
| 2389 | nl80211_register_frame(bss, bss->nl_mgmt, type, |
| 2390 | (u8 *) "\x07\x00", 2, false)) |
| 2391 | ret = -1; |
| 2392 | #endif /* CONFIG_PASN */ |
| 2393 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2394 | #ifdef CONFIG_INTERWORKING |
| 2395 | /* QoS Map Configure */ |
| 2396 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2397 | ret = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2398 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2399 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2400 | /* GAS Initial Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2401 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2402 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2403 | /* GAS Initial Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2404 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2405 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2406 | /* GAS Comeback Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2407 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2408 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2409 | /* GAS Comeback Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2410 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2411 | ret = -1; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2412 | /* Protected GAS Initial Request */ |
| 2413 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) |
| 2414 | ret = -1; |
| 2415 | /* Protected GAS Initial Response */ |
| 2416 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) |
| 2417 | ret = -1; |
| 2418 | /* Protected GAS Comeback Request */ |
| 2419 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) |
| 2420 | ret = -1; |
| 2421 | /* Protected GAS Comeback Response */ |
| 2422 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) |
| 2423 | ret = -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2424 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2425 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2426 | /* P2P Public Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2427 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2428 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
| 2429 | 6) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2430 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2431 | /* P2P Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2432 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2433 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
| 2434 | 5) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2435 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2436 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2437 | #ifdef CONFIG_DPP |
| 2438 | /* DPP Public Action */ |
| 2439 | if (nl80211_register_action_frame(bss, |
| 2440 | (u8 *) "\x04\x09\x50\x6f\x9a\x1a", |
| 2441 | 6) < 0) |
| 2442 | ret = -1; |
| 2443 | #endif /* CONFIG_DPP */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2444 | #ifdef CONFIG_OCV |
| 2445 | /* SA Query Request */ |
| 2446 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x00", 2) < 0) |
| 2447 | ret = -1; |
| 2448 | #endif /* CONFIG_OCV */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2449 | /* SA Query Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2450 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2451 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2452 | #ifdef CONFIG_TDLS |
| 2453 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { |
| 2454 | /* TDLS Discovery Response */ |
| 2455 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
| 2456 | 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2457 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2458 | } |
| 2459 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2460 | #ifdef CONFIG_FST |
| 2461 | /* FST Action frames */ |
| 2462 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2463 | ret = -1; |
| 2464 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2465 | |
| 2466 | /* FT Action frames */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2467 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2468 | ret = -1; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2469 | else if (!drv->has_driver_key_mgmt) { |
| 2470 | int i; |
| 2471 | |
| 2472 | /* Update supported AKMs only if the driver doesn't advertize |
| 2473 | * any AKM capabilities. */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2474 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | |
| 2475 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; |
| 2476 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2477 | /* Update per interface supported AKMs */ |
| 2478 | for (i = 0; i < WPA_IF_MAX; i++) |
| 2479 | drv->capa.key_mgmt_iftype[i] = drv->capa.key_mgmt; |
| 2480 | } |
| 2481 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2482 | /* WNM - BSS Transition Management Request */ |
| 2483 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2484 | ret = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2485 | /* WNM-Sleep Mode Response */ |
| 2486 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2487 | ret = -1; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2488 | #ifdef CONFIG_WNM |
| 2489 | /* WNM - Collocated Interference Request */ |
| 2490 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x0b", 2) < 0) |
| 2491 | ret = -1; |
| 2492 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2493 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2494 | #ifdef CONFIG_HS20 |
| 2495 | /* WNM-Notification */ |
| 2496 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2497 | ret = -1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2498 | #endif /* CONFIG_HS20 */ |
| 2499 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2500 | /* WMM-AC ADDTS Response */ |
| 2501 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) |
| 2502 | ret = -1; |
| 2503 | |
| 2504 | /* WMM-AC DELTS */ |
| 2505 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) |
| 2506 | ret = -1; |
| 2507 | |
| 2508 | /* Radio Measurement - Neighbor Report Response */ |
| 2509 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) |
| 2510 | ret = -1; |
| 2511 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2512 | /* Radio Measurement - Radio Measurement Request */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2513 | if (!drv->no_rrm && |
| 2514 | nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2515 | ret = -1; |
| 2516 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2517 | /* Radio Measurement - Link Measurement Request */ |
| 2518 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && |
| 2519 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) |
| 2520 | ret = -1; |
| 2521 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2522 | /* Robust AV SCS Response */ |
| 2523 | if (nl80211_register_action_frame(bss, (u8 *) "\x13\x01", 2) < 0) |
| 2524 | ret = -1; |
| 2525 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2526 | /* Robust AV MSCS Response */ |
| 2527 | if (nl80211_register_action_frame(bss, (u8 *) "\x13\x05", 2) < 0) |
| 2528 | ret = -1; |
| 2529 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2530 | /* Protected QoS Management Action frame */ |
| 2531 | if (nl80211_register_action_frame(bss, (u8 *) "\x7e\x50\x6f\x9a\x1a", |
| 2532 | 5) < 0) |
| 2533 | ret = -1; |
| 2534 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2535 | nl80211_mgmt_handle_register_eloop(bss); |
| 2536 | |
| 2537 | return ret; |
| 2538 | } |
| 2539 | |
| 2540 | |
| 2541 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
| 2542 | { |
| 2543 | int ret = 0; |
| 2544 | |
| 2545 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2546 | return -1; |
| 2547 | |
| 2548 | wpa_printf(MSG_DEBUG, |
| 2549 | "nl80211: Subscribe to mgmt frames with mesh handle %p", |
| 2550 | bss->nl_mgmt); |
| 2551 | |
| 2552 | /* Auth frames for mesh SAE */ |
| 2553 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2554 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2555 | (WLAN_FC_STYPE_AUTH << 4), |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2556 | NULL, 0, false) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2557 | ret = -1; |
| 2558 | |
| 2559 | /* Mesh peering open */ |
| 2560 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) |
| 2561 | ret = -1; |
| 2562 | /* Mesh peering confirm */ |
| 2563 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) |
| 2564 | ret = -1; |
| 2565 | /* Mesh peering close */ |
| 2566 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) |
| 2567 | ret = -1; |
| 2568 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2569 | nl80211_mgmt_handle_register_eloop(bss); |
| 2570 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2571 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2572 | } |
| 2573 | |
| 2574 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2575 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
| 2576 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2577 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2578 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2579 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2580 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2581 | ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL, |
| 2582 | NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2583 | if (ret) { |
| 2584 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " |
| 2585 | "failed: ret=%d (%s)", |
| 2586 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2587 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2588 | return ret; |
| 2589 | } |
| 2590 | |
| 2591 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2592 | static int nl80211_action_subscribe_ap(struct i802_bss *bss) |
| 2593 | { |
| 2594 | int ret = 0; |
| 2595 | |
| 2596 | /* Public Action frames */ |
| 2597 | if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0) |
| 2598 | ret = -1; |
| 2599 | /* RRM Measurement Report */ |
| 2600 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0) |
| 2601 | ret = -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2602 | /* RRM Link Measurement Report */ |
| 2603 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0) |
| 2604 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2605 | /* RRM Neighbor Report Request */ |
| 2606 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0) |
| 2607 | ret = -1; |
| 2608 | /* FT Action frames */ |
| 2609 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
| 2610 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2611 | /* SA Query */ |
| 2612 | if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0) |
| 2613 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2614 | /* Protected Dual of Public Action */ |
| 2615 | if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0) |
| 2616 | ret = -1; |
| 2617 | /* WNM */ |
| 2618 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0) |
| 2619 | ret = -1; |
| 2620 | /* WMM */ |
| 2621 | if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0) |
| 2622 | ret = -1; |
| 2623 | #ifdef CONFIG_FST |
| 2624 | /* FST Action frames */ |
| 2625 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2626 | ret = -1; |
| 2627 | #endif /* CONFIG_FST */ |
| 2628 | /* Vendor-specific */ |
| 2629 | if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0) |
| 2630 | ret = -1; |
| 2631 | |
| 2632 | return ret; |
| 2633 | } |
| 2634 | |
| 2635 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2636 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
| 2637 | { |
| 2638 | static const int stypes[] = { |
| 2639 | WLAN_FC_STYPE_AUTH, |
| 2640 | WLAN_FC_STYPE_ASSOC_REQ, |
| 2641 | WLAN_FC_STYPE_REASSOC_REQ, |
| 2642 | WLAN_FC_STYPE_DISASSOC, |
| 2643 | WLAN_FC_STYPE_DEAUTH, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2644 | WLAN_FC_STYPE_PROBE_REQ, |
| 2645 | /* Beacon doesn't work as mac80211 doesn't currently allow |
| 2646 | * it, but it wouldn't really be the right thing anyway as |
| 2647 | * it isn't per interface ... maybe just dump the scan |
| 2648 | * results periodically for OLBC? |
| 2649 | */ |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2650 | /* WLAN_FC_STYPE_BEACON, */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2651 | }; |
| 2652 | unsigned int i; |
| 2653 | |
| 2654 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2655 | return -1; |
| 2656 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2657 | "handle %p", bss->nl_mgmt); |
| 2658 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2659 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2660 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2661 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2662 | (stypes[i] << 4), |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2663 | NULL, 0, false) < 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2664 | goto out_err; |
| 2665 | } |
| 2666 | } |
| 2667 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2668 | if (nl80211_action_subscribe_ap(bss)) |
| 2669 | goto out_err; |
| 2670 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2671 | if (nl80211_register_spurious_class3(bss)) |
| 2672 | goto out_err; |
| 2673 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2674 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2675 | return 0; |
| 2676 | |
| 2677 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2678 | nl_destroy_handles(&bss->nl_mgmt); |
| 2679 | return -1; |
| 2680 | } |
| 2681 | |
| 2682 | |
| 2683 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
| 2684 | { |
| 2685 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2686 | return -1; |
| 2687 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2688 | "handle %p (device SME)", bss->nl_mgmt); |
| 2689 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2690 | if (nl80211_action_subscribe_ap(bss)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2691 | goto out_err; |
| 2692 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 2693 | if (bss->drv->device_ap_sme) { |
| 2694 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
| 2695 | |
| 2696 | /* Register for all Authentication frames */ |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2697 | if (nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0, |
| 2698 | false) < 0) |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 2699 | wpa_printf(MSG_DEBUG, |
| 2700 | "nl80211: Failed to subscribe to handle Authentication frames - SAE offload may not work"); |
| 2701 | } |
| 2702 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2703 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2704 | return 0; |
| 2705 | |
| 2706 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2707 | nl_destroy_handles(&bss->nl_mgmt); |
| 2708 | return -1; |
| 2709 | } |
| 2710 | |
| 2711 | |
| 2712 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
| 2713 | { |
| 2714 | if (bss->nl_mgmt == NULL) |
| 2715 | return; |
| 2716 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
| 2717 | "(%s)", bss->nl_mgmt, reason); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2718 | nl80211_destroy_eloop_handle(&bss->nl_mgmt, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2719 | |
| 2720 | nl80211_put_wiphy_data_ap(bss); |
| 2721 | } |
| 2722 | |
| 2723 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2724 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
| 2725 | { |
| 2726 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); |
| 2727 | } |
| 2728 | |
| 2729 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2730 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
| 2731 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2732 | struct nl_msg *msg; |
| 2733 | int ret; |
| 2734 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2735 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2736 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2737 | |
| 2738 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", |
| 2739 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2740 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2741 | } |
| 2742 | |
| 2743 | |
| 2744 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
| 2745 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2746 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2747 | int ret; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2748 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2749 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
| 2750 | NL80211_CMD_STOP_P2P_DEVICE); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2751 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2752 | |
| 2753 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
| 2754 | start ? "Start" : "Stop", |
| 2755 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2756 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2757 | return ret; |
| 2758 | } |
| 2759 | |
| 2760 | |
| 2761 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
| 2762 | { |
| 2763 | enum nl80211_iftype nlmode; |
| 2764 | |
| 2765 | nlmode = nl80211_get_ifmode(bss); |
| 2766 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2767 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, |
| 2768 | bss->ifname, up); |
| 2769 | } |
| 2770 | |
| 2771 | /* P2P Device has start/stop which is equivalent */ |
| 2772 | return nl80211_set_p2pdev(bss, up); |
| 2773 | } |
| 2774 | |
| 2775 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2776 | #ifdef CONFIG_TESTING_OPTIONS |
| 2777 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) |
| 2778 | { |
| 2779 | /* struct wpa_driver_nl80211_data *drv = arg; */ |
| 2780 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 2781 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2782 | |
| 2783 | |
| 2784 | wpa_printf(MSG_DEBUG, |
| 2785 | "nl80211: QCA vendor test command response received"); |
| 2786 | |
| 2787 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2788 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2789 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { |
| 2790 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); |
| 2791 | return NL_SKIP; |
| 2792 | } |
| 2793 | |
| 2794 | wpa_hexdump(MSG_DEBUG, |
| 2795 | "nl80211: Received QCA vendor test command response", |
| 2796 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), |
| 2797 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); |
| 2798 | |
| 2799 | return NL_SKIP; |
| 2800 | } |
| 2801 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2802 | |
| 2803 | |
| 2804 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) |
| 2805 | { |
| 2806 | #ifdef CONFIG_TESTING_OPTIONS |
| 2807 | struct nl_msg *msg; |
| 2808 | struct nlattr *params; |
| 2809 | int ret; |
| 2810 | |
| 2811 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2812 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2813 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2814 | QCA_NL80211_VENDOR_SUBCMD_TEST) || |
| 2815 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 2816 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { |
| 2817 | nlmsg_free(msg); |
| 2818 | return; |
| 2819 | } |
| 2820 | nla_nest_end(msg, params); |
| 2821 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2822 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv, |
| 2823 | NULL, NULL); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2824 | wpa_printf(MSG_DEBUG, |
| 2825 | "nl80211: QCA vendor test command returned %d (%s)", |
| 2826 | ret, strerror(-ret)); |
| 2827 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2828 | } |
| 2829 | |
| 2830 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2831 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2832 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2833 | const u8 *set_addr, int first, |
| 2834 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2835 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2836 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2837 | int send_rfkill_event = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2838 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2839 | |
| 2840 | drv->ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2841 | bss->ifindex = drv->ifindex; |
| 2842 | bss->wdev_id = drv->global->if_add_wdevid; |
| 2843 | bss->wdev_id_set = drv->global->if_add_wdevid_set; |
| 2844 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2845 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
| 2846 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2847 | drv->global->if_add_wdevid_set = 0; |
| 2848 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2849 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2850 | bss->static_ap = 1; |
| 2851 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 2852 | if (first && |
| 2853 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && |
| 2854 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) |
| 2855 | drv->start_iface_up = 1; |
| 2856 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2857 | if (wpa_driver_nl80211_capa(drv)) |
| 2858 | return -1; |
| 2859 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2860 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
| 2861 | return -1; |
| 2862 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2863 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
| 2864 | bss->ifname, drv->phyname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2865 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2866 | if (set_addr && |
| 2867 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || |
| 2868 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2869 | set_addr))) |
| 2870 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2871 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 2872 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_STATION) |
| 2873 | drv->start_mode_sta = 1; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2874 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2875 | if (drv->hostapd || bss->static_ap) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2876 | nlmode = NL80211_IFTYPE_AP; |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 2877 | else if (bss->if_dynamic || |
| 2878 | nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2879 | nlmode = nl80211_get_ifmode(bss); |
| 2880 | else |
| 2881 | nlmode = NL80211_IFTYPE_STATION; |
| 2882 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2883 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2884 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2885 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2886 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2887 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2888 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2889 | nl80211_get_macaddr(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2890 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2891 | wpa_driver_nl80211_drv_init_rfkill(drv); |
| 2892 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2893 | if (!rfkill_is_blocked(drv->rfkill)) { |
| 2894 | int ret = i802_set_iface_flags(bss, 1); |
| 2895 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2896 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
| 2897 | "interface '%s' UP", bss->ifname); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2898 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2899 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2900 | |
| 2901 | if (is_p2p_net_interface(nlmode)) |
| 2902 | nl80211_disable_11b_rates(bss->drv, |
| 2903 | bss->drv->ifindex, 1); |
| 2904 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2905 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2906 | return ret; |
| 2907 | } else { |
| 2908 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " |
| 2909 | "interface '%s' due to rfkill", bss->ifname); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2910 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 2911 | drv->if_disabled = 1; |
| 2912 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2913 | send_rfkill_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2914 | } |
| 2915 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2916 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2917 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
| 2918 | 1, IF_OPER_DORMANT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2919 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2920 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2921 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2922 | bss->addr)) |
| 2923 | return -1; |
| 2924 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); |
| 2925 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2926 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2927 | if (send_rfkill_event) { |
| 2928 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, |
| 2929 | drv, drv->ctx); |
| 2930 | } |
| 2931 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2932 | if (drv->vendor_cmd_test_avail) |
| 2933 | qca_vendor_test(drv); |
| 2934 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2935 | return 0; |
| 2936 | } |
| 2937 | |
| 2938 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2939 | static int wpa_driver_nl80211_del_beacon(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2940 | { |
| 2941 | struct nl_msg *msg; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2942 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2943 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2944 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
| 2945 | drv->ifindex); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2946 | nl80211_put_wiphy_data_ap(bss); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2947 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2948 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2949 | } |
| 2950 | |
| 2951 | |
| 2952 | /** |
| 2953 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2954 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2955 | * |
| 2956 | * Shut down driver interface and processing of driver events. Free |
| 2957 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). |
| 2958 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2959 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2960 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2961 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2962 | unsigned int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2963 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2964 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
| 2965 | bss->ifname, drv->disabled_11b_rates); |
| 2966 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2967 | bss->in_deinit = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2968 | if (drv->data_tx_status) |
| 2969 | eloop_unregister_read_sock(drv->eapol_tx_sock); |
| 2970 | if (drv->eapol_tx_sock >= 0) |
| 2971 | close(drv->eapol_tx_sock); |
| 2972 | |
| 2973 | if (bss->nl_preq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2974 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 2975 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2976 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 2977 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2978 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2979 | "interface %s from bridge %s: %s", |
| 2980 | bss->ifname, bss->brname, strerror(errno)); |
| 2981 | } |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 2982 | |
| 2983 | if (drv->rtnl_sk) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2984 | nl_socket_free(drv->rtnl_sk); |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 2985 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2986 | if (bss->added_bridge) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2987 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
| 2988 | 0) < 0) |
| 2989 | wpa_printf(MSG_INFO, |
| 2990 | "nl80211: Could not set bridge %s down", |
| 2991 | bss->brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2992 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2993 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2994 | "bridge %s: %s", |
| 2995 | bss->brname, strerror(errno)); |
| 2996 | } |
| 2997 | |
| 2998 | nl80211_remove_monitor_interface(drv); |
| 2999 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3000 | if (is_ap_interface(drv->nlmode)) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3001 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3002 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3003 | if (drv->eapol_sock >= 0) { |
| 3004 | eloop_unregister_read_sock(drv->eapol_sock); |
| 3005 | close(drv->eapol_sock); |
| 3006 | } |
| 3007 | |
| 3008 | if (drv->if_indices != drv->default_if_indices) |
| 3009 | os_free(drv->if_indices); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3010 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3011 | if (drv->disabled_11b_rates) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3012 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 3013 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3014 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
| 3015 | IF_OPER_UP); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 3016 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3017 | rfkill_deinit(drv->rfkill); |
| 3018 | |
| 3019 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 3020 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3021 | if (!drv->start_iface_up) |
| 3022 | (void) i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3023 | |
| 3024 | if (drv->addr_changed) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3025 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 3026 | 0) < 0) { |
| 3027 | wpa_printf(MSG_DEBUG, |
| 3028 | "nl80211: Could not set interface down to restore permanent MAC address"); |
| 3029 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 3030 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 3031 | drv->perm_addr) < 0) { |
| 3032 | wpa_printf(MSG_DEBUG, |
| 3033 | "nl80211: Could not restore permanent MAC address"); |
| 3034 | } |
| 3035 | } |
| 3036 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3037 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3038 | if (drv->start_mode_sta) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3039 | wpa_driver_nl80211_set_mode(bss, |
| 3040 | NL80211_IFTYPE_STATION); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 3041 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3042 | } else { |
| 3043 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
| 3044 | nl80211_del_p2pdev(bss); |
| 3045 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3046 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3047 | nl80211_destroy_bss(drv->first_bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3048 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3049 | os_free(drv->filter_ssids); |
| 3050 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3051 | os_free(drv->auth_ie); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3052 | os_free(drv->auth_data); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3053 | |
| 3054 | if (drv->in_interface_list) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3055 | dl_list_del(&drv->list); |
| 3056 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 3057 | os_free(drv->extended_capa); |
| 3058 | os_free(drv->extended_capa_mask); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 3059 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 3060 | os_free(drv->iface_ext_capa[i].ext_capa); |
| 3061 | os_free(drv->iface_ext_capa[i].ext_capa_mask); |
| 3062 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3063 | os_free(drv->first_bss); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3064 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 3065 | os_free(drv->pending_roam_data); |
| 3066 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3067 | os_free(drv); |
| 3068 | } |
| 3069 | |
| 3070 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3071 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
| 3072 | { |
| 3073 | switch (alg) { |
| 3074 | case WPA_ALG_WEP: |
| 3075 | if (key_len == 5) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3076 | return RSN_CIPHER_SUITE_WEP40; |
| 3077 | return RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3078 | case WPA_ALG_TKIP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3079 | return RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3080 | case WPA_ALG_CCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3081 | return RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3082 | case WPA_ALG_GCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3083 | return RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3084 | case WPA_ALG_CCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3085 | return RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3086 | case WPA_ALG_GCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3087 | return RSN_CIPHER_SUITE_GCMP_256; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3088 | case WPA_ALG_BIP_CMAC_128: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3089 | return RSN_CIPHER_SUITE_AES_128_CMAC; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3090 | case WPA_ALG_BIP_GMAC_128: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3091 | return RSN_CIPHER_SUITE_BIP_GMAC_128; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3092 | case WPA_ALG_BIP_GMAC_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3093 | return RSN_CIPHER_SUITE_BIP_GMAC_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3094 | case WPA_ALG_BIP_CMAC_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3095 | return RSN_CIPHER_SUITE_BIP_CMAC_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3096 | case WPA_ALG_SMS4: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3097 | return RSN_CIPHER_SUITE_SMS4; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3098 | case WPA_ALG_KRK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3099 | return RSN_CIPHER_SUITE_KRK; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3100 | case WPA_ALG_NONE: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3101 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", |
| 3102 | alg); |
| 3103 | return 0; |
| 3104 | } |
| 3105 | |
| 3106 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", |
| 3107 | alg); |
| 3108 | return 0; |
| 3109 | } |
| 3110 | |
| 3111 | |
| 3112 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) |
| 3113 | { |
| 3114 | switch (cipher) { |
| 3115 | case WPA_CIPHER_CCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3116 | return RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3117 | case WPA_CIPHER_GCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3118 | return RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3119 | case WPA_CIPHER_CCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3120 | return RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3121 | case WPA_CIPHER_GCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3122 | return RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3123 | case WPA_CIPHER_TKIP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3124 | return RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3125 | case WPA_CIPHER_WEP104: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3126 | return RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3127 | case WPA_CIPHER_WEP40: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3128 | return RSN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3129 | case WPA_CIPHER_GTK_NOT_USED: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3130 | return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3131 | } |
| 3132 | |
| 3133 | return 0; |
| 3134 | } |
| 3135 | |
| 3136 | |
| 3137 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], |
| 3138 | int max_suites) |
| 3139 | { |
| 3140 | int num_suites = 0; |
| 3141 | |
| 3142 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3143 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3144 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3145 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3146 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3147 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3148 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3149 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3150 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3151 | suites[num_suites++] = RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3152 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3153 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3154 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3155 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3156 | |
| 3157 | return num_suites; |
| 3158 | } |
| 3159 | |
| 3160 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3161 | static int wpa_key_mgmt_to_suites(unsigned int key_mgmt_suites, u32 suites[], |
| 3162 | int max_suites) |
| 3163 | { |
| 3164 | int num_suites = 0; |
| 3165 | |
| 3166 | #define __AKM(a, b) \ |
| 3167 | if (num_suites < max_suites && \ |
| 3168 | (key_mgmt_suites & (WPA_KEY_MGMT_ ## a))) \ |
| 3169 | suites[num_suites++] = (RSN_AUTH_KEY_MGMT_ ## b) |
| 3170 | __AKM(IEEE8021X, UNSPEC_802_1X); |
| 3171 | __AKM(PSK, PSK_OVER_802_1X); |
| 3172 | __AKM(FT_IEEE8021X, FT_802_1X); |
| 3173 | __AKM(FT_PSK, FT_PSK); |
| 3174 | __AKM(IEEE8021X_SHA256, 802_1X_SHA256); |
| 3175 | __AKM(PSK_SHA256, PSK_SHA256); |
| 3176 | __AKM(SAE, SAE); |
| 3177 | __AKM(FT_SAE, FT_SAE); |
| 3178 | __AKM(CCKM, CCKM); |
| 3179 | __AKM(OSEN, OSEN); |
| 3180 | __AKM(IEEE8021X_SUITE_B, 802_1X_SUITE_B); |
| 3181 | __AKM(IEEE8021X_SUITE_B_192, 802_1X_SUITE_B_192); |
| 3182 | __AKM(FILS_SHA256, FILS_SHA256); |
| 3183 | __AKM(FILS_SHA384, FILS_SHA384); |
| 3184 | __AKM(FT_FILS_SHA256, FT_FILS_SHA256); |
| 3185 | __AKM(FT_FILS_SHA384, FT_FILS_SHA384); |
| 3186 | __AKM(OWE, OWE); |
| 3187 | __AKM(DPP, DPP); |
| 3188 | __AKM(FT_IEEE8021X_SHA384, FT_802_1X_SHA384); |
| 3189 | #undef __AKM |
| 3190 | |
| 3191 | return num_suites; |
| 3192 | } |
| 3193 | |
Ajay Davanageri | b921bb8 | 2020-09-16 12:49:08 +0530 | [diff] [blame] | 3194 | #ifdef CONFIG_DRIVER_NL80211_BRCM |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3195 | static int wpa_driver_do_broadcom_acs(struct wpa_driver_nl80211_data *drv, |
| 3196 | struct drv_acs_params *params) |
Ajay Davanageri | b921bb8 | 2020-09-16 12:49:08 +0530 | [diff] [blame] | 3197 | { |
Ajay Davanageri | b921bb8 | 2020-09-16 12:49:08 +0530 | [diff] [blame] | 3198 | struct nl_msg *msg; |
| 3199 | struct nlattr *data; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3200 | int freq_list_len; |
| 3201 | int ret = -1; |
Ajay Davanageri | b921bb8 | 2020-09-16 12:49:08 +0530 | [diff] [blame] | 3202 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3203 | freq_list_len = int_array_len(params->freq_list); |
| 3204 | wpa_printf(MSG_DEBUG, "%s: freq_list_len=%d", |
| 3205 | __func__, freq_list_len); |
| 3206 | |
| 3207 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR); |
| 3208 | if (!msg || |
| 3209 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) || |
| 3210 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 3211 | BRCM_VENDOR_SCMD_ACS) || |
| 3212 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 3213 | nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_HW_MODE, params->hw_mode) || |
| 3214 | nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_HT_ENABLED, |
| 3215 | params->ht_enabled) || |
| 3216 | nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_HT40_ENABLED, |
| 3217 | params->ht40_enabled) || |
| 3218 | nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_VHT_ENABLED, |
| 3219 | params->vht_enabled) || |
| 3220 | nla_put_u16(msg, BRCM_VENDOR_ATTR_ACS_CHWIDTH, params->ch_width) || |
| 3221 | (freq_list_len > 0 && |
| 3222 | nla_put(msg, BRCM_VENDOR_ATTR_ACS_FREQ_LIST, |
| 3223 | sizeof(int) * freq_list_len, params->freq_list))) |
| 3224 | goto fail; |
| 3225 | nla_nest_end(msg, data); |
| 3226 | |
| 3227 | wpa_printf(MSG_DEBUG, |
| 3228 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d", |
| 3229 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
| 3230 | params->vht_enabled, params->ch_width); |
| 3231 | |
| 3232 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
| 3233 | if (ret) { |
| 3234 | wpa_printf(MSG_ERROR, |
| 3235 | "nl80211: BRCM Failed to invoke driver ACS function: %s", |
| 3236 | strerror(errno)); |
| 3237 | } |
| 3238 | |
| 3239 | msg = NULL; |
| 3240 | fail: |
| 3241 | nlmsg_free(msg); |
Ajay Davanageri | b921bb8 | 2020-09-16 12:49:08 +0530 | [diff] [blame] | 3242 | return ret; |
| 3243 | } |
| 3244 | #endif /* CONFIG_DRIVER_NL80211_BRCM */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3245 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3246 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3247 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 3248 | const u8 *key, size_t key_len) |
| 3249 | { |
| 3250 | struct nl_msg *msg; |
| 3251 | int ret; |
| 3252 | |
| 3253 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
| 3254 | return 0; |
| 3255 | |
| 3256 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 3257 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 3258 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 3259 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || |
| 3260 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { |
| 3261 | nl80211_nlmsg_clear(msg); |
| 3262 | nlmsg_free(msg); |
| 3263 | return -1; |
| 3264 | } |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3265 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3266 | if (ret) { |
| 3267 | wpa_printf(MSG_DEBUG, |
| 3268 | "nl80211: Key management set key failed: ret=%d (%s)", |
| 3269 | ret, strerror(-ret)); |
| 3270 | } |
| 3271 | |
| 3272 | return ret; |
| 3273 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3274 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3275 | |
| 3276 | |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3277 | #ifdef CONFIG_DRIVER_NL80211_BRCM |
| 3278 | static int key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 3279 | const u8 *key, size_t key_len) |
| 3280 | { |
| 3281 | struct nl_msg *msg; |
| 3282 | int ret; |
| 3283 | struct nlattr *params; |
| 3284 | |
| 3285 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 3286 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) || |
| 3287 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3288 | BRCM_VENDOR_SCMD_SET_PMK) || |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3289 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 3290 | nla_put(msg, BRCM_ATTR_DRIVER_KEY_PMK, key_len, key)) { |
| 3291 | nl80211_nlmsg_clear(msg); |
| 3292 | nlmsg_free(msg); |
| 3293 | return -ENOBUFS; |
| 3294 | } |
| 3295 | nla_nest_end(msg, params); |
| 3296 | |
| 3297 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1, NULL, NULL); |
| 3298 | if (ret) { |
| 3299 | wpa_printf(MSG_DEBUG, "nl80211: Key mgmt set key failed: ret=%d (%s)", |
| 3300 | ret, strerror(-ret)); |
| 3301 | } |
| 3302 | |
| 3303 | return ret; |
| 3304 | } |
| 3305 | #endif /* CONFIG_DRIVER_NL80211_BRCM */ |
| 3306 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3307 | static int nl80211_set_pmk(struct wpa_driver_nl80211_data *drv, |
| 3308 | const u8 *key, size_t key_len, |
| 3309 | const u8 *addr) |
| 3310 | { |
| 3311 | struct nl_msg *msg = NULL; |
| 3312 | int ret; |
| 3313 | |
| 3314 | /* |
| 3315 | * If the authenticator address is not set, assume it is |
| 3316 | * the current BSSID. |
| 3317 | */ |
| 3318 | if (!addr && drv->associated) |
| 3319 | addr = drv->bssid; |
| 3320 | else if (!addr) |
| 3321 | return -1; |
| 3322 | |
| 3323 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK to the driver for " MACSTR, |
| 3324 | MAC2STR(addr)); |
| 3325 | wpa_hexdump_key(MSG_DEBUG, "nl80211: PMK", key, key_len); |
| 3326 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_PMK); |
| 3327 | if (!msg || |
| 3328 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 3329 | nla_put(msg, NL80211_ATTR_PMK, key_len, key)) { |
| 3330 | nl80211_nlmsg_clear(msg); |
| 3331 | nlmsg_free(msg); |
| 3332 | return -ENOBUFS; |
| 3333 | } |
| 3334 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3335 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3336 | if (ret) { |
| 3337 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK failed: ret=%d (%s)", |
| 3338 | ret, strerror(-ret)); |
| 3339 | } |
| 3340 | |
| 3341 | return ret; |
| 3342 | } |
| 3343 | |
| 3344 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3345 | static int wpa_driver_nl80211_set_key(struct i802_bss *bss, |
| 3346 | struct wpa_driver_set_key_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3347 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3348 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3349 | int ifindex; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3350 | struct nl_msg *msg; |
| 3351 | struct nl_msg *key_msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3352 | int ret; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3353 | int skip_set_key = 1; |
| 3354 | const char *ifname = params->ifname; |
| 3355 | enum wpa_alg alg = params->alg; |
| 3356 | const u8 *addr = params->addr; |
| 3357 | int key_idx = params->key_idx; |
| 3358 | int set_tx = params->set_tx; |
| 3359 | const u8 *seq = params->seq; |
| 3360 | size_t seq_len = params->seq_len; |
| 3361 | const u8 *key = params->key; |
| 3362 | size_t key_len = params->key_len; |
| 3363 | int vlan_id = params->vlan_id; |
| 3364 | enum key_flag key_flag = params->key_flag; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3365 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3366 | /* Ignore for P2P Device */ |
| 3367 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 3368 | return 0; |
| 3369 | |
| 3370 | ifindex = if_nametoindex(ifname); |
| 3371 | 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] | 3372 | "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] | 3373 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3374 | (unsigned long) seq_len, (unsigned long) key_len, key_flag); |
| 3375 | |
| 3376 | if (check_key_flag(key_flag)) { |
| 3377 | wpa_printf(MSG_DEBUG, "%s: invalid key_flag", __func__); |
| 3378 | return -EINVAL; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 3379 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3380 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3381 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3382 | if ((key_flag & KEY_FLAG_PMK) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3383 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { |
| 3384 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
| 3385 | __func__); |
| 3386 | ret = issue_key_mgmt_set_key(drv, key, key_len); |
| 3387 | return ret; |
| 3388 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3389 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3390 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3391 | if (key_flag & KEY_FLAG_PMK) { |
| 3392 | if (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) |
| 3393 | return nl80211_set_pmk(drv, key, key_len, addr); |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3394 | #ifdef CONFIG_DRIVER_NL80211_BRCM |
| 3395 | if (drv->vendor_set_pmk) { |
Jay Patel | 731adae | 2021-02-17 14:55:58 -0800 | [diff] [blame] | 3396 | 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] | 3397 | return key_mgmt_set_key(drv, key, key_len); |
| 3398 | } |
| 3399 | #endif /* CONFIG_DRIVER_NL80211_BRCM */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3400 | /* The driver does not have any offload mechanism for PMK, so |
| 3401 | * there is no need to configure this key. */ |
| 3402 | return 0; |
| 3403 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3404 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3405 | ret = -ENOBUFS; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3406 | key_msg = nlmsg_alloc(); |
| 3407 | if (!key_msg) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3408 | return ret; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3409 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3410 | if ((key_flag & KEY_FLAG_PAIRWISE_MASK) == |
| 3411 | KEY_FLAG_PAIRWISE_RX_TX_MODIFY) { |
| 3412 | wpa_printf(MSG_DEBUG, |
| 3413 | "nl80211: SET_KEY (pairwise RX/TX modify)"); |
| 3414 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
| 3415 | if (!msg) |
| 3416 | goto fail2; |
| 3417 | } else if (alg == WPA_ALG_NONE && (key_flag & KEY_FLAG_RX_TX)) { |
| 3418 | wpa_printf(MSG_DEBUG, "%s: invalid key_flag to delete key", |
| 3419 | __func__); |
| 3420 | ret = -EINVAL; |
| 3421 | goto fail2; |
| 3422 | } else if (alg == WPA_ALG_NONE) { |
| 3423 | wpa_printf(MSG_DEBUG, "nl80211: DEL_KEY"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3424 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
| 3425 | if (!msg) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3426 | goto fail2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3427 | } else { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3428 | u32 suite; |
| 3429 | |
| 3430 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3431 | if (!suite) { |
| 3432 | ret = -EINVAL; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3433 | goto fail2; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3434 | } |
| 3435 | wpa_printf(MSG_DEBUG, "nl80211: NEW_KEY"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3436 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3437 | if (!msg) |
| 3438 | goto fail2; |
| 3439 | if (nla_put(key_msg, NL80211_KEY_DATA, key_len, key) || |
| 3440 | nla_put_u32(key_msg, NL80211_KEY_CIPHER, suite)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3441 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3442 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3443 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3444 | if (seq && seq_len) { |
| 3445 | if (nla_put(key_msg, NL80211_KEY_SEQ, seq_len, seq)) |
| 3446 | goto fail; |
| 3447 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", |
| 3448 | seq, seq_len); |
| 3449 | } |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3450 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3451 | |
| 3452 | if (addr && !is_broadcast_ether_addr(addr)) { |
| 3453 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3454 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 3455 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3456 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3457 | if ((key_flag & KEY_FLAG_PAIRWISE_MASK) == |
| 3458 | KEY_FLAG_PAIRWISE_RX || |
| 3459 | (key_flag & KEY_FLAG_PAIRWISE_MASK) == |
| 3460 | KEY_FLAG_PAIRWISE_RX_TX_MODIFY) { |
| 3461 | if (nla_put_u8(key_msg, NL80211_KEY_MODE, |
| 3462 | key_flag == KEY_FLAG_PAIRWISE_RX ? |
| 3463 | NL80211_KEY_NO_TX : NL80211_KEY_SET_TX)) |
| 3464 | goto fail; |
| 3465 | } else if ((key_flag & KEY_FLAG_GROUP_MASK) == |
| 3466 | KEY_FLAG_GROUP_RX) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3467 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3468 | if (nla_put_u32(key_msg, NL80211_KEY_TYPE, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3469 | NL80211_KEYTYPE_GROUP)) |
| 3470 | goto fail; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3471 | } else if (!(key_flag & KEY_FLAG_PAIRWISE)) { |
| 3472 | wpa_printf(MSG_DEBUG, |
| 3473 | " key_flag missing PAIRWISE when setting a pairwise key"); |
| 3474 | ret = -EINVAL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3475 | goto fail; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3476 | } else if (alg == WPA_ALG_WEP && |
| 3477 | (key_flag & KEY_FLAG_RX_TX) == KEY_FLAG_RX_TX) { |
| 3478 | wpa_printf(MSG_DEBUG, " unicast WEP key"); |
| 3479 | skip_set_key = 0; |
| 3480 | } else { |
| 3481 | wpa_printf(MSG_DEBUG, " pairwise key"); |
| 3482 | } |
| 3483 | } else if ((key_flag & KEY_FLAG_PAIRWISE) || |
| 3484 | !(key_flag & KEY_FLAG_GROUP)) { |
| 3485 | wpa_printf(MSG_DEBUG, |
| 3486 | " invalid key_flag for a broadcast key"); |
| 3487 | ret = -EINVAL; |
| 3488 | goto fail; |
| 3489 | } else { |
| 3490 | wpa_printf(MSG_DEBUG, " broadcast key"); |
| 3491 | if (key_flag & KEY_FLAG_DEFAULT) |
| 3492 | skip_set_key = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3493 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3494 | if (nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) || |
| 3495 | nla_put_nested(msg, NL80211_ATTR_KEY, key_msg)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3496 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3497 | nl80211_nlmsg_clear(key_msg); |
| 3498 | nlmsg_free(key_msg); |
| 3499 | key_msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3500 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3501 | if (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) { |
| 3502 | wpa_printf(MSG_DEBUG, "nl80211: VLAN ID %d", vlan_id); |
| 3503 | if (nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) |
| 3504 | goto fail; |
| 3505 | } |
| 3506 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3507 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3508 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
| 3509 | ret = 0; |
| 3510 | if (ret) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3511 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3512 | ret, strerror(-ret)); |
| 3513 | |
| 3514 | /* |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3515 | * 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] | 3516 | * we're done here. |
| 3517 | */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3518 | if (ret || skip_set_key) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3519 | return ret; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3520 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_SET_KEY - default key"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3521 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3522 | ret = -ENOBUFS; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3523 | key_msg = nlmsg_alloc(); |
| 3524 | if (!key_msg) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3525 | return ret; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3526 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3527 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3528 | if (!msg) |
| 3529 | goto fail2; |
| 3530 | if (!key_msg || |
| 3531 | nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) || |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3532 | nla_put_flag(key_msg, wpa_alg_bip(alg) ? |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3533 | (key_idx == 6 || key_idx == 7 ? |
| 3534 | NL80211_KEY_DEFAULT_BEACON : |
| 3535 | NL80211_KEY_DEFAULT_MGMT) : |
| 3536 | NL80211_KEY_DEFAULT)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3537 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3538 | if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3539 | struct nlattr *types; |
| 3540 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3541 | types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3542 | if (!types || |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3543 | nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3544 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3545 | nla_nest_end(key_msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3546 | } else if (addr) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3547 | struct nlattr *types; |
| 3548 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3549 | types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3550 | if (!types || |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3551 | nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3552 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3553 | nla_nest_end(key_msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3554 | } |
| 3555 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3556 | if (nla_put_nested(msg, NL80211_ATTR_KEY, key_msg)) |
| 3557 | goto fail; |
| 3558 | nl80211_nlmsg_clear(key_msg); |
| 3559 | nlmsg_free(key_msg); |
| 3560 | key_msg = NULL; |
| 3561 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3562 | if (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) { |
| 3563 | wpa_printf(MSG_DEBUG, "nl80211: set_key default - VLAN ID %d", |
| 3564 | vlan_id); |
| 3565 | if (nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) |
| 3566 | goto fail; |
| 3567 | } |
| 3568 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3569 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3570 | if (ret) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3571 | wpa_printf(MSG_DEBUG, |
| 3572 | "nl80211: set_key default failed; err=%d %s", |
| 3573 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3574 | return ret; |
| 3575 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3576 | fail: |
| 3577 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3578 | nlmsg_free(msg); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3579 | fail2: |
| 3580 | nl80211_nlmsg_clear(key_msg); |
| 3581 | nlmsg_free(key_msg); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3582 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3583 | } |
| 3584 | |
| 3585 | |
| 3586 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
| 3587 | int key_idx, int defkey, |
| 3588 | const u8 *seq, size_t seq_len, |
| 3589 | const u8 *key, size_t key_len) |
| 3590 | { |
| 3591 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3592 | u32 suite; |
| 3593 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3594 | if (!key_attr) |
| 3595 | return -1; |
| 3596 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3597 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 3598 | if (!suite) |
| 3599 | return -1; |
| 3600 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3601 | if (defkey && wpa_alg_bip(alg)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3602 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) |
| 3603 | return -1; |
| 3604 | } else if (defkey) { |
| 3605 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) |
| 3606 | return -1; |
| 3607 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3608 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3609 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3610 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3611 | (seq && seq_len && |
| 3612 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || |
| 3613 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) |
| 3614 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3615 | |
| 3616 | nla_nest_end(msg, key_attr); |
| 3617 | |
| 3618 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3619 | } |
| 3620 | |
| 3621 | |
| 3622 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
| 3623 | struct nl_msg *msg) |
| 3624 | { |
| 3625 | int i, privacy = 0; |
| 3626 | struct nlattr *nl_keys, *nl_key; |
| 3627 | |
| 3628 | for (i = 0; i < 4; i++) { |
| 3629 | if (!params->wep_key[i]) |
| 3630 | continue; |
| 3631 | privacy = 1; |
| 3632 | break; |
| 3633 | } |
| 3634 | if (params->wps == WPS_MODE_PRIVACY) |
| 3635 | privacy = 1; |
| 3636 | if (params->pairwise_suite && |
| 3637 | params->pairwise_suite != WPA_CIPHER_NONE) |
| 3638 | privacy = 1; |
| 3639 | |
| 3640 | if (!privacy) |
| 3641 | return 0; |
| 3642 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3643 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 3644 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3645 | |
| 3646 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); |
| 3647 | if (!nl_keys) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3648 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3649 | |
| 3650 | for (i = 0; i < 4; i++) { |
| 3651 | if (!params->wep_key[i]) |
| 3652 | continue; |
| 3653 | |
| 3654 | nl_key = nla_nest_start(msg, i); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3655 | if (!nl_key || |
| 3656 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], |
| 3657 | params->wep_key[i]) || |
| 3658 | nla_put_u32(msg, NL80211_KEY_CIPHER, |
| 3659 | params->wep_key_len[i] == 5 ? |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3660 | RSN_CIPHER_SUITE_WEP40 : |
| 3661 | RSN_CIPHER_SUITE_WEP104) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3662 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
| 3663 | (i == params->wep_tx_keyidx && |
| 3664 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) |
| 3665 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3666 | |
| 3667 | nla_nest_end(msg, nl_key); |
| 3668 | } |
| 3669 | nla_nest_end(msg, nl_keys); |
| 3670 | |
| 3671 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3672 | } |
| 3673 | |
| 3674 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3675 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 3676 | const u8 *addr, int cmd, u16 reason_code, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3677 | int local_state_change, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3678 | struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3679 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3680 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3681 | struct nl_msg *msg; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3682 | struct nl_sock *nl_connect = get_connect_handle(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3683 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3684 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
| 3685 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
| 3686 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 3687 | (local_state_change && |
| 3688 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { |
| 3689 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3690 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3691 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3692 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3693 | if (nl_connect) |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3694 | ret = send_and_recv(drv->global, nl_connect, msg, |
| 3695 | process_bss_event, bss, NULL, NULL); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3696 | else |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3697 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3698 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3699 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 3700 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", |
| 3701 | reason_code, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3702 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3703 | return ret; |
| 3704 | } |
| 3705 | |
| 3706 | |
| 3707 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3708 | u16 reason_code, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3709 | struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3710 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3711 | int ret; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3712 | int drv_associated = drv->associated; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3713 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3714 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3715 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3716 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3717 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3718 | reason_code, 0, bss); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3719 | /* |
| 3720 | * For locally generated disconnect, supplicant already generates a |
| 3721 | * DEAUTH event, so ignore the event from NL80211. |
| 3722 | */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3723 | drv->ignore_next_local_disconnect = drv_associated && (ret == 0); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3724 | |
| 3725 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3726 | } |
| 3727 | |
| 3728 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3729 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3730 | const u8 *addr, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3731 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3732 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3733 | int ret; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3734 | int drv_associated = drv->associated; |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3735 | |
| 3736 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3737 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3738 | return nl80211_leave_ibss(drv, 1); |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3739 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3740 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3741 | return wpa_driver_nl80211_disconnect(drv, reason_code, bss); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3742 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3743 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
| 3744 | __func__, MAC2STR(addr), reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3745 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3746 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 3747 | reason_code, 0, bss); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3748 | /* |
| 3749 | * For locally generated deauthenticate, supplicant already generates a |
| 3750 | * DEAUTH event, so ignore the event from NL80211. |
| 3751 | */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3752 | drv->ignore_next_local_deauth = drv_associated && (ret == 0); |
| 3753 | |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3754 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3755 | } |
| 3756 | |
| 3757 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3758 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
| 3759 | struct wpa_driver_auth_params *params) |
| 3760 | { |
| 3761 | int i; |
| 3762 | |
| 3763 | drv->auth_freq = params->freq; |
| 3764 | drv->auth_alg = params->auth_alg; |
| 3765 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; |
| 3766 | drv->auth_local_state_change = params->local_state_change; |
| 3767 | drv->auth_p2p = params->p2p; |
| 3768 | |
| 3769 | if (params->bssid) |
| 3770 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); |
| 3771 | else |
| 3772 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); |
| 3773 | |
| 3774 | if (params->ssid) { |
| 3775 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); |
| 3776 | drv->auth_ssid_len = params->ssid_len; |
| 3777 | } else |
| 3778 | drv->auth_ssid_len = 0; |
| 3779 | |
| 3780 | |
| 3781 | os_free(drv->auth_ie); |
| 3782 | drv->auth_ie = NULL; |
| 3783 | drv->auth_ie_len = 0; |
| 3784 | if (params->ie) { |
| 3785 | drv->auth_ie = os_malloc(params->ie_len); |
| 3786 | if (drv->auth_ie) { |
| 3787 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); |
| 3788 | drv->auth_ie_len = params->ie_len; |
| 3789 | } |
| 3790 | } |
| 3791 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 3792 | os_free(drv->auth_data); |
| 3793 | drv->auth_data = NULL; |
| 3794 | drv->auth_data_len = 0; |
| 3795 | if (params->auth_data) { |
| 3796 | drv->auth_data = os_memdup(params->auth_data, |
| 3797 | params->auth_data_len); |
| 3798 | if (drv->auth_data) |
| 3799 | drv->auth_data_len = params->auth_data_len; |
| 3800 | } |
| 3801 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3802 | for (i = 0; i < 4; i++) { |
| 3803 | if (params->wep_key[i] && params->wep_key_len[i] && |
| 3804 | params->wep_key_len[i] <= 16) { |
| 3805 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], |
| 3806 | params->wep_key_len[i]); |
| 3807 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; |
| 3808 | } else |
| 3809 | drv->auth_wep_key_len[i] = 0; |
| 3810 | } |
| 3811 | } |
| 3812 | |
| 3813 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3814 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
| 3815 | { |
| 3816 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3817 | |
| 3818 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) |
| 3819 | return; |
| 3820 | |
| 3821 | /* |
| 3822 | * Looks like we failed to unmask 11b rates previously. This could |
| 3823 | * happen, e.g., if the interface was down at the point in time when a |
| 3824 | * P2P group was terminated. |
| 3825 | */ |
| 3826 | wpa_printf(MSG_DEBUG, |
| 3827 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", |
| 3828 | bss->ifname); |
| 3829 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 3830 | } |
| 3831 | |
| 3832 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3833 | static enum nl80211_auth_type get_nl_auth_type(int wpa_auth_alg) |
| 3834 | { |
| 3835 | if (wpa_auth_alg & WPA_AUTH_ALG_OPEN) |
| 3836 | return NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 3837 | if (wpa_auth_alg & WPA_AUTH_ALG_SHARED) |
| 3838 | return NL80211_AUTHTYPE_SHARED_KEY; |
| 3839 | if (wpa_auth_alg & WPA_AUTH_ALG_LEAP) |
| 3840 | return NL80211_AUTHTYPE_NETWORK_EAP; |
| 3841 | if (wpa_auth_alg & WPA_AUTH_ALG_FT) |
| 3842 | return NL80211_AUTHTYPE_FT; |
| 3843 | if (wpa_auth_alg & WPA_AUTH_ALG_SAE) |
| 3844 | return NL80211_AUTHTYPE_SAE; |
| 3845 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS) |
| 3846 | return NL80211_AUTHTYPE_FILS_SK; |
| 3847 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS_SK_PFS) |
| 3848 | return NL80211_AUTHTYPE_FILS_SK_PFS; |
| 3849 | |
| 3850 | return NL80211_AUTHTYPE_MAX; |
| 3851 | } |
| 3852 | |
| 3853 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3854 | static int wpa_driver_nl80211_authenticate( |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3855 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3856 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3857 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3858 | int ret = -1, i; |
| 3859 | struct nl_msg *msg; |
| 3860 | enum nl80211_auth_type type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3861 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3862 | int count = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3863 | int is_retry; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3864 | struct wpa_driver_set_key_params p; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3865 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3866 | nl80211_unmask_11b_rates(bss); |
| 3867 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3868 | is_retry = drv->retry_auth; |
| 3869 | drv->retry_auth = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3870 | drv->ignore_deauth_event = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3871 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3872 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3873 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3874 | if (params->bssid) |
| 3875 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 3876 | else |
| 3877 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3878 | /* FIX: IBSS mode */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3879 | nlmode = params->p2p ? |
| 3880 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 3881 | if (drv->nlmode != nlmode && |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3882 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3883 | return -1; |
| 3884 | |
| 3885 | retry: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3886 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
| 3887 | drv->ifindex); |
| 3888 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3889 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
| 3890 | if (!msg) |
| 3891 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3892 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3893 | os_memset(&p, 0, sizeof(p)); |
| 3894 | p.ifname = bss->ifname; |
| 3895 | p.alg = WPA_ALG_WEP; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3896 | for (i = 0; i < 4; i++) { |
| 3897 | if (!params->wep_key[i]) |
| 3898 | continue; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3899 | p.key_idx = i; |
| 3900 | p.set_tx = i == params->wep_tx_keyidx; |
| 3901 | p.key = params->wep_key[i]; |
| 3902 | p.key_len = params->wep_key_len[i]; |
| 3903 | p.key_flag = i == params->wep_tx_keyidx ? |
| 3904 | KEY_FLAG_GROUP_RX_TX_DEFAULT : |
| 3905 | KEY_FLAG_GROUP_RX_TX; |
| 3906 | wpa_driver_nl80211_set_key(bss, &p); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3907 | if (params->wep_tx_keyidx != i) |
| 3908 | continue; |
| 3909 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3910 | params->wep_key[i], params->wep_key_len[i])) |
| 3911 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3912 | } |
| 3913 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3914 | if (params->bssid) { |
| 3915 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 3916 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3917 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 3918 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3919 | } |
| 3920 | if (params->freq) { |
| 3921 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3922 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
| 3923 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3924 | } |
| 3925 | if (params->ssid) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3926 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
| 3927 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3928 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 3929 | params->ssid)) |
| 3930 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3931 | } |
| 3932 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3933 | if (params->ie && |
| 3934 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) |
| 3935 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3936 | if (params->auth_data) { |
| 3937 | wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data, |
| 3938 | params->auth_data_len); |
| 3939 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len, |
| 3940 | params->auth_data)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3941 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3942 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3943 | type = get_nl_auth_type(params->auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3944 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3945 | if (type == NL80211_AUTHTYPE_MAX || |
| 3946 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3947 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3948 | if (params->local_state_change) { |
| 3949 | wpa_printf(MSG_DEBUG, " * Local state change only"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3950 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
| 3951 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3952 | } |
| 3953 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3954 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3955 | msg = NULL; |
| 3956 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3957 | wpa_dbg(drv->ctx, MSG_DEBUG, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3958 | "nl80211: MLME command failed (auth): count=%d ret=%d (%s)", |
| 3959 | count, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3960 | count++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3961 | if ((ret == -EALREADY || ret == -EEXIST) && count == 1 && |
| 3962 | params->bssid && !params->local_state_change) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3963 | /* |
| 3964 | * mac80211 does not currently accept new |
| 3965 | * authentication if we are already authenticated. As a |
| 3966 | * workaround, force deauthentication and try again. |
| 3967 | */ |
| 3968 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " |
| 3969 | "after forced deauthentication"); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3970 | drv->ignore_deauth_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3971 | wpa_driver_nl80211_deauthenticate( |
| 3972 | bss, params->bssid, |
| 3973 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 3974 | nlmsg_free(msg); |
| 3975 | goto retry; |
| 3976 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3977 | |
| 3978 | if (ret == -ENOENT && params->freq && !is_retry) { |
| 3979 | /* |
| 3980 | * cfg80211 has likely expired the BSS entry even |
| 3981 | * though it was previously available in our internal |
| 3982 | * BSS table. To recover quickly, start a single |
| 3983 | * channel scan on the specified channel. |
| 3984 | */ |
| 3985 | struct wpa_driver_scan_params scan; |
| 3986 | int freqs[2]; |
| 3987 | |
| 3988 | os_memset(&scan, 0, sizeof(scan)); |
| 3989 | scan.num_ssids = 1; |
| 3990 | if (params->ssid) { |
| 3991 | scan.ssids[0].ssid = params->ssid; |
| 3992 | scan.ssids[0].ssid_len = params->ssid_len; |
| 3993 | } |
| 3994 | freqs[0] = params->freq; |
| 3995 | freqs[1] = 0; |
| 3996 | scan.freqs = freqs; |
| 3997 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " |
| 3998 | "channel scan to refresh cfg80211 BSS " |
| 3999 | "entry"); |
| 4000 | ret = wpa_driver_nl80211_scan(bss, &scan); |
| 4001 | if (ret == 0) { |
| 4002 | nl80211_copy_auth_params(drv, params); |
| 4003 | drv->scan_for_auth = 1; |
| 4004 | } |
| 4005 | } else if (is_retry) { |
| 4006 | /* |
| 4007 | * Need to indicate this with an event since the return |
| 4008 | * value from the retry is not delivered to core code. |
| 4009 | */ |
| 4010 | union wpa_event_data event; |
| 4011 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " |
| 4012 | "failed"); |
| 4013 | os_memset(&event, 0, sizeof(event)); |
| 4014 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, |
| 4015 | ETH_ALEN); |
| 4016 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, |
| 4017 | &event); |
| 4018 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4019 | } else { |
| 4020 | wpa_printf(MSG_DEBUG, |
| 4021 | "nl80211: Authentication request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4022 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4023 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4024 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4025 | nlmsg_free(msg); |
| 4026 | return ret; |
| 4027 | } |
| 4028 | |
| 4029 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4030 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4031 | { |
| 4032 | struct wpa_driver_auth_params params; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4033 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4034 | int i; |
| 4035 | |
| 4036 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); |
| 4037 | |
| 4038 | os_memset(¶ms, 0, sizeof(params)); |
| 4039 | params.freq = drv->auth_freq; |
| 4040 | params.auth_alg = drv->auth_alg; |
| 4041 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; |
| 4042 | params.local_state_change = drv->auth_local_state_change; |
| 4043 | params.p2p = drv->auth_p2p; |
| 4044 | |
| 4045 | if (!is_zero_ether_addr(drv->auth_bssid_)) |
| 4046 | params.bssid = drv->auth_bssid_; |
| 4047 | |
| 4048 | if (drv->auth_ssid_len) { |
| 4049 | params.ssid = drv->auth_ssid; |
| 4050 | params.ssid_len = drv->auth_ssid_len; |
| 4051 | } |
| 4052 | |
| 4053 | params.ie = drv->auth_ie; |
| 4054 | params.ie_len = drv->auth_ie_len; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4055 | params.auth_data = drv->auth_data; |
| 4056 | params.auth_data_len = drv->auth_data_len; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4057 | |
| 4058 | for (i = 0; i < 4; i++) { |
| 4059 | if (drv->auth_wep_key_len[i]) { |
| 4060 | params.wep_key[i] = drv->auth_wep_key[i]; |
| 4061 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; |
| 4062 | } |
| 4063 | } |
| 4064 | |
| 4065 | drv->retry_auth = 1; |
| 4066 | return wpa_driver_nl80211_authenticate(bss, ¶ms); |
| 4067 | } |
| 4068 | |
| 4069 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4070 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
| 4071 | size_t data_len, int noack, |
| 4072 | unsigned int freq, int no_cck, |
| 4073 | int offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4074 | unsigned int wait_time, |
| 4075 | const u16 *csa_offs, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4076 | size_t csa_offs_len, int no_encrypt) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4077 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4078 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4079 | struct ieee80211_mgmt *mgmt; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4080 | int encrypt = !no_encrypt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4081 | u16 fc; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4082 | int use_cookie = 1; |
| 4083 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4084 | |
| 4085 | mgmt = (struct ieee80211_mgmt *) data; |
| 4086 | fc = le_to_host16(mgmt->frame_control); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4087 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da=" MACSTR |
| 4088 | " 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] | 4089 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4090 | no_encrypt, fc, fc2str(fc), drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4091 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4092 | if ((is_sta_interface(drv->nlmode) || |
| 4093 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4094 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 4095 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { |
| 4096 | /* |
| 4097 | * The use of last_mgmt_freq is a bit of a hack, |
| 4098 | * but it works due to the single-threaded nature |
| 4099 | * of wpa_supplicant. |
| 4100 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4101 | if (freq == 0) { |
| 4102 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", |
| 4103 | drv->last_mgmt_freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4104 | freq = drv->last_mgmt_freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4105 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4106 | wait_time = 0; |
| 4107 | use_cookie = 0; |
| 4108 | no_cck = 1; |
| 4109 | offchanok = 1; |
| 4110 | goto send_frame_cmd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4111 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4112 | |
| 4113 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4114 | if (freq == 0) { |
| 4115 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", |
| 4116 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4117 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4118 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4119 | if ((int) freq == bss->freq) |
| 4120 | wait_time = 0; |
| 4121 | goto send_frame_cmd; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 4122 | } |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 4123 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4124 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 4125 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 4126 | /* |
| 4127 | * Only one of the authentication frame types is encrypted. |
| 4128 | * In order for static WEP encryption to work properly (i.e., |
| 4129 | * to not encrypt the frame), we need to tell mac80211 about |
| 4130 | * the frames that must not be encrypted. |
| 4131 | */ |
| 4132 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 4133 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); |
| 4134 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
| 4135 | encrypt = 0; |
| 4136 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4137 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4138 | if (is_sta_interface(drv->nlmode) && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4139 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 4140 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4141 | if (freq == 0 && |
| 4142 | (drv->capa.flags & WPA_DRIVER_FLAGS_SAE) && |
| 4143 | !(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
| 4144 | freq = nl80211_get_assoc_freq(drv); |
| 4145 | wpa_printf(MSG_DEBUG, |
| 4146 | "nl80211: send_mlme - Use assoc_freq=%u for external auth", |
| 4147 | freq); |
| 4148 | } |
| 4149 | |
| 4150 | /* Allow off channel for PASN authentication */ |
| 4151 | if (data_len >= IEEE80211_HDRLEN + 2 && |
| 4152 | WPA_GET_LE16(data + IEEE80211_HDRLEN) == WLAN_AUTH_PASN && |
| 4153 | !offchanok) { |
| 4154 | wpa_printf(MSG_DEBUG, |
| 4155 | "nl80211: send_mlme: allow off channel for PASN"); |
| 4156 | offchanok = 1; |
| 4157 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4158 | } |
| 4159 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4160 | #ifdef CONFIG_PASN |
| 4161 | if (is_sta_interface(drv->nlmode) && |
| 4162 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 4163 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_DEAUTH) { |
| 4164 | wpa_printf(MSG_DEBUG, |
| 4165 | "nl80211: send_mlme: allow Deauthentication frame for PASN"); |
| 4166 | |
| 4167 | use_cookie = 0; |
| 4168 | offchanok = 1; |
| 4169 | goto send_frame_cmd; |
| 4170 | } |
| 4171 | #endif /* CONFIG_PASN */ |
| 4172 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4173 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 4174 | freq = nl80211_get_assoc_freq(drv); |
| 4175 | wpa_printf(MSG_DEBUG, |
| 4176 | "nl80211: send_mlme - Use assoc_freq=%u for IBSS", |
| 4177 | freq); |
| 4178 | } |
| 4179 | if (freq == 0) { |
| 4180 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - Use bss->freq=%u", |
| 4181 | bss->freq); |
| 4182 | freq = bss->freq; |
| 4183 | } |
| 4184 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4185 | if (drv->use_monitor && is_ap_interface(drv->nlmode)) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4186 | wpa_printf(MSG_DEBUG, |
| 4187 | "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor", |
| 4188 | freq, bss->freq); |
| 4189 | return nl80211_send_monitor(drv, data, data_len, encrypt, |
| 4190 | noack); |
| 4191 | } |
| 4192 | |
| 4193 | if (noack || WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT || |
| 4194 | WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION) |
| 4195 | use_cookie = 0; |
| 4196 | send_frame_cmd: |
| 4197 | #ifdef CONFIG_TESTING_OPTIONS |
| 4198 | if (no_encrypt && !encrypt && !drv->use_monitor) { |
| 4199 | wpa_printf(MSG_DEBUG, |
| 4200 | "nl80211: Request to send an unencrypted frame - use a monitor interface for this"); |
| 4201 | if (nl80211_create_monitor_interface(drv) < 0) |
| 4202 | return -1; |
| 4203 | res = nl80211_send_monitor(drv, data, data_len, encrypt, |
| 4204 | noack); |
| 4205 | nl80211_remove_monitor_interface(drv); |
| 4206 | return res; |
| 4207 | } |
| 4208 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 4209 | |
| 4210 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame_cmd"); |
| 4211 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, data_len, |
| 4212 | use_cookie, no_cck, noack, offchanok, |
| 4213 | csa_offs, csa_offs_len); |
| 4214 | |
| 4215 | return res; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4216 | } |
| 4217 | |
| 4218 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4219 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
| 4220 | { |
| 4221 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 4222 | u8 rates_len = 0; |
| 4223 | int i; |
| 4224 | |
| 4225 | if (!basic_rates) |
| 4226 | return 0; |
| 4227 | |
| 4228 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) |
| 4229 | rates[rates_len++] = basic_rates[i] / 5; |
| 4230 | |
| 4231 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); |
| 4232 | } |
| 4233 | |
| 4234 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4235 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
| 4236 | int slot, int ht_opmode, int ap_isolate, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4237 | const int *basic_rates) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4238 | { |
| 4239 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4240 | struct nl_msg *msg; |
| 4241 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4242 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
| 4243 | (cts >= 0 && |
| 4244 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || |
| 4245 | (preamble >= 0 && |
| 4246 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || |
| 4247 | (slot >= 0 && |
| 4248 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || |
| 4249 | (ht_opmode >= 0 && |
| 4250 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || |
| 4251 | (ap_isolate >= 0 && |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4252 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
| 4253 | nl80211_put_basic_rates(msg, basic_rates)) { |
| 4254 | nlmsg_free(msg); |
| 4255 | return -ENOBUFS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4256 | } |
| 4257 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4258 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4259 | } |
| 4260 | |
| 4261 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4262 | static int wpa_driver_nl80211_set_acl(void *priv, |
| 4263 | struct hostapd_acl_params *params) |
| 4264 | { |
| 4265 | struct i802_bss *bss = priv; |
| 4266 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4267 | struct nl_msg *msg; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4268 | struct nl_msg *acl; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4269 | unsigned int i; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4270 | int ret; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4271 | size_t acl_nla_sz, acl_nlmsg_sz, nla_sz, nlmsg_sz; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4272 | |
| 4273 | if (!(drv->capa.max_acl_mac_addrs)) |
| 4274 | return -ENOTSUP; |
| 4275 | |
| 4276 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) |
| 4277 | return -ENOTSUP; |
| 4278 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4279 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
| 4280 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); |
| 4281 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4282 | acl_nla_sz = nla_total_size(ETH_ALEN) * params->num_mac_acl; |
| 4283 | acl_nlmsg_sz = nlmsg_total_size(acl_nla_sz); |
| 4284 | acl = nlmsg_alloc_size(acl_nlmsg_sz); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4285 | if (!acl) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4286 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4287 | for (i = 0; i < params->num_mac_acl; i++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4288 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { |
| 4289 | nlmsg_free(acl); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4290 | return -ENOMEM; |
| 4291 | } |
| 4292 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4293 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4294 | /* |
| 4295 | * genetlink message header (Length of user header is 0) + |
| 4296 | * u32 attr: NL80211_ATTR_IFINDEX + |
| 4297 | * u32 attr: NL80211_ATTR_ACL_POLICY + |
| 4298 | * nested acl attr |
| 4299 | */ |
| 4300 | nla_sz = GENL_HDRLEN + |
| 4301 | nla_total_size(4) * 2 + |
| 4302 | nla_total_size(acl_nla_sz); |
| 4303 | nlmsg_sz = nlmsg_total_size(nla_sz); |
| 4304 | if (!(msg = nl80211_ifindex_msg_build(drv, nlmsg_alloc_size(nlmsg_sz), |
| 4305 | drv->ifindex, 0, |
| 4306 | NL80211_CMD_SET_MAC_ACL)) || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4307 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
| 4308 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : |
| 4309 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || |
| 4310 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
| 4311 | nlmsg_free(msg); |
| 4312 | nlmsg_free(acl); |
| 4313 | return -ENOMEM; |
| 4314 | } |
| 4315 | nlmsg_free(acl); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4316 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4317 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4318 | if (ret) { |
| 4319 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", |
| 4320 | ret, strerror(-ret)); |
| 4321 | } |
| 4322 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4323 | return ret; |
| 4324 | } |
| 4325 | |
| 4326 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4327 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
| 4328 | { |
| 4329 | if (beacon_int > 0) { |
| 4330 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); |
| 4331 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 4332 | beacon_int); |
| 4333 | } |
| 4334 | |
| 4335 | return 0; |
| 4336 | } |
| 4337 | |
| 4338 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4339 | static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period) |
| 4340 | { |
| 4341 | if (dtim_period > 0) { |
| 4342 | wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period); |
| 4343 | return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); |
| 4344 | } |
| 4345 | |
| 4346 | return 0; |
| 4347 | } |
| 4348 | |
| 4349 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4350 | #ifdef CONFIG_MESH |
| 4351 | static int nl80211_set_mesh_config(void *priv, |
| 4352 | struct wpa_driver_mesh_bss_params *params) |
| 4353 | { |
| 4354 | struct i802_bss *bss = priv; |
| 4355 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4356 | struct nl_msg *msg; |
| 4357 | int ret; |
| 4358 | |
| 4359 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG); |
| 4360 | if (!msg) |
| 4361 | return -1; |
| 4362 | |
| 4363 | ret = nl80211_put_mesh_config(msg, params); |
| 4364 | if (ret < 0) { |
| 4365 | nlmsg_free(msg); |
| 4366 | return ret; |
| 4367 | } |
| 4368 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4369 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4370 | if (ret) { |
| 4371 | wpa_printf(MSG_ERROR, |
| 4372 | "nl80211: Mesh config set failed: %d (%s)", |
| 4373 | ret, strerror(-ret)); |
| 4374 | return ret; |
| 4375 | } |
| 4376 | return 0; |
| 4377 | } |
| 4378 | #endif /* CONFIG_MESH */ |
| 4379 | |
| 4380 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4381 | 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] | 4382 | struct wpa_driver_ap_params *params) |
| 4383 | { |
| 4384 | struct nlattr *bands, *band; |
| 4385 | struct nl80211_txrate_vht vht_rate; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4386 | struct nl80211_txrate_he he_rate; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4387 | |
| 4388 | if (!params->freq || |
| 4389 | (params->beacon_rate == 0 && |
| 4390 | params->rate_type == BEACON_RATE_LEGACY)) |
| 4391 | return 0; |
| 4392 | |
| 4393 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 4394 | if (!bands) |
| 4395 | return -1; |
| 4396 | |
| 4397 | switch (params->freq->mode) { |
| 4398 | case HOSTAPD_MODE_IEEE80211B: |
| 4399 | case HOSTAPD_MODE_IEEE80211G: |
| 4400 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
| 4401 | break; |
| 4402 | case HOSTAPD_MODE_IEEE80211A: |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4403 | if (is_6ghz_freq(params->freq->freq)) |
| 4404 | band = nla_nest_start(msg, NL80211_BAND_6GHZ); |
| 4405 | else |
| 4406 | band = nla_nest_start(msg, NL80211_BAND_5GHZ); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4407 | break; |
| 4408 | case HOSTAPD_MODE_IEEE80211AD: |
| 4409 | band = nla_nest_start(msg, NL80211_BAND_60GHZ); |
| 4410 | break; |
| 4411 | default: |
| 4412 | return 0; |
| 4413 | } |
| 4414 | |
| 4415 | if (!band) |
| 4416 | return -1; |
| 4417 | |
| 4418 | os_memset(&vht_rate, 0, sizeof(vht_rate)); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4419 | os_memset(&he_rate, 0, sizeof(he_rate)); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4420 | |
| 4421 | switch (params->rate_type) { |
| 4422 | case BEACON_RATE_LEGACY: |
| 4423 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) { |
| 4424 | wpa_printf(MSG_INFO, |
| 4425 | "nl80211: Driver does not support setting Beacon frame rate (legacy)"); |
| 4426 | return -1; |
| 4427 | } |
| 4428 | |
| 4429 | if (nla_put_u8(msg, NL80211_TXRATE_LEGACY, |
| 4430 | (u8) params->beacon_rate / 5) || |
| 4431 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || |
| 4432 | (params->freq->vht_enabled && |
| 4433 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4434 | &vht_rate))) |
| 4435 | return -1; |
| 4436 | |
| 4437 | wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)", |
| 4438 | params->beacon_rate); |
| 4439 | break; |
| 4440 | case BEACON_RATE_HT: |
| 4441 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) { |
| 4442 | wpa_printf(MSG_INFO, |
| 4443 | "nl80211: Driver does not support setting Beacon frame rate (HT)"); |
| 4444 | return -1; |
| 4445 | } |
| 4446 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || |
| 4447 | nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) || |
| 4448 | (params->freq->vht_enabled && |
| 4449 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4450 | &vht_rate))) |
| 4451 | return -1; |
| 4452 | wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u", |
| 4453 | params->beacon_rate); |
| 4454 | break; |
| 4455 | case BEACON_RATE_VHT: |
| 4456 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) { |
| 4457 | wpa_printf(MSG_INFO, |
| 4458 | "nl80211: Driver does not support setting Beacon frame rate (VHT)"); |
| 4459 | return -1; |
| 4460 | } |
| 4461 | vht_rate.mcs[0] = BIT(params->beacon_rate); |
| 4462 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL)) |
| 4463 | return -1; |
| 4464 | if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL)) |
| 4465 | return -1; |
| 4466 | if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4467 | &vht_rate)) |
| 4468 | return -1; |
| 4469 | wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u", |
| 4470 | params->beacon_rate); |
| 4471 | break; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4472 | case BEACON_RATE_HE: |
| 4473 | if (!(flags2 & WPA_DRIVER_FLAGS2_BEACON_RATE_HE)) { |
| 4474 | wpa_printf(MSG_INFO, |
| 4475 | "nl80211: Driver does not support setting Beacon frame rate (HE)"); |
| 4476 | return -1; |
| 4477 | } |
| 4478 | he_rate.mcs[0] = BIT(params->beacon_rate); |
| 4479 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || |
| 4480 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || |
| 4481 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4482 | &vht_rate) || |
| 4483 | nla_put(msg, NL80211_TXRATE_HE, sizeof(he_rate), &he_rate)) |
| 4484 | return -1; |
| 4485 | wpa_printf(MSG_DEBUG, " * beacon_rate = HE-MCS %u", |
| 4486 | params->beacon_rate); |
| 4487 | break; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4488 | } |
| 4489 | |
| 4490 | nla_nest_end(msg, band); |
| 4491 | nla_nest_end(msg, bands); |
| 4492 | |
| 4493 | return 0; |
| 4494 | } |
| 4495 | |
| 4496 | |
| 4497 | static int nl80211_set_multicast_to_unicast(struct i802_bss *bss, |
| 4498 | int multicast_to_unicast) |
| 4499 | { |
| 4500 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4501 | struct nl_msg *msg; |
| 4502 | int ret; |
| 4503 | |
| 4504 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST); |
| 4505 | if (!msg || |
| 4506 | (multicast_to_unicast && |
| 4507 | nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) { |
| 4508 | wpa_printf(MSG_ERROR, |
| 4509 | "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s", |
| 4510 | bss->ifname); |
| 4511 | nlmsg_free(msg); |
| 4512 | return -ENOBUFS; |
| 4513 | } |
| 4514 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4515 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4516 | |
| 4517 | switch (ret) { |
| 4518 | case 0: |
| 4519 | wpa_printf(MSG_DEBUG, |
| 4520 | "nl80211: multicast to unicast %s on interface %s", |
| 4521 | multicast_to_unicast ? "enabled" : "disabled", |
| 4522 | bss->ifname); |
| 4523 | break; |
| 4524 | case -EOPNOTSUPP: |
| 4525 | if (!multicast_to_unicast) |
| 4526 | break; |
| 4527 | wpa_printf(MSG_INFO, |
| 4528 | "nl80211: multicast to unicast not supported on interface %s", |
| 4529 | bss->ifname); |
| 4530 | break; |
| 4531 | default: |
| 4532 | wpa_printf(MSG_ERROR, |
| 4533 | "nl80211: %s multicast to unicast failed with %d (%s) on interface %s", |
| 4534 | multicast_to_unicast ? "enabling" : "disabling", |
| 4535 | ret, strerror(-ret), bss->ifname); |
| 4536 | break; |
| 4537 | } |
| 4538 | |
| 4539 | return ret; |
| 4540 | } |
| 4541 | |
| 4542 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4543 | #ifdef CONFIG_SAE |
| 4544 | static int nl80211_put_sae_pwe(struct nl_msg *msg, int pwe) |
| 4545 | { |
| 4546 | u8 sae_pwe; |
| 4547 | |
| 4548 | wpa_printf(MSG_DEBUG, "nl802111: sae_pwe=%d", pwe); |
| 4549 | if (pwe == 0) |
| 4550 | sae_pwe = NL80211_SAE_PWE_HUNT_AND_PECK; |
| 4551 | else if (pwe == 1) |
| 4552 | sae_pwe = NL80211_SAE_PWE_HASH_TO_ELEMENT; |
| 4553 | else if (pwe == 2) |
| 4554 | sae_pwe = NL80211_SAE_PWE_BOTH; |
| 4555 | else if (pwe == 3) |
| 4556 | return 0; /* special test mode */ |
| 4557 | else |
| 4558 | return -1; |
| 4559 | if (nla_put_u8(msg, NL80211_ATTR_SAE_PWE, sae_pwe)) |
| 4560 | return -1; |
| 4561 | |
| 4562 | return 0; |
| 4563 | } |
| 4564 | #endif /* CONFIG_SAE */ |
| 4565 | |
| 4566 | |
| 4567 | #ifdef CONFIG_FILS |
| 4568 | static int nl80211_fils_discovery(struct i802_bss *bss, struct nl_msg *msg, |
| 4569 | struct wpa_driver_ap_params *params) |
| 4570 | { |
| 4571 | struct nlattr *attr; |
| 4572 | |
| 4573 | if (!bss->drv->fils_discovery) { |
| 4574 | wpa_printf(MSG_ERROR, |
| 4575 | "nl80211: Driver does not support FILS Discovery frame transmission for %s", |
| 4576 | bss->ifname); |
| 4577 | return -1; |
| 4578 | } |
| 4579 | |
| 4580 | attr = nla_nest_start(msg, NL80211_ATTR_FILS_DISCOVERY); |
| 4581 | if (!attr || |
| 4582 | nla_put_u32(msg, NL80211_FILS_DISCOVERY_ATTR_INT_MIN, |
| 4583 | params->fd_min_int) || |
| 4584 | nla_put_u32(msg, NL80211_FILS_DISCOVERY_ATTR_INT_MAX, |
| 4585 | params->fd_max_int) || |
| 4586 | (params->fd_frame_tmpl && |
| 4587 | nla_put(msg, NL80211_FILS_DISCOVERY_ATTR_TMPL, |
| 4588 | params->fd_frame_tmpl_len, params->fd_frame_tmpl))) |
| 4589 | return -1; |
| 4590 | |
| 4591 | nla_nest_end(msg, attr); |
| 4592 | return 0; |
| 4593 | } |
| 4594 | #endif /* CONFIG_FILS */ |
| 4595 | |
| 4596 | |
| 4597 | #ifdef CONFIG_IEEE80211AX |
| 4598 | static int nl80211_unsol_bcast_probe_resp(struct i802_bss *bss, |
| 4599 | struct nl_msg *msg, |
| 4600 | struct wpa_driver_ap_params *params) |
| 4601 | { |
| 4602 | struct nlattr *attr; |
| 4603 | |
| 4604 | if (!bss->drv->unsol_bcast_probe_resp) { |
| 4605 | wpa_printf(MSG_ERROR, |
| 4606 | "nl80211: Driver does not support unsolicited broadcast Probe Response frame transmission for %s", |
| 4607 | bss->ifname); |
| 4608 | return -1; |
| 4609 | } |
| 4610 | |
| 4611 | wpa_printf(MSG_DEBUG, |
| 4612 | "nl80211: Unsolicited broadcast Probe Response frame interval: %u", |
| 4613 | params->unsol_bcast_probe_resp_interval); |
| 4614 | attr = nla_nest_start(msg, NL80211_ATTR_UNSOL_BCAST_PROBE_RESP); |
| 4615 | if (!attr || |
| 4616 | nla_put_u32(msg, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_INT, |
| 4617 | params->unsol_bcast_probe_resp_interval) || |
| 4618 | (params->unsol_bcast_probe_resp_tmpl && |
| 4619 | nla_put(msg, NL80211_UNSOL_BCAST_PROBE_RESP_ATTR_TMPL, |
| 4620 | params->unsol_bcast_probe_resp_tmpl_len, |
| 4621 | params->unsol_bcast_probe_resp_tmpl))) |
| 4622 | return -1; |
| 4623 | |
| 4624 | nla_nest_end(msg, attr); |
| 4625 | return 0; |
| 4626 | } |
| 4627 | #endif /* CONFIG_IEEE80211AX */ |
| 4628 | |
| 4629 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4630 | static int wpa_driver_nl80211_set_ap(void *priv, |
| 4631 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4632 | { |
| 4633 | struct i802_bss *bss = priv; |
| 4634 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4635 | struct nl_msg *msg; |
| 4636 | u8 cmd = NL80211_CMD_NEW_BEACON; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4637 | int ret = -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4638 | int beacon_set; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4639 | int num_suites; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4640 | u32 suites[20], suite; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4641 | u32 ver; |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4642 | #ifdef CONFIG_MESH |
| 4643 | struct wpa_driver_mesh_bss_params mesh_params; |
| 4644 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4645 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4646 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4647 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4648 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
| 4649 | beacon_set); |
| 4650 | if (beacon_set) |
| 4651 | cmd = NL80211_CMD_SET_BEACON; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4652 | else if (!drv->device_ap_sme && !drv->use_monitor && |
| 4653 | !nl80211_get_wiphy_data_ap(bss)) |
| 4654 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4655 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4656 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
| 4657 | params->head, params->head_len); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4658 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
| 4659 | params->tail, params->tail_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4660 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4661 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4662 | wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate); |
| 4663 | wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4664 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4665 | wpa_printf(MSG_DEBUG, "nl80211: ssid=%s", |
| 4666 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4667 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 4668 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
| 4669 | params->head) || |
| 4670 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, |
| 4671 | params->tail) || |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4672 | nl80211_put_beacon_int(msg, params->beacon_int) || |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4673 | nl80211_put_beacon_rate(msg, drv->capa.flags, drv->capa.flags2, |
| 4674 | params) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4675 | nl80211_put_dtim_period(msg, params->dtim_period) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4676 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 4677 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4678 | if (params->proberesp && params->proberesp_len) { |
| 4679 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", |
| 4680 | params->proberesp, params->proberesp_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4681 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
| 4682 | params->proberesp)) |
| 4683 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4684 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4685 | switch (params->hide_ssid) { |
| 4686 | case NO_SSID_HIDING: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4687 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4688 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 4689 | NL80211_HIDDEN_SSID_NOT_IN_USE)) |
| 4690 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4691 | break; |
| 4692 | case HIDDEN_SSID_ZERO_LEN: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4693 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4694 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 4695 | NL80211_HIDDEN_SSID_ZERO_LEN)) |
| 4696 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4697 | break; |
| 4698 | case HIDDEN_SSID_ZERO_CONTENTS: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4699 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4700 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 4701 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) |
| 4702 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4703 | break; |
| 4704 | } |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4705 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4706 | if (params->privacy && |
| 4707 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 4708 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4709 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4710 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
| 4711 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { |
| 4712 | /* Leave out the attribute */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4713 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
| 4714 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 4715 | NL80211_AUTHTYPE_SHARED_KEY)) |
| 4716 | goto fail; |
| 4717 | } else { |
| 4718 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 4719 | NL80211_AUTHTYPE_OPEN_SYSTEM)) |
| 4720 | goto fail; |
| 4721 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4722 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4723 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4724 | ver = 0; |
| 4725 | if (params->wpa_version & WPA_PROTO_WPA) |
| 4726 | ver |= NL80211_WPA_VERSION_1; |
| 4727 | if (params->wpa_version & WPA_PROTO_RSN) |
| 4728 | ver |= NL80211_WPA_VERSION_2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4729 | if (ver && |
| 4730 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 4731 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4732 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4733 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
| 4734 | params->key_mgmt_suites); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4735 | num_suites = wpa_key_mgmt_to_suites(params->key_mgmt_suites, |
| 4736 | suites, ARRAY_SIZE(suites)); |
| 4737 | if (num_suites > NL80211_MAX_NR_AKM_SUITES) |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4738 | wpa_printf(MSG_DEBUG, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4739 | "nl80211: Not enough room for all AKM suites (num_suites=%d > NL80211_MAX_NR_AKM_SUITES)", |
| 4740 | num_suites); |
| 4741 | else if (num_suites && |
| 4742 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), |
| 4743 | suites)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4744 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4745 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4746 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4747 | (!params->pairwise_ciphers || |
| 4748 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) && |
| 4749 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 4750 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4751 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4752 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4753 | if (drv->device_ap_sme && |
| 4754 | (params->key_mgmt_suites & WPA_KEY_MGMT_SAE) && |
| 4755 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) |
| 4756 | goto fail; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 4757 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4758 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
| 4759 | params->pairwise_ciphers); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4760 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
| 4761 | suites, ARRAY_SIZE(suites)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4762 | if (num_suites && |
| 4763 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 4764 | num_suites * sizeof(u32), suites)) |
| 4765 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4766 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4767 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
| 4768 | params->group_cipher); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4769 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4770 | if (suite && |
| 4771 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) |
| 4772 | goto fail; |
| 4773 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4774 | if (params->beacon_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4775 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
| 4776 | params->beacon_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4777 | if (nla_put(msg, NL80211_ATTR_IE, |
| 4778 | wpabuf_len(params->beacon_ies), |
| 4779 | wpabuf_head(params->beacon_ies))) |
| 4780 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4781 | } |
| 4782 | if (params->proberesp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4783 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
| 4784 | params->proberesp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4785 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 4786 | wpabuf_len(params->proberesp_ies), |
| 4787 | wpabuf_head(params->proberesp_ies))) |
| 4788 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4789 | } |
| 4790 | if (params->assocresp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4791 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
| 4792 | params->assocresp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4793 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 4794 | wpabuf_len(params->assocresp_ies), |
| 4795 | wpabuf_head(params->assocresp_ies))) |
| 4796 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4797 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4798 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4799 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4800 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
| 4801 | params->ap_max_inactivity); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4802 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
| 4803 | params->ap_max_inactivity)) |
| 4804 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4805 | } |
| 4806 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4807 | #ifdef CONFIG_P2P |
| 4808 | if (params->p2p_go_ctwindow > 0) { |
| 4809 | if (drv->p2p_go_ctwindow_supported) { |
| 4810 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", |
| 4811 | params->p2p_go_ctwindow); |
| 4812 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, |
| 4813 | params->p2p_go_ctwindow)) |
| 4814 | goto fail; |
| 4815 | } else { |
| 4816 | wpa_printf(MSG_INFO, |
| 4817 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); |
| 4818 | } |
| 4819 | } |
| 4820 | #endif /* CONFIG_P2P */ |
| 4821 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4822 | if (params->pbss) { |
| 4823 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); |
| 4824 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 4825 | goto fail; |
| 4826 | } |
| 4827 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4828 | if (params->ftm_responder) { |
| 4829 | struct nlattr *ftm; |
| 4830 | |
| 4831 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_FTM_RESPONDER)) { |
| 4832 | ret = -ENOTSUP; |
| 4833 | goto fail; |
| 4834 | } |
| 4835 | |
| 4836 | ftm = nla_nest_start(msg, NL80211_ATTR_FTM_RESPONDER); |
| 4837 | if (!ftm || |
| 4838 | nla_put_flag(msg, NL80211_FTM_RESP_ATTR_ENABLED) || |
| 4839 | (params->lci && |
| 4840 | nla_put(msg, NL80211_FTM_RESP_ATTR_LCI, |
| 4841 | wpabuf_len(params->lci), |
| 4842 | wpabuf_head(params->lci))) || |
| 4843 | (params->civic && |
| 4844 | nla_put(msg, NL80211_FTM_RESP_ATTR_CIVICLOC, |
| 4845 | wpabuf_len(params->civic), |
| 4846 | wpabuf_head(params->civic)))) |
| 4847 | goto fail; |
| 4848 | nla_nest_end(msg, ftm); |
| 4849 | } |
| 4850 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4851 | #ifdef CONFIG_IEEE80211AX |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4852 | if (params->he_spr_ctrl) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4853 | struct nlattr *spr; |
| 4854 | |
| 4855 | spr = nla_nest_start(msg, NL80211_ATTR_HE_OBSS_PD); |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4856 | wpa_printf(MSG_DEBUG, "nl80211: he_spr_ctrl=0x%x", |
| 4857 | params->he_spr_ctrl); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4858 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4859 | if (!spr || |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4860 | nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_SR_CTRL, |
| 4861 | params->he_spr_ctrl) || |
| 4862 | ((params->he_spr_ctrl & |
| 4863 | SPATIAL_REUSE_NON_SRG_OFFSET_PRESENT) && |
| 4864 | nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_NON_SRG_MAX_OFFSET, |
| 4865 | params->he_spr_non_srg_obss_pd_max_offset))) |
| 4866 | goto fail; |
| 4867 | |
| 4868 | if ((params->he_spr_ctrl & |
| 4869 | SPATIAL_REUSE_SRG_INFORMATION_PRESENT) && |
| 4870 | (nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET, |
| 4871 | params->he_spr_srg_obss_pd_min_offset) || |
| 4872 | nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET, |
| 4873 | params->he_spr_srg_obss_pd_max_offset) || |
| 4874 | nla_put(msg, NL80211_HE_OBSS_PD_ATTR_BSS_COLOR_BITMAP, |
| 4875 | sizeof(params->he_spr_bss_color_bitmap), |
| 4876 | params->he_spr_bss_color_bitmap) || |
| 4877 | nla_put(msg, NL80211_HE_OBSS_PD_ATTR_PARTIAL_BSSID_BITMAP, |
| 4878 | sizeof(params->he_spr_partial_bssid_bitmap), |
| 4879 | params->he_spr_partial_bssid_bitmap))) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4880 | goto fail; |
| 4881 | |
| 4882 | nla_nest_end(msg, spr); |
| 4883 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4884 | |
| 4885 | if (params->freq && params->freq->he_enabled) { |
| 4886 | struct nlattr *bss_color; |
| 4887 | |
| 4888 | bss_color = nla_nest_start(msg, NL80211_ATTR_HE_BSS_COLOR); |
| 4889 | if (!bss_color || |
| 4890 | (params->he_bss_color_disabled && |
| 4891 | nla_put_flag(msg, NL80211_HE_BSS_COLOR_ATTR_DISABLED)) || |
| 4892 | (params->he_bss_color_partial && |
| 4893 | nla_put_flag(msg, NL80211_HE_BSS_COLOR_ATTR_PARTIAL)) || |
| 4894 | nla_put_u8(msg, NL80211_HE_BSS_COLOR_ATTR_COLOR, |
| 4895 | params->he_bss_color)) |
| 4896 | goto fail; |
| 4897 | nla_nest_end(msg, bss_color); |
| 4898 | } |
| 4899 | |
| 4900 | if (params->twt_responder) { |
| 4901 | wpa_printf(MSG_DEBUG, "nl80211: twt_responder=%d", |
| 4902 | params->twt_responder); |
| 4903 | if (nla_put_flag(msg, NL80211_ATTR_TWT_RESPONDER)) |
| 4904 | goto fail; |
| 4905 | } |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4906 | |
| 4907 | if (params->unsol_bcast_probe_resp_interval && |
| 4908 | nl80211_unsol_bcast_probe_resp(bss, msg, params) < 0) |
| 4909 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4910 | #endif /* CONFIG_IEEE80211AX */ |
| 4911 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 4912 | #ifdef CONFIG_SAE |
| 4913 | if (((params->key_mgmt_suites & WPA_KEY_MGMT_SAE) || |
| 4914 | (params->key_mgmt_suites & WPA_KEY_MGMT_FT_SAE)) && |
| 4915 | nl80211_put_sae_pwe(msg, params->sae_pwe) < 0) |
| 4916 | goto fail; |
| 4917 | #endif /* CONFIG_SAE */ |
| 4918 | |
| 4919 | #ifdef CONFIG_FILS |
| 4920 | if (params->fd_max_int && nl80211_fils_discovery(bss, msg, params) < 0) |
| 4921 | goto fail; |
| 4922 | #endif /* CONFIG_FILS */ |
| 4923 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 4924 | ret = send_and_recv_msgs_connect_handle(drv, msg, bss, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4925 | if (ret) { |
| 4926 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", |
| 4927 | ret, strerror(-ret)); |
| 4928 | } else { |
| 4929 | bss->beacon_set = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4930 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
| 4931 | params->short_slot_time, params->ht_opmode, |
| 4932 | params->isolate, params->basic_rates); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4933 | nl80211_set_multicast_to_unicast(bss, |
| 4934 | params->multicast_to_unicast); |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4935 | if (beacon_set && params->freq && |
| 4936 | params->freq->bandwidth != bss->bandwidth) { |
| 4937 | wpa_printf(MSG_DEBUG, |
| 4938 | "nl80211: Update BSS %s bandwidth: %d -> %d", |
| 4939 | bss->ifname, bss->bandwidth, |
| 4940 | params->freq->bandwidth); |
| 4941 | ret = nl80211_set_channel(bss, params->freq, 1); |
| 4942 | if (ret) { |
| 4943 | wpa_printf(MSG_DEBUG, |
| 4944 | "nl80211: Frequency set failed: %d (%s)", |
| 4945 | ret, strerror(-ret)); |
| 4946 | } else { |
| 4947 | wpa_printf(MSG_DEBUG, |
| 4948 | "nl80211: Frequency set succeeded for ht2040 coex"); |
| 4949 | bss->bandwidth = params->freq->bandwidth; |
| 4950 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4951 | } else if (!beacon_set && params->freq) { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4952 | /* |
| 4953 | * cfg80211 updates the driver on frequence change in AP |
| 4954 | * mode only at the point when beaconing is started, so |
| 4955 | * set the initial value here. |
| 4956 | */ |
| 4957 | bss->bandwidth = params->freq->bandwidth; |
| 4958 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4959 | } |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4960 | |
| 4961 | #ifdef CONFIG_MESH |
| 4962 | if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) { |
| 4963 | os_memset(&mesh_params, 0, sizeof(mesh_params)); |
| 4964 | mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE; |
| 4965 | mesh_params.ht_opmode = params->ht_opmode; |
| 4966 | ret = nl80211_set_mesh_config(priv, &mesh_params); |
| 4967 | if (ret < 0) |
| 4968 | return ret; |
| 4969 | } |
| 4970 | #endif /* CONFIG_MESH */ |
| 4971 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4972 | return ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4973 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4974 | nlmsg_free(msg); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4975 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4976 | } |
| 4977 | |
| 4978 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4979 | static int nl80211_put_freq_params(struct nl_msg *msg, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4980 | const struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4981 | { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4982 | enum hostapd_hw_mode hw_mode; |
| 4983 | int is_24ghz; |
| 4984 | u8 channel; |
| 4985 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4986 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4987 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
| 4988 | return -ENOBUFS; |
| 4989 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4990 | wpa_printf(MSG_DEBUG, " * he_enabled=%d", freq->he_enabled); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4991 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
| 4992 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); |
| 4993 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4994 | hw_mode = ieee80211_freq_to_chan(freq->freq, &channel); |
| 4995 | is_24ghz = hw_mode == HOSTAPD_MODE_IEEE80211G || |
| 4996 | hw_mode == HOSTAPD_MODE_IEEE80211B; |
| 4997 | |
| 4998 | if (freq->vht_enabled || (freq->he_enabled && !is_24ghz)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4999 | enum nl80211_chan_width cw; |
| 5000 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5001 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5002 | switch (freq->bandwidth) { |
| 5003 | case 20: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5004 | cw = NL80211_CHAN_WIDTH_20; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5005 | break; |
| 5006 | case 40: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5007 | cw = NL80211_CHAN_WIDTH_40; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5008 | break; |
| 5009 | case 80: |
| 5010 | if (freq->center_freq2) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5011 | cw = NL80211_CHAN_WIDTH_80P80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5012 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5013 | cw = NL80211_CHAN_WIDTH_80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5014 | break; |
| 5015 | case 160: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5016 | cw = NL80211_CHAN_WIDTH_160; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5017 | break; |
| 5018 | default: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5019 | return -EINVAL; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5020 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5021 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5022 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
| 5023 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", |
| 5024 | freq->center_freq1); |
| 5025 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", |
| 5026 | freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5027 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
| 5028 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, |
| 5029 | freq->center_freq1) || |
| 5030 | (freq->center_freq2 && |
| 5031 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 5032 | freq->center_freq2))) |
| 5033 | return -ENOBUFS; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5034 | } else if (freq->ht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5035 | enum nl80211_channel_type ct; |
| 5036 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5037 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
| 5038 | freq->sec_channel_offset); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5039 | switch (freq->sec_channel_offset) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5040 | case -1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5041 | ct = NL80211_CHAN_HT40MINUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5042 | break; |
| 5043 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5044 | ct = NL80211_CHAN_HT40PLUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5045 | break; |
| 5046 | default: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5047 | ct = NL80211_CHAN_HT20; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5048 | break; |
| 5049 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5050 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5051 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5052 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
| 5053 | return -ENOBUFS; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5054 | } else if (freq->edmg.channels && freq->edmg.bw_config) { |
| 5055 | wpa_printf(MSG_DEBUG, |
| 5056 | " * EDMG configuration: channels=0x%x bw_config=%d", |
| 5057 | freq->edmg.channels, freq->edmg.bw_config); |
| 5058 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS, |
| 5059 | freq->edmg.channels) || |
| 5060 | nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG, |
| 5061 | freq->edmg.bw_config)) |
| 5062 | return -1; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5063 | } else { |
| 5064 | wpa_printf(MSG_DEBUG, " * channel_type=%d", |
| 5065 | NL80211_CHAN_NO_HT); |
| 5066 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 5067 | NL80211_CHAN_NO_HT)) |
| 5068 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5069 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5070 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5071 | } |
| 5072 | |
| 5073 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5074 | static int nl80211_set_channel(struct i802_bss *bss, |
| 5075 | struct hostapd_freq_params *freq, int set_chan) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5076 | { |
| 5077 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5078 | struct nl_msg *msg; |
| 5079 | int ret; |
| 5080 | |
| 5081 | wpa_printf(MSG_DEBUG, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5082 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, he_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
| 5083 | freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5084 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5085 | |
| 5086 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
| 5087 | NL80211_CMD_SET_WIPHY); |
| 5088 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { |
| 5089 | nlmsg_free(msg); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 5090 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5091 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5092 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5093 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5094 | if (ret == 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5095 | bss->freq = freq->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5096 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5097 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5098 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5099 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5100 | return -1; |
| 5101 | } |
| 5102 | |
| 5103 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5104 | static u32 sta_flags_nl80211(int flags) |
| 5105 | { |
| 5106 | u32 f = 0; |
| 5107 | |
| 5108 | if (flags & WPA_STA_AUTHORIZED) |
| 5109 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 5110 | if (flags & WPA_STA_WMM) |
| 5111 | f |= BIT(NL80211_STA_FLAG_WME); |
| 5112 | if (flags & WPA_STA_SHORT_PREAMBLE) |
| 5113 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
| 5114 | if (flags & WPA_STA_MFP) |
| 5115 | f |= BIT(NL80211_STA_FLAG_MFP); |
| 5116 | if (flags & WPA_STA_TDLS_PEER) |
| 5117 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5118 | if (flags & WPA_STA_AUTHENTICATED) |
| 5119 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5120 | if (flags & WPA_STA_ASSOCIATED) |
| 5121 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5122 | |
| 5123 | return f; |
| 5124 | } |
| 5125 | |
| 5126 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5127 | #ifdef CONFIG_MESH |
| 5128 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) |
| 5129 | { |
| 5130 | switch (state) { |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5131 | case PLINK_IDLE: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5132 | return NL80211_PLINK_LISTEN; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5133 | case PLINK_OPN_SNT: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5134 | return NL80211_PLINK_OPN_SNT; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5135 | case PLINK_OPN_RCVD: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5136 | return NL80211_PLINK_OPN_RCVD; |
| 5137 | case PLINK_CNF_RCVD: |
| 5138 | return NL80211_PLINK_CNF_RCVD; |
| 5139 | case PLINK_ESTAB: |
| 5140 | return NL80211_PLINK_ESTAB; |
| 5141 | case PLINK_HOLDING: |
| 5142 | return NL80211_PLINK_HOLDING; |
| 5143 | case PLINK_BLOCKED: |
| 5144 | return NL80211_PLINK_BLOCKED; |
| 5145 | default: |
| 5146 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", |
| 5147 | state); |
| 5148 | } |
| 5149 | return -1; |
| 5150 | } |
| 5151 | #endif /* CONFIG_MESH */ |
| 5152 | |
| 5153 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5154 | static int wpa_driver_nl80211_sta_add(void *priv, |
| 5155 | struct hostapd_sta_add_params *params) |
| 5156 | { |
| 5157 | struct i802_bss *bss = priv; |
| 5158 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5159 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5160 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5161 | int ret = -ENOBUFS; |
| 5162 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5163 | if ((params->flags & WPA_STA_TDLS_PEER) && |
| 5164 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 5165 | return -EOPNOTSUPP; |
| 5166 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5167 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
| 5168 | params->set ? "Set" : "Add", MAC2STR(params->addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5169 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
| 5170 | NL80211_CMD_NEW_STATION); |
| 5171 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) |
| 5172 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5173 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5174 | /* |
| 5175 | * Set the below properties only in one of the following cases: |
| 5176 | * 1. New station is added, already associated. |
| 5177 | * 2. Set WPA_STA_TDLS_PEER station. |
| 5178 | * 3. Set an already added unassociated station, if driver supports |
| 5179 | * full AP client state. (Set these properties after station became |
| 5180 | * associated will be rejected by the driver). |
| 5181 | */ |
| 5182 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
| 5183 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 5184 | (params->flags & WPA_STA_ASSOCIATED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5185 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
| 5186 | params->supp_rates, params->supp_rates_len); |
| 5187 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
| 5188 | params->capability); |
| 5189 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, |
| 5190 | params->supp_rates_len, params->supp_rates) || |
| 5191 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, |
| 5192 | params->capability)) |
| 5193 | goto fail; |
| 5194 | |
| 5195 | if (params->ht_capabilities) { |
| 5196 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
| 5197 | (u8 *) params->ht_capabilities, |
| 5198 | sizeof(*params->ht_capabilities)); |
| 5199 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
| 5200 | sizeof(*params->ht_capabilities), |
| 5201 | params->ht_capabilities)) |
| 5202 | goto fail; |
| 5203 | } |
| 5204 | |
| 5205 | if (params->vht_capabilities) { |
| 5206 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
| 5207 | (u8 *) params->vht_capabilities, |
| 5208 | sizeof(*params->vht_capabilities)); |
| 5209 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
| 5210 | sizeof(*params->vht_capabilities), |
| 5211 | params->vht_capabilities)) |
| 5212 | goto fail; |
| 5213 | } |
| 5214 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5215 | if (params->he_capab) { |
| 5216 | wpa_hexdump(MSG_DEBUG, " * he_capab", |
| 5217 | params->he_capab, params->he_capab_len); |
| 5218 | if (nla_put(msg, NL80211_ATTR_HE_CAPABILITY, |
| 5219 | params->he_capab_len, params->he_capab)) |
| 5220 | goto fail; |
| 5221 | } |
| 5222 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5223 | if (params->he_6ghz_capab) { |
| 5224 | wpa_hexdump(MSG_DEBUG, " * he_6ghz_capab", |
| 5225 | params->he_6ghz_capab, |
| 5226 | sizeof(*params->he_6ghz_capab)); |
| 5227 | if (nla_put(msg, NL80211_ATTR_HE_6GHZ_CAPABILITY, |
| 5228 | sizeof(*params->he_6ghz_capab), |
| 5229 | params->he_6ghz_capab)) |
| 5230 | goto fail; |
| 5231 | } |
| 5232 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5233 | if (params->ext_capab) { |
| 5234 | wpa_hexdump(MSG_DEBUG, " * ext_capab", |
| 5235 | params->ext_capab, params->ext_capab_len); |
| 5236 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
| 5237 | params->ext_capab_len, params->ext_capab)) |
| 5238 | goto fail; |
| 5239 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5240 | |
| 5241 | if (is_ap_interface(drv->nlmode) && |
| 5242 | nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS, |
| 5243 | params->support_p2p_ps ? |
| 5244 | NL80211_P2P_PS_SUPPORTED : |
| 5245 | NL80211_P2P_PS_UNSUPPORTED)) |
| 5246 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5247 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5248 | if (!params->set) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 5249 | if (params->aid) { |
| 5250 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5251 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
| 5252 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 5253 | } else { |
| 5254 | /* |
| 5255 | * cfg80211 validates that AID is non-zero, so we have |
| 5256 | * to make this a non-zero value for the TDLS case where |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5257 | * a stub STA entry is used for now and for a station |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5258 | * that is still not associated. |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 5259 | */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5260 | wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)", |
| 5261 | (params->flags & WPA_STA_TDLS_PEER) ? |
| 5262 | "TDLS" : "UNASSOC_STA"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5263 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
| 5264 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 5265 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5266 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 5267 | params->listen_interval); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5268 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 5269 | params->listen_interval)) |
| 5270 | goto fail; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5271 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
| 5272 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5273 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
| 5274 | goto fail; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5275 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 5276 | (params->flags & WPA_STA_ASSOCIATED)) { |
| 5277 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
| 5278 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 5279 | params->listen_interval); |
| 5280 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || |
| 5281 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 5282 | params->listen_interval)) |
| 5283 | goto fail; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5284 | } |
| 5285 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 5286 | if (params->vht_opmode_enabled) { |
| 5287 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5288 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
| 5289 | params->vht_opmode)) |
| 5290 | goto fail; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5291 | } |
| 5292 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5293 | if (params->supp_channels) { |
| 5294 | wpa_hexdump(MSG_DEBUG, " * supported channels", |
| 5295 | params->supp_channels, params->supp_channels_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5296 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
| 5297 | params->supp_channels_len, params->supp_channels)) |
| 5298 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5299 | } |
| 5300 | |
| 5301 | if (params->supp_oper_classes) { |
| 5302 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", |
| 5303 | params->supp_oper_classes, |
| 5304 | params->supp_oper_classes_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5305 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
| 5306 | params->supp_oper_classes_len, |
| 5307 | params->supp_oper_classes)) |
| 5308 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5309 | } |
| 5310 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5311 | os_memset(&upd, 0, sizeof(upd)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5312 | upd.set = sta_flags_nl80211(params->flags); |
| 5313 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5314 | |
| 5315 | /* |
| 5316 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH |
| 5317 | * flags, as nl80211 driver moves a new station, by default, into |
| 5318 | * associated state. |
| 5319 | * |
| 5320 | * On the other hand, if the driver supports that feature and the |
| 5321 | * station is added in unauthenticated state, set the |
| 5322 | * authenticated/associated bits in the mask to prevent moving this |
| 5323 | * station to associated state before it is actually associated. |
| 5324 | * |
| 5325 | * This is irrelevant for mesh mode where the station is added to the |
| 5326 | * driver as authenticated already, and ASSOCIATED isn't part of the |
| 5327 | * nl80211 API. |
| 5328 | */ |
| 5329 | if (!is_mesh_interface(drv->nlmode)) { |
| 5330 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { |
| 5331 | wpa_printf(MSG_DEBUG, |
| 5332 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); |
| 5333 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 5334 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); |
| 5335 | } else if (!params->set && |
| 5336 | !(params->flags & WPA_STA_TDLS_PEER)) { |
| 5337 | if (!(params->flags & WPA_STA_AUTHENTICATED)) |
| 5338 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
| 5339 | if (!(params->flags & WPA_STA_ASSOCIATED)) |
| 5340 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 5341 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5342 | #ifdef CONFIG_MESH |
| 5343 | } else { |
| 5344 | if (params->plink_state == PLINK_ESTAB && params->peer_aid) { |
| 5345 | ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID, |
| 5346 | params->peer_aid); |
| 5347 | if (ret) |
| 5348 | goto fail; |
| 5349 | } |
| 5350 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5351 | } |
| 5352 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5353 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
| 5354 | upd.set, upd.mask); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5355 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 5356 | goto fail; |
| 5357 | |
| 5358 | #ifdef CONFIG_MESH |
| 5359 | if (params->plink_state && |
| 5360 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, |
| 5361 | sta_plink_state_nl80211(params->plink_state))) |
| 5362 | goto fail; |
| 5363 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5364 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5365 | if ((!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
| 5366 | FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) && |
| 5367 | (params->flags & WPA_STA_WMM)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5368 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 5369 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5370 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5371 | if (!wme || |
| 5372 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 5373 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || |
| 5374 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, |
| 5375 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
| 5376 | WMM_QOSINFO_STA_SP_MASK)) |
| 5377 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5378 | nla_nest_end(msg, wme); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5379 | } |
| 5380 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5381 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5382 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5383 | if (ret) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5384 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
| 5385 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, |
| 5386 | strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5387 | if (ret == -EEXIST) |
| 5388 | ret = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5389 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5390 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5391 | return ret; |
| 5392 | } |
| 5393 | |
| 5394 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5395 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
| 5396 | { |
| 5397 | #ifdef CONFIG_LIBNL3_ROUTE |
| 5398 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5399 | struct rtnl_neigh *rn; |
| 5400 | struct nl_addr *nl_addr; |
| 5401 | int err; |
| 5402 | |
| 5403 | rn = rtnl_neigh_alloc(); |
| 5404 | if (!rn) |
| 5405 | return; |
| 5406 | |
| 5407 | rtnl_neigh_set_family(rn, AF_BRIDGE); |
| 5408 | rtnl_neigh_set_ifindex(rn, bss->ifindex); |
| 5409 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); |
| 5410 | if (!nl_addr) { |
| 5411 | rtnl_neigh_put(rn); |
| 5412 | return; |
| 5413 | } |
| 5414 | rtnl_neigh_set_lladdr(rn, nl_addr); |
| 5415 | |
| 5416 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 5417 | if (err < 0) { |
| 5418 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " |
| 5419 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), |
| 5420 | bss->ifindex, nl_geterror(err)); |
| 5421 | } else { |
| 5422 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " |
| 5423 | MACSTR, MAC2STR(addr)); |
| 5424 | } |
| 5425 | |
| 5426 | nl_addr_put(nl_addr); |
| 5427 | rtnl_neigh_put(rn); |
| 5428 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 5429 | } |
| 5430 | |
| 5431 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5432 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
| 5433 | int deauth, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5434 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5435 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5436 | struct nl_msg *msg; |
| 5437 | int ret; |
| 5438 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5439 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
| 5440 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 5441 | (deauth == 0 && |
| 5442 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 5443 | WLAN_FC_STYPE_DISASSOC)) || |
| 5444 | (deauth == 1 && |
| 5445 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 5446 | WLAN_FC_STYPE_DEAUTH)) || |
| 5447 | (reason_code && |
| 5448 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { |
| 5449 | nlmsg_free(msg); |
| 5450 | return -ENOBUFS; |
| 5451 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5452 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5453 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5454 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
| 5455 | " --> %d (%s)", |
| 5456 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5457 | |
| 5458 | if (drv->rtnl_sk) |
| 5459 | rtnl_neigh_delete_fdb_entry(bss, addr); |
| 5460 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5461 | if (ret == -ENOENT) |
| 5462 | return 0; |
| 5463 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5464 | } |
| 5465 | |
| 5466 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5467 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5468 | { |
| 5469 | struct nl_msg *msg; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5470 | struct wpa_driver_nl80211_data *drv2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5471 | |
| 5472 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
| 5473 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5474 | /* stop listening for EAPOL on this interface */ |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5475 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 5476 | struct wpa_driver_nl80211_data, list) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5477 | { |
| 5478 | del_ifidx(drv2, ifidx, IFIDX_ANY); |
| 5479 | /* Remove all bridges learned for this iface */ |
| 5480 | del_ifidx(drv2, IFIDX_ANY, ifidx); |
| 5481 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5482 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5483 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5484 | if (send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5485 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5486 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
| 5487 | } |
| 5488 | |
| 5489 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5490 | const char * nl80211_iftype_str(enum nl80211_iftype mode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5491 | { |
| 5492 | switch (mode) { |
| 5493 | case NL80211_IFTYPE_ADHOC: |
| 5494 | return "ADHOC"; |
| 5495 | case NL80211_IFTYPE_STATION: |
| 5496 | return "STATION"; |
| 5497 | case NL80211_IFTYPE_AP: |
| 5498 | return "AP"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 5499 | case NL80211_IFTYPE_AP_VLAN: |
| 5500 | return "AP_VLAN"; |
| 5501 | case NL80211_IFTYPE_WDS: |
| 5502 | return "WDS"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5503 | case NL80211_IFTYPE_MONITOR: |
| 5504 | return "MONITOR"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 5505 | case NL80211_IFTYPE_MESH_POINT: |
| 5506 | return "MESH_POINT"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5507 | case NL80211_IFTYPE_P2P_CLIENT: |
| 5508 | return "P2P_CLIENT"; |
| 5509 | case NL80211_IFTYPE_P2P_GO: |
| 5510 | return "P2P_GO"; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5511 | case NL80211_IFTYPE_P2P_DEVICE: |
| 5512 | return "P2P_DEVICE"; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 5513 | case NL80211_IFTYPE_OCB: |
| 5514 | return "OCB"; |
| 5515 | case NL80211_IFTYPE_NAN: |
| 5516 | return "NAN"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5517 | default: |
| 5518 | return "unknown"; |
| 5519 | } |
| 5520 | } |
| 5521 | |
| 5522 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5523 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
| 5524 | const char *ifname, |
| 5525 | enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5526 | const u8 *addr, int wds, |
| 5527 | int (*handler)(struct nl_msg *, void *), |
| 5528 | void *arg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5529 | { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5530 | struct nl_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5531 | int ifidx; |
| 5532 | int ret = -ENOBUFS; |
| 5533 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5534 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
| 5535 | iftype, nl80211_iftype_str(iftype)); |
| 5536 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5537 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
| 5538 | if (!msg || |
| 5539 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
| 5540 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) |
| 5541 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5542 | |
| 5543 | if (iftype == NL80211_IFTYPE_MONITOR) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5544 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5545 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5546 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5547 | if (!flags || |
| 5548 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) |
| 5549 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5550 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5551 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5552 | } else if (wds) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5553 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
| 5554 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5555 | } |
| 5556 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 5557 | /* |
| 5558 | * Tell cfg80211 that the interface belongs to the socket that created |
| 5559 | * it, and the interface should be deleted when the socket is closed. |
| 5560 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5561 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 5562 | goto fail; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 5563 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 5564 | if ((addr && iftype == NL80211_IFTYPE_P2P_DEVICE) && |
| 5565 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 5566 | goto fail; |
| 5567 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5568 | ret = send_and_recv_msgs(drv, msg, handler, arg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5569 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5570 | if (ret) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5571 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5572 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5573 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
| 5574 | ifname, ret, strerror(-ret)); |
| 5575 | return ret; |
| 5576 | } |
| 5577 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5578 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
| 5579 | return 0; |
| 5580 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5581 | ifidx = if_nametoindex(ifname); |
| 5582 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
| 5583 | ifname, ifidx); |
| 5584 | |
| 5585 | if (ifidx <= 0) |
| 5586 | return -1; |
| 5587 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5588 | /* |
| 5589 | * Some virtual interfaces need to process EAPOL packets and events on |
| 5590 | * the parent interface. This is used mainly with hostapd. |
| 5591 | */ |
| 5592 | if (drv->hostapd || |
| 5593 | iftype == NL80211_IFTYPE_AP_VLAN || |
| 5594 | iftype == NL80211_IFTYPE_WDS || |
| 5595 | iftype == NL80211_IFTYPE_MONITOR) { |
| 5596 | /* start listening for EAPOL on this interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5597 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5598 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5599 | |
| 5600 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5601 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5602 | nl80211_remove_iface(drv, ifidx); |
| 5603 | return -1; |
| 5604 | } |
| 5605 | |
| 5606 | return ifidx; |
| 5607 | } |
| 5608 | |
| 5609 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5610 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
| 5611 | const char *ifname, enum nl80211_iftype iftype, |
| 5612 | const u8 *addr, int wds, |
| 5613 | int (*handler)(struct nl_msg *, void *), |
| 5614 | void *arg, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5615 | { |
| 5616 | int ret; |
| 5617 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5618 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
| 5619 | arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5620 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5621 | /* if error occurred and interface exists already */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5622 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5623 | if (use_existing) { |
| 5624 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", |
| 5625 | ifname); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5626 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
| 5627 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 5628 | addr) < 0 && |
| 5629 | (linux_set_iface_flags(drv->global->ioctl_sock, |
| 5630 | ifname, 0) < 0 || |
| 5631 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 5632 | addr) < 0 || |
| 5633 | linux_set_iface_flags(drv->global->ioctl_sock, |
| 5634 | ifname, 1) < 0)) |
| 5635 | return -1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5636 | return -ENFILE; |
| 5637 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5638 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
| 5639 | |
| 5640 | /* Try to remove the interface that was already there. */ |
| 5641 | nl80211_remove_iface(drv, if_nametoindex(ifname)); |
| 5642 | |
| 5643 | /* Try to create the interface again */ |
| 5644 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5645 | wds, handler, arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5646 | } |
| 5647 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5648 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
| 5649 | wpa_printf(MSG_DEBUG, |
| 5650 | "nl80211: Interface %s created for P2P - disable 11b rates", |
| 5651 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5652 | nl80211_disable_11b_rates(drv, ret, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5653 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5654 | |
| 5655 | return ret; |
| 5656 | } |
| 5657 | |
| 5658 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5659 | static int nl80211_setup_ap(struct i802_bss *bss) |
| 5660 | { |
| 5661 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5662 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5663 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 5664 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5665 | |
| 5666 | /* |
| 5667 | * Disable Probe Request reporting unless we need it in this way for |
| 5668 | * devices that include the AP SME, in the other case (unless using |
| 5669 | * monitor iface) we'll get it through the nl_mgmt socket instead. |
| 5670 | */ |
| 5671 | if (!drv->device_ap_sme) |
| 5672 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 5673 | |
| 5674 | if (!drv->device_ap_sme && !drv->use_monitor) |
| 5675 | if (nl80211_mgmt_subscribe_ap(bss)) |
| 5676 | return -1; |
| 5677 | |
| 5678 | if (drv->device_ap_sme && !drv->use_monitor) |
| 5679 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5680 | wpa_printf(MSG_DEBUG, |
| 5681 | "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] | 5682 | |
| 5683 | if (!drv->device_ap_sme && drv->use_monitor && |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 5684 | nl80211_create_monitor_interface(drv) && |
| 5685 | !drv->device_ap_sme) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5686 | return -1; |
| 5687 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5688 | if (drv->device_ap_sme && |
| 5689 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { |
| 5690 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " |
| 5691 | "Probe Request frame reporting in AP mode"); |
| 5692 | /* Try to survive without this */ |
| 5693 | } |
| 5694 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5695 | return 0; |
| 5696 | } |
| 5697 | |
| 5698 | |
| 5699 | static void nl80211_teardown_ap(struct i802_bss *bss) |
| 5700 | { |
| 5701 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5702 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5703 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 5704 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5705 | if (drv->device_ap_sme) { |
| 5706 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 5707 | if (!drv->use_monitor) |
| 5708 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); |
| 5709 | } else if (drv->use_monitor) |
| 5710 | nl80211_remove_monitor_interface(drv); |
| 5711 | else |
| 5712 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
| 5713 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5714 | nl80211_put_wiphy_data_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5715 | bss->beacon_set = 0; |
| 5716 | } |
| 5717 | |
| 5718 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5719 | static int nl80211_tx_control_port(void *priv, const u8 *dest, |
| 5720 | u16 proto, const u8 *buf, size_t len, |
| 5721 | int no_encrypt) |
| 5722 | { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5723 | struct nl80211_ack_ext_arg ext_arg; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5724 | struct i802_bss *bss = priv; |
| 5725 | struct nl_msg *msg; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5726 | u64 cookie = 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5727 | int ret; |
| 5728 | |
| 5729 | wpa_printf(MSG_DEBUG, |
| 5730 | "nl80211: Send over control port dest=" MACSTR |
| 5731 | " proto=0x%04x len=%u no_encrypt=%d", |
| 5732 | MAC2STR(dest), proto, (unsigned int) len, no_encrypt); |
| 5733 | |
| 5734 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CONTROL_PORT_FRAME); |
| 5735 | if (!msg || |
| 5736 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || |
| 5737 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dest) || |
| 5738 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 5739 | (no_encrypt && |
| 5740 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) { |
| 5741 | nlmsg_free(msg); |
| 5742 | return -ENOBUFS; |
| 5743 | } |
| 5744 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5745 | os_memset(&ext_arg, 0, sizeof(struct nl80211_ack_ext_arg)); |
| 5746 | ext_arg.ext_data = &cookie; |
| 5747 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL, |
| 5748 | ack_handler_cookie, &ext_arg); |
| 5749 | if (ret) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5750 | wpa_printf(MSG_DEBUG, |
| 5751 | "nl80211: tx_control_port failed: ret=%d (%s)", |
| 5752 | ret, strerror(-ret)); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5753 | } else { |
| 5754 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5755 | |
| 5756 | wpa_printf(MSG_DEBUG, |
| 5757 | "nl80211: tx_control_port cookie=0x%llx", |
| 5758 | (long long unsigned int) cookie); |
| 5759 | drv->eapol_tx_cookie = cookie; |
| 5760 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5761 | |
| 5762 | return ret; |
| 5763 | } |
| 5764 | |
| 5765 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5766 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
| 5767 | const u8 *addr, const u8 *data, |
| 5768 | size_t data_len) |
| 5769 | { |
| 5770 | struct sockaddr_ll ll; |
| 5771 | int ret; |
| 5772 | |
| 5773 | if (bss->drv->eapol_tx_sock < 0) { |
| 5774 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); |
| 5775 | return -1; |
| 5776 | } |
| 5777 | |
| 5778 | os_memset(&ll, 0, sizeof(ll)); |
| 5779 | ll.sll_family = AF_PACKET; |
| 5780 | ll.sll_ifindex = bss->ifindex; |
| 5781 | ll.sll_protocol = htons(ETH_P_PAE); |
| 5782 | ll.sll_halen = ETH_ALEN; |
| 5783 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); |
| 5784 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, |
| 5785 | (struct sockaddr *) &ll, sizeof(ll)); |
| 5786 | if (ret < 0) |
| 5787 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", |
| 5788 | strerror(errno)); |
| 5789 | |
| 5790 | return ret; |
| 5791 | } |
| 5792 | |
| 5793 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5794 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 5795 | |
| 5796 | static int wpa_driver_nl80211_hapd_send_eapol( |
| 5797 | void *priv, const u8 *addr, const u8 *data, |
| 5798 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
| 5799 | { |
| 5800 | struct i802_bss *bss = priv; |
| 5801 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5802 | struct ieee80211_hdr *hdr; |
| 5803 | size_t len; |
| 5804 | u8 *pos; |
| 5805 | int res; |
| 5806 | int qos = flags & WPA_STA_WMM; |
Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 5807 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 5808 | /* For now, disable EAPOL TX over control port in AP mode by default |
| 5809 | * since it does not provide TX status notifications. */ |
| 5810 | if (drv->control_port_ap && |
| 5811 | (drv->capa.flags & WPA_DRIVER_FLAGS_CONTROL_PORT)) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5812 | return nl80211_tx_control_port(bss, addr, ETH_P_EAPOL, |
| 5813 | data, data_len, !encrypt); |
| 5814 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5815 | if (drv->device_ap_sme || !drv->use_monitor) |
| 5816 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
| 5817 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5818 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
| 5819 | data_len; |
| 5820 | hdr = os_zalloc(len); |
| 5821 | if (hdr == NULL) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5822 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
| 5823 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5824 | return -1; |
| 5825 | } |
| 5826 | |
| 5827 | hdr->frame_control = |
| 5828 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); |
| 5829 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 5830 | if (encrypt) |
| 5831 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); |
| 5832 | if (qos) { |
| 5833 | hdr->frame_control |= |
| 5834 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); |
| 5835 | } |
| 5836 | |
| 5837 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 5838 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 5839 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 5840 | pos = (u8 *) (hdr + 1); |
| 5841 | |
| 5842 | if (qos) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 5843 | /* Set highest priority in QoS header */ |
| 5844 | pos[0] = 7; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5845 | pos[1] = 0; |
| 5846 | pos += 2; |
| 5847 | } |
| 5848 | |
| 5849 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); |
| 5850 | pos += sizeof(rfc1042_header); |
| 5851 | WPA_PUT_BE16(pos, ETH_P_PAE); |
| 5852 | pos += 2; |
| 5853 | memcpy(pos, data, data_len); |
| 5854 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5855 | res = nl80211_send_monitor(drv, hdr, len, encrypt, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5856 | if (res < 0) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5857 | wpa_printf(MSG_ERROR, |
| 5858 | "hapd_send_eapol - packet len: %lu - failed", |
| 5859 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5860 | } |
| 5861 | os_free(hdr); |
| 5862 | |
| 5863 | return res; |
| 5864 | } |
| 5865 | |
| 5866 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5867 | 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] | 5868 | unsigned int total_flags, |
| 5869 | unsigned int flags_or, |
| 5870 | unsigned int flags_and) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5871 | { |
| 5872 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5873 | struct nl_msg *msg; |
| 5874 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5875 | struct nl80211_sta_flag_update upd; |
| 5876 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5877 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
| 5878 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", |
| 5879 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, |
| 5880 | !!(total_flags & WPA_STA_AUTHORIZED)); |
| 5881 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5882 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5883 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 5884 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5885 | |
| 5886 | /* |
| 5887 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This |
| 5888 | * can be removed eventually. |
| 5889 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5890 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5891 | if (!flags || |
| 5892 | ((total_flags & WPA_STA_AUTHORIZED) && |
| 5893 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || |
| 5894 | ((total_flags & WPA_STA_WMM) && |
| 5895 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || |
| 5896 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && |
| 5897 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || |
| 5898 | ((total_flags & WPA_STA_MFP) && |
| 5899 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || |
| 5900 | ((total_flags & WPA_STA_TDLS_PEER) && |
| 5901 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) |
| 5902 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5903 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5904 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5905 | |
| 5906 | os_memset(&upd, 0, sizeof(upd)); |
| 5907 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); |
| 5908 | upd.set = sta_flags_nl80211(flags_or); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5909 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 5910 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5911 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5912 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5913 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5914 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5915 | return -ENOBUFS; |
| 5916 | } |
| 5917 | |
| 5918 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5919 | static int driver_nl80211_sta_set_airtime_weight(void *priv, const u8 *addr, |
| 5920 | unsigned int weight) |
| 5921 | { |
| 5922 | struct i802_bss *bss = priv; |
| 5923 | struct nl_msg *msg; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5924 | int ret; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5925 | |
| 5926 | wpa_printf(MSG_DEBUG, |
| 5927 | "nl80211: Set STA airtime weight - ifname=%s addr=" MACSTR |
| 5928 | " weight=%u", bss->ifname, MAC2STR(addr), weight); |
| 5929 | |
| 5930 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5931 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 5932 | nla_put_u16(msg, NL80211_ATTR_AIRTIME_WEIGHT, weight)) |
| 5933 | goto fail; |
| 5934 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5935 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
| 5936 | if (ret) { |
| 5937 | wpa_printf(MSG_DEBUG, |
| 5938 | "nl80211: SET_STATION[AIRTIME_WEIGHT] failed: ret=%d (%s)", |
| 5939 | ret, strerror(-ret)); |
| 5940 | } |
| 5941 | return ret; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5942 | fail: |
| 5943 | nlmsg_free(msg); |
| 5944 | return -ENOBUFS; |
| 5945 | } |
| 5946 | |
| 5947 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5948 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
| 5949 | struct wpa_driver_associate_params *params) |
| 5950 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5951 | enum nl80211_iftype nlmode, old_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5952 | |
| 5953 | if (params->p2p) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5954 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
| 5955 | "group (GO)"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5956 | nlmode = NL80211_IFTYPE_P2P_GO; |
| 5957 | } else |
| 5958 | nlmode = NL80211_IFTYPE_AP; |
| 5959 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5960 | old_mode = drv->nlmode; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5961 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5962 | nl80211_remove_monitor_interface(drv); |
| 5963 | return -1; |
| 5964 | } |
| 5965 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5966 | if (params->freq.freq && |
| 5967 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5968 | if (old_mode != nlmode) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5969 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5970 | nl80211_remove_monitor_interface(drv); |
| 5971 | return -1; |
| 5972 | } |
| 5973 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5974 | return 0; |
| 5975 | } |
| 5976 | |
| 5977 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5978 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 5979 | int reset_mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5980 | { |
| 5981 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5982 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5983 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5984 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 5985 | 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] | 5986 | if (ret) { |
| 5987 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " |
| 5988 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5989 | } else { |
| 5990 | wpa_printf(MSG_DEBUG, |
| 5991 | "nl80211: Leave IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5992 | } |
| 5993 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5994 | if (reset_mode && |
| 5995 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 5996 | NL80211_IFTYPE_STATION)) { |
| 5997 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 5998 | "station mode"); |
| 5999 | } |
| 6000 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6001 | return ret; |
| 6002 | } |
| 6003 | |
| 6004 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6005 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
| 6006 | struct wpa_driver_associate_params *params) |
| 6007 | { |
| 6008 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) |
| 6009 | return -1; |
| 6010 | |
| 6011 | if (params->htcaps && params->htcaps_mask) { |
| 6012 | int sz = sizeof(struct ieee80211_ht_capabilities); |
| 6013 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); |
| 6014 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", |
| 6015 | params->htcaps_mask, sz); |
| 6016 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, |
| 6017 | params->htcaps) || |
| 6018 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 6019 | params->htcaps_mask)) |
| 6020 | return -1; |
| 6021 | } |
| 6022 | |
| 6023 | #ifdef CONFIG_VHT_OVERRIDES |
| 6024 | if (params->disable_vht) { |
| 6025 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
| 6026 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) |
| 6027 | return -1; |
| 6028 | } |
| 6029 | |
| 6030 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 6031 | int sz = sizeof(struct ieee80211_vht_capabilities); |
| 6032 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); |
| 6033 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", |
| 6034 | params->vhtcaps_mask, sz); |
| 6035 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, |
| 6036 | params->vhtcaps) || |
| 6037 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 6038 | params->vhtcaps_mask)) |
| 6039 | return -1; |
| 6040 | } |
| 6041 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 6042 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6043 | #ifdef CONFIG_HE_OVERRIDES |
| 6044 | if (params->disable_he) { |
| 6045 | wpa_printf(MSG_DEBUG, " * HE disabled"); |
| 6046 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_HE)) |
| 6047 | return -1; |
| 6048 | } |
| 6049 | #endif /* CONFIG_HE_OVERRIDES */ |
| 6050 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6051 | return 0; |
| 6052 | } |
| 6053 | |
| 6054 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6055 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
| 6056 | struct wpa_driver_associate_params *params) |
| 6057 | { |
| 6058 | struct nl_msg *msg; |
| 6059 | int ret = -1; |
| 6060 | int count = 0; |
| 6061 | |
| 6062 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); |
| 6063 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6064 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6065 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 6066 | "IBSS mode"); |
| 6067 | return -1; |
| 6068 | } |
| 6069 | |
| 6070 | retry: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6071 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
| 6072 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
| 6073 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6074 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6075 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
| 6076 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6077 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 6078 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6079 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 6080 | drv->ssid_len = params->ssid_len; |
| 6081 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 6082 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
| 6083 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6084 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6085 | |
| 6086 | ret = nl80211_set_conn_keys(params, msg); |
| 6087 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6088 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6089 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6090 | if (params->bssid && params->fixed_bssid) { |
| 6091 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, |
| 6092 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6093 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 6094 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6095 | } |
| 6096 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 6097 | if (params->fixed_freq) { |
| 6098 | wpa_printf(MSG_DEBUG, " * fixed_freq"); |
| 6099 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) |
| 6100 | goto fail; |
| 6101 | } |
| 6102 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6103 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 6104 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 6105 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
| 6106 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6107 | wpa_printf(MSG_DEBUG, " * control port"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6108 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 6109 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6110 | } |
| 6111 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6112 | if (params->wpa_ie) { |
| 6113 | wpa_hexdump(MSG_DEBUG, |
| 6114 | " * Extra IEs for Beacon/Probe Response frames", |
| 6115 | params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6116 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 6117 | params->wpa_ie)) |
| 6118 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6119 | } |
| 6120 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 6121 | ret = nl80211_ht_vht_overrides(msg, params); |
| 6122 | if (ret < 0) |
| 6123 | goto fail; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6124 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6125 | 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] | 6126 | msg = NULL; |
| 6127 | if (ret) { |
| 6128 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", |
| 6129 | ret, strerror(-ret)); |
| 6130 | count++; |
| 6131 | if (ret == -EALREADY && count == 1) { |
| 6132 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " |
| 6133 | "forced leave"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6134 | nl80211_leave_ibss(drv, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6135 | nlmsg_free(msg); |
| 6136 | goto retry; |
| 6137 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6138 | } else { |
| 6139 | wpa_printf(MSG_DEBUG, |
| 6140 | "nl80211: Join IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6141 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6142 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6143 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6144 | nlmsg_free(msg); |
| 6145 | return ret; |
| 6146 | } |
| 6147 | |
| 6148 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6149 | static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data *drv, |
| 6150 | struct wpa_driver_associate_params *params, |
| 6151 | struct nl_msg *msg) |
| 6152 | { |
| 6153 | if (params->fils_erp_username_len) { |
| 6154 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP EMSKname/username", |
| 6155 | params->fils_erp_username, |
| 6156 | params->fils_erp_username_len); |
| 6157 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_USERNAME, |
| 6158 | params->fils_erp_username_len, |
| 6159 | params->fils_erp_username)) |
| 6160 | return -1; |
| 6161 | } |
| 6162 | |
| 6163 | if (params->fils_erp_realm_len) { |
| 6164 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP Realm", |
| 6165 | params->fils_erp_realm, |
| 6166 | params->fils_erp_realm_len); |
| 6167 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_REALM, |
| 6168 | params->fils_erp_realm_len, params->fils_erp_realm)) |
| 6169 | return -1; |
| 6170 | } |
| 6171 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6172 | if (params->fils_erp_rrk_len) { |
Vinita S. Maloo | 3a5b441 | 2020-05-19 17:43:22 +0530 | [diff] [blame] | 6173 | wpa_printf(MSG_DEBUG, " * FILS ERP next seq %u", |
| 6174 | params->fils_erp_next_seq_num); |
| 6175 | if (nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 6176 | params->fils_erp_next_seq_num)) |
| 6177 | return -1; |
| 6178 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6179 | wpa_printf(MSG_DEBUG, " * FILS ERP rRK (len=%lu)", |
| 6180 | (unsigned long) params->fils_erp_rrk_len); |
| 6181 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_RRK, |
| 6182 | params->fils_erp_rrk_len, params->fils_erp_rrk)) |
| 6183 | return -1; |
| 6184 | } |
| 6185 | |
| 6186 | return 0; |
| 6187 | } |
| 6188 | |
| 6189 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6190 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
| 6191 | struct wpa_driver_associate_params *params, |
| 6192 | struct nl_msg *msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6193 | { |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6194 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 6195 | return -1; |
| 6196 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6197 | if (params->bssid) { |
| 6198 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 6199 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6200 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 6201 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6202 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6203 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 6204 | if (params->bssid_hint) { |
| 6205 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, |
| 6206 | MAC2STR(params->bssid_hint)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6207 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
| 6208 | params->bssid_hint)) |
| 6209 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 6210 | } |
| 6211 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6212 | if (params->freq.freq) { |
| 6213 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6214 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 6215 | params->freq.freq)) |
| 6216 | return -1; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6217 | drv->assoc_freq = params->freq.freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6218 | } else |
| 6219 | drv->assoc_freq = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6220 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 6221 | if (params->freq_hint) { |
| 6222 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6223 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
| 6224 | params->freq_hint)) |
| 6225 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 6226 | } |
| 6227 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 6228 | if (params->freq.edmg.channels && params->freq.edmg.bw_config) { |
| 6229 | wpa_printf(MSG_DEBUG, |
| 6230 | " * EDMG configuration: channels=0x%x bw_config=%d", |
| 6231 | params->freq.edmg.channels, |
| 6232 | params->freq.edmg.bw_config); |
| 6233 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS, |
| 6234 | params->freq.edmg.channels) || |
| 6235 | nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG, |
| 6236 | params->freq.edmg.bw_config)) |
| 6237 | return -1; |
| 6238 | } |
| 6239 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6240 | if (params->bg_scan_period >= 0) { |
| 6241 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 6242 | params->bg_scan_period); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6243 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 6244 | params->bg_scan_period)) |
| 6245 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6246 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6247 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6248 | if (params->ssid) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6249 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
| 6250 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6251 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 6252 | params->ssid)) |
| 6253 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6254 | if (params->ssid_len > sizeof(drv->ssid)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6255 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6256 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 6257 | drv->ssid_len = params->ssid_len; |
| 6258 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6259 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6260 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6261 | if (params->wpa_ie && |
| 6262 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) |
| 6263 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6264 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6265 | if (params->wpa_proto) { |
| 6266 | enum nl80211_wpa_versions ver = 0; |
| 6267 | |
| 6268 | if (params->wpa_proto & WPA_PROTO_WPA) |
| 6269 | ver |= NL80211_WPA_VERSION_1; |
| 6270 | if (params->wpa_proto & WPA_PROTO_RSN) |
| 6271 | ver |= NL80211_WPA_VERSION_2; |
| 6272 | |
| 6273 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6274 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 6275 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6276 | } |
| 6277 | |
| 6278 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
| 6279 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
| 6280 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6281 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 6282 | cipher)) |
| 6283 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6284 | } |
| 6285 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 6286 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
| 6287 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { |
| 6288 | /* |
| 6289 | * This is likely to work even though many drivers do not |
| 6290 | * advertise support for operations without GTK. |
| 6291 | */ |
| 6292 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); |
| 6293 | } else if (params->group_suite != WPA_CIPHER_NONE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6294 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
| 6295 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6296 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
| 6297 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6298 | } |
| 6299 | |
| 6300 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 6301 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 6302 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || |
| 6303 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6304 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 6305 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
| 6306 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6307 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6308 | params->key_mgmt_suite == WPA_KEY_MGMT_SAE || |
| 6309 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 6310 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6311 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6312 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X_SHA384 || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6313 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA256 || |
| 6314 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA384 || |
| 6315 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA256 || |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6316 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA384 || |
| 6317 | params->key_mgmt_suite == WPA_KEY_MGMT_OWE || |
| 6318 | params->key_mgmt_suite == WPA_KEY_MGMT_DPP) { |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6319 | int mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6320 | |
| 6321 | switch (params->key_mgmt_suite) { |
| 6322 | case WPA_KEY_MGMT_CCKM: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6323 | mgmt = RSN_AUTH_KEY_MGMT_CCKM; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6324 | break; |
| 6325 | case WPA_KEY_MGMT_IEEE8021X: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6326 | mgmt = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6327 | break; |
| 6328 | case WPA_KEY_MGMT_FT_IEEE8021X: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6329 | mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6330 | break; |
| 6331 | case WPA_KEY_MGMT_FT_PSK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6332 | mgmt = RSN_AUTH_KEY_MGMT_FT_PSK; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6333 | break; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 6334 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6335 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SHA256; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 6336 | break; |
| 6337 | case WPA_KEY_MGMT_PSK_SHA256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6338 | mgmt = RSN_AUTH_KEY_MGMT_PSK_SHA256; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 6339 | break; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6340 | case WPA_KEY_MGMT_OSEN: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6341 | mgmt = RSN_AUTH_KEY_MGMT_OSEN; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6342 | break; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6343 | case WPA_KEY_MGMT_SAE: |
| 6344 | mgmt = RSN_AUTH_KEY_MGMT_SAE; |
| 6345 | break; |
| 6346 | case WPA_KEY_MGMT_FT_SAE: |
| 6347 | mgmt = RSN_AUTH_KEY_MGMT_FT_SAE; |
| 6348 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6349 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6350 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6351 | break; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 6352 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6353 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 6354 | break; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6355 | case WPA_KEY_MGMT_FT_IEEE8021X_SHA384: |
| 6356 | mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384; |
| 6357 | break; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6358 | case WPA_KEY_MGMT_FILS_SHA256: |
| 6359 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA256; |
| 6360 | break; |
| 6361 | case WPA_KEY_MGMT_FILS_SHA384: |
| 6362 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA384; |
| 6363 | break; |
| 6364 | case WPA_KEY_MGMT_FT_FILS_SHA256: |
| 6365 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256; |
| 6366 | break; |
| 6367 | case WPA_KEY_MGMT_FT_FILS_SHA384: |
| 6368 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384; |
| 6369 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6370 | case WPA_KEY_MGMT_OWE: |
| 6371 | mgmt = RSN_AUTH_KEY_MGMT_OWE; |
| 6372 | break; |
| 6373 | case WPA_KEY_MGMT_DPP: |
| 6374 | mgmt = RSN_AUTH_KEY_MGMT_DPP; |
| 6375 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6376 | case WPA_KEY_MGMT_PSK: |
| 6377 | default: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6378 | mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6379 | break; |
| 6380 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6381 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6382 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
| 6383 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6384 | } |
| 6385 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 6386 | if (params->req_handshake_offload && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6387 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)) { |
| 6388 | wpa_printf(MSG_DEBUG, " * WANT_1X_4WAY_HS"); |
| 6389 | if (nla_put_flag(msg, NL80211_ATTR_WANT_1X_4WAY_HS)) |
| 6390 | return -1; |
| 6391 | } |
| 6392 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6393 | /* Add PSK in case of 4-way handshake offload */ |
| 6394 | if (params->psk && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6395 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6396 | wpa_hexdump_key(MSG_DEBUG, " * PSK", params->psk, 32); |
| 6397 | if (nla_put(msg, NL80211_ATTR_PMK, 32, params->psk)) |
| 6398 | return -1; |
| 6399 | } |
| 6400 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6401 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 6402 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6403 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 6404 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 6405 | (params->pairwise_suite == WPA_CIPHER_NONE || |
| 6406 | params->pairwise_suite == WPA_CIPHER_WEP104 || |
| 6407 | params->pairwise_suite == WPA_CIPHER_WEP40) && |
| 6408 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 6409 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
| 6410 | return -1; |
| 6411 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6412 | if (params->rrm_used) { |
| 6413 | u32 drv_rrm_flags = drv->capa.rrm_flags; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6414 | if ((!((drv_rrm_flags & |
| 6415 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && |
| 6416 | (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && |
| 6417 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6418 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
| 6419 | return -1; |
| 6420 | } |
| 6421 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6422 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6423 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6424 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6425 | if (params->p2p) |
| 6426 | wpa_printf(MSG_DEBUG, " * P2P group"); |
| 6427 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6428 | if (params->pbss) { |
| 6429 | wpa_printf(MSG_DEBUG, " * PBSS"); |
| 6430 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 6431 | return -1; |
| 6432 | } |
| 6433 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 6434 | drv->connect_reassoc = 0; |
| 6435 | if (params->prev_bssid) { |
| 6436 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, |
| 6437 | MAC2STR(params->prev_bssid)); |
| 6438 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
| 6439 | params->prev_bssid)) |
| 6440 | return -1; |
| 6441 | drv->connect_reassoc = 1; |
| 6442 | } |
| 6443 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6444 | if ((params->auth_alg & WPA_AUTH_ALG_FILS) && |
| 6445 | nl80211_put_fils_connect_params(drv, params, msg) != 0) |
| 6446 | return -1; |
| 6447 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 6448 | if ((params->key_mgmt_suite == WPA_KEY_MGMT_SAE || |
| 6449 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6450 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) && |
| 6451 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) |
| 6452 | return -1; |
| 6453 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6454 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6455 | } |
| 6456 | |
| 6457 | |
| 6458 | static int wpa_driver_nl80211_try_connect( |
| 6459 | struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6460 | struct wpa_driver_associate_params *params, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6461 | struct i802_bss *bss) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6462 | { |
| 6463 | struct nl_msg *msg; |
| 6464 | enum nl80211_auth_type type; |
| 6465 | int ret; |
| 6466 | int algs; |
| 6467 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6468 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6469 | if (params->req_key_mgmt_offload && params->psk && |
| 6470 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 6471 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
| 6472 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { |
| 6473 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); |
| 6474 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); |
| 6475 | if (ret) |
| 6476 | return ret; |
| 6477 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6478 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6479 | |
| 6480 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
| 6481 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6482 | if (!msg) |
| 6483 | return -1; |
| 6484 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6485 | ret = nl80211_connect_common(drv, params, msg); |
| 6486 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6487 | goto fail; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6488 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6489 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 6490 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 6491 | goto fail; |
| 6492 | |
| 6493 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_OPTIONAL && |
| 6494 | (drv->capa.flags & WPA_DRIVER_FLAGS_MFP_OPTIONAL) && |
| 6495 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_OPTIONAL)) |
| 6496 | goto fail; |
| 6497 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6498 | #ifdef CONFIG_SAE |
| 6499 | if ((params->key_mgmt_suite == WPA_KEY_MGMT_SAE || |
| 6500 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE) && |
| 6501 | nl80211_put_sae_pwe(msg, params->sae_pwe) < 0) |
| 6502 | goto fail; |
| 6503 | #endif /* CONFIG_SAE */ |
| 6504 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6505 | algs = 0; |
| 6506 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 6507 | algs++; |
| 6508 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 6509 | algs++; |
| 6510 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 6511 | algs++; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6512 | if (params->auth_alg & WPA_AUTH_ALG_FILS) |
| 6513 | algs++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6514 | if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 6515 | algs++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6516 | if (algs > 1) { |
| 6517 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " |
| 6518 | "selection"); |
| 6519 | goto skip_auth_type; |
| 6520 | } |
| 6521 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6522 | type = get_nl_auth_type(params->auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6523 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6524 | if (type == NL80211_AUTHTYPE_MAX || |
| 6525 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6526 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6527 | |
| 6528 | skip_auth_type: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6529 | ret = nl80211_set_conn_keys(params, msg); |
| 6530 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6531 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6532 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6533 | ret = send_and_recv_msgs_connect_handle(drv, msg, bss, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6534 | msg = NULL; |
| 6535 | if (ret) { |
| 6536 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " |
| 6537 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6538 | } else { |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 6539 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 6540 | drv->roam_indication_done = false; |
| 6541 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6542 | wpa_printf(MSG_DEBUG, |
| 6543 | "nl80211: Connect request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6544 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6545 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6546 | fail: |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6547 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6548 | nlmsg_free(msg); |
| 6549 | return ret; |
| 6550 | |
| 6551 | } |
| 6552 | |
| 6553 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6554 | static int wpa_driver_nl80211_connect( |
| 6555 | struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6556 | struct wpa_driver_associate_params *params, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6557 | struct i802_bss *bss) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6558 | { |
Jithu Jance | a7c60b4 | 2014-12-03 18:54:40 +0530 | [diff] [blame] | 6559 | int ret; |
| 6560 | |
| 6561 | /* Store the connection attempted bssid for future use */ |
| 6562 | if (params->bssid) |
| 6563 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 6564 | else |
| 6565 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
| 6566 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6567 | ret = wpa_driver_nl80211_try_connect(drv, params, bss); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6568 | if (ret == -EALREADY) { |
| 6569 | /* |
| 6570 | * cfg80211 does not currently accept new connections if |
| 6571 | * we are already connected. As a workaround, force |
| 6572 | * disconnection and try again. |
| 6573 | */ |
| 6574 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " |
| 6575 | "disconnecting before reassociation " |
| 6576 | "attempt"); |
| 6577 | if (wpa_driver_nl80211_disconnect( |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6578 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID, bss)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6579 | return -1; |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6580 | ret = wpa_driver_nl80211_try_connect(drv, params, bss); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6581 | } |
| 6582 | return ret; |
| 6583 | } |
| 6584 | |
| 6585 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6586 | static int wpa_driver_nl80211_associate( |
| 6587 | void *priv, struct wpa_driver_associate_params *params) |
| 6588 | { |
| 6589 | struct i802_bss *bss = priv; |
| 6590 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6591 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6592 | struct nl_msg *msg; |
| 6593 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6594 | nl80211_unmask_11b_rates(bss); |
| 6595 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6596 | if (params->mode == IEEE80211_MODE_AP) |
| 6597 | return wpa_driver_nl80211_ap(drv, params); |
| 6598 | |
| 6599 | if (params->mode == IEEE80211_MODE_IBSS) |
| 6600 | return wpa_driver_nl80211_ibss(drv, params); |
| 6601 | |
| 6602 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6603 | enum nl80211_iftype nlmode = params->p2p ? |
| 6604 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 6605 | |
| 6606 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6607 | return -1; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 6608 | if (params->key_mgmt_suite == WPA_KEY_MGMT_SAE || |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 6609 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE) |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6610 | bss->use_nl_connect = 1; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 6611 | else |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6612 | bss->use_nl_connect = 0; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6613 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6614 | return wpa_driver_nl80211_connect(drv, params, bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6615 | } |
| 6616 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6617 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6618 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6619 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
| 6620 | drv->ifindex); |
| 6621 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6622 | if (!msg) |
| 6623 | return -1; |
| 6624 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6625 | ret = nl80211_connect_common(drv, params, msg); |
| 6626 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6627 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6628 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6629 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 6630 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 6631 | goto fail; |
| 6632 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 6633 | if (params->fils_kek) { |
| 6634 | wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)", |
| 6635 | (unsigned int) params->fils_kek_len); |
| 6636 | if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len, |
| 6637 | params->fils_kek)) |
| 6638 | goto fail; |
| 6639 | } |
| 6640 | if (params->fils_nonces) { |
| 6641 | wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)", |
| 6642 | params->fils_nonces, |
| 6643 | params->fils_nonces_len); |
| 6644 | if (nla_put(msg, NL80211_ATTR_FILS_NONCES, |
| 6645 | params->fils_nonces_len, params->fils_nonces)) |
| 6646 | goto fail; |
| 6647 | } |
| 6648 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 6649 | 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] | 6650 | msg = NULL; |
| 6651 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6652 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 6653 | "nl80211: MLME command failed (assoc): ret=%d (%s)", |
| 6654 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6655 | nl80211_dump_scan(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6656 | } else { |
| 6657 | wpa_printf(MSG_DEBUG, |
| 6658 | "nl80211: Association request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6659 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6660 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6661 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6662 | nlmsg_free(msg); |
| 6663 | return ret; |
| 6664 | } |
| 6665 | |
| 6666 | |
| 6667 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6668 | int ifindex, enum nl80211_iftype mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6669 | { |
| 6670 | struct nl_msg *msg; |
| 6671 | int ret = -ENOBUFS; |
| 6672 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6673 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
| 6674 | ifindex, mode, nl80211_iftype_str(mode)); |
| 6675 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6676 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 6677 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) |
| 6678 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6679 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6680 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6681 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6682 | if (!ret) |
| 6683 | return 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6684 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6685 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6686 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
| 6687 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); |
| 6688 | return ret; |
| 6689 | } |
| 6690 | |
| 6691 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6692 | static int wpa_driver_nl80211_set_mode_impl( |
| 6693 | struct i802_bss *bss, |
| 6694 | enum nl80211_iftype nlmode, |
| 6695 | struct hostapd_freq_params *desired_freq_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6696 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6697 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6698 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6699 | int i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6700 | int was_ap = is_ap_interface(drv->nlmode); |
| 6701 | int res; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6702 | int mode_switch_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6703 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 6704 | if (TEST_FAIL()) |
| 6705 | return -1; |
| 6706 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6707 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 6708 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) |
| 6709 | mode_switch_res = 0; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6710 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6711 | if (mode_switch_res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6712 | drv->nlmode = nlmode; |
| 6713 | ret = 0; |
| 6714 | goto done; |
| 6715 | } |
| 6716 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6717 | if (mode_switch_res == -ENODEV) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6718 | return -1; |
| 6719 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6720 | if (nlmode == drv->nlmode) { |
| 6721 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
| 6722 | "requested mode - ignore error"); |
| 6723 | ret = 0; |
| 6724 | goto done; /* Already in the requested mode */ |
| 6725 | } |
| 6726 | |
| 6727 | /* mac80211 doesn't allow mode changes while the device is up, so |
| 6728 | * take the device down, try to set the mode again, and bring the |
| 6729 | * device back up. |
| 6730 | */ |
| 6731 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
| 6732 | "interface down"); |
| 6733 | for (i = 0; i < 10; i++) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6734 | res = i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6735 | if (res == -EACCES || res == -ENODEV) |
| 6736 | break; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6737 | if (res != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6738 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
| 6739 | "interface down"); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6740 | os_sleep(0, 100000); |
| 6741 | continue; |
| 6742 | } |
| 6743 | |
| 6744 | /* |
| 6745 | * Setting the mode will fail for some drivers if the phy is |
| 6746 | * on a frequency that the mode is disallowed in. |
| 6747 | */ |
| 6748 | if (desired_freq_params) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6749 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6750 | if (res) { |
| 6751 | wpa_printf(MSG_DEBUG, |
| 6752 | "nl80211: Failed to set frequency on interface"); |
| 6753 | } |
| 6754 | } |
| 6755 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 6756 | if (i == 0 && was_ap && !is_ap_interface(nlmode) && |
| 6757 | bss->brname[0] && |
| 6758 | (bss->added_if_into_bridge || bss->already_in_bridge)) { |
| 6759 | wpa_printf(MSG_DEBUG, |
| 6760 | "nl80211: Remove AP interface %s temporarily from the bridge %s to allow its mode to be set to STATION", |
| 6761 | bss->ifname, bss->brname); |
| 6762 | if (linux_br_del_if(drv->global->ioctl_sock, |
| 6763 | bss->brname, bss->ifname) < 0) |
| 6764 | wpa_printf(MSG_INFO, |
| 6765 | "nl80211: Failed to remove interface %s from bridge %s: %s", |
| 6766 | bss->ifname, bss->brname, |
| 6767 | strerror(errno)); |
| 6768 | } |
| 6769 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6770 | /* Try to set the mode again while the interface is down */ |
| 6771 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 6772 | if (mode_switch_res == -EBUSY) { |
| 6773 | wpa_printf(MSG_DEBUG, |
| 6774 | "nl80211: Delaying mode set while interface going down"); |
| 6775 | os_sleep(0, 100000); |
| 6776 | continue; |
| 6777 | } |
| 6778 | ret = mode_switch_res; |
| 6779 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6780 | } |
| 6781 | |
| 6782 | if (!ret) { |
| 6783 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " |
| 6784 | "interface is down"); |
| 6785 | drv->nlmode = nlmode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6786 | drv->ignore_if_down_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6787 | } |
| 6788 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6789 | /* Bring the interface back up */ |
| 6790 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); |
| 6791 | if (res != 0) { |
| 6792 | wpa_printf(MSG_DEBUG, |
| 6793 | "nl80211: Failed to set interface up after switching mode"); |
| 6794 | ret = -1; |
| 6795 | } |
| 6796 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6797 | done: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6798 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6799 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " |
| 6800 | "from %d failed", nlmode, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6801 | return ret; |
| 6802 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6803 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6804 | if (is_p2p_net_interface(nlmode)) { |
| 6805 | wpa_printf(MSG_DEBUG, |
| 6806 | "nl80211: Interface %s mode change to P2P - disable 11b rates", |
| 6807 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6808 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6809 | } else if (drv->disabled_11b_rates) { |
| 6810 | wpa_printf(MSG_DEBUG, |
| 6811 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", |
| 6812 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6813 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6814 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6815 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6816 | if (is_ap_interface(nlmode)) { |
| 6817 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
| 6818 | /* Setup additional AP mode functionality if needed */ |
| 6819 | if (nl80211_setup_ap(bss)) |
| 6820 | return -1; |
| 6821 | } else if (was_ap) { |
| 6822 | /* Remove additional AP mode functionality */ |
| 6823 | nl80211_teardown_ap(bss); |
| 6824 | } else { |
| 6825 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
| 6826 | } |
| 6827 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6828 | if (is_mesh_interface(nlmode) && |
| 6829 | nl80211_mgmt_subscribe_mesh(bss)) |
| 6830 | return -1; |
| 6831 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6832 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6833 | !is_mesh_interface(nlmode) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6834 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 6835 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " |
| 6836 | "frame processing - ignore for now"); |
| 6837 | |
| 6838 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6839 | } |
| 6840 | |
| 6841 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 6842 | void nl80211_restore_ap_mode(struct i802_bss *bss) |
| 6843 | { |
| 6844 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6845 | int was_ap = is_ap_interface(drv->nlmode); |
lesl | c3979c3 | 2021-03-29 22:34:02 +0800 | [diff] [blame] | 6846 | int br_ifindex; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 6847 | |
| 6848 | wpa_driver_nl80211_set_mode(bss, drv->ap_scan_as_station); |
| 6849 | if (!was_ap && is_ap_interface(drv->ap_scan_as_station) && |
| 6850 | bss->brname[0] && |
| 6851 | (bss->added_if_into_bridge || bss->already_in_bridge)) { |
| 6852 | wpa_printf(MSG_DEBUG, |
| 6853 | "nl80211: Add AP interface %s back into the bridge %s", |
| 6854 | bss->ifname, bss->brname); |
| 6855 | if (linux_br_add_if(drv->global->ioctl_sock, bss->brname, |
| 6856 | bss->ifname) < 0) { |
| 6857 | wpa_printf(MSG_WARNING, |
| 6858 | "nl80211: Failed to add interface %s into bridge %s: %s", |
| 6859 | bss->ifname, bss->brname, strerror(errno)); |
| 6860 | } |
lesl | c3979c3 | 2021-03-29 22:34:02 +0800 | [diff] [blame] | 6861 | br_ifindex = if_nametoindex(bss->brname); |
| 6862 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 6863 | } |
| 6864 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
| 6865 | } |
| 6866 | |
| 6867 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6868 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 6869 | enum nl80211_iftype nlmode) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6870 | { |
| 6871 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); |
| 6872 | } |
| 6873 | |
| 6874 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6875 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 6876 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6877 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6878 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6879 | freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6880 | } |
| 6881 | |
| 6882 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6883 | static int wpa_driver_nl80211_get_capa(void *priv, |
| 6884 | struct wpa_driver_capa *capa) |
| 6885 | { |
| 6886 | struct i802_bss *bss = priv; |
| 6887 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 6888 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6889 | if (!drv->has_capability) |
| 6890 | return -1; |
| 6891 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 6892 | if (drv->extended_capa && drv->extended_capa_mask) { |
| 6893 | capa->extended_capa = drv->extended_capa; |
| 6894 | capa->extended_capa_mask = drv->extended_capa_mask; |
| 6895 | capa->extended_capa_len = drv->extended_capa_len; |
| 6896 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6897 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6898 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6899 | } |
| 6900 | |
| 6901 | |
| 6902 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) |
| 6903 | { |
| 6904 | struct i802_bss *bss = priv; |
| 6905 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6906 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6907 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
| 6908 | bss->ifname, drv->operstate, state, |
| 6909 | state ? "UP" : "DORMANT"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6910 | drv->operstate = state; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6911 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6912 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
| 6913 | } |
| 6914 | |
| 6915 | |
| 6916 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) |
| 6917 | { |
| 6918 | struct i802_bss *bss = priv; |
| 6919 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6920 | struct nl_msg *msg; |
| 6921 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6922 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6923 | |
| 6924 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { |
| 6925 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); |
| 6926 | return 0; |
| 6927 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6928 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6929 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
| 6930 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); |
| 6931 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6932 | os_memset(&upd, 0, sizeof(upd)); |
| 6933 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 6934 | if (authorized) |
| 6935 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6936 | |
| 6937 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 6938 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
| 6939 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { |
| 6940 | nlmsg_free(msg); |
| 6941 | return -ENOBUFS; |
| 6942 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6943 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6944 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6945 | if (!ret) |
| 6946 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6947 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
| 6948 | ret, strerror(-ret)); |
| 6949 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6950 | } |
| 6951 | |
| 6952 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6953 | /* Set kernel driver on given frequency (MHz) */ |
| 6954 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6955 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6956 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 6957 | return nl80211_set_channel(bss, freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6958 | } |
| 6959 | |
| 6960 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6961 | static inline int min_int(int a, int b) |
| 6962 | { |
| 6963 | if (a < b) |
| 6964 | return a; |
| 6965 | return b; |
| 6966 | } |
| 6967 | |
| 6968 | |
| 6969 | static int get_key_handler(struct nl_msg *msg, void *arg) |
| 6970 | { |
| 6971 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6972 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6973 | |
| 6974 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6975 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6976 | |
| 6977 | /* |
| 6978 | * TODO: validate the key index and mac address! |
| 6979 | * Otherwise, there's a race condition as soon as |
| 6980 | * the kernel starts sending key notifications. |
| 6981 | */ |
| 6982 | |
| 6983 | if (tb[NL80211_ATTR_KEY_SEQ]) |
| 6984 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 6985 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6986 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6987 | return NL_SKIP; |
| 6988 | } |
| 6989 | |
| 6990 | |
| 6991 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, |
| 6992 | int idx, u8 *seq) |
| 6993 | { |
| 6994 | struct i802_bss *bss = priv; |
| 6995 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6996 | struct nl_msg *msg; |
| 6997 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6998 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
| 6999 | NL80211_CMD_GET_KEY); |
| 7000 | if (!msg || |
| 7001 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 7002 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
| 7003 | nlmsg_free(msg); |
| 7004 | return -ENOBUFS; |
| 7005 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7006 | |
| 7007 | memset(seq, 0, 6); |
| 7008 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7009 | 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] | 7010 | } |
| 7011 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7012 | |
| 7013 | static int i802_set_rts(void *priv, int rts) |
| 7014 | { |
| 7015 | struct i802_bss *bss = priv; |
| 7016 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7017 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7018 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7019 | u32 val; |
| 7020 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 7021 | if (rts >= 2347 || rts == -1) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7022 | val = (u32) -1; |
| 7023 | else |
| 7024 | val = rts; |
| 7025 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7026 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 7027 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
| 7028 | nlmsg_free(msg); |
| 7029 | return -ENOBUFS; |
| 7030 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7031 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7032 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7033 | if (!ret) |
| 7034 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7035 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
| 7036 | "%d (%s)", rts, ret, strerror(-ret)); |
| 7037 | return ret; |
| 7038 | } |
| 7039 | |
| 7040 | |
| 7041 | static int i802_set_frag(void *priv, int frag) |
| 7042 | { |
| 7043 | struct i802_bss *bss = priv; |
| 7044 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7045 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7046 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7047 | u32 val; |
| 7048 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 7049 | if (frag >= 2346 || frag == -1) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7050 | val = (u32) -1; |
| 7051 | else |
| 7052 | val = frag; |
| 7053 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7054 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 7055 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
| 7056 | nlmsg_free(msg); |
| 7057 | return -ENOBUFS; |
| 7058 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7059 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7060 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7061 | if (!ret) |
| 7062 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7063 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
| 7064 | "%d: %d (%s)", frag, ret, strerror(-ret)); |
| 7065 | return ret; |
| 7066 | } |
| 7067 | |
| 7068 | |
| 7069 | static int i802_flush(void *priv) |
| 7070 | { |
| 7071 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7072 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7073 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7074 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7075 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
| 7076 | bss->ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7077 | |
| 7078 | /* |
| 7079 | * XXX: FIX! this needs to flush all VLANs too |
| 7080 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7081 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7082 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7083 | if (res) { |
| 7084 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " |
| 7085 | "(%s)", res, strerror(-res)); |
| 7086 | } |
| 7087 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7088 | } |
| 7089 | |
| 7090 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7091 | static void get_sta_tid_stats(struct hostap_sta_driver_data *data, |
| 7092 | struct nlattr *attr) |
| 7093 | { |
| 7094 | struct nlattr *tid_stats[NL80211_TID_STATS_MAX + 1], *tidattr; |
| 7095 | struct nlattr *txq_stats[NL80211_TXQ_STATS_MAX + 1]; |
| 7096 | static struct nla_policy txq_stats_policy[NL80211_TXQ_STATS_MAX + 1] = { |
| 7097 | [NL80211_TXQ_STATS_BACKLOG_BYTES] = { .type = NLA_U32 }, |
| 7098 | [NL80211_TXQ_STATS_BACKLOG_PACKETS] = { .type = NLA_U32 }, |
| 7099 | }; |
| 7100 | int rem; |
| 7101 | |
| 7102 | nla_for_each_nested(tidattr, attr, rem) { |
| 7103 | if (nla_parse_nested(tid_stats, NL80211_TID_STATS_MAX, |
| 7104 | tidattr, NULL) != 0 || |
| 7105 | !tid_stats[NL80211_TID_STATS_TXQ_STATS] || |
| 7106 | nla_parse_nested(txq_stats, NL80211_TXQ_STATS_MAX, |
| 7107 | tid_stats[NL80211_TID_STATS_TXQ_STATS], |
| 7108 | txq_stats_policy) != 0) |
| 7109 | continue; |
| 7110 | /* sum the backlogs over all TIDs for station */ |
| 7111 | if (txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]) |
| 7112 | data->backlog_bytes += nla_get_u32( |
| 7113 | txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]); |
| 7114 | if (txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]) |
| 7115 | data->backlog_bytes += nla_get_u32( |
| 7116 | txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]); |
| 7117 | } |
| 7118 | } |
| 7119 | |
| 7120 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7121 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
| 7122 | { |
| 7123 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7124 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7125 | struct hostap_sta_driver_data *data = arg; |
| 7126 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; |
| 7127 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
| 7128 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, |
| 7129 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, |
| 7130 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, |
| 7131 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
| 7132 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 7133 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7134 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
| 7135 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7136 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7137 | [NL80211_STA_INFO_ACK_SIGNAL] = { .type = NLA_U8 }, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7138 | [NL80211_STA_INFO_RX_DURATION] = { .type = NLA_U64 }, |
| 7139 | [NL80211_STA_INFO_TX_DURATION] = { .type = NLA_U64 }, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7140 | [NL80211_STA_INFO_CONNECTED_TIME] = { .type = NLA_U32 }, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7141 | }; |
| 7142 | struct nlattr *rate[NL80211_RATE_INFO_MAX + 1]; |
| 7143 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 7144 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 7145 | [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 }, |
| 7146 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 7147 | [NL80211_RATE_INFO_VHT_MCS] = { .type = NLA_U8 }, |
| 7148 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 7149 | [NL80211_RATE_INFO_VHT_NSS] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7150 | }; |
| 7151 | |
| 7152 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7153 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7154 | |
| 7155 | /* |
| 7156 | * TODO: validate the interface and mac address! |
| 7157 | * Otherwise, there's a race condition as soon as |
| 7158 | * the kernel starts sending station notifications. |
| 7159 | */ |
| 7160 | |
| 7161 | if (!tb[NL80211_ATTR_STA_INFO]) { |
| 7162 | wpa_printf(MSG_DEBUG, "sta stats missing!"); |
| 7163 | return NL_SKIP; |
| 7164 | } |
| 7165 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, |
| 7166 | tb[NL80211_ATTR_STA_INFO], |
| 7167 | stats_policy)) { |
| 7168 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); |
| 7169 | return NL_SKIP; |
| 7170 | } |
| 7171 | |
| 7172 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) |
| 7173 | data->inactive_msec = |
| 7174 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7175 | /* For backwards compatibility, fetch the 32-bit counters first. */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7176 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
| 7177 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); |
| 7178 | if (stats[NL80211_STA_INFO_TX_BYTES]) |
| 7179 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7180 | if (stats[NL80211_STA_INFO_RX_BYTES64] && |
| 7181 | stats[NL80211_STA_INFO_TX_BYTES64]) { |
| 7182 | /* |
| 7183 | * The driver supports 64-bit counters, so use them to override |
| 7184 | * the 32-bit values. |
| 7185 | */ |
| 7186 | data->rx_bytes = |
| 7187 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); |
| 7188 | data->tx_bytes = |
| 7189 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); |
| 7190 | data->bytes_64bit = 1; |
| 7191 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7192 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
| 7193 | data->rx_packets = |
| 7194 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); |
| 7195 | if (stats[NL80211_STA_INFO_TX_PACKETS]) |
| 7196 | data->tx_packets = |
| 7197 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7198 | if (stats[NL80211_STA_INFO_RX_DURATION]) |
| 7199 | data->rx_airtime = |
| 7200 | nla_get_u64(stats[NL80211_STA_INFO_RX_DURATION]); |
| 7201 | if (stats[NL80211_STA_INFO_TX_DURATION]) |
| 7202 | data->tx_airtime = |
| 7203 | nla_get_u64(stats[NL80211_STA_INFO_TX_DURATION]); |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 7204 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
| 7205 | data->tx_retry_failed = |
| 7206 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7207 | if (stats[NL80211_STA_INFO_SIGNAL]) |
| 7208 | data->signal = nla_get_u8(stats[NL80211_STA_INFO_SIGNAL]); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7209 | if (stats[NL80211_STA_INFO_ACK_SIGNAL]) { |
| 7210 | data->last_ack_rssi = |
| 7211 | nla_get_u8(stats[NL80211_STA_INFO_ACK_SIGNAL]); |
| 7212 | data->flags |= STA_DRV_DATA_LAST_ACK_RSSI; |
| 7213 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7214 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 7215 | if (stats[NL80211_STA_INFO_CONNECTED_TIME]) { |
| 7216 | data->connected_sec = |
| 7217 | nla_get_u32(stats[NL80211_STA_INFO_CONNECTED_TIME]); |
| 7218 | data->flags |= STA_DRV_DATA_CONN_TIME; |
| 7219 | } |
| 7220 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7221 | if (stats[NL80211_STA_INFO_TX_BITRATE] && |
| 7222 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, |
| 7223 | stats[NL80211_STA_INFO_TX_BITRATE], |
| 7224 | rate_policy) == 0) { |
| 7225 | if (rate[NL80211_RATE_INFO_BITRATE32]) |
| 7226 | data->current_tx_rate = |
| 7227 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); |
| 7228 | else if (rate[NL80211_RATE_INFO_BITRATE]) |
| 7229 | data->current_tx_rate = |
| 7230 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); |
| 7231 | |
| 7232 | if (rate[NL80211_RATE_INFO_MCS]) { |
| 7233 | data->tx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]); |
| 7234 | data->flags |= STA_DRV_DATA_TX_MCS; |
| 7235 | } |
| 7236 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { |
| 7237 | data->tx_vhtmcs = |
| 7238 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); |
| 7239 | data->flags |= STA_DRV_DATA_TX_VHT_MCS; |
| 7240 | } |
| 7241 | if (rate[NL80211_RATE_INFO_SHORT_GI]) |
| 7242 | data->flags |= STA_DRV_DATA_TX_SHORT_GI; |
| 7243 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { |
| 7244 | data->tx_vht_nss = |
| 7245 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); |
| 7246 | data->flags |= STA_DRV_DATA_TX_VHT_NSS; |
| 7247 | } |
| 7248 | } |
| 7249 | |
| 7250 | if (stats[NL80211_STA_INFO_RX_BITRATE] && |
| 7251 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, |
| 7252 | stats[NL80211_STA_INFO_RX_BITRATE], |
| 7253 | rate_policy) == 0) { |
| 7254 | if (rate[NL80211_RATE_INFO_BITRATE32]) |
| 7255 | data->current_rx_rate = |
| 7256 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); |
| 7257 | else if (rate[NL80211_RATE_INFO_BITRATE]) |
| 7258 | data->current_rx_rate = |
| 7259 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); |
| 7260 | |
| 7261 | if (rate[NL80211_RATE_INFO_MCS]) { |
| 7262 | data->rx_mcs = |
| 7263 | nla_get_u8(rate[NL80211_RATE_INFO_MCS]); |
| 7264 | data->flags |= STA_DRV_DATA_RX_MCS; |
| 7265 | } |
| 7266 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { |
| 7267 | data->rx_vhtmcs = |
| 7268 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); |
| 7269 | data->flags |= STA_DRV_DATA_RX_VHT_MCS; |
| 7270 | } |
| 7271 | if (rate[NL80211_RATE_INFO_SHORT_GI]) |
| 7272 | data->flags |= STA_DRV_DATA_RX_SHORT_GI; |
| 7273 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { |
| 7274 | data->rx_vht_nss = |
| 7275 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); |
| 7276 | data->flags |= STA_DRV_DATA_RX_VHT_NSS; |
| 7277 | } |
| 7278 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7279 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7280 | if (stats[NL80211_STA_INFO_TID_STATS]) |
| 7281 | get_sta_tid_stats(data, stats[NL80211_STA_INFO_TID_STATS]); |
| 7282 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7283 | return NL_SKIP; |
| 7284 | } |
| 7285 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7286 | static int i802_read_sta_data(struct i802_bss *bss, |
| 7287 | struct hostap_sta_driver_data *data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7288 | const u8 *addr) |
| 7289 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7290 | struct nl_msg *msg; |
| 7291 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7292 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
| 7293 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 7294 | nlmsg_free(msg); |
| 7295 | return -ENOBUFS; |
| 7296 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7297 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7298 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data, |
| 7299 | NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7300 | } |
| 7301 | |
| 7302 | |
| 7303 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
| 7304 | int cw_min, int cw_max, int burst_time) |
| 7305 | { |
| 7306 | struct i802_bss *bss = priv; |
| 7307 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7308 | struct nl_msg *msg; |
| 7309 | struct nlattr *txq, *params; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7310 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7311 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7312 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7313 | if (!msg) |
| 7314 | return -1; |
| 7315 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7316 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
| 7317 | if (!txq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7318 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7319 | |
| 7320 | /* We are only sending parameters for a single TXQ at a time */ |
| 7321 | params = nla_nest_start(msg, 1); |
| 7322 | if (!params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7323 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7324 | |
| 7325 | switch (queue) { |
| 7326 | case 0: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7327 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
| 7328 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7329 | break; |
| 7330 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7331 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
| 7332 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7333 | break; |
| 7334 | case 2: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7335 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
| 7336 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7337 | break; |
| 7338 | case 3: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7339 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
| 7340 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7341 | break; |
| 7342 | } |
| 7343 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
| 7344 | * 32 usec, so need to convert the value here. */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7345 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
| 7346 | (burst_time * 100 + 16) / 32) || |
| 7347 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || |
| 7348 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || |
| 7349 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) |
| 7350 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7351 | |
| 7352 | nla_nest_end(msg, params); |
| 7353 | |
| 7354 | nla_nest_end(msg, txq); |
| 7355 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7356 | res = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7357 | wpa_printf(MSG_DEBUG, |
| 7358 | "nl80211: TX queue param set: queue=%d aifs=%d cw_min=%d cw_max=%d burst_time=%d --> res=%d", |
| 7359 | queue, aifs, cw_min, cw_max, burst_time, res); |
| 7360 | if (res == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7361 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7362 | msg = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7363 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7364 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7365 | return -1; |
| 7366 | } |
| 7367 | |
| 7368 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7369 | 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] | 7370 | const char *ifname, int vlan_id) |
| 7371 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7372 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7373 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7374 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7375 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7376 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
| 7377 | ", ifname=%s[%d], vlan_id=%d)", |
| 7378 | bss->ifname, if_nametoindex(bss->ifname), |
| 7379 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7380 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 7381 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7382 | (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD) && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7383 | nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7384 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { |
| 7385 | nlmsg_free(msg); |
| 7386 | return -ENOBUFS; |
| 7387 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7388 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7389 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7390 | if (ret < 0) { |
| 7391 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" |
| 7392 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", |
| 7393 | MAC2STR(addr), ifname, vlan_id, ret, |
| 7394 | strerror(-ret)); |
| 7395 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7396 | return ret; |
| 7397 | } |
| 7398 | |
| 7399 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7400 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
| 7401 | { |
| 7402 | struct hostap_sta_driver_data data; |
| 7403 | int ret; |
| 7404 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 7405 | os_memset(&data, 0, sizeof(data)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7406 | data.inactive_msec = (unsigned long) -1; |
| 7407 | ret = i802_read_sta_data(priv, &data, addr); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7408 | if (ret == -ENOENT) |
| 7409 | return -ENOENT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7410 | if (ret || data.inactive_msec == (unsigned long) -1) |
| 7411 | return -1; |
| 7412 | return data.inactive_msec / 1000; |
| 7413 | } |
| 7414 | |
| 7415 | |
| 7416 | static int i802_sta_clear_stats(void *priv, const u8 *addr) |
| 7417 | { |
| 7418 | #if 0 |
| 7419 | /* TODO */ |
| 7420 | #endif |
| 7421 | return 0; |
| 7422 | } |
| 7423 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7424 | |
| 7425 | 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] | 7426 | u16 reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7427 | { |
| 7428 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7429 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7430 | struct ieee80211_mgmt mgmt; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 7431 | u8 channel; |
| 7432 | |
| 7433 | if (ieee80211_freq_to_chan(bss->freq, &channel) == |
| 7434 | HOSTAPD_MODE_IEEE80211AD) { |
| 7435 | /* Deauthentication is not used in DMG/IEEE 802.11ad; |
| 7436 | * disassociate the STA instead. */ |
| 7437 | return i802_sta_disassoc(priv, own_addr, addr, reason); |
| 7438 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7439 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7440 | if (is_mesh_interface(drv->nlmode)) |
| 7441 | return -1; |
| 7442 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7443 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7444 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7445 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7446 | memset(&mgmt, 0, sizeof(mgmt)); |
| 7447 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 7448 | WLAN_FC_STYPE_DEAUTH); |
| 7449 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 7450 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 7451 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 7452 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
| 7453 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 7454 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7455 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7456 | 0, NULL, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7457 | } |
| 7458 | |
| 7459 | |
| 7460 | 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] | 7461 | u16 reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7462 | { |
| 7463 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7464 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7465 | struct ieee80211_mgmt mgmt; |
| 7466 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7467 | if (is_mesh_interface(drv->nlmode)) |
| 7468 | return -1; |
| 7469 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7470 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7471 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7472 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7473 | memset(&mgmt, 0, sizeof(mgmt)); |
| 7474 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 7475 | WLAN_FC_STYPE_DISASSOC); |
| 7476 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 7477 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 7478 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 7479 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
| 7480 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 7481 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7482 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7483 | 0, NULL, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7484 | } |
| 7485 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7486 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7487 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
| 7488 | { |
| 7489 | char buf[200], *pos, *end; |
| 7490 | int i, res; |
| 7491 | |
| 7492 | pos = buf; |
| 7493 | end = pos + sizeof(buf); |
| 7494 | |
| 7495 | for (i = 0; i < drv->num_if_indices; i++) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7496 | if (!drv->if_indices[i].ifindex) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7497 | continue; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7498 | res = os_snprintf(pos, end - pos, " %d(%d)", |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7499 | drv->if_indices[i].ifindex, |
| 7500 | drv->if_indices[i].reason); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7501 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7502 | break; |
| 7503 | pos += res; |
| 7504 | } |
| 7505 | *pos = '\0'; |
| 7506 | |
| 7507 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", |
| 7508 | drv->num_if_indices, buf); |
| 7509 | } |
| 7510 | |
| 7511 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7512 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 7513 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7514 | { |
| 7515 | int i; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7516 | struct drv_nl80211_if_info *old; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7517 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7518 | wpa_printf(MSG_DEBUG, |
| 7519 | "nl80211: Add own interface ifindex %d (ifidx_reason %d)", |
| 7520 | ifidx, ifidx_reason); |
| 7521 | if (have_ifidx(drv, ifidx, ifidx_reason)) { |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7522 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
| 7523 | ifidx); |
| 7524 | return; |
| 7525 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7526 | for (i = 0; i < drv->num_if_indices; i++) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7527 | if (drv->if_indices[i].ifindex == 0) { |
| 7528 | drv->if_indices[i].ifindex = ifidx; |
| 7529 | drv->if_indices[i].reason = ifidx_reason; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7530 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7531 | return; |
| 7532 | } |
| 7533 | } |
| 7534 | |
| 7535 | if (drv->if_indices != drv->default_if_indices) |
| 7536 | old = drv->if_indices; |
| 7537 | else |
| 7538 | old = NULL; |
| 7539 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7540 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7541 | sizeof(*old)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7542 | if (!drv->if_indices) { |
| 7543 | if (!old) |
| 7544 | drv->if_indices = drv->default_if_indices; |
| 7545 | else |
| 7546 | drv->if_indices = old; |
| 7547 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
| 7548 | "interfaces"); |
| 7549 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); |
| 7550 | return; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7551 | } |
| 7552 | if (!old) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7553 | os_memcpy(drv->if_indices, drv->default_if_indices, |
| 7554 | sizeof(drv->default_if_indices)); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7555 | drv->if_indices[drv->num_if_indices].ifindex = ifidx; |
| 7556 | drv->if_indices[drv->num_if_indices].reason = ifidx_reason; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7557 | drv->num_if_indices++; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7558 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7559 | } |
| 7560 | |
| 7561 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7562 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 7563 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7564 | { |
| 7565 | int i; |
| 7566 | |
| 7567 | for (i = 0; i < drv->num_if_indices; i++) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7568 | if ((drv->if_indices[i].ifindex == ifidx || |
| 7569 | ifidx == IFIDX_ANY) && |
| 7570 | (drv->if_indices[i].reason == ifidx_reason || |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7571 | ifidx_reason == IFIDX_ANY)) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7572 | drv->if_indices[i].ifindex = 0; |
| 7573 | drv->if_indices[i].reason = 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7574 | break; |
| 7575 | } |
| 7576 | } |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7577 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7578 | } |
| 7579 | |
| 7580 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7581 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 7582 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7583 | { |
| 7584 | int i; |
| 7585 | |
| 7586 | for (i = 0; i < drv->num_if_indices; i++) |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7587 | if (drv->if_indices[i].ifindex == ifidx && |
| 7588 | (drv->if_indices[i].reason == ifidx_reason || |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7589 | ifidx_reason == IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7590 | return 1; |
| 7591 | |
| 7592 | return 0; |
| 7593 | } |
| 7594 | |
| 7595 | |
| 7596 | 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] | 7597 | const char *bridge_ifname, char *ifname_wds) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7598 | { |
| 7599 | struct i802_bss *bss = priv; |
| 7600 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7601 | char name[IFNAMSIZ + 1]; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7602 | union wpa_event_data event; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 7603 | int ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7604 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 7605 | ret = os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
| 7606 | if (ret >= (int) sizeof(name)) |
| 7607 | wpa_printf(MSG_WARNING, |
| 7608 | "nl80211: WDS interface name was truncated"); |
| 7609 | else if (ret < 0) |
| 7610 | return ret; |
| 7611 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7612 | if (ifname_wds) |
| 7613 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); |
| 7614 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7615 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
| 7616 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); |
| 7617 | if (val) { |
| 7618 | if (!if_nametoindex(name)) { |
| 7619 | if (nl80211_create_iface(drv, name, |
| 7620 | NL80211_IFTYPE_AP_VLAN, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7621 | bss->addr, 1, NULL, NULL, 0) < |
| 7622 | 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7623 | return -1; |
| 7624 | if (bridge_ifname && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7625 | linux_br_add_if(drv->global->ioctl_sock, |
| 7626 | bridge_ifname, name) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7627 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7628 | |
| 7629 | os_memset(&event, 0, sizeof(event)); |
| 7630 | event.wds_sta_interface.sta_addr = addr; |
| 7631 | event.wds_sta_interface.ifname = name; |
| 7632 | event.wds_sta_interface.istatus = INTERFACE_ADDED; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 7633 | wpa_supplicant_event(bss->ctx, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7634 | EVENT_WDS_STA_INTERFACE_STATUS, |
| 7635 | &event); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7636 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7637 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
| 7638 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " |
| 7639 | "interface %s up", name); |
| 7640 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7641 | return i802_set_sta_vlan(priv, addr, name, 0); |
| 7642 | } else { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7643 | if (bridge_ifname && |
| 7644 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, |
| 7645 | name) < 0) |
| 7646 | wpa_printf(MSG_INFO, |
| 7647 | "nl80211: Failed to remove interface %s from bridge %s: %s", |
| 7648 | name, bridge_ifname, strerror(errno)); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7649 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7650 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7651 | nl80211_remove_iface(drv, if_nametoindex(name)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7652 | os_memset(&event, 0, sizeof(event)); |
| 7653 | event.wds_sta_interface.sta_addr = addr; |
| 7654 | event.wds_sta_interface.ifname = name; |
| 7655 | event.wds_sta_interface.istatus = INTERFACE_REMOVED; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 7656 | wpa_supplicant_event(bss->ctx, EVENT_WDS_STA_INTERFACE_STATUS, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7657 | &event); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7658 | return 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7659 | } |
| 7660 | } |
| 7661 | |
| 7662 | |
| 7663 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
| 7664 | { |
| 7665 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 7666 | struct sockaddr_ll lladdr; |
| 7667 | unsigned char buf[3000]; |
| 7668 | int len; |
| 7669 | socklen_t fromlen = sizeof(lladdr); |
| 7670 | |
| 7671 | len = recvfrom(sock, buf, sizeof(buf), 0, |
| 7672 | (struct sockaddr *)&lladdr, &fromlen); |
| 7673 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7674 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
| 7675 | strerror(errno)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7676 | return; |
| 7677 | } |
| 7678 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7679 | if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7680 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
| 7681 | } |
| 7682 | |
| 7683 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7684 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
| 7685 | struct i802_bss *bss, |
| 7686 | const char *brname, const char *ifname) |
| 7687 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7688 | int br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7689 | char in_br[IFNAMSIZ]; |
| 7690 | |
| 7691 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7692 | br_ifindex = if_nametoindex(brname); |
| 7693 | if (br_ifindex == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7694 | /* |
| 7695 | * Bridge was configured, but the bridge device does |
| 7696 | * not exist. Try to add it now. |
| 7697 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7698 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7699 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
| 7700 | "bridge interface %s: %s", |
| 7701 | brname, strerror(errno)); |
| 7702 | return -1; |
| 7703 | } |
| 7704 | bss->added_bridge = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7705 | br_ifindex = if_nametoindex(brname); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7706 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7707 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7708 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7709 | |
| 7710 | if (linux_br_get(in_br, ifname) == 0) { |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 7711 | if (os_strcmp(in_br, brname) == 0) { |
| 7712 | bss->already_in_bridge = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7713 | return 0; /* already in the bridge */ |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 7714 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7715 | |
| 7716 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " |
| 7717 | "bridge %s", ifname, in_br); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7718 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
| 7719 | 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7720 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
| 7721 | "remove interface %s from bridge " |
| 7722 | "%s: %s", |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7723 | ifname, in_br, strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7724 | return -1; |
| 7725 | } |
| 7726 | } |
| 7727 | |
| 7728 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", |
| 7729 | ifname, brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7730 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7731 | wpa_printf(MSG_WARNING, |
| 7732 | "nl80211: Failed to add interface %s into bridge %s: %s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7733 | ifname, brname, strerror(errno)); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7734 | /* Try to continue without the interface being in a bridge. This |
| 7735 | * may be needed for some cases, e.g., with Open vSwitch, where |
| 7736 | * an external component will need to handle bridge |
| 7737 | * configuration. */ |
| 7738 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7739 | } |
| 7740 | bss->added_if_into_bridge = 1; |
| 7741 | |
| 7742 | return 0; |
| 7743 | } |
| 7744 | |
| 7745 | |
| 7746 | static void *i802_init(struct hostapd_data *hapd, |
| 7747 | struct wpa_init_params *params) |
| 7748 | { |
| 7749 | struct wpa_driver_nl80211_data *drv; |
| 7750 | struct i802_bss *bss; |
| 7751 | size_t i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7752 | char master_ifname[IFNAMSIZ]; |
| 7753 | int ifindex, br_ifindex = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7754 | int br_added = 0; |
| 7755 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7756 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
| 7757 | params->global_priv, 1, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7758 | params->bssid, params->driver_params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7759 | if (bss == NULL) |
| 7760 | return NULL; |
| 7761 | |
| 7762 | drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7763 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7764 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7765 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7766 | params->ifname, master_ifname); |
| 7767 | br_ifindex = if_nametoindex(master_ifname); |
| 7768 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 7769 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && |
| 7770 | linux_master_get(master_ifname, params->ifname) == 0) { |
| 7771 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", |
| 7772 | params->ifname, master_ifname); |
| 7773 | /* start listening for EAPOL on the master interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7774 | add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 7775 | |
| 7776 | /* check if master itself is under bridge */ |
| 7777 | if (linux_br_get(master_ifname, master_ifname) == 0) { |
| 7778 | wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s", |
| 7779 | master_ifname); |
| 7780 | br_ifindex = if_nametoindex(master_ifname); |
| 7781 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 7782 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7783 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7784 | master_ifname[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7785 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7786 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7787 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7788 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7789 | for (i = 0; i < params->num_bridge; i++) { |
| 7790 | if (params->bridge[i]) { |
| 7791 | ifindex = if_nametoindex(params->bridge[i]); |
| 7792 | if (ifindex) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7793 | add_ifidx(drv, ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7794 | if (ifindex == br_ifindex) |
| 7795 | br_added = 1; |
| 7796 | } |
| 7797 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7798 | |
| 7799 | /* start listening for EAPOL on the default AP interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7800 | add_ifidx(drv, drv->ifindex, IFIDX_ANY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7801 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7802 | if (params->num_bridge && params->bridge[0]) { |
| 7803 | if (i802_check_bridge(drv, bss, params->bridge[0], |
| 7804 | params->ifname) < 0) |
| 7805 | goto failed; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7806 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7807 | br_added = 1; |
| 7808 | } |
| 7809 | |
| 7810 | if (!br_added && br_ifindex && |
| 7811 | (params->num_bridge == 0 || !params->bridge[0])) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7812 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7813 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7814 | #ifdef CONFIG_LIBNL3_ROUTE |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 7815 | if (bss->added_if_into_bridge || bss->already_in_bridge) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7816 | int err; |
| 7817 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7818 | drv->rtnl_sk = nl_socket_alloc(); |
| 7819 | if (drv->rtnl_sk == NULL) { |
| 7820 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); |
| 7821 | goto failed; |
| 7822 | } |
| 7823 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7824 | err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE); |
| 7825 | if (err) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7826 | 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] | 7827 | nl_geterror(err)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7828 | goto failed; |
| 7829 | } |
| 7830 | } |
| 7831 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 7832 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 7833 | if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) { |
| 7834 | wpa_printf(MSG_DEBUG, |
| 7835 | "nl80211: Do not open EAPOL RX socket - using control port for RX"); |
| 7836 | goto skip_eapol_sock; |
| 7837 | } |
| 7838 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7839 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
| 7840 | if (drv->eapol_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7841 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
| 7842 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7843 | goto failed; |
| 7844 | } |
| 7845 | |
| 7846 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) |
| 7847 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7848 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7849 | goto failed; |
| 7850 | } |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 7851 | skip_eapol_sock: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7852 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7853 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 7854 | params->own_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7855 | goto failed; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7856 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7857 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7858 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
| 7859 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7860 | return bss; |
| 7861 | |
| 7862 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7863 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7864 | return NULL; |
| 7865 | } |
| 7866 | |
| 7867 | |
| 7868 | static void i802_deinit(void *priv) |
| 7869 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7870 | struct i802_bss *bss = priv; |
| 7871 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7872 | } |
| 7873 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7874 | |
| 7875 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
| 7876 | enum wpa_driver_if_type type) |
| 7877 | { |
| 7878 | switch (type) { |
| 7879 | case WPA_IF_STATION: |
| 7880 | return NL80211_IFTYPE_STATION; |
| 7881 | case WPA_IF_P2P_CLIENT: |
| 7882 | case WPA_IF_P2P_GROUP: |
| 7883 | return NL80211_IFTYPE_P2P_CLIENT; |
| 7884 | case WPA_IF_AP_VLAN: |
| 7885 | return NL80211_IFTYPE_AP_VLAN; |
| 7886 | case WPA_IF_AP_BSS: |
| 7887 | return NL80211_IFTYPE_AP; |
| 7888 | case WPA_IF_P2P_GO: |
| 7889 | return NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7890 | case WPA_IF_P2P_DEVICE: |
| 7891 | return NL80211_IFTYPE_P2P_DEVICE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7892 | case WPA_IF_MESH: |
| 7893 | return NL80211_IFTYPE_MESH_POINT; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7894 | default: |
| 7895 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7896 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7897 | } |
| 7898 | |
| 7899 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7900 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
| 7901 | { |
| 7902 | struct wpa_driver_nl80211_data *drv; |
| 7903 | dl_list_for_each(drv, &global->interfaces, |
| 7904 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7905 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7906 | return 1; |
| 7907 | } |
| 7908 | return 0; |
| 7909 | } |
| 7910 | |
| 7911 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7912 | 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] | 7913 | { |
| 7914 | unsigned int idx; |
| 7915 | |
| 7916 | if (!drv->global) |
| 7917 | return -1; |
| 7918 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7919 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7920 | for (idx = 0; idx < 64; idx++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7921 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7922 | new_addr[0] ^= idx << 2; |
| 7923 | if (!nl80211_addr_in_use(drv->global, new_addr)) |
| 7924 | break; |
| 7925 | } |
| 7926 | if (idx == 64) |
| 7927 | return -1; |
| 7928 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7929 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7930 | MACSTR, MAC2STR(new_addr)); |
| 7931 | |
| 7932 | return 0; |
| 7933 | } |
| 7934 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7935 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7936 | struct wdev_info { |
| 7937 | u64 wdev_id; |
| 7938 | int wdev_id_set; |
| 7939 | u8 macaddr[ETH_ALEN]; |
| 7940 | }; |
| 7941 | |
| 7942 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) |
| 7943 | { |
| 7944 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7945 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7946 | struct wdev_info *wi = arg; |
| 7947 | |
| 7948 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7949 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7950 | if (tb[NL80211_ATTR_WDEV]) { |
| 7951 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 7952 | wi->wdev_id_set = 1; |
| 7953 | } |
| 7954 | |
| 7955 | if (tb[NL80211_ATTR_MAC]) |
| 7956 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 7957 | ETH_ALEN); |
| 7958 | |
| 7959 | return NL_SKIP; |
| 7960 | } |
| 7961 | |
| 7962 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7963 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
| 7964 | const char *ifname, const u8 *addr, |
| 7965 | void *bss_ctx, void **drv_priv, |
| 7966 | char *force_ifname, u8 *if_addr, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7967 | const char *bridge, int use_existing, |
| 7968 | int setup_ap) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7969 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7970 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7971 | struct i802_bss *bss = priv; |
| 7972 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7973 | int ifidx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7974 | int added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7975 | |
| 7976 | if (addr) |
| 7977 | os_memcpy(if_addr, addr, ETH_ALEN); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7978 | nlmode = wpa_driver_nl80211_if_type(type); |
| 7979 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 7980 | struct wdev_info p2pdev_info; |
| 7981 | |
| 7982 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); |
| 7983 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
| 7984 | 0, nl80211_wdev_handler, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7985 | &p2pdev_info, use_existing); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7986 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
| 7987 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
| 7988 | ifname); |
| 7989 | return -1; |
| 7990 | } |
| 7991 | |
| 7992 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; |
| 7993 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 7994 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7995 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 7996 | os_memcpy(drv->global->p2p_perm_addr, p2pdev_info.macaddr, ETH_ALEN); |
| 7997 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7998 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", |
| 7999 | ifname, |
| 8000 | (long long unsigned int) p2pdev_info.wdev_id); |
| 8001 | } else { |
| 8002 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8003 | 0, NULL, NULL, use_existing); |
| 8004 | if (use_existing && ifidx == -ENFILE) { |
| 8005 | added = 0; |
| 8006 | ifidx = if_nametoindex(ifname); |
| 8007 | } else if (ifidx < 0) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8008 | return -1; |
| 8009 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8010 | } |
| 8011 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8012 | if (!addr) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 8013 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8014 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
| 8015 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 8016 | ifname, if_addr) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8017 | if (added) |
| 8018 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8019 | return -1; |
| 8020 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8021 | } |
| 8022 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8023 | if (!addr && |
| 8024 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 8025 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
| 8026 | type == WPA_IF_STATION)) { |
| 8027 | /* Enforce unique address */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8028 | u8 new_addr[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8029 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8030 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8031 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8032 | if (added) |
| 8033 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8034 | return -1; |
| 8035 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8036 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8037 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 8038 | "for interface %s type %d", ifname, type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8039 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8040 | if (added) |
| 8041 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8042 | return -1; |
| 8043 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8044 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8045 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8046 | if (added) |
| 8047 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8048 | return -1; |
| 8049 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8050 | } |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8051 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8052 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8053 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8054 | if (type == WPA_IF_AP_BSS && setup_ap) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8055 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
| 8056 | if (new_bss == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8057 | if (added) |
| 8058 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8059 | return -1; |
| 8060 | } |
| 8061 | |
| 8062 | if (bridge && |
| 8063 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { |
| 8064 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " |
| 8065 | "interface %s to a bridge %s", |
| 8066 | ifname, bridge); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8067 | if (added) |
| 8068 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8069 | os_free(new_bss); |
| 8070 | return -1; |
| 8071 | } |
| 8072 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8073 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
| 8074 | { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 8075 | if (added) |
| 8076 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8077 | os_free(new_bss); |
| 8078 | return -1; |
| 8079 | } |
| 8080 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8081 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8082 | new_bss->ifindex = ifidx; |
| 8083 | new_bss->drv = drv; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8084 | new_bss->next = drv->first_bss->next; |
| 8085 | new_bss->freq = drv->first_bss->freq; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 8086 | new_bss->ctx = bss_ctx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8087 | new_bss->added_if = added; |
| 8088 | drv->first_bss->next = new_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8089 | if (drv_priv) |
| 8090 | *drv_priv = new_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8091 | nl80211_init_bss(new_bss); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8092 | |
| 8093 | /* Subscribe management frames for this WPA_IF_AP_BSS */ |
| 8094 | if (nl80211_setup_ap(new_bss)) |
| 8095 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8096 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8097 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8098 | if (drv->global) |
| 8099 | drv->global->if_add_ifindex = ifidx; |
| 8100 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 8101 | /* |
| 8102 | * Some virtual interfaces need to process EAPOL packets and events on |
| 8103 | * the parent interface. This is used mainly with hostapd. |
| 8104 | */ |
| 8105 | if (ifidx > 0 && |
| 8106 | (drv->hostapd || |
| 8107 | nlmode == NL80211_IFTYPE_AP_VLAN || |
| 8108 | nlmode == NL80211_IFTYPE_WDS || |
| 8109 | nlmode == NL80211_IFTYPE_MONITOR)) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8110 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8111 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8112 | return 0; |
| 8113 | } |
| 8114 | |
| 8115 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8116 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8117 | enum wpa_driver_if_type type, |
| 8118 | const char *ifname) |
| 8119 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8120 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8121 | int ifindex = if_nametoindex(ifname); |
| 8122 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8123 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
| 8124 | __func__, type, ifname, ifindex, bss->added_if); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 8125 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8126 | nl80211_remove_iface(drv, ifindex); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 8127 | else if (ifindex > 0 && !bss->added_if) { |
| 8128 | struct wpa_driver_nl80211_data *drv2; |
| 8129 | dl_list_for_each(drv2, &drv->global->interfaces, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 8130 | struct wpa_driver_nl80211_data, list) { |
| 8131 | del_ifidx(drv2, ifindex, IFIDX_ANY); |
| 8132 | del_ifidx(drv2, IFIDX_ANY, ifindex); |
| 8133 | } |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 8134 | } |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 8135 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 8136 | if (type != WPA_IF_AP_BSS) |
| 8137 | return 0; |
| 8138 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8139 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8140 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 8141 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8142 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 8143 | "interface %s from bridge %s: %s", |
| 8144 | bss->ifname, bss->brname, strerror(errno)); |
| 8145 | } |
| 8146 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8147 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8148 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 8149 | "bridge %s: %s", |
| 8150 | bss->brname, strerror(errno)); |
| 8151 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8152 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8153 | if (bss != drv->first_bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8154 | struct i802_bss *tbss; |
| 8155 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8156 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
| 8157 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8158 | if (tbss->next == bss) { |
| 8159 | tbss->next = bss->next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8160 | /* Unsubscribe management frames */ |
| 8161 | nl80211_teardown_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8162 | nl80211_destroy_bss(bss); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8163 | if (!bss->added_if) |
| 8164 | i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8165 | os_free(bss); |
| 8166 | bss = NULL; |
| 8167 | break; |
| 8168 | } |
| 8169 | } |
| 8170 | if (bss) |
| 8171 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " |
| 8172 | "BSS %p in the list", __func__, bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8173 | } else { |
| 8174 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
| 8175 | nl80211_teardown_ap(bss); |
| 8176 | if (!bss->added_if && !drv->first_bss->next) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8177 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 8178 | nl80211_destroy_bss(bss); |
| 8179 | if (!bss->added_if) |
| 8180 | i802_set_iface_flags(bss, 0); |
| 8181 | if (drv->first_bss->next) { |
| 8182 | drv->first_bss = drv->first_bss->next; |
| 8183 | drv->ctx = drv->first_bss->ctx; |
| 8184 | os_free(bss); |
| 8185 | } else { |
| 8186 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); |
| 8187 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8188 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8189 | |
| 8190 | return 0; |
| 8191 | } |
| 8192 | |
| 8193 | |
| 8194 | static int cookie_handler(struct nl_msg *msg, void *arg) |
| 8195 | { |
| 8196 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8197 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8198 | u64 *cookie = arg; |
| 8199 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8200 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8201 | if (tb[NL80211_ATTR_COOKIE]) |
| 8202 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 8203 | return NL_SKIP; |
| 8204 | } |
| 8205 | |
| 8206 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8207 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8208 | unsigned int freq, unsigned int wait, |
| 8209 | const u8 *buf, size_t buf_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8210 | int save_cookie, int no_cck, int no_ack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8211 | int offchanok, const u16 *csa_offs, |
| 8212 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8213 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8214 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8215 | struct nl_msg *msg; |
| 8216 | u64 cookie; |
| 8217 | int ret = -1; |
| 8218 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8219 | 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] | 8220 | "no_ack=%d offchanok=%d", |
| 8221 | freq, wait, no_cck, no_ack, offchanok); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 8222 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8223 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8224 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
| 8225 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 8226 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || |
| 8227 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 8228 | drv->test_use_roc_tx) && |
| 8229 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || |
| 8230 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || |
| 8231 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8232 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
| 8233 | csa_offs_len * sizeof(u16), csa_offs)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8234 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
| 8235 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8236 | |
| 8237 | cookie = 0; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8238 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8239 | msg = NULL; |
| 8240 | if (ret) { |
| 8241 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8242 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
| 8243 | freq, wait); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8244 | } else { |
| 8245 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " |
| 8246 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
| 8247 | (long long unsigned int) cookie); |
| 8248 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8249 | if (save_cookie) |
| 8250 | drv->send_frame_cookie = no_ack ? (u64) -1 : cookie; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8251 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8252 | if (drv->num_send_frame_cookies == MAX_SEND_FRAME_COOKIES) { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8253 | wpa_printf(MSG_DEBUG, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8254 | "nl80211: Drop oldest pending send frame cookie 0x%llx", |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8255 | (long long unsigned int) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8256 | drv->send_frame_cookies[0]); |
| 8257 | os_memmove(&drv->send_frame_cookies[0], |
| 8258 | &drv->send_frame_cookies[1], |
| 8259 | (MAX_SEND_FRAME_COOKIES - 1) * |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8260 | sizeof(u64)); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8261 | drv->num_send_frame_cookies--; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8262 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8263 | drv->send_frame_cookies[drv->num_send_frame_cookies] = cookie; |
| 8264 | drv->num_send_frame_cookies++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8265 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8266 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8267 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8268 | nlmsg_free(msg); |
| 8269 | return ret; |
| 8270 | } |
| 8271 | |
| 8272 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8273 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
| 8274 | unsigned int freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8275 | unsigned int wait_time, |
| 8276 | const u8 *dst, const u8 *src, |
| 8277 | const u8 *bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8278 | const u8 *data, size_t data_len, |
| 8279 | int no_cck) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8280 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8281 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8282 | int ret = -1; |
| 8283 | u8 *buf; |
| 8284 | struct ieee80211_hdr *hdr; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8285 | int offchanok = 1; |
| 8286 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 8287 | if (is_ap_interface(drv->nlmode) && (int) freq == bss->freq && |
| 8288 | bss->beacon_set) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8289 | offchanok = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8290 | |
| 8291 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8292 | "freq=%u MHz wait=%d ms no_cck=%d offchanok=%d)", |
| 8293 | drv->ifindex, freq, wait_time, no_cck, offchanok); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8294 | |
| 8295 | buf = os_zalloc(24 + data_len); |
| 8296 | if (buf == NULL) |
| 8297 | return ret; |
| 8298 | os_memcpy(buf + 24, data, data_len); |
| 8299 | hdr = (struct ieee80211_hdr *) buf; |
| 8300 | hdr->frame_control = |
| 8301 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); |
| 8302 | os_memcpy(hdr->addr1, dst, ETH_ALEN); |
| 8303 | os_memcpy(hdr->addr2, src, ETH_ALEN); |
| 8304 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); |
| 8305 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 8306 | if (os_memcmp(bss->addr, src, ETH_ALEN) != 0) { |
| 8307 | wpa_printf(MSG_DEBUG, "nl80211: Use random TA " MACSTR, |
| 8308 | MAC2STR(src)); |
| 8309 | os_memcpy(bss->rand_addr, src, ETH_ALEN); |
| 8310 | } else { |
| 8311 | os_memset(bss->rand_addr, 0, ETH_ALEN); |
| 8312 | } |
| 8313 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8314 | #ifdef CONFIG_MESH |
| 8315 | if (is_mesh_interface(drv->nlmode)) { |
| 8316 | struct hostapd_hw_modes *modes; |
| 8317 | u16 num_modes, flags; |
| 8318 | u8 dfs_domain; |
| 8319 | int i; |
| 8320 | |
| 8321 | modes = nl80211_get_hw_feature_data(bss, &num_modes, |
| 8322 | &flags, &dfs_domain); |
| 8323 | if (dfs_domain != HOSTAPD_DFS_REGION_ETSI && |
| 8324 | ieee80211_is_dfs(bss->freq, modes, num_modes)) |
| 8325 | offchanok = 0; |
| 8326 | if (modes) { |
| 8327 | for (i = 0; i < num_modes; i++) { |
| 8328 | os_free(modes[i].channels); |
| 8329 | os_free(modes[i].rates); |
| 8330 | } |
| 8331 | os_free(modes); |
| 8332 | } |
| 8333 | } |
| 8334 | #endif /* CONFIG_MESH */ |
| 8335 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8336 | if (is_ap_interface(drv->nlmode) && |
| 8337 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 8338 | (int) freq == bss->freq || drv->device_ap_sme || |
| 8339 | !drv->use_monitor)) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8340 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8341 | 0, freq, no_cck, offchanok, |
| 8342 | wait_time, NULL, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8343 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8344 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8345 | 24 + data_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8346 | 1, no_cck, 0, offchanok, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8347 | |
| 8348 | os_free(buf); |
| 8349 | return ret; |
| 8350 | } |
| 8351 | |
| 8352 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8353 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8354 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8355 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8356 | struct nl_msg *msg; |
| 8357 | int ret; |
| 8358 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 8359 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8360 | (long long unsigned int) cookie); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8361 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8362 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8363 | nlmsg_free(msg); |
| 8364 | return; |
| 8365 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8366 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8367 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8368 | if (ret) |
| 8369 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " |
| 8370 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8371 | } |
| 8372 | |
| 8373 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8374 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
| 8375 | { |
| 8376 | struct i802_bss *bss = priv; |
| 8377 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8378 | unsigned int i; |
| 8379 | u64 cookie; |
| 8380 | |
| 8381 | /* Cancel the last pending TX cookie */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8382 | nl80211_frame_wait_cancel(bss, drv->send_frame_cookie); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8383 | |
| 8384 | /* |
| 8385 | * Cancel the other pending TX cookies, if any. This is needed since |
| 8386 | * the driver may keep a list of all pending offchannel TX operations |
| 8387 | * and free up the radio only once they have expired or cancelled. |
| 8388 | */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8389 | for (i = drv->num_send_frame_cookies; i > 0; i--) { |
| 8390 | cookie = drv->send_frame_cookies[i - 1]; |
| 8391 | if (cookie != drv->send_frame_cookie) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8392 | nl80211_frame_wait_cancel(bss, cookie); |
| 8393 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8394 | drv->num_send_frame_cookies = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8395 | } |
| 8396 | |
| 8397 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8398 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
| 8399 | unsigned int duration) |
| 8400 | { |
| 8401 | struct i802_bss *bss = priv; |
| 8402 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8403 | struct nl_msg *msg; |
| 8404 | int ret; |
| 8405 | u64 cookie; |
| 8406 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8407 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
| 8408 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 8409 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { |
| 8410 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8411 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8412 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8413 | |
| 8414 | cookie = 0; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8415 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8416 | if (ret == 0) { |
| 8417 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " |
| 8418 | "0x%llx for freq=%u MHz duration=%u", |
| 8419 | (long long unsigned int) cookie, freq, duration); |
| 8420 | drv->remain_on_chan_cookie = cookie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8421 | drv->pending_remain_on_chan = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8422 | return 0; |
| 8423 | } |
| 8424 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " |
| 8425 | "(freq=%d duration=%u): %d (%s)", |
| 8426 | freq, duration, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8427 | return -1; |
| 8428 | } |
| 8429 | |
| 8430 | |
| 8431 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) |
| 8432 | { |
| 8433 | struct i802_bss *bss = priv; |
| 8434 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8435 | struct nl_msg *msg; |
| 8436 | int ret; |
| 8437 | |
| 8438 | if (!drv->pending_remain_on_chan) { |
| 8439 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " |
| 8440 | "to cancel"); |
| 8441 | return -1; |
| 8442 | } |
| 8443 | |
| 8444 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " |
| 8445 | "0x%llx", |
| 8446 | (long long unsigned int) drv->remain_on_chan_cookie); |
| 8447 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8448 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
| 8449 | if (!msg || |
| 8450 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
| 8451 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8452 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8453 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8454 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8455 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8456 | if (ret == 0) |
| 8457 | return 0; |
| 8458 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " |
| 8459 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8460 | return -1; |
| 8461 | } |
| 8462 | |
| 8463 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8464 | 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] | 8465 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8466 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8467 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8468 | if (!report) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8469 | if (bss->nl_preq && drv->device_ap_sme && |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 8470 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
| 8471 | !bss->static_ap) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8472 | /* |
| 8473 | * Do not disable Probe Request reporting that was |
| 8474 | * enabled in nl80211_setup_ap(). |
| 8475 | */ |
| 8476 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " |
| 8477 | "Probe Request reporting nl_preq=%p while " |
| 8478 | "in AP mode", bss->nl_preq); |
| 8479 | } else if (bss->nl_preq) { |
| 8480 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
| 8481 | "reporting nl_preq=%p", bss->nl_preq); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8482 | nl80211_destroy_eloop_handle(&bss->nl_preq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8483 | } |
| 8484 | return 0; |
| 8485 | } |
| 8486 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8487 | if (bss->nl_preq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8488 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8489 | "already on! nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8490 | return 0; |
| 8491 | } |
| 8492 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8493 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
| 8494 | if (bss->nl_preq == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8495 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8496 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
| 8497 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8498 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8499 | if (nl80211_register_frame(bss, bss->nl_preq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8500 | (WLAN_FC_TYPE_MGMT << 2) | |
| 8501 | (WLAN_FC_STYPE_PROBE_REQ << 4), |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 8502 | NULL, 0, false) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8503 | goto out_err; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 8504 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8505 | nl80211_register_eloop_read(&bss->nl_preq, |
| 8506 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8507 | bss->nl_cb, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8508 | |
| 8509 | return 0; |
| 8510 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8511 | out_err: |
| 8512 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8513 | return -1; |
| 8514 | } |
| 8515 | |
| 8516 | |
| 8517 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 8518 | int ifindex, int disabled) |
| 8519 | { |
| 8520 | struct nl_msg *msg; |
| 8521 | struct nlattr *bands, *band; |
| 8522 | int ret; |
| 8523 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8524 | wpa_printf(MSG_DEBUG, |
| 8525 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", |
| 8526 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : |
| 8527 | "no NL80211_TXRATE_LEGACY constraint"); |
| 8528 | |
| 8529 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
| 8530 | NL80211_CMD_SET_TX_BITRATE_MASK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8531 | if (!msg) |
| 8532 | return -1; |
| 8533 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8534 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 8535 | if (!bands) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8536 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8537 | |
| 8538 | /* |
| 8539 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything |
| 8540 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS |
| 8541 | * rates. All 5 GHz rates are left enabled. |
| 8542 | */ |
| 8543 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8544 | if (!band || |
| 8545 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, |
| 8546 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) |
| 8547 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8548 | nla_nest_end(msg, band); |
| 8549 | |
| 8550 | nla_nest_end(msg, bands); |
| 8551 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8552 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8553 | if (ret) { |
| 8554 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " |
| 8555 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8556 | } else |
| 8557 | drv->disabled_11b_rates = disabled; |
| 8558 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8559 | return ret; |
| 8560 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8561 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8562 | nlmsg_free(msg); |
| 8563 | return -1; |
| 8564 | } |
| 8565 | |
| 8566 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8567 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
| 8568 | { |
| 8569 | struct i802_bss *bss = priv; |
| 8570 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8571 | if (!is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8572 | return -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8573 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8574 | bss->beacon_set = 0; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8575 | |
| 8576 | /* |
| 8577 | * If the P2P GO interface was dynamically added, then it is |
| 8578 | * possible that the interface change to station is not possible. |
| 8579 | */ |
| 8580 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) |
| 8581 | return 0; |
| 8582 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8583 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8584 | } |
| 8585 | |
| 8586 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8587 | static int wpa_driver_nl80211_stop_ap(void *priv) |
| 8588 | { |
| 8589 | struct i802_bss *bss = priv; |
| 8590 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8591 | if (!is_ap_interface(drv->nlmode)) |
| 8592 | return -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8593 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8594 | bss->beacon_set = 0; |
| 8595 | return 0; |
| 8596 | } |
| 8597 | |
| 8598 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8599 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
| 8600 | { |
| 8601 | struct i802_bss *bss = priv; |
| 8602 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8603 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) |
| 8604 | return -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8605 | |
| 8606 | /* |
| 8607 | * If the P2P Client interface was dynamically added, then it is |
| 8608 | * possible that the interface change to station is not possible. |
| 8609 | */ |
| 8610 | if (bss->if_dynamic) |
| 8611 | return 0; |
| 8612 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8613 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
| 8614 | } |
| 8615 | |
| 8616 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8617 | static void wpa_driver_nl80211_resume(void *priv) |
| 8618 | { |
| 8619 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8620 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8621 | |
| 8622 | if (i802_set_iface_flags(bss, 1)) |
| 8623 | 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] | 8624 | |
| 8625 | if (is_p2p_net_interface(nlmode)) |
| 8626 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8627 | } |
| 8628 | |
| 8629 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8630 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
| 8631 | { |
| 8632 | struct i802_bss *bss = priv; |
| 8633 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8634 | struct nl_msg *msg; |
| 8635 | struct nlattr *cqm; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8636 | |
| 8637 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " |
| 8638 | "hysteresis=%d", threshold, hysteresis); |
| 8639 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8640 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
| 8641 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
| 8642 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || |
| 8643 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { |
| 8644 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8645 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8646 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8647 | nla_nest_end(msg, cqm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8648 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8649 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8650 | } |
| 8651 | |
| 8652 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8653 | static int get_channel_width(struct nl_msg *msg, void *arg) |
| 8654 | { |
| 8655 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8656 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8657 | struct wpa_signal_info *sig_change = arg; |
| 8658 | |
| 8659 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8660 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8661 | |
| 8662 | sig_change->center_frq1 = -1; |
| 8663 | sig_change->center_frq2 = -1; |
| 8664 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 8665 | |
| 8666 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 8667 | sig_change->chanwidth = convert2width( |
| 8668 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 8669 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 8670 | sig_change->center_frq1 = |
| 8671 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 8672 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 8673 | sig_change->center_frq2 = |
| 8674 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 8675 | } |
| 8676 | |
| 8677 | return NL_SKIP; |
| 8678 | } |
| 8679 | |
| 8680 | |
| 8681 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, |
| 8682 | struct wpa_signal_info *sig) |
| 8683 | { |
| 8684 | struct nl_msg *msg; |
| 8685 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8686 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8687 | 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] | 8688 | } |
| 8689 | |
| 8690 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8691 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
| 8692 | { |
| 8693 | struct i802_bss *bss = priv; |
| 8694 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8695 | int res; |
| 8696 | |
| 8697 | os_memset(si, 0, sizeof(*si)); |
| 8698 | res = nl80211_get_link_signal(drv, si); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8699 | if (res) { |
| 8700 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && |
| 8701 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
| 8702 | return res; |
| 8703 | si->current_signal = 0; |
| 8704 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8705 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8706 | res = nl80211_get_channel_width(drv, si); |
| 8707 | if (res != 0) |
| 8708 | return res; |
| 8709 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8710 | return nl80211_get_link_noise(drv, si); |
| 8711 | } |
| 8712 | |
| 8713 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8714 | static int nl80211_set_param(void *priv, const char *param) |
| 8715 | { |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 8716 | struct i802_bss *bss = priv; |
| 8717 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8718 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8719 | if (param == NULL) |
| 8720 | return 0; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 8721 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8722 | |
| 8723 | #ifdef CONFIG_P2P |
| 8724 | if (os_strstr(param, "use_p2p_group_interface=1")) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8725 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 8726 | "interface"); |
| 8727 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 8728 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 8729 | } |
| 8730 | #endif /* CONFIG_P2P */ |
| 8731 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 8732 | if (os_strstr(param, "use_monitor=1")) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8733 | drv->use_monitor = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8734 | |
| 8735 | if (os_strstr(param, "force_connect_cmd=1")) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8736 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8737 | drv->force_connect_cmd = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8738 | } |
| 8739 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 8740 | if (os_strstr(param, "force_bss_selection=1")) |
| 8741 | drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
| 8742 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 8743 | if (os_strstr(param, "no_offchannel_tx=1")) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 8744 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 8745 | drv->test_use_roc_tx = 1; |
| 8746 | } |
| 8747 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 8748 | if (os_strstr(param, "control_port=0")) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8749 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_CONTROL_PORT; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8750 | drv->capa.flags2 &= ~(WPA_DRIVER_FLAGS2_CONTROL_PORT_RX | |
| 8751 | WPA_DRIVER_FLAGS2_CONTROL_PORT_TX_STATUS); |
| 8752 | drv->control_port_ap = 0; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 8753 | } |
| 8754 | |
| 8755 | if (os_strstr(param, "control_port_ap=1")) |
| 8756 | drv->control_port_ap = 1; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8757 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8758 | if (os_strstr(param, "control_port_ap=0")) { |
| 8759 | drv->capa.flags2 &= ~WPA_DRIVER_FLAGS2_CONTROL_PORT_TX_STATUS; |
| 8760 | drv->control_port_ap = 0; |
| 8761 | } |
| 8762 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8763 | if (os_strstr(param, "full_ap_client_state=0")) |
| 8764 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE; |
| 8765 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8766 | if (os_strstr(param, "no_rrm=1")) { |
| 8767 | drv->no_rrm = 1; |
| 8768 | |
| 8769 | if (!bss->in_deinit && !is_ap_interface(drv->nlmode) && |
| 8770 | !is_mesh_interface(drv->nlmode)) { |
| 8771 | nl80211_mgmt_unsubscribe(bss, "no_rrm=1"); |
| 8772 | if (nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 8773 | wpa_printf(MSG_DEBUG, |
| 8774 | "nl80211: Failed to re-register Action frame processing - ignore for now"); |
| 8775 | } |
| 8776 | } |
| 8777 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8778 | return 0; |
| 8779 | } |
| 8780 | |
| 8781 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 8782 | static void * nl80211_global_init(void *ctx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8783 | { |
| 8784 | struct nl80211_global *global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8785 | struct netlink_config *cfg; |
| 8786 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8787 | global = os_zalloc(sizeof(*global)); |
| 8788 | if (global == NULL) |
| 8789 | return NULL; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 8790 | global->ctx = ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8791 | global->ioctl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8792 | dl_list_init(&global->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8793 | global->if_add_ifindex = -1; |
| 8794 | |
| 8795 | cfg = os_zalloc(sizeof(*cfg)); |
| 8796 | if (cfg == NULL) |
| 8797 | goto err; |
| 8798 | |
| 8799 | cfg->ctx = global; |
| 8800 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; |
| 8801 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; |
| 8802 | global->netlink = netlink_init(cfg); |
| 8803 | if (global->netlink == NULL) { |
| 8804 | os_free(cfg); |
| 8805 | goto err; |
| 8806 | } |
| 8807 | |
| 8808 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
| 8809 | goto err; |
| 8810 | |
| 8811 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 8812 | if (global->ioctl_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8813 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
| 8814 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8815 | goto err; |
| 8816 | } |
| 8817 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8818 | return global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8819 | |
| 8820 | err: |
| 8821 | nl80211_global_deinit(global); |
| 8822 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8823 | } |
| 8824 | |
| 8825 | |
| 8826 | static void nl80211_global_deinit(void *priv) |
| 8827 | { |
| 8828 | struct nl80211_global *global = priv; |
| 8829 | if (global == NULL) |
| 8830 | return; |
| 8831 | if (!dl_list_empty(&global->interfaces)) { |
| 8832 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " |
| 8833 | "nl80211_global_deinit", |
| 8834 | dl_list_len(&global->interfaces)); |
| 8835 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8836 | |
| 8837 | if (global->netlink) |
| 8838 | netlink_deinit(global->netlink); |
| 8839 | |
| 8840 | nl_destroy_handles(&global->nl); |
| 8841 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8842 | if (global->nl_event) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8843 | nl80211_destroy_eloop_handle(&global->nl_event, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8844 | |
| 8845 | nl_cb_put(global->nl_cb); |
| 8846 | |
| 8847 | if (global->ioctl_sock >= 0) |
| 8848 | close(global->ioctl_sock); |
| 8849 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8850 | os_free(global); |
| 8851 | } |
| 8852 | |
| 8853 | |
| 8854 | static const char * nl80211_get_radio_name(void *priv) |
| 8855 | { |
| 8856 | struct i802_bss *bss = priv; |
| 8857 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8858 | return drv->phyname; |
| 8859 | } |
| 8860 | |
| 8861 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8862 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, |
| 8863 | struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8864 | { |
| 8865 | struct nl_msg *msg; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8866 | const size_t PMK_MAX_LEN = 48; /* current cfg80211 limit */ |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8867 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8868 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8869 | (params->pmkid && |
| 8870 | nla_put(msg, NL80211_ATTR_PMKID, 16, params->pmkid)) || |
| 8871 | (params->bssid && |
| 8872 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) || |
| 8873 | (params->ssid_len && |
| 8874 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || |
| 8875 | (params->fils_cache_id && |
| 8876 | nla_put(msg, NL80211_ATTR_FILS_CACHE_ID, 2, |
| 8877 | params->fils_cache_id)) || |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8878 | (params->pmk_lifetime && |
| 8879 | nla_put_u32(msg, NL80211_ATTR_PMK_LIFETIME, |
| 8880 | params->pmk_lifetime)) || |
| 8881 | (params->pmk_reauth_threshold && |
| 8882 | nla_put_u8(msg, NL80211_ATTR_PMK_REAUTH_THRESHOLD, |
| 8883 | params->pmk_reauth_threshold)) || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 8884 | (cmd != NL80211_CMD_DEL_PMKSA && |
| 8885 | params->pmk_len && params->pmk_len <= PMK_MAX_LEN && |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8886 | nla_put(msg, NL80211_ATTR_PMK, params->pmk_len, params->pmk))) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8887 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8888 | nlmsg_free(msg); |
| 8889 | return -ENOBUFS; |
| 8890 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8891 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 8892 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8893 | } |
| 8894 | |
| 8895 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8896 | static int nl80211_add_pmkid(void *priv, struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8897 | { |
| 8898 | struct i802_bss *bss = priv; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8899 | int ret; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8900 | |
| 8901 | if (params->bssid) |
| 8902 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, |
| 8903 | MAC2STR(params->bssid)); |
| 8904 | else if (params->fils_cache_id && params->ssid_len) { |
| 8905 | wpa_printf(MSG_DEBUG, |
| 8906 | "nl80211: Add PMKSA for cache id %02x%02x SSID %s", |
| 8907 | params->fils_cache_id[0], params->fils_cache_id[1], |
| 8908 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
| 8909 | } |
| 8910 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8911 | ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params); |
| 8912 | if (ret < 0) { |
| 8913 | wpa_printf(MSG_DEBUG, |
| 8914 | "nl80211: NL80211_CMD_SET_PMKSA failed: %d (%s)", |
| 8915 | ret, strerror(-ret)); |
| 8916 | } |
| 8917 | |
| 8918 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8919 | } |
| 8920 | |
| 8921 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8922 | static int nl80211_remove_pmkid(void *priv, struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8923 | { |
| 8924 | struct i802_bss *bss = priv; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8925 | int ret; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8926 | |
| 8927 | if (params->bssid) |
| 8928 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, |
| 8929 | MAC2STR(params->bssid)); |
| 8930 | else if (params->fils_cache_id && params->ssid_len) { |
| 8931 | wpa_printf(MSG_DEBUG, |
| 8932 | "nl80211: Delete PMKSA for cache id %02x%02x SSID %s", |
| 8933 | params->fils_cache_id[0], params->fils_cache_id[1], |
| 8934 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
| 8935 | } |
| 8936 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8937 | ret = nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, params); |
| 8938 | if (ret < 0) { |
| 8939 | wpa_printf(MSG_DEBUG, |
| 8940 | "nl80211: NL80211_CMD_DEL_PMKSA failed: %d (%s)", |
| 8941 | ret, strerror(-ret)); |
| 8942 | } |
| 8943 | |
| 8944 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8945 | } |
| 8946 | |
| 8947 | |
| 8948 | static int nl80211_flush_pmkid(void *priv) |
| 8949 | { |
| 8950 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8951 | struct nl_msg *msg; |
| 8952 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8953 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8954 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_FLUSH_PMKSA); |
| 8955 | if (!msg) |
| 8956 | return -ENOBUFS; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8957 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8958 | } |
| 8959 | |
| 8960 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8961 | static void clean_survey_results(struct survey_results *survey_results) |
| 8962 | { |
| 8963 | struct freq_survey *survey, *tmp; |
| 8964 | |
| 8965 | if (dl_list_empty(&survey_results->survey_list)) |
| 8966 | return; |
| 8967 | |
| 8968 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 8969 | struct freq_survey, list) { |
| 8970 | dl_list_del(&survey->list); |
| 8971 | os_free(survey); |
| 8972 | } |
| 8973 | } |
| 8974 | |
| 8975 | |
| 8976 | static void add_survey(struct nlattr **sinfo, u32 ifidx, |
| 8977 | struct dl_list *survey_list) |
| 8978 | { |
| 8979 | struct freq_survey *survey; |
| 8980 | |
| 8981 | survey = os_zalloc(sizeof(struct freq_survey)); |
| 8982 | if (!survey) |
| 8983 | return; |
| 8984 | |
| 8985 | survey->ifidx = ifidx; |
| 8986 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 8987 | survey->filled = 0; |
| 8988 | |
| 8989 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { |
| 8990 | survey->nf = (int8_t) |
| 8991 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 8992 | survey->filled |= SURVEY_HAS_NF; |
| 8993 | } |
| 8994 | |
| 8995 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { |
| 8996 | survey->channel_time = |
| 8997 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); |
| 8998 | survey->filled |= SURVEY_HAS_CHAN_TIME; |
| 8999 | } |
| 9000 | |
| 9001 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { |
| 9002 | survey->channel_time_busy = |
| 9003 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); |
| 9004 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; |
| 9005 | } |
| 9006 | |
| 9007 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { |
| 9008 | survey->channel_time_rx = |
| 9009 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); |
| 9010 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; |
| 9011 | } |
| 9012 | |
| 9013 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { |
| 9014 | survey->channel_time_tx = |
| 9015 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); |
| 9016 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; |
| 9017 | } |
| 9018 | |
| 9019 | 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)", |
| 9020 | survey->freq, |
| 9021 | survey->nf, |
| 9022 | (unsigned long int) survey->channel_time, |
| 9023 | (unsigned long int) survey->channel_time_busy, |
| 9024 | (unsigned long int) survey->channel_time_tx, |
| 9025 | (unsigned long int) survey->channel_time_rx, |
| 9026 | survey->filled); |
| 9027 | |
| 9028 | dl_list_add_tail(survey_list, &survey->list); |
| 9029 | } |
| 9030 | |
| 9031 | |
| 9032 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, |
| 9033 | unsigned int freq_filter) |
| 9034 | { |
| 9035 | if (!freq_filter) |
| 9036 | return 1; |
| 9037 | |
| 9038 | return freq_filter == surveyed_freq; |
| 9039 | } |
| 9040 | |
| 9041 | |
| 9042 | static int survey_handler(struct nl_msg *msg, void *arg) |
| 9043 | { |
| 9044 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9045 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9046 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 9047 | struct survey_results *survey_results; |
| 9048 | u32 surveyed_freq = 0; |
| 9049 | u32 ifidx; |
| 9050 | |
| 9051 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 9052 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 9053 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 9054 | }; |
| 9055 | |
| 9056 | survey_results = (struct survey_results *) arg; |
| 9057 | |
| 9058 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9059 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9060 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 9061 | if (!tb[NL80211_ATTR_IFINDEX]) |
| 9062 | return NL_SKIP; |
| 9063 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9064 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 9065 | |
| 9066 | if (!tb[NL80211_ATTR_SURVEY_INFO]) |
| 9067 | return NL_SKIP; |
| 9068 | |
| 9069 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 9070 | tb[NL80211_ATTR_SURVEY_INFO], |
| 9071 | survey_policy)) |
| 9072 | return NL_SKIP; |
| 9073 | |
| 9074 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { |
| 9075 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); |
| 9076 | return NL_SKIP; |
| 9077 | } |
| 9078 | |
| 9079 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 9080 | |
| 9081 | if (!check_survey_ok(sinfo, surveyed_freq, |
| 9082 | survey_results->freq_filter)) |
| 9083 | return NL_SKIP; |
| 9084 | |
| 9085 | if (survey_results->freq_filter && |
| 9086 | survey_results->freq_filter != surveyed_freq) { |
| 9087 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", |
| 9088 | surveyed_freq); |
| 9089 | return NL_SKIP; |
| 9090 | } |
| 9091 | |
| 9092 | add_survey(sinfo, ifidx, &survey_results->survey_list); |
| 9093 | |
| 9094 | return NL_SKIP; |
| 9095 | } |
| 9096 | |
| 9097 | |
| 9098 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) |
| 9099 | { |
| 9100 | struct i802_bss *bss = priv; |
| 9101 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9102 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9103 | int err; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9104 | union wpa_event_data data; |
| 9105 | struct survey_results *survey_results; |
| 9106 | |
| 9107 | os_memset(&data, 0, sizeof(data)); |
| 9108 | survey_results = &data.survey_results; |
| 9109 | |
| 9110 | dl_list_init(&survey_results->survey_list); |
| 9111 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9112 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9113 | if (!msg) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9114 | return -ENOBUFS; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9115 | |
| 9116 | if (freq) |
| 9117 | data.survey_results.freq_filter = freq; |
| 9118 | |
| 9119 | do { |
| 9120 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); |
| 9121 | err = send_and_recv_msgs(drv, msg, survey_handler, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9122 | survey_results, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9123 | } while (err > 0); |
| 9124 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9125 | if (err) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9126 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9127 | else |
| 9128 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9129 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9130 | clean_survey_results(survey_results); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9131 | return err; |
| 9132 | } |
| 9133 | |
| 9134 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 9135 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
| 9136 | const u8 *kck, size_t kck_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9137 | const u8 *replay_ctr) |
| 9138 | { |
| 9139 | struct i802_bss *bss = priv; |
| 9140 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9141 | struct nlattr *replay_nested; |
| 9142 | struct nl_msg *msg; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9143 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9144 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9145 | if (!drv->set_rekey_offload) |
| 9146 | return; |
| 9147 | |
| 9148 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9149 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
| 9150 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 9151 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9152 | (kck_len && nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9153 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
| 9154 | replay_ctr)) { |
| 9155 | nl80211_nlmsg_clear(msg); |
| 9156 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9157 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9158 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9159 | |
| 9160 | nla_nest_end(msg, replay_nested); |
| 9161 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 9162 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9163 | if (ret == -EOPNOTSUPP) { |
| 9164 | wpa_printf(MSG_DEBUG, |
| 9165 | "nl80211: Driver does not support rekey offload"); |
| 9166 | drv->set_rekey_offload = 0; |
| 9167 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9168 | } |
| 9169 | |
| 9170 | |
| 9171 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
| 9172 | const u8 *addr, int qos) |
| 9173 | { |
| 9174 | /* send data frame to poll STA and check whether |
| 9175 | * this frame is ACKed */ |
| 9176 | struct { |
| 9177 | struct ieee80211_hdr hdr; |
| 9178 | u16 qos_ctl; |
| 9179 | } STRUCT_PACKED nulldata; |
| 9180 | size_t size; |
| 9181 | |
| 9182 | /* Send data frame to poll STA and check whether this frame is ACKed */ |
| 9183 | |
| 9184 | os_memset(&nulldata, 0, sizeof(nulldata)); |
| 9185 | |
| 9186 | if (qos) { |
| 9187 | nulldata.hdr.frame_control = |
| 9188 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 9189 | WLAN_FC_STYPE_QOS_NULL); |
| 9190 | size = sizeof(nulldata); |
| 9191 | } else { |
| 9192 | nulldata.hdr.frame_control = |
| 9193 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 9194 | WLAN_FC_STYPE_NULLFUNC); |
| 9195 | size = sizeof(struct ieee80211_hdr); |
| 9196 | } |
| 9197 | |
| 9198 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 9199 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 9200 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 9201 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 9202 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9203 | 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] | 9204 | 0, 0, NULL, 0, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9205 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
| 9206 | "send poll frame"); |
| 9207 | } |
| 9208 | |
| 9209 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
| 9210 | int qos) |
| 9211 | { |
| 9212 | struct i802_bss *bss = priv; |
| 9213 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9214 | struct nl_msg *msg; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 9215 | u64 cookie; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9216 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9217 | |
| 9218 | if (!drv->poll_command_supported) { |
| 9219 | nl80211_send_null_frame(bss, own_addr, addr, qos); |
| 9220 | return; |
| 9221 | } |
| 9222 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9223 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
| 9224 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 9225 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9226 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9227 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9228 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9229 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie, NULL, NULL); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9230 | if (ret < 0) { |
| 9231 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " |
| 9232 | MACSTR " failed: ret=%d (%s)", |
| 9233 | MAC2STR(addr), ret, strerror(-ret)); |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 9234 | } else { |
| 9235 | wpa_printf(MSG_DEBUG, |
| 9236 | "nl80211: Client probe request addr=" MACSTR |
| 9237 | " cookie=%llu", MAC2STR(addr), |
| 9238 | (long long unsigned int) cookie); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9239 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9240 | } |
| 9241 | |
| 9242 | |
| 9243 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
| 9244 | { |
| 9245 | struct nl_msg *msg; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9246 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9247 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9248 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
| 9249 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
| 9250 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { |
| 9251 | nlmsg_free(msg); |
| 9252 | return -ENOBUFS; |
| 9253 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9254 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9255 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9256 | if (ret < 0) { |
| 9257 | wpa_printf(MSG_DEBUG, |
| 9258 | "nl80211: Setting PS state %s failed: %d (%s)", |
| 9259 | enabled ? "enabled" : "disabled", |
| 9260 | ret, strerror(-ret)); |
| 9261 | } |
| 9262 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9263 | } |
| 9264 | |
| 9265 | |
| 9266 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, |
| 9267 | int ctwindow) |
| 9268 | { |
| 9269 | struct i802_bss *bss = priv; |
| 9270 | |
| 9271 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " |
| 9272 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); |
| 9273 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 9274 | if (opp_ps != -1 || ctwindow != -1) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 9275 | #ifdef ANDROID_P2P |
| 9276 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 9277 | #else /* ANDROID_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9278 | return -1; /* Not yet supported */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 9279 | #endif /* ANDROID_P2P */ |
| 9280 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9281 | |
| 9282 | if (legacy_ps == -1) |
| 9283 | return 0; |
| 9284 | if (legacy_ps != 0 && legacy_ps != 1) |
| 9285 | return -1; /* Not yet supported */ |
| 9286 | |
| 9287 | return nl80211_set_power_save(bss, legacy_ps); |
| 9288 | } |
| 9289 | |
| 9290 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 9291 | static int nl80211_start_radar_detection(void *priv, |
| 9292 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9293 | { |
| 9294 | struct i802_bss *bss = priv; |
| 9295 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9296 | struct nl_msg *msg; |
| 9297 | int ret; |
| 9298 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 9299 | 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)", |
| 9300 | freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 9301 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 9302 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9303 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
| 9304 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " |
| 9305 | "detection"); |
| 9306 | return -1; |
| 9307 | } |
| 9308 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9309 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
| 9310 | nl80211_put_freq_params(msg, freq) < 0) { |
| 9311 | nlmsg_free(msg); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9312 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9313 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9314 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9315 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9316 | if (ret == 0) |
| 9317 | return 0; |
| 9318 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " |
| 9319 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9320 | return -1; |
| 9321 | } |
| 9322 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9323 | #ifdef CONFIG_TDLS |
| 9324 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9325 | static int nl80211_add_peer_capab(struct nl_msg *msg, |
| 9326 | enum tdls_peer_capability capa) |
| 9327 | { |
| 9328 | u32 peer_capab = 0; |
| 9329 | |
| 9330 | if (!capa) |
| 9331 | return 0; |
| 9332 | |
| 9333 | if (capa & TDLS_PEER_HT) |
| 9334 | peer_capab |= NL80211_TDLS_PEER_HT; |
| 9335 | if (capa & TDLS_PEER_VHT) |
| 9336 | peer_capab |= NL80211_TDLS_PEER_VHT; |
| 9337 | if (capa & TDLS_PEER_WMM) |
| 9338 | peer_capab |= NL80211_TDLS_PEER_WMM; |
| 9339 | if (capa & TDLS_PEER_HE) |
| 9340 | peer_capab |= NL80211_TDLS_PEER_HE; |
| 9341 | |
| 9342 | return nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
| 9343 | peer_capab); |
| 9344 | } |
| 9345 | |
| 9346 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9347 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, |
| 9348 | u8 dialog_token, u16 status_code, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 9349 | u32 peer_capab, int initiator, const u8 *buf, |
| 9350 | size_t len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9351 | { |
| 9352 | struct i802_bss *bss = priv; |
| 9353 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9354 | struct nl_msg *msg; |
| 9355 | |
| 9356 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 9357 | return -EOPNOTSUPP; |
| 9358 | |
| 9359 | if (!dst) |
| 9360 | return -EINVAL; |
| 9361 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9362 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
| 9363 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 9364 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || |
| 9365 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9366 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code) || |
| 9367 | nl80211_add_peer_capab(msg, peer_capab) || |
| 9368 | (initiator && nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9369 | nla_put(msg, NL80211_ATTR_IE, len, buf)) |
| 9370 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9371 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9372 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9373 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9374 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9375 | nlmsg_free(msg); |
| 9376 | return -ENOBUFS; |
| 9377 | } |
| 9378 | |
| 9379 | |
| 9380 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) |
| 9381 | { |
| 9382 | struct i802_bss *bss = priv; |
| 9383 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9384 | struct nl_msg *msg; |
| 9385 | enum nl80211_tdls_operation nl80211_oper; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9386 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9387 | |
| 9388 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 9389 | return -EOPNOTSUPP; |
| 9390 | |
| 9391 | switch (oper) { |
| 9392 | case TDLS_DISCOVERY_REQ: |
| 9393 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; |
| 9394 | break; |
| 9395 | case TDLS_SETUP: |
| 9396 | nl80211_oper = NL80211_TDLS_SETUP; |
| 9397 | break; |
| 9398 | case TDLS_TEARDOWN: |
| 9399 | nl80211_oper = NL80211_TDLS_TEARDOWN; |
| 9400 | break; |
| 9401 | case TDLS_ENABLE_LINK: |
| 9402 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; |
| 9403 | break; |
| 9404 | case TDLS_DISABLE_LINK: |
| 9405 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; |
| 9406 | break; |
| 9407 | case TDLS_ENABLE: |
| 9408 | return 0; |
| 9409 | case TDLS_DISABLE: |
| 9410 | return 0; |
| 9411 | default: |
| 9412 | return -EINVAL; |
| 9413 | } |
| 9414 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9415 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
| 9416 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
| 9417 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
| 9418 | nlmsg_free(msg); |
| 9419 | return -ENOBUFS; |
| 9420 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9421 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9422 | res = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9423 | wpa_printf(MSG_DEBUG, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR |
| 9424 | " --> res=%d (%s)", nl80211_oper, MAC2STR(peer), res, |
| 9425 | strerror(-res)); |
| 9426 | return res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9427 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9428 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9429 | |
| 9430 | static int |
| 9431 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, |
| 9432 | const struct hostapd_freq_params *params) |
| 9433 | { |
| 9434 | struct i802_bss *bss = priv; |
| 9435 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9436 | struct nl_msg *msg; |
| 9437 | int ret = -ENOBUFS; |
| 9438 | |
| 9439 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 9440 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 9441 | return -EOPNOTSUPP; |
| 9442 | |
| 9443 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR |
| 9444 | " oper_class=%u freq=%u", |
| 9445 | MAC2STR(addr), oper_class, params->freq); |
| 9446 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); |
| 9447 | if (!msg || |
| 9448 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 9449 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || |
| 9450 | (ret = nl80211_put_freq_params(msg, params))) { |
| 9451 | nlmsg_free(msg); |
| 9452 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); |
| 9453 | return ret; |
| 9454 | } |
| 9455 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9456 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9457 | } |
| 9458 | |
| 9459 | |
| 9460 | static int |
| 9461 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) |
| 9462 | { |
| 9463 | struct i802_bss *bss = priv; |
| 9464 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9465 | struct nl_msg *msg; |
| 9466 | |
| 9467 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 9468 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 9469 | return -EOPNOTSUPP; |
| 9470 | |
| 9471 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, |
| 9472 | MAC2STR(addr)); |
| 9473 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); |
| 9474 | if (!msg || |
| 9475 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 9476 | nlmsg_free(msg); |
| 9477 | wpa_printf(MSG_DEBUG, |
| 9478 | "nl80211: Could not build TDLS cancel chan switch"); |
| 9479 | return -ENOBUFS; |
| 9480 | } |
| 9481 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9482 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9483 | } |
| 9484 | |
| 9485 | #endif /* CONFIG TDLS */ |
| 9486 | |
| 9487 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9488 | static int driver_nl80211_set_key(void *priv, |
| 9489 | struct wpa_driver_set_key_params *params) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9490 | { |
| 9491 | struct i802_bss *bss = priv; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9492 | |
| 9493 | return wpa_driver_nl80211_set_key(bss, params); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9494 | } |
| 9495 | |
| 9496 | |
| 9497 | static int driver_nl80211_scan2(void *priv, |
| 9498 | struct wpa_driver_scan_params *params) |
| 9499 | { |
| 9500 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9501 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 9502 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9503 | |
| 9504 | /* |
| 9505 | * Do a vendor specific scan if possible. If only_new_results is |
| 9506 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush |
| 9507 | * cannot be achieved through a vendor scan. The below condition may |
| 9508 | * need to be modified if new scan flags are added in the future whose |
| 9509 | * functionality can only be achieved through a normal scan. |
| 9510 | */ |
| 9511 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) |
| 9512 | return wpa_driver_nl80211_vendor_scan(bss, params); |
| 9513 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9514 | return wpa_driver_nl80211_scan(bss, params); |
| 9515 | } |
| 9516 | |
| 9517 | |
| 9518 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 9519 | u16 reason_code) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9520 | { |
| 9521 | struct i802_bss *bss = priv; |
| 9522 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); |
| 9523 | } |
| 9524 | |
| 9525 | |
| 9526 | static int driver_nl80211_authenticate(void *priv, |
| 9527 | struct wpa_driver_auth_params *params) |
| 9528 | { |
| 9529 | struct i802_bss *bss = priv; |
| 9530 | return wpa_driver_nl80211_authenticate(bss, params); |
| 9531 | } |
| 9532 | |
| 9533 | |
| 9534 | static void driver_nl80211_deinit(void *priv) |
| 9535 | { |
| 9536 | struct i802_bss *bss = priv; |
| 9537 | wpa_driver_nl80211_deinit(bss); |
| 9538 | } |
| 9539 | |
| 9540 | |
| 9541 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, |
| 9542 | const char *ifname) |
| 9543 | { |
| 9544 | struct i802_bss *bss = priv; |
| 9545 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 9546 | } |
| 9547 | |
| 9548 | |
| 9549 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 9550 | size_t data_len, int noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9551 | unsigned int freq, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9552 | const u16 *csa_offs, size_t csa_offs_len, |
| 9553 | int no_encrypt, unsigned int wait) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9554 | { |
| 9555 | struct i802_bss *bss = priv; |
| 9556 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9557 | freq, 0, 0, wait, csa_offs, |
| 9558 | csa_offs_len, no_encrypt); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9559 | } |
| 9560 | |
| 9561 | |
| 9562 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) |
| 9563 | { |
| 9564 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9565 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9566 | } |
| 9567 | |
| 9568 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9569 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
| 9570 | const char *ifname, int vlan_id) |
| 9571 | { |
| 9572 | struct i802_bss *bss = priv; |
| 9573 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); |
| 9574 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9575 | |
| 9576 | |
| 9577 | static int driver_nl80211_read_sta_data(void *priv, |
| 9578 | struct hostap_sta_driver_data *data, |
| 9579 | const u8 *addr) |
| 9580 | { |
| 9581 | struct i802_bss *bss = priv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 9582 | |
| 9583 | os_memset(data, 0, sizeof(*data)); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9584 | return i802_read_sta_data(bss, data, addr); |
| 9585 | } |
| 9586 | |
| 9587 | |
| 9588 | static int driver_nl80211_send_action(void *priv, unsigned int freq, |
| 9589 | unsigned int wait_time, |
| 9590 | const u8 *dst, const u8 *src, |
| 9591 | const u8 *bssid, |
| 9592 | const u8 *data, size_t data_len, |
| 9593 | int no_cck) |
| 9594 | { |
| 9595 | struct i802_bss *bss = priv; |
| 9596 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, |
| 9597 | bssid, data, data_len, no_cck); |
| 9598 | } |
| 9599 | |
| 9600 | |
| 9601 | static int driver_nl80211_probe_req_report(void *priv, int report) |
| 9602 | { |
| 9603 | struct i802_bss *bss = priv; |
| 9604 | return wpa_driver_nl80211_probe_req_report(bss, report); |
| 9605 | } |
| 9606 | |
| 9607 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 9608 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
| 9609 | const u8 *ies, size_t ies_len) |
| 9610 | { |
| 9611 | int ret; |
| 9612 | struct nl_msg *msg; |
| 9613 | struct i802_bss *bss = priv; |
| 9614 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9615 | u16 mdid = WPA_GET_LE16(md); |
| 9616 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 9617 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9618 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
| 9619 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
| 9620 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { |
| 9621 | nlmsg_free(msg); |
| 9622 | return -ENOBUFS; |
| 9623 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 9624 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9625 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 9626 | if (ret) { |
| 9627 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " |
| 9628 | "err=%d (%s)", ret, strerror(-ret)); |
| 9629 | } |
| 9630 | |
| 9631 | return ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 9632 | } |
| 9633 | |
| 9634 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 9635 | static int nl80211_update_dh_ie(void *priv, const u8 *peer_mac, |
| 9636 | u16 reason_code, const u8 *ie, size_t ie_len) |
| 9637 | { |
| 9638 | int ret; |
| 9639 | struct nl_msg *msg; |
| 9640 | struct i802_bss *bss = priv; |
| 9641 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9642 | |
| 9643 | wpa_printf(MSG_DEBUG, "nl80211: Updating DH IE peer: " MACSTR |
| 9644 | " reason %u", MAC2STR(peer_mac), reason_code); |
| 9645 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UPDATE_OWE_INFO)) || |
| 9646 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer_mac) || |
| 9647 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, reason_code) || |
| 9648 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) { |
| 9649 | nlmsg_free(msg); |
| 9650 | return -ENOBUFS; |
| 9651 | } |
| 9652 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9653 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 9654 | if (ret) { |
| 9655 | wpa_printf(MSG_DEBUG, |
| 9656 | "nl80211: update_dh_ie failed err=%d (%s)", |
| 9657 | ret, strerror(-ret)); |
| 9658 | } |
| 9659 | |
| 9660 | return ret; |
| 9661 | } |
| 9662 | |
| 9663 | |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 9664 | static const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9665 | { |
| 9666 | struct i802_bss *bss = priv; |
| 9667 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9668 | |
| 9669 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 9670 | return NULL; |
| 9671 | |
| 9672 | return bss->addr; |
| 9673 | } |
| 9674 | |
| 9675 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9676 | static const char * scan_state_str(enum scan_states scan_state) |
| 9677 | { |
| 9678 | switch (scan_state) { |
| 9679 | case NO_SCAN: |
| 9680 | return "NO_SCAN"; |
| 9681 | case SCAN_REQUESTED: |
| 9682 | return "SCAN_REQUESTED"; |
| 9683 | case SCAN_STARTED: |
| 9684 | return "SCAN_STARTED"; |
| 9685 | case SCAN_COMPLETED: |
| 9686 | return "SCAN_COMPLETED"; |
| 9687 | case SCAN_ABORTED: |
| 9688 | return "SCAN_ABORTED"; |
| 9689 | case SCHED_SCAN_STARTED: |
| 9690 | return "SCHED_SCAN_STARTED"; |
| 9691 | case SCHED_SCAN_STOPPED: |
| 9692 | return "SCHED_SCAN_STOPPED"; |
| 9693 | case SCHED_SCAN_RESULTS: |
| 9694 | return "SCHED_SCAN_RESULTS"; |
| 9695 | } |
| 9696 | |
| 9697 | return "??"; |
| 9698 | } |
| 9699 | |
| 9700 | |
| 9701 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) |
| 9702 | { |
| 9703 | struct i802_bss *bss = priv; |
| 9704 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9705 | int res; |
| 9706 | char *pos, *end; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9707 | struct nl_msg *msg; |
| 9708 | char alpha2[3] = { 0, 0, 0 }; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9709 | |
| 9710 | pos = buf; |
| 9711 | end = buf + buflen; |
| 9712 | |
| 9713 | res = os_snprintf(pos, end - pos, |
| 9714 | "ifindex=%d\n" |
| 9715 | "ifname=%s\n" |
| 9716 | "brname=%s\n" |
| 9717 | "addr=" MACSTR "\n" |
| 9718 | "freq=%d\n" |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 9719 | "%s%s%s%s%s%s", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9720 | bss->ifindex, |
| 9721 | bss->ifname, |
| 9722 | bss->brname, |
| 9723 | MAC2STR(bss->addr), |
| 9724 | bss->freq, |
| 9725 | bss->beacon_set ? "beacon_set=1\n" : "", |
| 9726 | bss->added_if_into_bridge ? |
| 9727 | "added_if_into_bridge=1\n" : "", |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 9728 | bss->already_in_bridge ? "already_in_bridge=1\n" : "", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9729 | bss->added_bridge ? "added_bridge=1\n" : "", |
| 9730 | bss->in_deinit ? "in_deinit=1\n" : "", |
| 9731 | bss->if_dynamic ? "if_dynamic=1\n" : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9732 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9733 | return pos - buf; |
| 9734 | pos += res; |
| 9735 | |
| 9736 | if (bss->wdev_id_set) { |
| 9737 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", |
| 9738 | (unsigned long long) bss->wdev_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9739 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9740 | return pos - buf; |
| 9741 | pos += res; |
| 9742 | } |
| 9743 | |
| 9744 | res = os_snprintf(pos, end - pos, |
| 9745 | "phyname=%s\n" |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9746 | "perm_addr=" MACSTR "\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9747 | "drv_ifindex=%d\n" |
| 9748 | "operstate=%d\n" |
| 9749 | "scan_state=%s\n" |
| 9750 | "auth_bssid=" MACSTR "\n" |
| 9751 | "auth_attempt_bssid=" MACSTR "\n" |
| 9752 | "bssid=" MACSTR "\n" |
| 9753 | "prev_bssid=" MACSTR "\n" |
| 9754 | "associated=%d\n" |
| 9755 | "assoc_freq=%u\n" |
| 9756 | "monitor_sock=%d\n" |
| 9757 | "monitor_ifidx=%d\n" |
| 9758 | "monitor_refcount=%d\n" |
| 9759 | "last_mgmt_freq=%u\n" |
| 9760 | "eapol_tx_sock=%d\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9761 | "%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] | 9762 | drv->phyname, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9763 | MAC2STR(drv->perm_addr), |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9764 | drv->ifindex, |
| 9765 | drv->operstate, |
| 9766 | scan_state_str(drv->scan_state), |
| 9767 | MAC2STR(drv->auth_bssid), |
| 9768 | MAC2STR(drv->auth_attempt_bssid), |
| 9769 | MAC2STR(drv->bssid), |
| 9770 | MAC2STR(drv->prev_bssid), |
| 9771 | drv->associated, |
| 9772 | drv->assoc_freq, |
| 9773 | drv->monitor_sock, |
| 9774 | drv->monitor_ifidx, |
| 9775 | drv->monitor_refcount, |
| 9776 | drv->last_mgmt_freq, |
| 9777 | drv->eapol_tx_sock, |
| 9778 | drv->ignore_if_down_event ? |
| 9779 | "ignore_if_down_event=1\n" : "", |
| 9780 | drv->scan_complete_events ? |
| 9781 | "scan_complete_events=1\n" : "", |
| 9782 | drv->disabled_11b_rates ? |
| 9783 | "disabled_11b_rates=1\n" : "", |
| 9784 | drv->pending_remain_on_chan ? |
| 9785 | "pending_remain_on_chan=1\n" : "", |
| 9786 | drv->in_interface_list ? "in_interface_list=1\n" : "", |
| 9787 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", |
| 9788 | drv->poll_command_supported ? |
| 9789 | "poll_command_supported=1\n" : "", |
| 9790 | drv->data_tx_status ? "data_tx_status=1\n" : "", |
| 9791 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", |
| 9792 | drv->retry_auth ? "retry_auth=1\n" : "", |
| 9793 | drv->use_monitor ? "use_monitor=1\n" : "", |
| 9794 | drv->ignore_next_local_disconnect ? |
| 9795 | "ignore_next_local_disconnect=1\n" : "", |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 9796 | drv->ignore_next_local_deauth ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9797 | "ignore_next_local_deauth=1\n" : ""); |
| 9798 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9799 | return pos - buf; |
| 9800 | pos += res; |
| 9801 | |
| 9802 | if (drv->has_capability) { |
| 9803 | res = os_snprintf(pos, end - pos, |
| 9804 | "capa.key_mgmt=0x%x\n" |
| 9805 | "capa.enc=0x%x\n" |
| 9806 | "capa.auth=0x%x\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9807 | "capa.flags=0x%llx\n" |
| 9808 | "capa.rrm_flags=0x%x\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9809 | "capa.max_scan_ssids=%d\n" |
| 9810 | "capa.max_sched_scan_ssids=%d\n" |
| 9811 | "capa.sched_scan_supported=%d\n" |
| 9812 | "capa.max_match_sets=%d\n" |
| 9813 | "capa.max_remain_on_chan=%u\n" |
| 9814 | "capa.max_stations=%u\n" |
| 9815 | "capa.probe_resp_offloads=0x%x\n" |
| 9816 | "capa.max_acl_mac_addrs=%u\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9817 | "capa.num_multichan_concurrent=%u\n" |
| 9818 | "capa.mac_addr_rand_sched_scan_supported=%d\n" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9819 | "capa.mac_addr_rand_scan_supported=%d\n" |
| 9820 | "capa.conc_capab=%u\n" |
| 9821 | "capa.max_conc_chan_2_4=%u\n" |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9822 | "capa.max_conc_chan_5_0=%u\n" |
| 9823 | "capa.max_sched_scan_plans=%u\n" |
| 9824 | "capa.max_sched_scan_plan_interval=%u\n" |
| 9825 | "capa.max_sched_scan_plan_iterations=%u\n", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9826 | drv->capa.key_mgmt, |
| 9827 | drv->capa.enc, |
| 9828 | drv->capa.auth, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9829 | (unsigned long long) drv->capa.flags, |
| 9830 | drv->capa.rrm_flags, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9831 | drv->capa.max_scan_ssids, |
| 9832 | drv->capa.max_sched_scan_ssids, |
| 9833 | drv->capa.sched_scan_supported, |
| 9834 | drv->capa.max_match_sets, |
| 9835 | drv->capa.max_remain_on_chan, |
| 9836 | drv->capa.max_stations, |
| 9837 | drv->capa.probe_resp_offloads, |
| 9838 | drv->capa.max_acl_mac_addrs, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9839 | drv->capa.num_multichan_concurrent, |
| 9840 | drv->capa.mac_addr_rand_sched_scan_supported, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9841 | drv->capa.mac_addr_rand_scan_supported, |
| 9842 | drv->capa.conc_capab, |
| 9843 | drv->capa.max_conc_chan_2_4, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9844 | drv->capa.max_conc_chan_5_0, |
| 9845 | drv->capa.max_sched_scan_plans, |
| 9846 | drv->capa.max_sched_scan_plan_interval, |
| 9847 | drv->capa.max_sched_scan_plan_iterations); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9848 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9849 | return pos - buf; |
| 9850 | pos += res; |
| 9851 | } |
| 9852 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9853 | msg = nlmsg_alloc(); |
| 9854 | if (msg && |
| 9855 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG) && |
| 9856 | nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx) == 0) { |
| 9857 | if (send_and_recv_msgs(drv, msg, nl80211_get_country, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9858 | alpha2, NULL, NULL) == 0 && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9859 | alpha2[0]) { |
| 9860 | res = os_snprintf(pos, end - pos, "country=%s\n", |
| 9861 | alpha2); |
| 9862 | if (os_snprintf_error(end - pos, res)) |
| 9863 | return pos - buf; |
| 9864 | pos += res; |
| 9865 | } |
| 9866 | } else { |
| 9867 | nlmsg_free(msg); |
| 9868 | } |
| 9869 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9870 | return pos - buf; |
| 9871 | } |
| 9872 | |
| 9873 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9874 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
| 9875 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9876 | if ((settings->head && |
| 9877 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, |
| 9878 | settings->head_len, settings->head)) || |
| 9879 | (settings->tail && |
| 9880 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, |
| 9881 | settings->tail_len, settings->tail)) || |
| 9882 | (settings->beacon_ies && |
| 9883 | nla_put(msg, NL80211_ATTR_IE, |
| 9884 | settings->beacon_ies_len, settings->beacon_ies)) || |
| 9885 | (settings->proberesp_ies && |
| 9886 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 9887 | settings->proberesp_ies_len, settings->proberesp_ies)) || |
| 9888 | (settings->assocresp_ies && |
| 9889 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 9890 | settings->assocresp_ies_len, settings->assocresp_ies)) || |
| 9891 | (settings->probe_resp && |
| 9892 | nla_put(msg, NL80211_ATTR_PROBE_RESP, |
| 9893 | settings->probe_resp_len, settings->probe_resp))) |
| 9894 | return -ENOBUFS; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9895 | |
| 9896 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9897 | } |
| 9898 | |
| 9899 | |
| 9900 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) |
| 9901 | { |
| 9902 | struct nl_msg *msg; |
| 9903 | struct i802_bss *bss = priv; |
| 9904 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9905 | struct nlattr *beacon_csa; |
| 9906 | int ret = -ENOBUFS; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9907 | int csa_off_len = 0; |
| 9908 | int i; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9909 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9910 | wpa_printf(MSG_DEBUG, |
| 9911 | "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] | 9912 | settings->cs_count, settings->block_tx, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9913 | settings->freq_params.freq, |
| 9914 | settings->freq_params.channel, |
| 9915 | settings->freq_params.sec_channel_offset, |
| 9916 | settings->freq_params.bandwidth, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 9917 | settings->freq_params.center_freq1, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 9918 | settings->freq_params.center_freq2, |
| 9919 | settings->freq_params.ht_enabled ? " ht" : "", |
| 9920 | settings->freq_params.vht_enabled ? " vht" : "", |
| 9921 | settings->freq_params.he_enabled ? " he" : ""); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9922 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9923 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9924 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
| 9925 | return -EOPNOTSUPP; |
| 9926 | } |
| 9927 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9928 | if (drv->nlmode != NL80211_IFTYPE_AP && |
| 9929 | drv->nlmode != NL80211_IFTYPE_P2P_GO && |
| 9930 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9931 | return -EOPNOTSUPP; |
| 9932 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9933 | /* |
| 9934 | * Remove empty counters, assuming Probe Response and Beacon frame |
| 9935 | * counters match. This implementation assumes that there are only two |
| 9936 | * counters. |
| 9937 | */ |
| 9938 | if (settings->counter_offset_beacon[0] && |
| 9939 | !settings->counter_offset_beacon[1]) { |
| 9940 | csa_off_len = 1; |
| 9941 | } else if (settings->counter_offset_beacon[1] && |
| 9942 | !settings->counter_offset_beacon[0]) { |
| 9943 | csa_off_len = 1; |
| 9944 | settings->counter_offset_beacon[0] = |
| 9945 | settings->counter_offset_beacon[1]; |
| 9946 | settings->counter_offset_presp[0] = |
| 9947 | settings->counter_offset_presp[1]; |
| 9948 | } else if (settings->counter_offset_beacon[1] && |
| 9949 | settings->counter_offset_beacon[0]) { |
| 9950 | csa_off_len = 2; |
| 9951 | } else { |
| 9952 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); |
| 9953 | return -EINVAL; |
| 9954 | } |
| 9955 | |
| 9956 | /* Check CSA counters validity */ |
| 9957 | if (drv->capa.max_csa_counters && |
| 9958 | csa_off_len > drv->capa.max_csa_counters) { |
| 9959 | wpa_printf(MSG_ERROR, |
| 9960 | "nl80211: Too many CSA counters provided"); |
| 9961 | return -EINVAL; |
| 9962 | } |
| 9963 | |
| 9964 | if (!settings->beacon_csa.tail) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9965 | return -EINVAL; |
| 9966 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9967 | for (i = 0; i < csa_off_len; i++) { |
| 9968 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; |
| 9969 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; |
| 9970 | |
| 9971 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || |
| 9972 | (settings->beacon_csa.tail[csa_c_off_bcn] != |
| 9973 | settings->cs_count)) |
| 9974 | return -EINVAL; |
| 9975 | |
| 9976 | if (settings->beacon_csa.probe_resp && |
| 9977 | ((settings->beacon_csa.probe_resp_len <= |
| 9978 | csa_c_off_presp) || |
| 9979 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != |
| 9980 | settings->cs_count))) |
| 9981 | return -EINVAL; |
| 9982 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9983 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9984 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
| 9985 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
| 9986 | settings->cs_count) || |
| 9987 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || |
| 9988 | (settings->block_tx && |
| 9989 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9990 | goto error; |
| 9991 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9992 | /* beacon_after params */ |
| 9993 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 9994 | if (ret) |
| 9995 | goto error; |
| 9996 | |
| 9997 | /* beacon_csa params */ |
| 9998 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); |
| 9999 | if (!beacon_csa) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10000 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10001 | |
| 10002 | ret = set_beacon_data(msg, &settings->beacon_csa); |
| 10003 | if (ret) |
| 10004 | goto error; |
| 10005 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10006 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
| 10007 | csa_off_len * sizeof(u16), |
| 10008 | settings->counter_offset_beacon) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10009 | (settings->beacon_csa.probe_resp && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10010 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
| 10011 | csa_off_len * sizeof(u16), |
| 10012 | settings->counter_offset_presp))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10013 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10014 | |
| 10015 | nla_nest_end(msg, beacon_csa); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10016 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10017 | if (ret) { |
| 10018 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", |
| 10019 | ret, strerror(-ret)); |
| 10020 | } |
| 10021 | return ret; |
| 10022 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10023 | fail: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10024 | ret = -ENOBUFS; |
| 10025 | error: |
| 10026 | nlmsg_free(msg); |
| 10027 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); |
| 10028 | return ret; |
| 10029 | } |
| 10030 | |
| 10031 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10032 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
| 10033 | u8 user_priority, u16 admitted_time) |
| 10034 | { |
| 10035 | struct i802_bss *bss = priv; |
| 10036 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10037 | struct nl_msg *msg; |
| 10038 | int ret; |
| 10039 | |
| 10040 | wpa_printf(MSG_DEBUG, |
| 10041 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", |
| 10042 | tsid, admitted_time, user_priority); |
| 10043 | |
| 10044 | if (!is_sta_interface(drv->nlmode)) |
| 10045 | return -ENOTSUP; |
| 10046 | |
| 10047 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
| 10048 | if (!msg || |
| 10049 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 10050 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10051 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || |
| 10052 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { |
| 10053 | nlmsg_free(msg); |
| 10054 | return -ENOBUFS; |
| 10055 | } |
| 10056 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10057 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10058 | if (ret) |
| 10059 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", |
| 10060 | ret, strerror(-ret)); |
| 10061 | return ret; |
| 10062 | } |
| 10063 | |
| 10064 | |
| 10065 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) |
| 10066 | { |
| 10067 | struct i802_bss *bss = priv; |
| 10068 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10069 | struct nl_msg *msg; |
| 10070 | int ret; |
| 10071 | |
| 10072 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); |
| 10073 | |
| 10074 | if (!is_sta_interface(drv->nlmode)) |
| 10075 | return -ENOTSUP; |
| 10076 | |
| 10077 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
| 10078 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 10079 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 10080 | nlmsg_free(msg); |
| 10081 | return -ENOBUFS; |
| 10082 | } |
| 10083 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10084 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10085 | if (ret) |
| 10086 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", |
| 10087 | ret, strerror(-ret)); |
| 10088 | return ret; |
| 10089 | } |
| 10090 | |
| 10091 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10092 | #ifdef CONFIG_TESTING_OPTIONS |
| 10093 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) |
| 10094 | { |
| 10095 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 10096 | struct wpabuf *buf = arg; |
| 10097 | |
| 10098 | if (!buf) |
| 10099 | return NL_SKIP; |
| 10100 | |
| 10101 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { |
| 10102 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); |
| 10103 | return NL_SKIP; |
| 10104 | } |
| 10105 | |
| 10106 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), |
| 10107 | genlmsg_attrlen(gnlh, 0)); |
| 10108 | |
| 10109 | return NL_SKIP; |
| 10110 | } |
| 10111 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 10112 | |
| 10113 | |
| 10114 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
| 10115 | { |
| 10116 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 10117 | struct nlattr *nl_vendor_reply, *nl; |
| 10118 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 10119 | struct wpabuf *buf = arg; |
| 10120 | int rem; |
| 10121 | |
| 10122 | if (!buf) |
| 10123 | return NL_SKIP; |
| 10124 | |
| 10125 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 10126 | genlmsg_attrlen(gnlh, 0), NULL); |
| 10127 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; |
| 10128 | |
| 10129 | if (!nl_vendor_reply) |
| 10130 | return NL_SKIP; |
| 10131 | |
| 10132 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { |
| 10133 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); |
| 10134 | return NL_SKIP; |
| 10135 | } |
| 10136 | |
| 10137 | nla_for_each_nested(nl, nl_vendor_reply, rem) { |
| 10138 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); |
| 10139 | } |
| 10140 | |
| 10141 | return NL_SKIP; |
| 10142 | } |
| 10143 | |
| 10144 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10145 | static bool is_cmd_with_nested_attrs(unsigned int vendor_id, |
| 10146 | unsigned int subcmd) |
| 10147 | { |
| 10148 | if (vendor_id != OUI_QCA) |
| 10149 | return true; |
| 10150 | |
| 10151 | switch (subcmd) { |
| 10152 | case QCA_NL80211_VENDOR_SUBCMD_AVOID_FREQUENCY: |
| 10153 | case QCA_NL80211_VENDOR_SUBCMD_STATS_EXT: |
| 10154 | case QCA_NL80211_VENDOR_SUBCMD_SCANNING_MAC_OUI: |
| 10155 | case QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY: |
| 10156 | case QCA_NL80211_VENDOR_SUBCMD_SPECTRAL_SCAN_GET_STATUS: |
| 10157 | case QCA_NL80211_VENDOR_SUBCMD_NAN: |
| 10158 | return false; |
| 10159 | default: |
| 10160 | return true; |
| 10161 | } |
| 10162 | } |
| 10163 | |
| 10164 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10165 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, |
| 10166 | unsigned int subcmd, const u8 *data, |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10167 | size_t data_len, enum nested_attr nested_attr, |
| 10168 | struct wpabuf *buf) |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10169 | { |
| 10170 | struct i802_bss *bss = priv; |
| 10171 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10172 | struct nl_msg *msg; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10173 | int ret, nla_flag; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10174 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10175 | #ifdef CONFIG_TESTING_OPTIONS |
| 10176 | if (vendor_id == 0xffffffff) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10177 | msg = nlmsg_alloc(); |
| 10178 | if (!msg) |
| 10179 | return -ENOMEM; |
| 10180 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10181 | nl80211_cmd(drv, msg, 0, subcmd); |
| 10182 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < |
| 10183 | 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10184 | goto fail; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 10185 | /* This test vendor_cmd can be used with nl80211 commands that |
| 10186 | * need the connect nl_sock, so use the owner-setting variant |
| 10187 | * of send_and_recv_msgs(). */ |
| 10188 | ret = send_and_recv_msgs_owner(drv, msg, |
| 10189 | get_connect_handle(bss), 0, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10190 | cmd_reply_handler, buf, |
| 10191 | NULL, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10192 | if (ret) |
| 10193 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", |
| 10194 | ret); |
| 10195 | return ret; |
| 10196 | } |
| 10197 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 10198 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10199 | if (nested_attr == NESTED_ATTR_USED) |
| 10200 | nla_flag = NLA_F_NESTED; |
| 10201 | else if (nested_attr == NESTED_ATTR_UNSPECIFIED && |
| 10202 | is_cmd_with_nested_attrs(vendor_id, subcmd)) |
| 10203 | nla_flag = NLA_F_NESTED; |
| 10204 | else |
| 10205 | nla_flag = 0; |
| 10206 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10207 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 10208 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
| 10209 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || |
| 10210 | (data && |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10211 | nla_put(msg, nla_flag | NL80211_ATTR_VENDOR_DATA, |
| 10212 | data_len, data))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10213 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10214 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10215 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf, |
| 10216 | NULL, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10217 | if (ret) |
| 10218 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", |
| 10219 | ret); |
| 10220 | return ret; |
| 10221 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10222 | fail: |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10223 | nlmsg_free(msg); |
| 10224 | return -ENOBUFS; |
| 10225 | } |
| 10226 | |
| 10227 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10228 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
| 10229 | u8 qos_map_set_len) |
| 10230 | { |
| 10231 | struct i802_bss *bss = priv; |
| 10232 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10233 | struct nl_msg *msg; |
| 10234 | int ret; |
| 10235 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10236 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
| 10237 | qos_map_set, qos_map_set_len); |
| 10238 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10239 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
| 10240 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
| 10241 | nlmsg_free(msg); |
| 10242 | return -ENOBUFS; |
| 10243 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10244 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10245 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10246 | if (ret) |
| 10247 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); |
| 10248 | |
| 10249 | return ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10250 | } |
| 10251 | |
| 10252 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10253 | static int get_wowlan_handler(struct nl_msg *msg, void *arg) |
| 10254 | { |
| 10255 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 10256 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 10257 | int *wowlan_enabled = arg; |
| 10258 | |
| 10259 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 10260 | genlmsg_attrlen(gnlh, 0), NULL); |
| 10261 | |
| 10262 | *wowlan_enabled = !!tb[NL80211_ATTR_WOWLAN_TRIGGERS]; |
| 10263 | |
| 10264 | return NL_SKIP; |
| 10265 | } |
| 10266 | |
| 10267 | |
| 10268 | static int nl80211_get_wowlan(void *priv) |
| 10269 | { |
| 10270 | struct i802_bss *bss = priv; |
| 10271 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10272 | struct nl_msg *msg; |
| 10273 | int wowlan_enabled; |
| 10274 | int ret; |
| 10275 | |
| 10276 | wpa_printf(MSG_DEBUG, "nl80211: Getting wowlan status"); |
| 10277 | |
| 10278 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_WOWLAN); |
| 10279 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10280 | ret = send_and_recv_msgs(drv, msg, get_wowlan_handler, &wowlan_enabled, |
| 10281 | NULL, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10282 | if (ret) { |
| 10283 | wpa_printf(MSG_DEBUG, "nl80211: Getting wowlan status failed"); |
| 10284 | return 0; |
| 10285 | } |
| 10286 | |
| 10287 | wpa_printf(MSG_DEBUG, "nl80211: wowlan is %s", |
| 10288 | wowlan_enabled ? "enabled" : "disabled"); |
| 10289 | |
| 10290 | return wowlan_enabled; |
| 10291 | } |
| 10292 | |
| 10293 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 10294 | static int nl80211_set_wowlan(void *priv, |
| 10295 | const struct wowlan_triggers *triggers) |
| 10296 | { |
| 10297 | struct i802_bss *bss = priv; |
| 10298 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10299 | struct nl_msg *msg; |
| 10300 | struct nlattr *wowlan_triggers; |
| 10301 | int ret; |
| 10302 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 10303 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
| 10304 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 10305 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10306 | !(wowlan_triggers = nla_nest_start(msg, |
| 10307 | NL80211_ATTR_WOWLAN_TRIGGERS)) || |
| 10308 | (triggers->any && |
| 10309 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 10310 | (triggers->disconnect && |
| 10311 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 10312 | (triggers->magic_pkt && |
| 10313 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 10314 | (triggers->gtk_rekey_failure && |
| 10315 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 10316 | (triggers->eap_identity_req && |
| 10317 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 10318 | (triggers->four_way_handshake && |
| 10319 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 10320 | (triggers->rfkill_release && |
| 10321 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { |
| 10322 | nlmsg_free(msg); |
| 10323 | return -ENOBUFS; |
| 10324 | } |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 10325 | |
| 10326 | nla_nest_end(msg, wowlan_triggers); |
| 10327 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10328 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 10329 | if (ret) |
| 10330 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); |
| 10331 | |
| 10332 | return ret; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 10333 | } |
| 10334 | |
| 10335 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10336 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10337 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
| 10338 | { |
| 10339 | struct i802_bss *bss = priv; |
| 10340 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10341 | struct nl_msg *msg; |
| 10342 | struct nlattr *params; |
| 10343 | |
| 10344 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); |
| 10345 | |
| 10346 | if (!drv->roaming_vendor_cmd_avail) { |
| 10347 | wpa_printf(MSG_DEBUG, |
| 10348 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); |
| 10349 | return -1; |
| 10350 | } |
| 10351 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10352 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10353 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10354 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10355 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || |
| 10356 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10357 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, |
| 10358 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : |
| 10359 | QCA_ROAMING_NOT_ALLOWED) || |
| 10360 | (bssid && |
| 10361 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { |
| 10362 | nlmsg_free(msg); |
| 10363 | return -1; |
| 10364 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10365 | nla_nest_end(msg, params); |
| 10366 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10367 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10368 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10369 | |
| 10370 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10371 | static int nl80211_disable_fils(void *priv, int disable) |
| 10372 | { |
| 10373 | struct i802_bss *bss = priv; |
| 10374 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10375 | struct nl_msg *msg; |
| 10376 | struct nlattr *params; |
| 10377 | |
| 10378 | wpa_printf(MSG_DEBUG, "nl80211: Disable FILS=%d", disable); |
| 10379 | |
| 10380 | if (!drv->set_wifi_conf_vendor_cmd_avail) |
| 10381 | return -1; |
| 10382 | |
| 10383 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10384 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10385 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10386 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) || |
| 10387 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10388 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS, |
| 10389 | disable)) { |
| 10390 | nlmsg_free(msg); |
| 10391 | return -1; |
| 10392 | } |
| 10393 | nla_nest_end(msg, params); |
| 10394 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10395 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10396 | } |
| 10397 | |
| 10398 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10399 | /* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */ |
| 10400 | #define WPA_SUPPLICANT_CLIENT_ID 1 |
| 10401 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10402 | static int nl80211_set_bssid_tmp_disallow(void *priv, unsigned int num_bssid, |
| 10403 | const u8 *bssid) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10404 | { |
| 10405 | struct i802_bss *bss = priv; |
| 10406 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10407 | struct nl_msg *msg; |
| 10408 | struct nlattr *params, *nlbssids, *attr; |
| 10409 | unsigned int i; |
| 10410 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10411 | wpa_printf(MSG_DEBUG, |
| 10412 | "nl80211: Set temporarily disallowed BSSIDs (num=%u)", |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10413 | num_bssid); |
| 10414 | |
| 10415 | if (!drv->roam_vendor_cmd_avail) |
| 10416 | return -1; |
| 10417 | |
| 10418 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10419 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10420 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10421 | QCA_NL80211_VENDOR_SUBCMD_ROAM) || |
| 10422 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10423 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 10424 | QCA_WLAN_VENDOR_ROAMING_SUBCMD_SET_BLACKLIST_BSSID) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10425 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID, |
| 10426 | WPA_SUPPLICANT_CLIENT_ID) || |
| 10427 | nla_put_u32(msg, |
| 10428 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID, |
| 10429 | num_bssid)) |
| 10430 | goto fail; |
| 10431 | |
| 10432 | nlbssids = nla_nest_start( |
| 10433 | msg, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS); |
| 10434 | if (!nlbssids) |
| 10435 | goto fail; |
| 10436 | |
| 10437 | for (i = 0; i < num_bssid; i++) { |
| 10438 | attr = nla_nest_start(msg, i); |
| 10439 | if (!attr) |
| 10440 | goto fail; |
| 10441 | if (nla_put(msg, |
| 10442 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID, |
| 10443 | ETH_ALEN, &bssid[i * ETH_ALEN])) |
| 10444 | goto fail; |
| 10445 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%u]: " MACSTR, i, |
| 10446 | MAC2STR(&bssid[i * ETH_ALEN])); |
| 10447 | nla_nest_end(msg, attr); |
| 10448 | } |
| 10449 | nla_nest_end(msg, nlbssids); |
| 10450 | nla_nest_end(msg, params); |
| 10451 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10452 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10453 | |
| 10454 | fail: |
| 10455 | nlmsg_free(msg); |
| 10456 | return -1; |
| 10457 | } |
| 10458 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 10459 | |
| 10460 | static int nl80211_add_sta_node(void *priv, const u8 *addr, u16 auth_alg) |
| 10461 | { |
| 10462 | struct i802_bss *bss = priv; |
| 10463 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10464 | struct nl_msg *msg; |
| 10465 | struct nlattr *params; |
| 10466 | |
| 10467 | if (!drv->add_sta_node_vendor_cmd_avail) |
| 10468 | return -EOPNOTSUPP; |
| 10469 | |
| 10470 | wpa_printf(MSG_DEBUG, "nl80211: Add STA node"); |
| 10471 | |
| 10472 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10473 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10474 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10475 | QCA_NL80211_VENDOR_SUBCMD_ADD_STA_NODE) || |
| 10476 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10477 | (addr && |
| 10478 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_MAC_ADDR, ETH_ALEN, |
| 10479 | addr)) || |
| 10480 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_AUTH_ALGO, |
| 10481 | auth_alg)) { |
| 10482 | nlmsg_free(msg); |
| 10483 | wpa_printf(MSG_ERROR, |
| 10484 | "%s: err in adding vendor_cmd and vendor_data", |
| 10485 | __func__); |
| 10486 | return -1; |
| 10487 | } |
| 10488 | nla_nest_end(msg, params); |
| 10489 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10490 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 10491 | } |
| 10492 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10493 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10494 | |
| 10495 | |
| 10496 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
| 10497 | { |
| 10498 | struct i802_bss *bss = priv; |
| 10499 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10500 | int new_addr = addr != NULL; |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 10501 | #ifdef CONFIG_DRIVER_NL80211_BRCM |
| 10502 | struct nl_msg *msg; |
| 10503 | struct nlattr *params; |
| 10504 | int ret; |
| 10505 | #endif /* CONFIG_DRIVER_NL80211_BRCM */ |
| 10506 | wpa_printf(MSG_DEBUG, "Enter: %s", __FUNCTION__); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10507 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10508 | if (TEST_FAIL()) |
| 10509 | return -1; |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 10510 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 10511 | #ifdef CONFIG_DRIVER_NL80211_BRCM |
| 10512 | if (!addr ) { |
| 10513 | addr = drv->global->p2p_perm_addr; |
| 10514 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10515 | |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 10516 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 10517 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) || |
| 10518 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10519 | BRCM_VENDOR_SCMD_SET_MAC) || |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 10520 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10521 | nla_put(msg, BRCM_ATTR_DRIVER_MAC_ADDR, ETH_ALEN, addr)) { |
| 10522 | wpa_printf(MSG_ERROR, "failed to put p2p randmac"); |
| 10523 | nl80211_nlmsg_clear(msg); |
| 10524 | nlmsg_free(msg); |
| 10525 | return -ENOBUFS; |
| 10526 | } |
| 10527 | nla_nest_end(msg, params); |
| 10528 | |
| 10529 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1, NULL, NULL); |
| 10530 | if (ret) { |
| 10531 | wpa_printf(MSG_ERROR, "nl80211: p2p set macaddr failed: ret=%d (%s)", |
| 10532 | ret, strerror(-ret)); |
| 10533 | } |
| 10534 | memcpy(bss->addr, addr, ETH_ALEN); |
| 10535 | return ret; |
| 10536 | #else |
| 10537 | return -ENOTSUP; |
| 10538 | #endif /* CONFIG_DRIVER_NL80211_BRCM */ |
| 10539 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10540 | if (!addr) |
| 10541 | addr = drv->perm_addr; |
| 10542 | |
| 10543 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) |
| 10544 | return -1; |
| 10545 | |
| 10546 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) |
| 10547 | { |
| 10548 | wpa_printf(MSG_DEBUG, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 10549 | "nl80211: failed to set_mac_addr for %s to " MACSTR, |
| 10550 | bss->ifname, MAC2STR(addr)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10551 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 10552 | 1) < 0) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10553 | wpa_printf(MSG_DEBUG, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 10554 | "nl80211: Could not restore interface UP after failed set_mac_addr"); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10555 | } |
| 10556 | return -1; |
| 10557 | } |
| 10558 | |
| 10559 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 10560 | bss->ifname, MAC2STR(addr)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10561 | drv->addr_changed = new_addr; |
| 10562 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 10563 | |
| 10564 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) |
| 10565 | { |
| 10566 | wpa_printf(MSG_DEBUG, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 10567 | "nl80211: Could not restore interface UP after set_mac_addr"); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10568 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10569 | return 0; |
| 10570 | } |
| 10571 | |
| 10572 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10573 | #ifdef CONFIG_MESH |
| 10574 | |
| 10575 | static int wpa_driver_nl80211_init_mesh(void *priv) |
| 10576 | { |
| 10577 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { |
| 10578 | wpa_printf(MSG_INFO, |
| 10579 | "nl80211: Failed to set interface into mesh mode"); |
| 10580 | return -1; |
| 10581 | } |
| 10582 | return 0; |
| 10583 | } |
| 10584 | |
| 10585 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 10586 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
| 10587 | size_t mesh_id_len) |
| 10588 | { |
| 10589 | if (mesh_id) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 10590 | wpa_printf(MSG_DEBUG, " * Mesh ID (SSID)=%s", |
| 10591 | wpa_ssid_txt(mesh_id, mesh_id_len)); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 10592 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); |
| 10593 | } |
| 10594 | |
| 10595 | return 0; |
| 10596 | } |
| 10597 | |
| 10598 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 10599 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
| 10600 | struct wpa_driver_mesh_bss_params *params) |
| 10601 | { |
| 10602 | struct nlattr *container; |
| 10603 | |
| 10604 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
| 10605 | if (!container) |
| 10606 | return -1; |
| 10607 | |
| 10608 | if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10609 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 10610 | params->auto_plinks)) || |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10611 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_FORWARDING) && |
| 10612 | nla_put_u8(msg, NL80211_MESHCONF_FORWARDING, |
| 10613 | params->forwarding)) || |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 10614 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) && |
| 10615 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10616 | params->max_peer_links)) || |
| 10617 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD) && |
| 10618 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 10619 | params->rssi_threshold))) |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 10620 | return -1; |
| 10621 | |
| 10622 | /* |
| 10623 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because |
| 10624 | * the timer could disconnect stations even in that case. |
| 10625 | */ |
| 10626 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) && |
| 10627 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 10628 | params->peer_link_timeout)) { |
| 10629 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); |
| 10630 | return -1; |
| 10631 | } |
| 10632 | |
| 10633 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) && |
| 10634 | nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) { |
| 10635 | wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE"); |
| 10636 | return -1; |
| 10637 | } |
| 10638 | |
| 10639 | nla_nest_end(msg, container); |
| 10640 | |
| 10641 | return 0; |
| 10642 | } |
| 10643 | |
| 10644 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 10645 | static int nl80211_join_mesh(struct i802_bss *bss, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10646 | struct wpa_driver_mesh_join_params *params) |
| 10647 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10648 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10649 | struct nl_msg *msg; |
| 10650 | struct nlattr *container; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 10651 | int ret = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10652 | |
| 10653 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
| 10654 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 10655 | if (!msg || |
| 10656 | nl80211_put_freq_params(msg, ¶ms->freq) || |
| 10657 | nl80211_put_basic_rates(msg, params->basic_rates) || |
| 10658 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 10659 | nl80211_put_beacon_int(msg, params->beacon_int) || |
| 10660 | nl80211_put_dtim_period(msg, params->dtim_period)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10661 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10662 | |
| 10663 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
| 10664 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 10665 | if (params->handle_dfs && nla_put_flag(msg, NL80211_ATTR_HANDLE_DFS)) |
| 10666 | goto fail; |
| 10667 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10668 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); |
| 10669 | if (!container) |
| 10670 | goto fail; |
| 10671 | |
| 10672 | if (params->ies) { |
| 10673 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); |
| 10674 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
| 10675 | params->ies)) |
| 10676 | goto fail; |
| 10677 | } |
| 10678 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ |
| 10679 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { |
| 10680 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
| 10681 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) |
| 10682 | goto fail; |
| 10683 | } |
| 10684 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
| 10685 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) |
| 10686 | goto fail; |
| 10687 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && |
| 10688 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) |
| 10689 | goto fail; |
| 10690 | nla_nest_end(msg, container); |
| 10691 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 10692 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS; |
| 10693 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT; |
| 10694 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS; |
| 10695 | if (nl80211_put_mesh_config(msg, ¶ms->conf) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10696 | goto fail; |
| 10697 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10698 | ret = send_and_recv_msgs_connect_handle(drv, msg, bss, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10699 | msg = NULL; |
| 10700 | if (ret) { |
| 10701 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", |
| 10702 | ret, strerror(-ret)); |
| 10703 | goto fail; |
| 10704 | } |
| 10705 | ret = 0; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 10706 | drv->assoc_freq = bss->freq = params->freq.freq; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10707 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
| 10708 | |
| 10709 | fail: |
| 10710 | nlmsg_free(msg); |
| 10711 | return ret; |
| 10712 | } |
| 10713 | |
| 10714 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 10715 | static int |
| 10716 | wpa_driver_nl80211_join_mesh(void *priv, |
| 10717 | struct wpa_driver_mesh_join_params *params) |
| 10718 | { |
| 10719 | struct i802_bss *bss = priv; |
| 10720 | int ret, timeout; |
| 10721 | |
| 10722 | timeout = params->conf.peer_link_timeout; |
| 10723 | |
| 10724 | /* Disable kernel inactivity timer */ |
| 10725 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) |
| 10726 | params->conf.peer_link_timeout = 0; |
| 10727 | |
| 10728 | ret = nl80211_join_mesh(bss, params); |
| 10729 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { |
| 10730 | wpa_printf(MSG_DEBUG, |
| 10731 | "nl80211: Mesh join retry for peer_link_timeout"); |
| 10732 | /* |
| 10733 | * Old kernel does not support setting |
| 10734 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds |
| 10735 | * into future from peer_link_timeout. |
| 10736 | */ |
| 10737 | params->conf.peer_link_timeout = timeout + 60; |
| 10738 | ret = nl80211_join_mesh(priv, params); |
| 10739 | } |
| 10740 | |
| 10741 | params->conf.peer_link_timeout = timeout; |
| 10742 | return ret; |
| 10743 | } |
| 10744 | |
| 10745 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10746 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
| 10747 | { |
| 10748 | struct i802_bss *bss = priv; |
| 10749 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10750 | struct nl_msg *msg; |
| 10751 | int ret; |
| 10752 | |
| 10753 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); |
| 10754 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10755 | ret = send_and_recv_msgs_connect_handle(drv, msg, bss, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10756 | if (ret) { |
| 10757 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", |
| 10758 | ret, strerror(-ret)); |
| 10759 | } else { |
| 10760 | wpa_printf(MSG_DEBUG, |
| 10761 | "nl80211: mesh leave request send successfully"); |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10762 | drv->first_bss->freq = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10763 | } |
| 10764 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 10765 | if (drv->start_mode_sta && |
| 10766 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10767 | NL80211_IFTYPE_STATION)) { |
| 10768 | wpa_printf(MSG_INFO, |
| 10769 | "nl80211: Failed to set interface into station mode"); |
| 10770 | } |
| 10771 | return ret; |
| 10772 | } |
| 10773 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 10774 | |
| 10775 | static int nl80211_probe_mesh_link(void *priv, const u8 *addr, const u8 *eth, |
| 10776 | size_t len) |
| 10777 | { |
| 10778 | struct i802_bss *bss = priv; |
| 10779 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10780 | struct nl_msg *msg; |
| 10781 | int ret; |
| 10782 | |
| 10783 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_PROBE_MESH_LINK); |
| 10784 | if (!msg || |
| 10785 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10786 | nla_put(msg, NL80211_ATTR_FRAME, len, eth)) { |
| 10787 | nlmsg_free(msg); |
| 10788 | return -ENOBUFS; |
| 10789 | } |
| 10790 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10791 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 10792 | if (ret) { |
| 10793 | wpa_printf(MSG_DEBUG, "nl80211: mesh link probe to " MACSTR |
| 10794 | " failed: ret=%d (%s)", |
| 10795 | MAC2STR(addr), ret, strerror(-ret)); |
| 10796 | } else { |
| 10797 | wpa_printf(MSG_DEBUG, "nl80211: Mesh link to " MACSTR |
| 10798 | " probed successfully", MAC2STR(addr)); |
| 10799 | } |
| 10800 | |
| 10801 | return ret; |
| 10802 | } |
| 10803 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10804 | #endif /* CONFIG_MESH */ |
| 10805 | |
| 10806 | |
| 10807 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
| 10808 | const u8 *ipaddr, int prefixlen, |
| 10809 | const u8 *addr) |
| 10810 | { |
| 10811 | #ifdef CONFIG_LIBNL3_ROUTE |
| 10812 | struct i802_bss *bss = priv; |
| 10813 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10814 | struct rtnl_neigh *rn; |
| 10815 | struct nl_addr *nl_ipaddr = NULL; |
| 10816 | struct nl_addr *nl_lladdr = NULL; |
| 10817 | int family, addrsize; |
| 10818 | int res; |
| 10819 | |
| 10820 | if (!ipaddr || prefixlen == 0 || !addr) |
| 10821 | return -EINVAL; |
| 10822 | |
| 10823 | if (bss->br_ifindex == 0) { |
| 10824 | wpa_printf(MSG_DEBUG, |
| 10825 | "nl80211: bridge must be set before adding an ip neigh to it"); |
| 10826 | return -1; |
| 10827 | } |
| 10828 | |
| 10829 | if (!drv->rtnl_sk) { |
| 10830 | wpa_printf(MSG_DEBUG, |
| 10831 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 10832 | return -1; |
| 10833 | } |
| 10834 | |
| 10835 | if (version == 4) { |
| 10836 | family = AF_INET; |
| 10837 | addrsize = 4; |
| 10838 | } else if (version == 6) { |
| 10839 | family = AF_INET6; |
| 10840 | addrsize = 16; |
| 10841 | } else { |
| 10842 | return -EINVAL; |
| 10843 | } |
| 10844 | |
| 10845 | rn = rtnl_neigh_alloc(); |
| 10846 | if (rn == NULL) |
| 10847 | return -ENOMEM; |
| 10848 | |
| 10849 | /* set the destination ip address for neigh */ |
| 10850 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 10851 | if (nl_ipaddr == NULL) { |
| 10852 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 10853 | res = -ENOMEM; |
| 10854 | goto errout; |
| 10855 | } |
| 10856 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); |
| 10857 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 10858 | if (res) { |
| 10859 | wpa_printf(MSG_DEBUG, |
| 10860 | "nl80211: neigh set destination addr failed"); |
| 10861 | goto errout; |
| 10862 | } |
| 10863 | |
| 10864 | /* set the corresponding lladdr for neigh */ |
| 10865 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); |
| 10866 | if (nl_lladdr == NULL) { |
| 10867 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); |
| 10868 | res = -ENOMEM; |
| 10869 | goto errout; |
| 10870 | } |
| 10871 | rtnl_neigh_set_lladdr(rn, nl_lladdr); |
| 10872 | |
| 10873 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 10874 | rtnl_neigh_set_state(rn, NUD_PERMANENT); |
| 10875 | |
| 10876 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); |
| 10877 | if (res) { |
| 10878 | wpa_printf(MSG_DEBUG, |
| 10879 | "nl80211: Adding bridge ip neigh failed: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10880 | nl_geterror(res)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10881 | } |
| 10882 | errout: |
| 10883 | if (nl_lladdr) |
| 10884 | nl_addr_put(nl_lladdr); |
| 10885 | if (nl_ipaddr) |
| 10886 | nl_addr_put(nl_ipaddr); |
| 10887 | if (rn) |
| 10888 | rtnl_neigh_put(rn); |
| 10889 | return res; |
| 10890 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 10891 | return -1; |
| 10892 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 10893 | } |
| 10894 | |
| 10895 | |
| 10896 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
| 10897 | const u8 *ipaddr) |
| 10898 | { |
| 10899 | #ifdef CONFIG_LIBNL3_ROUTE |
| 10900 | struct i802_bss *bss = priv; |
| 10901 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10902 | struct rtnl_neigh *rn; |
| 10903 | struct nl_addr *nl_ipaddr; |
| 10904 | int family, addrsize; |
| 10905 | int res; |
| 10906 | |
| 10907 | if (!ipaddr) |
| 10908 | return -EINVAL; |
| 10909 | |
| 10910 | if (version == 4) { |
| 10911 | family = AF_INET; |
| 10912 | addrsize = 4; |
| 10913 | } else if (version == 6) { |
| 10914 | family = AF_INET6; |
| 10915 | addrsize = 16; |
| 10916 | } else { |
| 10917 | return -EINVAL; |
| 10918 | } |
| 10919 | |
| 10920 | if (bss->br_ifindex == 0) { |
| 10921 | wpa_printf(MSG_DEBUG, |
| 10922 | "nl80211: bridge must be set to delete an ip neigh"); |
| 10923 | return -1; |
| 10924 | } |
| 10925 | |
| 10926 | if (!drv->rtnl_sk) { |
| 10927 | wpa_printf(MSG_DEBUG, |
| 10928 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 10929 | return -1; |
| 10930 | } |
| 10931 | |
| 10932 | rn = rtnl_neigh_alloc(); |
| 10933 | if (rn == NULL) |
| 10934 | return -ENOMEM; |
| 10935 | |
| 10936 | /* set the destination ip address for neigh */ |
| 10937 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 10938 | if (nl_ipaddr == NULL) { |
| 10939 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 10940 | res = -ENOMEM; |
| 10941 | goto errout; |
| 10942 | } |
| 10943 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 10944 | if (res) { |
| 10945 | wpa_printf(MSG_DEBUG, |
| 10946 | "nl80211: neigh set destination addr failed"); |
| 10947 | goto errout; |
| 10948 | } |
| 10949 | |
| 10950 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 10951 | |
| 10952 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 10953 | if (res) { |
| 10954 | wpa_printf(MSG_DEBUG, |
| 10955 | "nl80211: Deleting bridge ip neigh failed: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10956 | nl_geterror(res)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10957 | } |
| 10958 | errout: |
| 10959 | if (nl_ipaddr) |
| 10960 | nl_addr_put(nl_ipaddr); |
| 10961 | if (rn) |
| 10962 | rtnl_neigh_put(rn); |
| 10963 | return res; |
| 10964 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 10965 | return -1; |
| 10966 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 10967 | } |
| 10968 | |
| 10969 | |
| 10970 | static int linux_write_system_file(const char *path, unsigned int val) |
| 10971 | { |
| 10972 | char buf[50]; |
| 10973 | int fd, len; |
| 10974 | |
| 10975 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); |
| 10976 | if (os_snprintf_error(sizeof(buf), len)) |
| 10977 | return -1; |
| 10978 | |
| 10979 | fd = open(path, O_WRONLY); |
| 10980 | if (fd < 0) |
| 10981 | return -1; |
| 10982 | |
| 10983 | if (write(fd, buf, len) < 0) { |
| 10984 | wpa_printf(MSG_DEBUG, |
| 10985 | "nl80211: Failed to write Linux system file: %s with the value of %d", |
| 10986 | path, val); |
| 10987 | close(fd); |
| 10988 | return -1; |
| 10989 | } |
| 10990 | close(fd); |
| 10991 | |
| 10992 | return 0; |
| 10993 | } |
| 10994 | |
| 10995 | |
| 10996 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) |
| 10997 | { |
| 10998 | switch (attr) { |
| 10999 | case DRV_BR_PORT_ATTR_PROXYARP: |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 11000 | return "proxyarp_wifi"; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11001 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
| 11002 | return "hairpin_mode"; |
| 11003 | } |
| 11004 | |
| 11005 | return NULL; |
| 11006 | } |
| 11007 | |
| 11008 | |
| 11009 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, |
| 11010 | unsigned int val) |
| 11011 | { |
| 11012 | struct i802_bss *bss = priv; |
| 11013 | char path[128]; |
| 11014 | const char *attr_txt; |
| 11015 | |
| 11016 | attr_txt = drv_br_port_attr_str(attr); |
| 11017 | if (attr_txt == NULL) |
| 11018 | return -EINVAL; |
| 11019 | |
| 11020 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", |
| 11021 | bss->ifname, attr_txt); |
| 11022 | |
| 11023 | if (linux_write_system_file(path, val)) |
| 11024 | return -1; |
| 11025 | |
| 11026 | return 0; |
| 11027 | } |
| 11028 | |
| 11029 | |
| 11030 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
| 11031 | { |
| 11032 | switch (param) { |
| 11033 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 11034 | return "arp_accept"; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 11035 | default: |
| 11036 | return NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11037 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11038 | } |
| 11039 | |
| 11040 | |
| 11041 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, |
| 11042 | unsigned int val) |
| 11043 | { |
| 11044 | struct i802_bss *bss = priv; |
| 11045 | char path[128]; |
| 11046 | const char *param_txt; |
| 11047 | int ip_version = 4; |
| 11048 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 11049 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
| 11050 | os_snprintf(path, sizeof(path), |
| 11051 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", |
| 11052 | bss->brname); |
| 11053 | goto set_val; |
| 11054 | } |
| 11055 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11056 | param_txt = drv_br_net_param_str(param); |
| 11057 | if (param_txt == NULL) |
| 11058 | return -EINVAL; |
| 11059 | |
| 11060 | switch (param) { |
| 11061 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 11062 | ip_version = 4; |
| 11063 | break; |
| 11064 | default: |
| 11065 | return -EINVAL; |
| 11066 | } |
| 11067 | |
| 11068 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", |
| 11069 | ip_version, bss->brname, param_txt); |
| 11070 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 11071 | set_val: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11072 | if (linux_write_system_file(path, val)) |
| 11073 | return -1; |
| 11074 | |
| 11075 | return 0; |
| 11076 | } |
| 11077 | |
| 11078 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11079 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 11080 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11081 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
| 11082 | { |
| 11083 | switch (hw_mode) { |
| 11084 | case HOSTAPD_MODE_IEEE80211B: |
| 11085 | return QCA_ACS_MODE_IEEE80211B; |
| 11086 | case HOSTAPD_MODE_IEEE80211G: |
| 11087 | return QCA_ACS_MODE_IEEE80211G; |
| 11088 | case HOSTAPD_MODE_IEEE80211A: |
| 11089 | return QCA_ACS_MODE_IEEE80211A; |
| 11090 | case HOSTAPD_MODE_IEEE80211AD: |
| 11091 | return QCA_ACS_MODE_IEEE80211AD; |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 11092 | case HOSTAPD_MODE_IEEE80211ANY: |
| 11093 | return QCA_ACS_MODE_IEEE80211ANY; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11094 | default: |
| 11095 | return -1; |
| 11096 | } |
| 11097 | } |
| 11098 | |
| 11099 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 11100 | static int add_acs_ch_list(struct nl_msg *msg, const int *freq_list) |
| 11101 | { |
| 11102 | int num_channels = 0, num_freqs; |
| 11103 | u8 *ch_list; |
| 11104 | enum hostapd_hw_mode hw_mode; |
| 11105 | int ret = 0; |
| 11106 | int i; |
| 11107 | |
| 11108 | if (!freq_list) |
| 11109 | return 0; |
| 11110 | |
| 11111 | num_freqs = int_array_len(freq_list); |
| 11112 | ch_list = os_malloc(sizeof(u8) * num_freqs); |
| 11113 | if (!ch_list) |
| 11114 | return -1; |
| 11115 | |
| 11116 | for (i = 0; i < num_freqs; i++) { |
| 11117 | const int freq = freq_list[i]; |
| 11118 | |
| 11119 | if (freq == 0) |
| 11120 | break; |
| 11121 | /* Send 2.4 GHz and 5 GHz channels with |
| 11122 | * QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST to maintain backwards |
| 11123 | * compatibility. |
| 11124 | */ |
| 11125 | if (!(freq >= 2412 && freq <= 2484) && |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11126 | !(freq >= 5180 && freq <= 5900) && |
| 11127 | !(freq >= 5945 && freq <= 7115)) |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 11128 | continue; |
| 11129 | hw_mode = ieee80211_freq_to_chan(freq, &ch_list[num_channels]); |
| 11130 | if (hw_mode != NUM_HOSTAPD_MODES) |
| 11131 | num_channels++; |
| 11132 | } |
| 11133 | |
| 11134 | if (num_channels) |
| 11135 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, |
| 11136 | num_channels, ch_list); |
| 11137 | |
| 11138 | os_free(ch_list); |
| 11139 | return ret; |
| 11140 | } |
| 11141 | |
| 11142 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11143 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
| 11144 | { |
| 11145 | int i, len, ret; |
| 11146 | u32 *freqs; |
| 11147 | |
| 11148 | if (!freq_list) |
| 11149 | return 0; |
| 11150 | len = int_array_len(freq_list); |
| 11151 | freqs = os_malloc(sizeof(u32) * len); |
| 11152 | if (!freqs) |
| 11153 | return -1; |
| 11154 | for (i = 0; i < len; i++) |
| 11155 | freqs[i] = freq_list[i]; |
| 11156 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, |
| 11157 | sizeof(u32) * len, freqs); |
| 11158 | os_free(freqs); |
| 11159 | return ret; |
| 11160 | } |
| 11161 | |
| 11162 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11163 | static int nl80211_qca_do_acs(struct wpa_driver_nl80211_data *drv, |
| 11164 | struct drv_acs_params *params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11165 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11166 | struct nl_msg *msg; |
| 11167 | struct nlattr *data; |
| 11168 | int ret; |
| 11169 | int mode; |
| 11170 | |
| 11171 | mode = hw_mode_to_qca_acs(params->hw_mode); |
| 11172 | if (mode < 0) |
| 11173 | return -1; |
| 11174 | |
| 11175 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11176 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11177 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11178 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || |
| 11179 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 11180 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || |
| 11181 | (params->ht_enabled && |
| 11182 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || |
| 11183 | (params->ht40_enabled && |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 11184 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
| 11185 | (params->vht_enabled && |
| 11186 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || |
| 11187 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, |
| 11188 | params->ch_width) || |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 11189 | add_acs_ch_list(msg, params->freq_list) || |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11190 | add_acs_freq_list(msg, params->freq_list) || |
| 11191 | (params->edmg_enabled && |
| 11192 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_EDMG_ENABLED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11193 | nlmsg_free(msg); |
| 11194 | return -ENOBUFS; |
| 11195 | } |
| 11196 | nla_nest_end(msg, data); |
| 11197 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 11198 | wpa_printf(MSG_DEBUG, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11199 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d EDMG: %d", |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 11200 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11201 | params->vht_enabled, params->ch_width, params->edmg_enabled); |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 11202 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11203 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11204 | if (ret) { |
| 11205 | wpa_printf(MSG_DEBUG, |
| 11206 | "nl80211: Failed to invoke driver ACS function: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11207 | strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11208 | } |
| 11209 | return ret; |
| 11210 | } |
| 11211 | |
| 11212 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11213 | static int nl80211_set_band(void *priv, u32 band_mask) |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11214 | { |
| 11215 | struct i802_bss *bss = priv; |
| 11216 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11217 | struct nl_msg *msg; |
| 11218 | struct nlattr *data; |
| 11219 | int ret; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11220 | enum qca_set_band qca_band_value; |
| 11221 | u32 qca_band_mask = QCA_SETBAND_AUTO; |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11222 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11223 | if (!drv->setband_vendor_cmd_avail || |
| 11224 | (band_mask > (WPA_SETBAND_2G | WPA_SETBAND_5G | WPA_SETBAND_6G))) |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11225 | return -1; |
| 11226 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11227 | if (band_mask & WPA_SETBAND_5G) |
| 11228 | qca_band_mask |= QCA_SETBAND_5G; |
| 11229 | if (band_mask & WPA_SETBAND_2G) |
| 11230 | qca_band_mask |= QCA_SETBAND_2G; |
| 11231 | if (band_mask & WPA_SETBAND_6G) |
| 11232 | qca_band_mask |= QCA_SETBAND_6G; |
| 11233 | |
| 11234 | /* |
| 11235 | * QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE is a legacy interface hence make |
| 11236 | * it suite to its values (AUTO/5G/2G) for backwards compatibility. |
| 11237 | */ |
| 11238 | qca_band_value = ((qca_band_mask & QCA_SETBAND_5G) && |
| 11239 | (qca_band_mask & QCA_SETBAND_2G)) ? |
| 11240 | QCA_SETBAND_AUTO : |
| 11241 | qca_band_mask & ~QCA_SETBAND_6G; |
| 11242 | |
| 11243 | wpa_printf(MSG_DEBUG, |
| 11244 | "nl80211: QCA_BAND_MASK = 0x%x, QCA_BAND_VALUE = %d", |
| 11245 | qca_band_mask, qca_band_value); |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11246 | |
| 11247 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11248 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11249 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11250 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || |
| 11251 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11252 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, |
| 11253 | qca_band_value) || |
| 11254 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_MASK, |
| 11255 | qca_band_mask)) { |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11256 | nlmsg_free(msg); |
| 11257 | return -ENOBUFS; |
| 11258 | } |
| 11259 | nla_nest_end(msg, data); |
| 11260 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11261 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11262 | if (ret) { |
| 11263 | wpa_printf(MSG_DEBUG, |
| 11264 | "nl80211: Driver setband function failed: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11265 | strerror(-ret)); |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11266 | } |
| 11267 | return ret; |
| 11268 | } |
| 11269 | |
| 11270 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11271 | struct nl80211_pcl { |
| 11272 | unsigned int num; |
| 11273 | unsigned int *freq_list; |
| 11274 | }; |
| 11275 | |
| 11276 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) |
| 11277 | { |
| 11278 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 11279 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 11280 | struct nl80211_pcl *param = arg; |
| 11281 | struct nlattr *nl_vend, *attr; |
| 11282 | enum qca_iface_type iface_type; |
| 11283 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 11284 | unsigned int num, max_num; |
| 11285 | u32 *freqs; |
| 11286 | |
| 11287 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 11288 | genlmsg_attrlen(gnlh, 0), NULL); |
| 11289 | |
| 11290 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; |
| 11291 | if (!nl_vend) |
| 11292 | return NL_SKIP; |
| 11293 | |
| 11294 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 11295 | nla_data(nl_vend), nla_len(nl_vend), NULL); |
| 11296 | |
| 11297 | attr = tb_vendor[ |
| 11298 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; |
| 11299 | if (!attr) { |
| 11300 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); |
| 11301 | param->num = 0; |
| 11302 | return NL_SKIP; |
| 11303 | } |
| 11304 | |
| 11305 | iface_type = (enum qca_iface_type) nla_get_u32(attr); |
| 11306 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", |
| 11307 | iface_type); |
| 11308 | |
| 11309 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; |
| 11310 | if (!attr) { |
| 11311 | wpa_printf(MSG_ERROR, |
| 11312 | "nl80211: preferred_freq_list couldn't be found"); |
| 11313 | param->num = 0; |
| 11314 | return NL_SKIP; |
| 11315 | } |
| 11316 | |
| 11317 | /* |
| 11318 | * param->num has the maximum number of entries for which there |
| 11319 | * is room in the freq_list provided by the caller. |
| 11320 | */ |
| 11321 | freqs = nla_data(attr); |
| 11322 | max_num = nla_len(attr) / sizeof(u32); |
| 11323 | if (max_num > param->num) |
| 11324 | max_num = param->num; |
| 11325 | for (num = 0; num < max_num; num++) |
| 11326 | param->freq_list[num] = freqs[num]; |
| 11327 | param->num = num; |
| 11328 | |
| 11329 | return NL_SKIP; |
| 11330 | } |
| 11331 | |
| 11332 | |
| 11333 | static int nl80211_get_pref_freq_list(void *priv, |
| 11334 | enum wpa_driver_if_type if_type, |
| 11335 | unsigned int *num, |
| 11336 | unsigned int *freq_list) |
| 11337 | { |
| 11338 | struct i802_bss *bss = priv; |
| 11339 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11340 | struct nl_msg *msg; |
| 11341 | int ret; |
| 11342 | unsigned int i; |
| 11343 | struct nlattr *params; |
| 11344 | struct nl80211_pcl param; |
| 11345 | enum qca_iface_type iface_type; |
| 11346 | |
| 11347 | if (!drv->get_pref_freq_list) |
| 11348 | return -1; |
| 11349 | |
| 11350 | switch (if_type) { |
| 11351 | case WPA_IF_STATION: |
| 11352 | iface_type = QCA_IFACE_TYPE_STA; |
| 11353 | break; |
| 11354 | case WPA_IF_AP_BSS: |
| 11355 | iface_type = QCA_IFACE_TYPE_AP; |
| 11356 | break; |
| 11357 | case WPA_IF_P2P_GO: |
| 11358 | iface_type = QCA_IFACE_TYPE_P2P_GO; |
| 11359 | break; |
| 11360 | case WPA_IF_P2P_CLIENT: |
| 11361 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; |
| 11362 | break; |
| 11363 | case WPA_IF_IBSS: |
| 11364 | iface_type = QCA_IFACE_TYPE_IBSS; |
| 11365 | break; |
| 11366 | case WPA_IF_TDLS: |
| 11367 | iface_type = QCA_IFACE_TYPE_TDLS; |
| 11368 | break; |
| 11369 | default: |
| 11370 | return -1; |
| 11371 | } |
| 11372 | |
| 11373 | param.num = *num; |
| 11374 | param.freq_list = freq_list; |
| 11375 | |
| 11376 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11377 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || |
| 11378 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11379 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11380 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || |
| 11381 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 11382 | nla_put_u32(msg, |
| 11383 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, |
| 11384 | iface_type)) { |
| 11385 | wpa_printf(MSG_ERROR, |
| 11386 | "%s: err in adding vendor_cmd and vendor_data", |
| 11387 | __func__); |
| 11388 | nlmsg_free(msg); |
| 11389 | return -1; |
| 11390 | } |
| 11391 | nla_nest_end(msg, params); |
| 11392 | |
| 11393 | os_memset(freq_list, 0, *num * sizeof(freq_list[0])); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11394 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m, |
| 11395 | NULL, NULL); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11396 | if (ret) { |
| 11397 | wpa_printf(MSG_ERROR, |
| 11398 | "%s: err in send_and_recv_msgs", __func__); |
| 11399 | return ret; |
| 11400 | } |
| 11401 | |
| 11402 | *num = param.num; |
| 11403 | |
| 11404 | for (i = 0; i < *num; i++) { |
| 11405 | wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d", |
| 11406 | i, freq_list[i]); |
| 11407 | } |
| 11408 | |
| 11409 | return 0; |
| 11410 | } |
| 11411 | |
| 11412 | |
| 11413 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
| 11414 | { |
| 11415 | struct i802_bss *bss = priv; |
| 11416 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11417 | struct nl_msg *msg; |
| 11418 | int ret; |
| 11419 | struct nlattr *params; |
| 11420 | |
| 11421 | if (!drv->set_prob_oper_freq) |
| 11422 | return -1; |
| 11423 | |
| 11424 | wpa_printf(MSG_DEBUG, |
| 11425 | "nl80211: Set P2P probable operating freq %u for ifindex %d", |
| 11426 | freq, bss->ifindex); |
| 11427 | |
| 11428 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11429 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11430 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11431 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || |
| 11432 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 11433 | nla_put_u32(msg, |
| 11434 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, |
| 11435 | QCA_IFACE_TYPE_P2P_CLIENT) || |
| 11436 | nla_put_u32(msg, |
| 11437 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, |
| 11438 | freq)) { |
| 11439 | wpa_printf(MSG_ERROR, |
| 11440 | "%s: err in adding vendor_cmd and vendor_data", |
| 11441 | __func__); |
| 11442 | nlmsg_free(msg); |
| 11443 | return -1; |
| 11444 | } |
| 11445 | nla_nest_end(msg, params); |
| 11446 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11447 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11448 | msg = NULL; |
| 11449 | if (ret) { |
| 11450 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", |
| 11451 | __func__); |
| 11452 | return ret; |
| 11453 | } |
| 11454 | nlmsg_free(msg); |
| 11455 | return 0; |
| 11456 | } |
| 11457 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 11458 | |
| 11459 | static int nl80211_p2p_lo_start(void *priv, unsigned int freq, |
| 11460 | unsigned int period, unsigned int interval, |
| 11461 | unsigned int count, const u8 *device_types, |
| 11462 | size_t dev_types_len, |
| 11463 | const u8 *ies, size_t ies_len) |
| 11464 | { |
| 11465 | struct i802_bss *bss = priv; |
| 11466 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11467 | struct nl_msg *msg; |
| 11468 | struct nlattr *container; |
| 11469 | int ret; |
| 11470 | |
| 11471 | wpa_printf(MSG_DEBUG, |
| 11472 | "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u", |
| 11473 | freq, period, interval, count); |
| 11474 | |
| 11475 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 11476 | return -1; |
| 11477 | |
| 11478 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11479 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11480 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11481 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START)) |
| 11482 | goto fail; |
| 11483 | |
| 11484 | container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 11485 | if (!container) |
| 11486 | goto fail; |
| 11487 | |
| 11488 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL, |
| 11489 | freq) || |
| 11490 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD, |
| 11491 | period) || |
| 11492 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL, |
| 11493 | interval) || |
| 11494 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT, |
| 11495 | count) || |
| 11496 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES, |
| 11497 | dev_types_len, device_types) || |
| 11498 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE, |
| 11499 | ies_len, ies)) |
| 11500 | goto fail; |
| 11501 | |
| 11502 | nla_nest_end(msg, container); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11503 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 11504 | msg = NULL; |
| 11505 | if (ret) { |
| 11506 | wpa_printf(MSG_DEBUG, |
| 11507 | "nl80211: Failed to send P2P Listen offload vendor command"); |
| 11508 | goto fail; |
| 11509 | } |
| 11510 | |
| 11511 | return 0; |
| 11512 | |
| 11513 | fail: |
| 11514 | nlmsg_free(msg); |
| 11515 | return -1; |
| 11516 | } |
| 11517 | |
| 11518 | |
| 11519 | static int nl80211_p2p_lo_stop(void *priv) |
| 11520 | { |
| 11521 | struct i802_bss *bss = priv; |
| 11522 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11523 | struct nl_msg *msg; |
| 11524 | |
| 11525 | wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload"); |
| 11526 | |
| 11527 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 11528 | return -1; |
| 11529 | |
| 11530 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11531 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11532 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11533 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) { |
| 11534 | nlmsg_free(msg); |
| 11535 | return -1; |
| 11536 | } |
| 11537 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11538 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 11539 | } |
| 11540 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 11541 | |
| 11542 | static int nl80211_set_tdls_mode(void *priv, int tdls_external_control) |
| 11543 | { |
| 11544 | struct i802_bss *bss = priv; |
| 11545 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11546 | struct nl_msg *msg; |
| 11547 | struct nlattr *params; |
| 11548 | int ret; |
| 11549 | u32 tdls_mode; |
| 11550 | |
| 11551 | wpa_printf(MSG_DEBUG, |
| 11552 | "nl80211: Set TDKS mode: tdls_external_control=%d", |
| 11553 | tdls_external_control); |
| 11554 | |
| 11555 | if (tdls_external_control == 1) |
| 11556 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT | |
| 11557 | QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL; |
| 11558 | else |
| 11559 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT; |
| 11560 | |
| 11561 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11562 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11563 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11564 | QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS)) |
| 11565 | goto fail; |
| 11566 | |
| 11567 | params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 11568 | if (!params) |
| 11569 | goto fail; |
| 11570 | |
| 11571 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE, |
| 11572 | tdls_mode)) |
| 11573 | goto fail; |
| 11574 | |
| 11575 | nla_nest_end(msg, params); |
| 11576 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11577 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 11578 | msg = NULL; |
| 11579 | if (ret) { |
| 11580 | wpa_printf(MSG_ERROR, |
| 11581 | "nl80211: Set TDLS mode failed: ret=%d (%s)", |
| 11582 | ret, strerror(-ret)); |
| 11583 | goto fail; |
| 11584 | } |
| 11585 | return 0; |
| 11586 | fail: |
| 11587 | nlmsg_free(msg); |
| 11588 | return -1; |
| 11589 | } |
| 11590 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11591 | |
| 11592 | #ifdef CONFIG_MBO |
| 11593 | |
| 11594 | static enum mbo_transition_reject_reason |
| 11595 | nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status) |
| 11596 | { |
| 11597 | switch (status) { |
| 11598 | case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED: |
| 11599 | return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS; |
| 11600 | case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED: |
| 11601 | return MBO_TRANSITION_REJECT_REASON_DELAY; |
| 11602 | case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY: |
| 11603 | return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY; |
| 11604 | case QCA_STATUS_REJECT_LOW_RSSI: |
| 11605 | return MBO_TRANSITION_REJECT_REASON_RSSI; |
| 11606 | case QCA_STATUS_REJECT_HIGH_INTERFERENCE: |
| 11607 | return MBO_TRANSITION_REJECT_REASON_INTERFERENCE; |
| 11608 | case QCA_STATUS_REJECT_UNKNOWN: |
| 11609 | default: |
| 11610 | return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED; |
| 11611 | } |
| 11612 | } |
| 11613 | |
| 11614 | |
| 11615 | static void nl80211_parse_btm_candidate_info(struct candidate_list *candidate, |
| 11616 | struct nlattr *tb[], int num) |
| 11617 | { |
| 11618 | enum qca_wlan_btm_candidate_status status; |
| 11619 | char buf[50]; |
| 11620 | |
| 11621 | os_memcpy(candidate->bssid, |
| 11622 | nla_data(tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID]), |
| 11623 | ETH_ALEN); |
| 11624 | |
| 11625 | status = nla_get_u32( |
| 11626 | tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]); |
| 11627 | candidate->is_accept = status == QCA_STATUS_ACCEPT; |
| 11628 | candidate->reject_reason = nl80211_mbo_reject_reason_mapping(status); |
| 11629 | |
| 11630 | if (candidate->is_accept) |
| 11631 | os_snprintf(buf, sizeof(buf), "Accepted"); |
| 11632 | else |
| 11633 | os_snprintf(buf, sizeof(buf), |
| 11634 | "Rejected, Reject_reason: %d", |
| 11635 | candidate->reject_reason); |
| 11636 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR " %s", |
| 11637 | num, MAC2STR(candidate->bssid), buf); |
| 11638 | } |
| 11639 | |
| 11640 | |
| 11641 | static int |
| 11642 | nl80211_get_bss_transition_status_handler(struct nl_msg *msg, void *arg) |
| 11643 | { |
| 11644 | struct wpa_bss_candidate_info *info = arg; |
| 11645 | struct candidate_list *candidate = info->candidates; |
| 11646 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 11647 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 11648 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1]; |
| 11649 | static struct nla_policy policy[ |
| 11650 | QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1] = { |
| 11651 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] = { |
| 11652 | .minlen = ETH_ALEN |
| 11653 | }, |
| 11654 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS] = { |
| 11655 | .type = NLA_U32, |
| 11656 | }, |
| 11657 | }; |
| 11658 | struct nlattr *attr; |
| 11659 | int rem; |
| 11660 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 11661 | u8 num; |
| 11662 | |
| 11663 | num = info->num; /* number of candidates sent to driver */ |
| 11664 | info->num = 0; |
| 11665 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 11666 | genlmsg_attrlen(gnlh, 0), NULL); |
| 11667 | |
| 11668 | if (!tb_msg[NL80211_ATTR_VENDOR_DATA] || |
| 11669 | nla_parse_nested(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 11670 | tb_msg[NL80211_ATTR_VENDOR_DATA], NULL) || |
| 11671 | !tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO]) |
| 11672 | return NL_SKIP; |
| 11673 | |
| 11674 | wpa_printf(MSG_DEBUG, |
| 11675 | "nl80211: WNM Candidate list received from driver"); |
| 11676 | nla_for_each_nested(attr, |
| 11677 | tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO], |
| 11678 | rem) { |
| 11679 | if (info->num >= num || |
| 11680 | nla_parse_nested( |
| 11681 | tb, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX, |
| 11682 | attr, policy) || |
| 11683 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] || |
| 11684 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]) |
| 11685 | break; |
| 11686 | |
| 11687 | nl80211_parse_btm_candidate_info(candidate, tb, info->num); |
| 11688 | |
| 11689 | candidate++; |
| 11690 | info->num++; |
| 11691 | } |
| 11692 | |
| 11693 | return NL_SKIP; |
| 11694 | } |
| 11695 | |
| 11696 | |
| 11697 | static struct wpa_bss_candidate_info * |
| 11698 | nl80211_get_bss_transition_status(void *priv, struct wpa_bss_trans_info *params) |
| 11699 | { |
| 11700 | struct i802_bss *bss = priv; |
| 11701 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11702 | struct nl_msg *msg; |
| 11703 | struct nlattr *attr, *attr1, *attr2; |
| 11704 | struct wpa_bss_candidate_info *info; |
| 11705 | u8 i; |
| 11706 | int ret; |
| 11707 | u8 *pos; |
| 11708 | |
| 11709 | if (!drv->fetch_bss_trans_status) |
| 11710 | return NULL; |
| 11711 | |
| 11712 | info = os_zalloc(sizeof(*info)); |
| 11713 | if (!info) |
| 11714 | return NULL; |
| 11715 | /* Allocate memory for number of candidates sent to driver */ |
| 11716 | info->candidates = os_calloc(params->n_candidates, |
| 11717 | sizeof(*info->candidates)); |
| 11718 | if (!info->candidates) { |
| 11719 | os_free(info); |
| 11720 | return NULL; |
| 11721 | } |
| 11722 | |
| 11723 | /* Copy the number of candidates being sent to driver. This is used in |
| 11724 | * nl80211_get_bss_transition_status_handler() to limit the number of |
| 11725 | * candidates that can be populated in info->candidates and will be |
| 11726 | * later overwritten with the actual number of candidates received from |
| 11727 | * the driver. |
| 11728 | */ |
| 11729 | info->num = params->n_candidates; |
| 11730 | |
| 11731 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11732 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11733 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11734 | QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS)) |
| 11735 | goto fail; |
| 11736 | |
| 11737 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 11738 | if (!attr) |
| 11739 | goto fail; |
| 11740 | |
| 11741 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON, |
| 11742 | params->mbo_transition_reason)) |
| 11743 | goto fail; |
| 11744 | |
| 11745 | attr1 = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO); |
| 11746 | if (!attr1) |
| 11747 | goto fail; |
| 11748 | |
| 11749 | wpa_printf(MSG_DEBUG, |
| 11750 | "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d", |
| 11751 | params->mbo_transition_reason, params->n_candidates); |
| 11752 | pos = params->bssid; |
| 11753 | for (i = 0; i < params->n_candidates; i++) { |
| 11754 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR, i, |
| 11755 | MAC2STR(pos)); |
| 11756 | attr2 = nla_nest_start(msg, i); |
| 11757 | if (!attr2 || |
| 11758 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID, |
| 11759 | ETH_ALEN, pos)) |
| 11760 | goto fail; |
| 11761 | pos += ETH_ALEN; |
| 11762 | nla_nest_end(msg, attr2); |
| 11763 | } |
| 11764 | |
| 11765 | nla_nest_end(msg, attr1); |
| 11766 | nla_nest_end(msg, attr); |
| 11767 | |
| 11768 | ret = send_and_recv_msgs(drv, msg, |
| 11769 | nl80211_get_bss_transition_status_handler, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11770 | info, NULL, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11771 | msg = NULL; |
| 11772 | if (ret) { |
| 11773 | wpa_printf(MSG_ERROR, |
| 11774 | "nl80211: WNM Get BSS transition status failed: ret=%d (%s)", |
| 11775 | ret, strerror(-ret)); |
| 11776 | goto fail; |
| 11777 | } |
| 11778 | return info; |
| 11779 | |
| 11780 | fail: |
| 11781 | nlmsg_free(msg); |
| 11782 | os_free(info->candidates); |
| 11783 | os_free(info); |
| 11784 | return NULL; |
| 11785 | } |
| 11786 | |
| 11787 | |
| 11788 | /** |
| 11789 | * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow |
| 11790 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() |
| 11791 | * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore |
| 11792 | * Returns: 0 on success, -1 on failure |
| 11793 | */ |
| 11794 | static int nl80211_ignore_assoc_disallow(void *priv, int ignore_disallow) |
| 11795 | { |
| 11796 | struct i802_bss *bss = priv; |
| 11797 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11798 | struct nl_msg *msg; |
| 11799 | struct nlattr *attr; |
| 11800 | int ret = -1; |
| 11801 | |
| 11802 | if (!drv->set_wifi_conf_vendor_cmd_avail) |
| 11803 | return -1; |
| 11804 | |
| 11805 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11806 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11807 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11808 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) |
| 11809 | goto fail; |
| 11810 | |
| 11811 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 11812 | if (!attr) |
| 11813 | goto fail; |
| 11814 | |
| 11815 | wpa_printf(MSG_DEBUG, "nl80211: Set ignore_assoc_disallow %d", |
| 11816 | ignore_disallow); |
| 11817 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED, |
| 11818 | ignore_disallow)) |
| 11819 | goto fail; |
| 11820 | |
| 11821 | nla_nest_end(msg, attr); |
| 11822 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11823 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11824 | msg = NULL; |
| 11825 | if (ret) { |
| 11826 | wpa_printf(MSG_ERROR, |
| 11827 | "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)", |
| 11828 | ret, strerror(-ret)); |
| 11829 | goto fail; |
| 11830 | } |
| 11831 | |
| 11832 | fail: |
| 11833 | nlmsg_free(msg); |
| 11834 | return ret; |
| 11835 | } |
| 11836 | |
| 11837 | #endif /* CONFIG_MBO */ |
| 11838 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11839 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 11840 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 11841 | static int nl80211_do_acs(void *priv, struct drv_acs_params *params) |
| 11842 | { |
| 11843 | #if defined(CONFIG_DRIVER_NL80211_QCA) || defined(CONFIG_DRIVER_NL80211_BRCM) |
| 11844 | struct i802_bss *bss = priv; |
| 11845 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11846 | #endif /* CONFIG_DRIVER_NL80211_QCA || CONFIG_DRIVER_NL80211_BRCM */ |
| 11847 | |
| 11848 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 11849 | if (drv->qca_do_acs) |
| 11850 | return nl80211_qca_do_acs(drv, params); |
| 11851 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 11852 | |
| 11853 | #ifdef CONFIG_DRIVER_NL80211_BRCM |
| 11854 | if (drv->brcm_do_acs) |
| 11855 | return wpa_driver_do_broadcom_acs(drv, params); |
| 11856 | #endif /* CONFIG_DRIVER_NL80211_BRCM */ |
| 11857 | |
| 11858 | return -1; |
| 11859 | } |
| 11860 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11861 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11862 | static int nl80211_write_to_file(const char *name, unsigned int val) |
| 11863 | { |
| 11864 | int fd, len; |
| 11865 | char tmp[128]; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11866 | int ret = 0; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11867 | |
| 11868 | fd = open(name, O_RDWR); |
| 11869 | if (fd < 0) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11870 | int level; |
| 11871 | /* |
| 11872 | * Flags may not exist on older kernels, or while we're tearing |
| 11873 | * down a disappearing device. |
| 11874 | */ |
| 11875 | if (errno == ENOENT) { |
| 11876 | ret = 0; |
| 11877 | level = MSG_DEBUG; |
| 11878 | } else { |
| 11879 | ret = -1; |
| 11880 | level = MSG_ERROR; |
| 11881 | } |
| 11882 | wpa_printf(level, "nl80211: Failed to open %s: %s", |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11883 | name, strerror(errno)); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11884 | return ret; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11885 | } |
| 11886 | |
| 11887 | len = os_snprintf(tmp, sizeof(tmp), "%u\n", val); |
| 11888 | len = write(fd, tmp, len); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11889 | if (len < 0) { |
| 11890 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11891 | wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s", |
| 11892 | name, strerror(errno)); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11893 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11894 | close(fd); |
| 11895 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11896 | return ret; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11897 | } |
| 11898 | |
| 11899 | |
| 11900 | static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags) |
| 11901 | { |
| 11902 | struct i802_bss *bss = priv; |
| 11903 | char path[128]; |
| 11904 | int ret; |
| 11905 | |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 11906 | /* P2P-Device has no netdev that can (or should) be configured here */ |
| 11907 | if (nl80211_get_ifmode(bss) == NL80211_IFTYPE_P2P_DEVICE) |
| 11908 | return 0; |
| 11909 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11910 | wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x", |
| 11911 | filter_flags); |
| 11912 | |
| 11913 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 11914 | ret = os_snprintf(path, sizeof(path), |
| 11915 | "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast", |
| 11916 | bss->ifname); |
| 11917 | if (os_snprintf_error(sizeof(path), ret)) |
| 11918 | return -1; |
| 11919 | |
| 11920 | ret = nl80211_write_to_file(path, |
| 11921 | !!(filter_flags & |
| 11922 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 11923 | if (ret) { |
| 11924 | wpa_printf(MSG_ERROR, |
| 11925 | "nl80211: Failed to set IPv4 unicast in multicast filter"); |
| 11926 | return ret; |
| 11927 | } |
| 11928 | |
| 11929 | os_snprintf(path, sizeof(path), |
| 11930 | "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast", |
| 11931 | bss->ifname); |
| 11932 | ret = nl80211_write_to_file(path, |
| 11933 | !!(filter_flags & |
| 11934 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 11935 | |
| 11936 | if (ret) { |
| 11937 | wpa_printf(MSG_ERROR, |
| 11938 | "nl80211: Failed to set IPv6 unicast in multicast filter"); |
| 11939 | return ret; |
| 11940 | } |
| 11941 | |
| 11942 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 11943 | os_snprintf(path, sizeof(path), |
| 11944 | "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp", |
| 11945 | bss->ifname); |
| 11946 | ret = nl80211_write_to_file(path, |
| 11947 | !!(filter_flags & |
| 11948 | WPA_DATA_FRAME_FILTER_FLAG_ARP)); |
| 11949 | if (ret) { |
| 11950 | wpa_printf(MSG_ERROR, |
| 11951 | "nl80211: Failed set gratuitous ARP filter"); |
| 11952 | return ret; |
| 11953 | } |
| 11954 | |
| 11955 | /* Configure filtering of IPv6 NA frames */ |
| 11956 | os_snprintf(path, sizeof(path), |
| 11957 | "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na", |
| 11958 | bss->ifname); |
| 11959 | ret = nl80211_write_to_file(path, |
| 11960 | !!(filter_flags & |
| 11961 | WPA_DATA_FRAME_FILTER_FLAG_NA)); |
| 11962 | if (ret) { |
| 11963 | wpa_printf(MSG_ERROR, |
| 11964 | "nl80211: Failed to set unsolicited NA filter"); |
| 11965 | return ret; |
| 11966 | } |
| 11967 | |
| 11968 | return 0; |
| 11969 | } |
| 11970 | |
| 11971 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 11972 | static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type, |
| 11973 | const u8 **ext_capa, const u8 **ext_capa_mask, |
| 11974 | unsigned int *ext_capa_len) |
| 11975 | { |
| 11976 | struct i802_bss *bss = priv; |
| 11977 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11978 | enum nl80211_iftype nlmode; |
| 11979 | unsigned int i; |
| 11980 | |
| 11981 | if (!ext_capa || !ext_capa_mask || !ext_capa_len) |
| 11982 | return -1; |
| 11983 | |
| 11984 | nlmode = wpa_driver_nl80211_if_type(type); |
| 11985 | |
| 11986 | /* By default, use the per-radio values */ |
| 11987 | *ext_capa = drv->extended_capa; |
| 11988 | *ext_capa_mask = drv->extended_capa_mask; |
| 11989 | *ext_capa_len = drv->extended_capa_len; |
| 11990 | |
| 11991 | /* Replace the default value if a per-interface type value exists */ |
| 11992 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 11993 | if (nlmode == drv->iface_ext_capa[i].iftype) { |
| 11994 | *ext_capa = drv->iface_ext_capa[i].ext_capa; |
| 11995 | *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask; |
| 11996 | *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len; |
| 11997 | break; |
| 11998 | } |
| 11999 | } |
| 12000 | |
| 12001 | return 0; |
| 12002 | } |
| 12003 | |
| 12004 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12005 | static int nl80211_update_connection_params( |
| 12006 | void *priv, struct wpa_driver_associate_params *params, |
| 12007 | enum wpa_drv_update_connect_params_mask mask) |
| 12008 | { |
| 12009 | struct i802_bss *bss = priv; |
| 12010 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12011 | struct nl_msg *msg; |
| 12012 | int ret = -1; |
| 12013 | enum nl80211_auth_type type; |
| 12014 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 12015 | /* Update Connection Params is intended for drivers that implement |
| 12016 | * internal SME and expect these updated connection params from |
| 12017 | * wpa_supplicant. Do not send this request for the drivers using |
| 12018 | * SME from wpa_supplicant. |
| 12019 | */ |
| 12020 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) |
| 12021 | return 0; |
| 12022 | |
Vinayak Yadawad | e62409f | 2022-01-20 12:32:07 +0530 | [diff] [blame^] | 12023 | /* Handle any connection param update here which might receive kernel handling in future */ |
| 12024 | #ifdef CONFIG_DRIVER_NL80211_BRCM |
| 12025 | if (mask & WPA_DRV_UPDATE_TD_POLICY) { |
| 12026 | ret = nl80211_set_td_policy(priv, params->td_policy); |
| 12027 | if (ret) { |
| 12028 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 12029 | "nl80211: Update connect params command failed: ret=%d (%s)", |
| 12030 | ret, strerror(-ret)); |
| 12031 | } |
| 12032 | return ret; |
| 12033 | } |
| 12034 | #endif /* CONFIG_DRIVER_NL80211_BRCM */ |
| 12035 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12036 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS); |
| 12037 | if (!msg) |
| 12038 | goto fail; |
| 12039 | |
| 12040 | wpa_printf(MSG_DEBUG, "nl80211: Update connection params (ifindex=%d)", |
| 12041 | drv->ifindex); |
| 12042 | |
| 12043 | if ((mask & WPA_DRV_UPDATE_ASSOC_IES) && params->wpa_ie) { |
| 12044 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 12045 | params->wpa_ie)) |
| 12046 | goto fail; |
| 12047 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, |
| 12048 | params->wpa_ie_len); |
| 12049 | } |
| 12050 | |
| 12051 | if (mask & WPA_DRV_UPDATE_AUTH_TYPE) { |
| 12052 | type = get_nl_auth_type(params->auth_alg); |
| 12053 | if (type == NL80211_AUTHTYPE_MAX || |
| 12054 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 12055 | goto fail; |
| 12056 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
| 12057 | } |
| 12058 | |
| 12059 | if ((mask & WPA_DRV_UPDATE_FILS_ERP_INFO) && |
| 12060 | nl80211_put_fils_connect_params(drv, params, msg)) |
| 12061 | goto fail; |
| 12062 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12063 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12064 | msg = NULL; |
| 12065 | if (ret) |
| 12066 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 12067 | "nl80211: Update connect params command failed: ret=%d (%s)", |
| 12068 | ret, strerror(-ret)); |
| 12069 | |
| 12070 | fail: |
| 12071 | nlmsg_free(msg); |
| 12072 | return ret; |
| 12073 | } |
| 12074 | |
| 12075 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 12076 | static int nl80211_send_external_auth_status(void *priv, |
| 12077 | struct external_auth *params) |
| 12078 | { |
| 12079 | struct i802_bss *bss = priv; |
| 12080 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12081 | struct nl_msg *msg = NULL; |
| 12082 | int ret = -1; |
| 12083 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 12084 | /* External auth command/status is intended for drivers that implement |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 12085 | * internal SME but want to offload authentication processing (e.g., |
| 12086 | * SAE) to hostapd/wpa_supplicant. Do not send the status to drivers |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 12087 | * which do not support AP SME or use wpa_supplicant/hostapd SME. |
| 12088 | */ |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 12089 | if ((is_ap_interface(drv->nlmode) && !bss->drv->device_ap_sme) || |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 12090 | (drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
| 12091 | return -1; |
| 12092 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 12093 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 12094 | "nl80211: External auth status: %u", params->status); |
| 12095 | |
| 12096 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_EXTERNAL_AUTH); |
| 12097 | if (!msg || |
| 12098 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, params->status) || |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 12099 | (params->ssid && params->ssid_len && |
| 12100 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || |
| 12101 | (params->pmkid && |
| 12102 | nla_put(msg, NL80211_ATTR_PMKID, PMKID_LEN, params->pmkid)) || |
| 12103 | (params->bssid && |
| 12104 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid))) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 12105 | goto fail; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12106 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 12107 | msg = NULL; |
| 12108 | if (ret) { |
| 12109 | wpa_printf(MSG_DEBUG, |
| 12110 | "nl80211: External Auth status update failed: ret=%d (%s)", |
| 12111 | ret, strerror(-ret)); |
| 12112 | goto fail; |
| 12113 | } |
| 12114 | fail: |
| 12115 | nlmsg_free(msg); |
| 12116 | return ret; |
| 12117 | } |
| 12118 | |
| 12119 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 12120 | static int nl80211_set_4addr_mode(void *priv, const char *bridge_ifname, |
| 12121 | int val) |
| 12122 | { |
| 12123 | struct i802_bss *bss = priv; |
| 12124 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12125 | struct nl_msg *msg; |
| 12126 | int ret = -ENOBUFS; |
| 12127 | |
| 12128 | wpa_printf(MSG_DEBUG, "nl80211: %s 4addr mode (bridge_ifname: %s)", |
| 12129 | val ? "Enable" : "Disable", bridge_ifname); |
| 12130 | |
| 12131 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 12132 | if (!msg || nla_put_u8(msg, NL80211_ATTR_4ADDR, val)) |
| 12133 | goto fail; |
| 12134 | |
| 12135 | if (bridge_ifname[0] && bss->added_if_into_bridge && !val) { |
| 12136 | if (linux_br_del_if(drv->global->ioctl_sock, |
| 12137 | bridge_ifname, bss->ifname)) { |
| 12138 | wpa_printf(MSG_ERROR, |
| 12139 | "nl80211: Failed to remove interface %s from bridge %s", |
| 12140 | bss->ifname, bridge_ifname); |
| 12141 | return -1; |
| 12142 | } |
| 12143 | bss->added_if_into_bridge = 0; |
| 12144 | } |
| 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); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 12147 | msg = NULL; |
Hai Shalom | 6084025 | 2021-02-19 19:02:11 -0800 | [diff] [blame] | 12148 | if (ret && val && nl80211_get_4addr(bss) == 1) { |
| 12149 | wpa_printf(MSG_DEBUG, |
| 12150 | "nl80211: 4addr mode was already enabled"); |
| 12151 | ret = 0; |
| 12152 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 12153 | if (!ret) { |
| 12154 | if (bridge_ifname[0] && val && |
| 12155 | i802_check_bridge(drv, bss, bridge_ifname, bss->ifname) < 0) |
| 12156 | return -1; |
| 12157 | return 0; |
| 12158 | } |
| 12159 | |
| 12160 | fail: |
| 12161 | nlmsg_free(msg); |
| 12162 | wpa_printf(MSG_ERROR, "nl80211: Failed to enable/disable 4addr"); |
| 12163 | |
| 12164 | return ret; |
| 12165 | } |
| 12166 | |
| 12167 | |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 12168 | #ifdef CONFIG_DPP |
| 12169 | static int nl80211_dpp_listen(void *priv, bool enable) |
| 12170 | { |
| 12171 | struct i802_bss *bss = priv; |
| 12172 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12173 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
| 12174 | struct nl_sock *handle; |
| 12175 | |
| 12176 | if (!drv->multicast_registrations || !bss->nl_mgmt) |
| 12177 | return 0; /* cannot do more than hope broadcast RX works */ |
| 12178 | |
| 12179 | wpa_printf(MSG_DEBUG, |
| 12180 | "nl80211: Update DPP Public Action frame registration (%s multicast RX)", |
| 12181 | enable ? "enable" : "disable"); |
| 12182 | handle = (void *) (((intptr_t) bss->nl_mgmt) ^ ELOOP_SOCKET_INVALID); |
| 12183 | return nl80211_register_frame(bss, handle, type, |
| 12184 | (u8 *) "\x04\x09\x50\x6f\x9a\x1a", 6, |
| 12185 | enable); |
| 12186 | } |
| 12187 | #endif /* CONFIG_DPP */ |
| 12188 | |
Vinayak Yadawad | e62409f | 2022-01-20 12:32:07 +0530 | [diff] [blame^] | 12189 | #ifdef CONFIG_DRIVER_NL80211_BRCM |
| 12190 | static int nl80211_set_td_policy(void *priv, u32 td_policy) |
| 12191 | { |
| 12192 | struct i802_bss *bss = priv; |
| 12193 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12194 | struct nl_msg *msg; |
| 12195 | int ret; |
| 12196 | struct nlattr *params; |
| 12197 | |
| 12198 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 12199 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) || |
| 12200 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, BRCM_VENDOR_SCMD_SET_TD_POLICY) || |
| 12201 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 12202 | (nla_put_u32(msg, BRCM_ATTR_DRIVER_TD_POLICY, td_policy))) { |
| 12203 | nl80211_nlmsg_clear(msg); |
| 12204 | nlmsg_free(msg); |
| 12205 | return -ENOBUFS; |
| 12206 | } |
| 12207 | nla_nest_end(msg, params); |
| 12208 | wpa_printf(MSG_DEBUG, "nl80211: Transition Disable Policy %d\n", td_policy); |
| 12209 | |
| 12210 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1, NULL, NULL); |
| 12211 | if (ret) { |
| 12212 | wpa_printf(MSG_DEBUG, "nl80211: Transition Disable setting failed: ret=%d (%s)", |
| 12213 | ret, strerror(-ret)); |
| 12214 | } |
| 12215 | |
| 12216 | return ret; |
| 12217 | } |
| 12218 | #endif /* CONFIG_DRIVER_NL80211_BRCM */ |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 12219 | |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12220 | #ifdef CONFIG_TESTING_OPTIONS |
| 12221 | |
| 12222 | static int testing_nl80211_register_frame(void *priv, u16 type, |
| 12223 | const u8 *match, size_t match_len, |
| 12224 | bool multicast) |
| 12225 | { |
| 12226 | struct i802_bss *bss = priv; |
| 12227 | struct nl_sock *handle; |
| 12228 | |
| 12229 | if (!bss->nl_mgmt) |
| 12230 | return -1; |
| 12231 | handle = (void *) (((intptr_t) bss->nl_mgmt) ^ ELOOP_SOCKET_INVALID); |
| 12232 | return nl80211_register_frame(bss, handle, type, match, match_len, |
| 12233 | multicast); |
| 12234 | } |
| 12235 | |
| 12236 | |
| 12237 | static int testing_nl80211_radio_disable(void *priv, int disabled) |
| 12238 | { |
| 12239 | struct i802_bss *bss = priv; |
| 12240 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 12241 | |
| 12242 | /* For now, this is supported only partially in station mode with |
| 12243 | * SME-in-wpa_supplicant case where the NL80211_ATTR_LOCAL_STATE_CHANGE |
| 12244 | * attribute can be used to avoid sending out the Deauthentication frame |
| 12245 | * to the currently associated AP. */ |
| 12246 | |
| 12247 | if (!disabled) |
| 12248 | return 0; |
| 12249 | |
| 12250 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
| 12251 | return -1; |
| 12252 | |
| 12253 | if (!drv->associated) |
| 12254 | return 0; |
| 12255 | |
| 12256 | return wpa_driver_nl80211_mlme(drv, drv->bssid, |
| 12257 | NL80211_CMD_DEAUTHENTICATE, |
| 12258 | WLAN_REASON_PREV_AUTH_NOT_VALID, 1, |
| 12259 | drv->first_bss); |
| 12260 | } |
| 12261 | |
| 12262 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 12263 | |
| 12264 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12265 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 12266 | .name = "nl80211", |
| 12267 | .desc = "Linux nl80211/cfg80211", |
| 12268 | .get_bssid = wpa_driver_nl80211_get_bssid, |
| 12269 | .get_ssid = wpa_driver_nl80211_get_ssid, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 12270 | .set_key = driver_nl80211_set_key, |
| 12271 | .scan2 = driver_nl80211_scan2, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 12272 | .sched_scan = wpa_driver_nl80211_sched_scan, |
| 12273 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12274 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 12275 | .abort_scan = wpa_driver_nl80211_abort_scan, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 12276 | .deauthenticate = driver_nl80211_deauthenticate, |
| 12277 | .authenticate = driver_nl80211_authenticate, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12278 | .associate = wpa_driver_nl80211_associate, |
| 12279 | .global_init = nl80211_global_init, |
| 12280 | .global_deinit = nl80211_global_deinit, |
| 12281 | .init2 = wpa_driver_nl80211_init, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 12282 | .deinit = driver_nl80211_deinit, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12283 | .get_capa = wpa_driver_nl80211_get_capa, |
| 12284 | .set_operstate = wpa_driver_nl80211_set_operstate, |
| 12285 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
| 12286 | .set_country = wpa_driver_nl80211_set_country, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 12287 | .get_country = wpa_driver_nl80211_get_country, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 12288 | .set_ap = wpa_driver_nl80211_set_ap, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 12289 | .set_acl = wpa_driver_nl80211_set_acl, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12290 | .if_add = wpa_driver_nl80211_if_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 12291 | .if_remove = driver_nl80211_if_remove, |
| 12292 | .send_mlme = driver_nl80211_send_mlme, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12293 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12294 | .sta_add = wpa_driver_nl80211_sta_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 12295 | .sta_remove = driver_nl80211_sta_remove, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 12296 | .tx_control_port = nl80211_tx_control_port, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12297 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
| 12298 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 12299 | .sta_set_airtime_weight = driver_nl80211_sta_set_airtime_weight, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12300 | .hapd_init = i802_init, |
| 12301 | .hapd_deinit = i802_deinit, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 12302 | .set_wds_sta = i802_set_wds_sta, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12303 | .get_seqnum = i802_get_seqnum, |
| 12304 | .flush = i802_flush, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12305 | .get_inact_sec = i802_get_inact_sec, |
| 12306 | .sta_clear_stats = i802_sta_clear_stats, |
| 12307 | .set_rts = i802_set_rts, |
| 12308 | .set_frag = i802_set_frag, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12309 | .set_tx_queue_params = i802_set_tx_queue_params, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 12310 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12311 | .sta_deauth = i802_sta_deauth, |
| 12312 | .sta_disassoc = i802_sta_disassoc, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 12313 | .read_sta_data = driver_nl80211_read_sta_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12314 | .set_freq = i802_set_freq, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 12315 | .send_action = driver_nl80211_send_action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12316 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
| 12317 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
| 12318 | .cancel_remain_on_channel = |
| 12319 | wpa_driver_nl80211_cancel_remain_on_channel, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 12320 | .probe_req_report = driver_nl80211_probe_req_report, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12321 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 12322 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12323 | .resume = wpa_driver_nl80211_resume, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12324 | .signal_monitor = nl80211_signal_monitor, |
| 12325 | .signal_poll = nl80211_signal_poll, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 12326 | .channel_info = nl80211_channel_info, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12327 | .set_param = nl80211_set_param, |
| 12328 | .get_radio_name = nl80211_get_radio_name, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 12329 | .add_pmkid = nl80211_add_pmkid, |
| 12330 | .remove_pmkid = nl80211_remove_pmkid, |
| 12331 | .flush_pmkid = nl80211_flush_pmkid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 12332 | .set_rekey_info = nl80211_set_rekey_info, |
| 12333 | .poll_client = nl80211_poll_client, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 12334 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 12335 | .start_dfs_cac = nl80211_start_radar_detection, |
| 12336 | .stop_ap = wpa_driver_nl80211_stop_ap, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 12337 | #ifdef CONFIG_TDLS |
| 12338 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, |
| 12339 | .tdls_oper = nl80211_tdls_oper, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12340 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
| 12341 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 12342 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 12343 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 12344 | .update_dh_ie = nl80211_update_dh_ie, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 12345 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 12346 | .get_survey = wpa_driver_nl80211_get_survey, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 12347 | .status = wpa_driver_nl80211_status, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 12348 | .switch_channel = nl80211_switch_channel, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 12349 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 12350 | .set_noa = wpa_driver_set_p2p_noa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 12351 | .get_noa = wpa_driver_get_p2p_noa, |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 12352 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 12353 | #endif /* ANDROID_P2P */ |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 12354 | #ifdef ANDROID |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 12355 | #ifndef ANDROID_LIB_STUB |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 12356 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 12357 | #endif /* !ANDROID_LIB_STUB */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 12358 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 12359 | .vendor_cmd = nl80211_vendor_cmd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 12360 | .set_qos_map = nl80211_set_qos_map, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 12361 | .get_wowlan = nl80211_get_wowlan, |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 12362 | .set_wowlan = nl80211_set_wowlan, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 12363 | .set_mac_addr = nl80211_set_mac_addr, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12364 | #ifdef CONFIG_MESH |
| 12365 | .init_mesh = wpa_driver_nl80211_init_mesh, |
| 12366 | .join_mesh = wpa_driver_nl80211_join_mesh, |
| 12367 | .leave_mesh = wpa_driver_nl80211_leave_mesh, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 12368 | .probe_mesh_link = nl80211_probe_mesh_link, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 12369 | #endif /* CONFIG_MESH */ |
| 12370 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
| 12371 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, |
| 12372 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
| 12373 | .br_set_net_param = wpa_driver_br_set_net_param, |
| 12374 | .add_tx_ts = nl80211_add_ts, |
| 12375 | .del_tx_ts = nl80211_del_ts, |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 12376 | .get_ifindex = nl80211_get_ifindex, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12377 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 12378 | .roaming = nl80211_roaming, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 12379 | .disable_fils = nl80211_disable_fils, |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 12380 | .set_band = nl80211_set_band, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12381 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
| 12382 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 12383 | .p2p_lo_start = nl80211_p2p_lo_start, |
| 12384 | .p2p_lo_stop = nl80211_p2p_lo_stop, |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 12385 | .set_default_scan_ies = nl80211_set_default_scan_ies, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 12386 | .set_tdls_mode = nl80211_set_tdls_mode, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12387 | #ifdef CONFIG_MBO |
| 12388 | .get_bss_transition_status = nl80211_get_bss_transition_status, |
| 12389 | .ignore_assoc_disallow = nl80211_ignore_assoc_disallow, |
| 12390 | #endif /* CONFIG_MBO */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 12391 | .set_bssid_tmp_disallow = nl80211_set_bssid_tmp_disallow, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 12392 | .add_sta_node = nl80211_add_sta_node, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 12393 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12394 | .do_acs = nl80211_do_acs, |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 12395 | .configure_data_frame_filters = nl80211_configure_data_frame_filters, |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 12396 | .get_ext_capab = nl80211_get_ext_capab, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 12397 | .update_connect_params = nl80211_update_connection_params, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 12398 | .send_external_auth_status = nl80211_send_external_auth_status, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 12399 | .set_4addr_mode = nl80211_set_4addr_mode, |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 12400 | #ifdef CONFIG_DPP |
| 12401 | .dpp_listen = nl80211_dpp_listen, |
| 12402 | #endif /* CONFIG_DPP */ |
Hai Shalom | c1a2144 | 2022-02-04 13:43:00 -0800 | [diff] [blame] | 12403 | #ifdef CONFIG_TESTING_OPTIONS |
| 12404 | .register_frame = testing_nl80211_register_frame, |
| 12405 | .radio_disable = testing_nl80211_radio_disable, |
| 12406 | #endif /* CONFIG_TESTING_OPTIONS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 12407 | }; |