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" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 30 | #include "common/ieee802_11_defs.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 31 | #include "common/ieee802_11_common.h" |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 32 | #include "common/wpa_common.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 33 | #include "netlink.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 34 | #include "linux_defines.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 35 | #include "linux_ioctl.h" |
| 36 | #include "radiotap.h" |
| 37 | #include "radiotap_iter.h" |
| 38 | #include "rfkill.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 39 | #include "driver_nl80211.h" |
Ajay Davanageri | b921bb8 | 2020-09-16 12:49:08 +0530 | [diff] [blame] | 40 | #ifdef CONFIG_DRIVER_NL80211_BRCM |
| 41 | #include "common/brcm_vendor.h" |
| 42 | #endif /* CONFIG_DRIVER_NL80211_BRCM */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 43 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 44 | #ifndef NETLINK_CAP_ACK |
| 45 | #define NETLINK_CAP_ACK 10 |
| 46 | #endif /* NETLINK_CAP_ACK */ |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 47 | /* support for extack if compilation headers are too old */ |
| 48 | #ifndef NETLINK_EXT_ACK |
| 49 | #define NETLINK_EXT_ACK 11 |
| 50 | enum nlmsgerr_attrs { |
| 51 | NLMSGERR_ATTR_UNUSED, |
| 52 | NLMSGERR_ATTR_MSG, |
| 53 | NLMSGERR_ATTR_OFFS, |
| 54 | NLMSGERR_ATTR_COOKIE, |
| 55 | |
| 56 | __NLMSGERR_ATTR_MAX, |
| 57 | NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1 |
| 58 | }; |
| 59 | #endif |
| 60 | #ifndef NLM_F_CAPPED |
| 61 | #define NLM_F_CAPPED 0x100 |
| 62 | #endif |
| 63 | #ifndef NLM_F_ACK_TLVS |
| 64 | #define NLM_F_ACK_TLVS 0x200 |
| 65 | #endif |
| 66 | #ifndef SOL_NETLINK |
| 67 | #define SOL_NETLINK 270 |
| 68 | #endif |
| 69 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 70 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 71 | #ifdef ANDROID |
| 72 | /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */ |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 73 | #undef nl_socket_set_nonblocking |
| 74 | #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 75 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 76 | #endif /* ANDROID */ |
| 77 | |
| 78 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 79 | 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] | 80 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 81 | struct nl_sock *handle; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 82 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 83 | handle = nl_socket_alloc_cb(cb); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 84 | if (handle == NULL) { |
| 85 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 86 | "callbacks (%s)", dbg); |
| 87 | return NULL; |
| 88 | } |
| 89 | |
| 90 | if (genl_connect(handle)) { |
| 91 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " |
| 92 | "netlink (%s)", dbg); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 93 | nl_socket_free(handle); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 94 | return NULL; |
| 95 | } |
| 96 | |
| 97 | return handle; |
| 98 | } |
| 99 | |
| 100 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 101 | static void nl_destroy_handles(struct nl_sock **handle) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 102 | { |
| 103 | if (*handle == NULL) |
| 104 | return; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 105 | nl_socket_free(*handle); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 106 | *handle = NULL; |
| 107 | } |
| 108 | |
| 109 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 110 | #if __WORDSIZE == 64 |
| 111 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL |
| 112 | #else |
| 113 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL |
| 114 | #endif |
| 115 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 116 | static void nl80211_register_eloop_read(struct nl_sock **handle, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 117 | eloop_sock_handler handler, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 118 | void *eloop_data, int persist) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 119 | { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 120 | /* |
| 121 | * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB) |
| 122 | * by default. It is possible to hit that limit in some cases where |
| 123 | * operations are blocked, e.g., with a burst of Deauthentication frames |
| 124 | * to hostapd and STA entry deletion. Try to increase the buffer to make |
| 125 | * this less likely to occur. |
| 126 | */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 127 | int err; |
| 128 | |
| 129 | err = nl_socket_set_buffer_size(*handle, 262144, 0); |
| 130 | if (err < 0) { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 131 | wpa_printf(MSG_DEBUG, |
| 132 | "nl80211: Could not set nl_socket RX buffer size: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 133 | nl_geterror(err)); |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 134 | /* continue anyway with the default (smaller) buffer */ |
| 135 | } |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 136 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 137 | nl_socket_set_nonblocking(*handle); |
| 138 | eloop_register_read_sock(nl_socket_get_fd(*handle), handler, |
| 139 | eloop_data, *handle); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 140 | if (!persist) |
| 141 | *handle = (void *) (((intptr_t) *handle) ^ |
| 142 | ELOOP_SOCKET_INVALID); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 146 | static void nl80211_destroy_eloop_handle(struct nl_sock **handle, int persist) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 147 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 148 | if (!persist) |
| 149 | *handle = (void *) (((intptr_t) *handle) ^ |
| 150 | ELOOP_SOCKET_INVALID); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 151 | eloop_unregister_read_sock(nl_socket_get_fd(*handle)); |
| 152 | nl_destroy_handles(handle); |
| 153 | } |
| 154 | |
| 155 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 156 | static void nl80211_global_deinit(void *priv); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 157 | static void nl80211_check_global(struct nl80211_global *global); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 158 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 159 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 160 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 161 | struct hostapd_freq_params *freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 162 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 163 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 164 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 165 | const u8 *set_addr, int first, |
| 166 | const char *driver_params); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 167 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 168 | unsigned int freq, unsigned int wait, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 169 | const u8 *buf, size_t buf_len, |
| 170 | int save_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 171 | int no_cck, int no_ack, int offchanok, |
| 172 | const u16 *csa_offs, size_t csa_offs_len); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 173 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, |
| 174 | int report); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 175 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 176 | #define IFIDX_ANY -1 |
| 177 | |
| 178 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 179 | int ifidx_reason); |
| 180 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 181 | int ifidx_reason); |
| 182 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 183 | int ifidx_reason); |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 184 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 185 | static int nl80211_set_channel(struct i802_bss *bss, |
| 186 | struct hostapd_freq_params *freq, int set_chan); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 187 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 188 | int ifindex, int disabled); |
| 189 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 190 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 191 | int reset_mode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 192 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 193 | static int i802_set_iface_flags(struct i802_bss *bss, int up); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 194 | static int nl80211_set_param(void *priv, const char *param); |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 195 | #ifdef CONFIG_MESH |
| 196 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
| 197 | struct wpa_driver_mesh_bss_params *params); |
| 198 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 199 | 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] | 200 | u16 reason); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 201 | |
| 202 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 203 | /* Converts nl80211_chan_width to a common format */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 204 | enum chan_width convert2width(int width) |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 205 | { |
| 206 | switch (width) { |
| 207 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 208 | return CHAN_WIDTH_20_NOHT; |
| 209 | case NL80211_CHAN_WIDTH_20: |
| 210 | return CHAN_WIDTH_20; |
| 211 | case NL80211_CHAN_WIDTH_40: |
| 212 | return CHAN_WIDTH_40; |
| 213 | case NL80211_CHAN_WIDTH_80: |
| 214 | return CHAN_WIDTH_80; |
| 215 | case NL80211_CHAN_WIDTH_80P80: |
| 216 | return CHAN_WIDTH_80P80; |
| 217 | case NL80211_CHAN_WIDTH_160: |
| 218 | return CHAN_WIDTH_160; |
| 219 | } |
| 220 | return CHAN_WIDTH_UNKNOWN; |
| 221 | } |
| 222 | |
| 223 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 224 | int is_ap_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 225 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 226 | return nlmode == NL80211_IFTYPE_AP || |
| 227 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 231 | int is_sta_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 232 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 233 | return nlmode == NL80211_IFTYPE_STATION || |
| 234 | nlmode == NL80211_IFTYPE_P2P_CLIENT; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 238 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 239 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 240 | return nlmode == NL80211_IFTYPE_P2P_CLIENT || |
| 241 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 242 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 243 | |
| 244 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 245 | struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, |
| 246 | int ifindex) |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 247 | { |
| 248 | struct i802_bss *bss; |
| 249 | |
| 250 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 251 | if (bss->ifindex == ifindex) |
| 252 | return bss; |
| 253 | } |
| 254 | |
| 255 | return NULL; |
| 256 | } |
| 257 | |
| 258 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 259 | static int is_mesh_interface(enum nl80211_iftype nlmode) |
| 260 | { |
| 261 | return nlmode == NL80211_IFTYPE_MESH_POINT; |
| 262 | } |
| 263 | |
| 264 | |
| 265 | void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 266 | { |
| 267 | if (drv->associated) |
| 268 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); |
| 269 | drv->associated = 0; |
| 270 | os_memset(drv->bssid, 0, ETH_ALEN); |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 271 | drv->first_bss->freq = 0; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 275 | /* nl80211 code */ |
| 276 | static int ack_handler(struct nl_msg *msg, void *arg) |
| 277 | { |
| 278 | int *err = arg; |
| 279 | *err = 0; |
| 280 | return NL_STOP; |
| 281 | } |
| 282 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 283 | |
| 284 | struct nl80211_ack_ext_arg { |
| 285 | int *err; |
| 286 | void *ext_data; |
| 287 | }; |
| 288 | |
| 289 | |
| 290 | static int ack_handler_cookie(struct nl_msg *msg, void *arg) |
| 291 | { |
| 292 | struct nl80211_ack_ext_arg *ext_arg = arg; |
| 293 | struct nlattr *tb[NLMSGERR_ATTR_MAX + 1]; |
| 294 | u64 *cookie = ext_arg->ext_data; |
| 295 | struct nlattr *attrs; |
| 296 | size_t ack_len, attr_len; |
| 297 | |
| 298 | *ext_arg->err = 0; |
| 299 | ack_len = sizeof(struct nlmsghdr) + sizeof(int) + |
| 300 | sizeof(struct nlmsghdr); |
| 301 | attrs = (struct nlattr *) |
| 302 | ((u8 *) nlmsg_data(nlmsg_hdr(msg)) + sizeof(struct nlmsghdr) + |
| 303 | sizeof(int)); |
| 304 | if (nlmsg_hdr(msg)->nlmsg_len <= ack_len) |
| 305 | return NL_STOP; |
| 306 | |
| 307 | attr_len = nlmsg_hdr(msg)->nlmsg_len - ack_len; |
| 308 | |
| 309 | if(!(nlmsg_hdr(msg)->nlmsg_flags & NLM_F_ACK_TLVS)) |
| 310 | return NL_STOP; |
| 311 | |
| 312 | nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, attr_len, NULL); |
| 313 | if (tb[NLMSGERR_ATTR_COOKIE]) |
| 314 | *cookie = nla_get_u64(tb[NLMSGERR_ATTR_COOKIE]); |
| 315 | |
| 316 | return NL_STOP; |
| 317 | } |
| 318 | |
| 319 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 320 | static int finish_handler(struct nl_msg *msg, void *arg) |
| 321 | { |
| 322 | int *ret = arg; |
| 323 | *ret = 0; |
| 324 | return NL_SKIP; |
| 325 | } |
| 326 | |
| 327 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, |
| 328 | void *arg) |
| 329 | { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 330 | struct nlmsghdr *nlh = (struct nlmsghdr *) err - 1; |
| 331 | int len = nlh->nlmsg_len; |
| 332 | struct nlattr *attrs; |
| 333 | struct nlattr *tb[NLMSGERR_ATTR_MAX + 1]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 334 | int *ret = arg; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 335 | int ack_len = sizeof(*nlh) + sizeof(int) + sizeof(*nlh); |
| 336 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 337 | *ret = err->error; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 338 | |
| 339 | if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS)) |
| 340 | return NL_SKIP; |
| 341 | |
| 342 | if (!(nlh->nlmsg_flags & NLM_F_CAPPED)) |
| 343 | ack_len += err->msg.nlmsg_len - sizeof(*nlh); |
| 344 | |
| 345 | if (len <= ack_len) |
| 346 | return NL_STOP; |
| 347 | |
| 348 | attrs = (void *) ((unsigned char *) nlh + ack_len); |
| 349 | len -= ack_len; |
| 350 | |
| 351 | nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, len, NULL); |
| 352 | if (tb[NLMSGERR_ATTR_MSG]) { |
| 353 | len = strnlen((char *) nla_data(tb[NLMSGERR_ATTR_MSG]), |
| 354 | nla_len(tb[NLMSGERR_ATTR_MSG])); |
| 355 | wpa_printf(MSG_ERROR, "nl80211: kernel reports: %*s", |
| 356 | len, (char *) nla_data(tb[NLMSGERR_ATTR_MSG])); |
| 357 | } |
| 358 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 359 | return NL_SKIP; |
| 360 | } |
| 361 | |
| 362 | |
| 363 | static int no_seq_check(struct nl_msg *msg, void *arg) |
| 364 | { |
| 365 | return NL_OK; |
| 366 | } |
| 367 | |
| 368 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 369 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
| 370 | { |
| 371 | /* |
| 372 | * Clear nlmsg data, e.g., to make sure key material is not left in |
| 373 | * heap memory for unnecessarily long time. |
| 374 | */ |
| 375 | if (msg) { |
| 376 | struct nlmsghdr *hdr = nlmsg_hdr(msg); |
| 377 | void *data = nlmsg_data(hdr); |
| 378 | /* |
| 379 | * This would use nlmsg_datalen() or the older nlmsg_len() if |
| 380 | * only libnl were to maintain a stable API.. Neither will work |
| 381 | * with all released versions, so just calculate the length |
| 382 | * here. |
| 383 | */ |
| 384 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; |
| 385 | |
| 386 | os_memset(data, 0, len); |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 391 | static int send_and_recv(struct nl80211_global *global, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 392 | struct nl_sock *nl_handle, struct nl_msg *msg, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 393 | int (*valid_handler)(struct nl_msg *, void *), |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 394 | void *valid_data, |
| 395 | int (*ack_handler_custom)(struct nl_msg *, void *), |
| 396 | void *ack_data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 397 | { |
| 398 | struct nl_cb *cb; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 399 | int err = -ENOMEM, opt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 400 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 401 | if (!msg) |
| 402 | return -ENOMEM; |
| 403 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 404 | cb = nl_cb_clone(global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 405 | if (!cb) |
| 406 | goto out; |
| 407 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 408 | /* try to set NETLINK_EXT_ACK to 1, ignoring errors */ |
| 409 | opt = 1; |
| 410 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, |
| 411 | NETLINK_EXT_ACK, &opt, sizeof(opt)); |
| 412 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 413 | /* try to set NETLINK_CAP_ACK to 1, ignoring errors */ |
| 414 | opt = 1; |
| 415 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, |
| 416 | NETLINK_CAP_ACK, &opt, sizeof(opt)); |
| 417 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 418 | err = nl_send_auto_complete(nl_handle, msg); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 419 | if (err < 0) { |
| 420 | wpa_printf(MSG_INFO, |
| 421 | "nl80211: nl_send_auto_complete() failed: %s", |
| 422 | nl_geterror(err)); |
| 423 | /* Need to convert libnl error code to an errno value. For now, |
| 424 | * just hardcode this to EBADF; the real error reason is shown |
| 425 | * in that error print above. */ |
| 426 | err = -EBADF; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 427 | goto out; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 428 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 429 | |
| 430 | err = 1; |
| 431 | |
| 432 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); |
| 433 | 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] | 434 | if (ack_handler_custom) { |
| 435 | struct nl80211_ack_ext_arg *ext_arg = ack_data; |
| 436 | |
| 437 | ext_arg->err = &err; |
| 438 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, |
| 439 | ack_handler_custom, ack_data); |
| 440 | } else { |
| 441 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
| 442 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 443 | |
| 444 | if (valid_handler) |
| 445 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 446 | valid_handler, valid_data); |
| 447 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 448 | while (err > 0) { |
| 449 | int res = nl_recvmsgs(nl_handle, cb); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 450 | |
| 451 | if (res == -NLE_DUMP_INTR) { |
| 452 | /* Most likely one of the nl80211 dump routines hit a |
| 453 | * case where internal results changed while the dump |
| 454 | * was being sent. The most common known case for this |
| 455 | * is scan results fetching while associated were every |
| 456 | * received Beacon frame from the AP may end up |
| 457 | * incrementing bss_generation. This |
| 458 | * NL80211_CMD_GET_SCAN case tries again in the caller; |
| 459 | * other cases (of which there are no known common ones) |
| 460 | * will stop and return an error. */ |
| 461 | wpa_printf(MSG_DEBUG, "nl80211: %s; convert to -EAGAIN", |
| 462 | nl_geterror(res)); |
| 463 | err = -EAGAIN; |
| 464 | } else if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 465 | wpa_printf(MSG_INFO, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 466 | "nl80211: %s->nl_recvmsgs failed: %d (%s)", |
| 467 | __func__, res, nl_geterror(res)); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 468 | } |
| 469 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 470 | out: |
| 471 | nl_cb_put(cb); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 472 | if (!valid_handler && valid_data == (void *) -1) |
| 473 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 474 | nlmsg_free(msg); |
| 475 | return err; |
| 476 | } |
| 477 | |
| 478 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 479 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
| 480 | struct nl_msg *msg, |
| 481 | int (*valid_handler)(struct nl_msg *, void *), |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 482 | void *valid_data, |
| 483 | int (*ack_handler_custom)(struct nl_msg *, void *), |
| 484 | void *ack_data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 485 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 486 | return send_and_recv(drv->global, drv->global->nl, msg, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 487 | valid_handler, valid_data, |
| 488 | ack_handler_custom, ack_data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 492 | /* Use this method to mark that it is necessary to own the connection/interface |
| 493 | * for this operation. |
| 494 | * handle may be set to NULL, to get the same behavior as send_and_recv_msgs(). |
| 495 | * set_owner can be used to mark this socket for receiving control port frames. |
| 496 | */ |
| 497 | static int send_and_recv_msgs_owner(struct wpa_driver_nl80211_data *drv, |
| 498 | struct nl_msg *msg, |
| 499 | struct nl_sock *handle, int set_owner, |
| 500 | int (*valid_handler)(struct nl_msg *, |
| 501 | void *), |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 502 | void *valid_data, |
| 503 | int (*ack_handler_custom)(struct nl_msg *, |
| 504 | void *), |
| 505 | void *ack_data) |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 506 | { |
| 507 | /* Control port over nl80211 needs the flags and attributes below. |
| 508 | * |
| 509 | * The Linux kernel has initial checks for them (in nl80211.c) like: |
| 510 | * validate_pae_over_nl80211(...) |
| 511 | * or final checks like: |
| 512 | * dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid |
| 513 | * |
| 514 | * Final operations (e.g., disassociate) don't need to set these |
| 515 | * attributes, but they have to be performed on the socket, which has |
| 516 | * the connection owner property set in the kernel. |
| 517 | */ |
| 518 | if ((drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) && |
| 519 | handle && set_owner && |
| 520 | (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_OVER_NL80211) || |
| 521 | nla_put_flag(msg, NL80211_ATTR_SOCKET_OWNER) || |
| 522 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 523 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_PREAUTH))) |
| 524 | return -1; |
| 525 | |
| 526 | return send_and_recv(drv->global, handle ? handle : drv->global->nl, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 527 | msg, valid_handler, valid_data, |
| 528 | ack_handler_custom, ack_data); |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | |
| 532 | struct nl_sock * get_connect_handle(struct i802_bss *bss) |
| 533 | { |
| 534 | if ((bss->drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) || |
| 535 | bss->use_nl_connect) |
| 536 | return bss->nl_connect; |
| 537 | |
| 538 | return NULL; |
| 539 | } |
| 540 | |
| 541 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 542 | struct family_data { |
| 543 | const char *group; |
| 544 | int id; |
| 545 | }; |
| 546 | |
| 547 | |
| 548 | static int family_handler(struct nl_msg *msg, void *arg) |
| 549 | { |
| 550 | struct family_data *res = arg; |
| 551 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; |
| 552 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 553 | struct nlattr *mcgrp; |
| 554 | int i; |
| 555 | |
| 556 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 557 | genlmsg_attrlen(gnlh, 0), NULL); |
| 558 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) |
| 559 | return NL_SKIP; |
| 560 | |
| 561 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { |
| 562 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; |
| 563 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), |
| 564 | nla_len(mcgrp), NULL); |
| 565 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || |
| 566 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || |
| 567 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), |
| 568 | res->group, |
| 569 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) |
| 570 | continue; |
| 571 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); |
| 572 | break; |
| 573 | }; |
| 574 | |
| 575 | return NL_SKIP; |
| 576 | } |
| 577 | |
| 578 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 579 | static int nl_get_multicast_id(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 580 | const char *family, const char *group) |
| 581 | { |
| 582 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 583 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 584 | struct family_data res = { group, -ENOENT }; |
| 585 | |
| 586 | msg = nlmsg_alloc(); |
| 587 | if (!msg) |
| 588 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 589 | if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
| 590 | 0, 0, CTRL_CMD_GETFAMILY, 0) || |
| 591 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { |
| 592 | nlmsg_free(msg); |
| 593 | return -1; |
| 594 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 595 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 596 | ret = send_and_recv(global, global->nl, msg, family_handler, &res, |
| 597 | NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 598 | if (ret == 0) |
| 599 | ret = res.id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 600 | return ret; |
| 601 | } |
| 602 | |
| 603 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 604 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
| 605 | struct nl_msg *msg, int flags, uint8_t cmd) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 606 | { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 607 | if (TEST_FAIL()) |
| 608 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 609 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
| 610 | 0, flags, cmd, 0); |
| 611 | } |
| 612 | |
| 613 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 614 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
| 615 | { |
| 616 | if (bss->wdev_id_set) |
| 617 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); |
| 618 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 619 | } |
| 620 | |
| 621 | |
| 622 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 623 | { |
| 624 | struct nl_msg *msg; |
| 625 | |
| 626 | msg = nlmsg_alloc(); |
| 627 | if (!msg) |
| 628 | return NULL; |
| 629 | |
| 630 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || |
| 631 | nl80211_set_iface_id(msg, bss) < 0) { |
| 632 | nlmsg_free(msg); |
| 633 | return NULL; |
| 634 | } |
| 635 | |
| 636 | return msg; |
| 637 | } |
| 638 | |
| 639 | |
| 640 | static struct nl_msg * |
| 641 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, |
| 642 | int flags, uint8_t cmd) |
| 643 | { |
| 644 | struct nl_msg *msg; |
| 645 | |
| 646 | msg = nlmsg_alloc(); |
| 647 | if (!msg) |
| 648 | return NULL; |
| 649 | |
| 650 | if (!nl80211_cmd(drv, msg, flags, cmd) || |
| 651 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { |
| 652 | nlmsg_free(msg); |
| 653 | return NULL; |
| 654 | } |
| 655 | |
| 656 | return msg; |
| 657 | } |
| 658 | |
| 659 | |
| 660 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, |
| 661 | uint8_t cmd) |
| 662 | { |
| 663 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); |
| 664 | } |
| 665 | |
| 666 | |
| 667 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 668 | { |
| 669 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); |
| 670 | } |
| 671 | |
| 672 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 673 | struct wiphy_idx_data { |
| 674 | int wiphy_idx; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 675 | enum nl80211_iftype nlmode; |
| 676 | u8 *macaddr; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 677 | }; |
| 678 | |
| 679 | |
| 680 | static int netdev_info_handler(struct nl_msg *msg, void *arg) |
| 681 | { |
| 682 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 683 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 684 | struct wiphy_idx_data *info = arg; |
| 685 | |
| 686 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 687 | genlmsg_attrlen(gnlh, 0), NULL); |
| 688 | |
| 689 | if (tb[NL80211_ATTR_WIPHY]) |
| 690 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 691 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 692 | if (tb[NL80211_ATTR_IFTYPE]) |
| 693 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); |
| 694 | |
| 695 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
| 696 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 697 | ETH_ALEN); |
| 698 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 699 | return NL_SKIP; |
| 700 | } |
| 701 | |
| 702 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 703 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 704 | { |
| 705 | struct nl_msg *msg; |
| 706 | struct wiphy_idx_data data = { |
| 707 | .wiphy_idx = -1, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 708 | .macaddr = NULL, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 709 | }; |
| 710 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 711 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 712 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 713 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 714 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data, |
| 715 | NULL, NULL) == 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 716 | return data.wiphy_idx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 717 | return -1; |
| 718 | } |
| 719 | |
| 720 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 721 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
| 722 | { |
| 723 | struct nl_msg *msg; |
| 724 | struct wiphy_idx_data data = { |
| 725 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
| 726 | .macaddr = NULL, |
| 727 | }; |
| 728 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 729 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 730 | return NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 731 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 732 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data, |
| 733 | NULL, NULL) == 0) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 734 | return data.nlmode; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 735 | return NL80211_IFTYPE_UNSPECIFIED; |
| 736 | } |
| 737 | |
| 738 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 739 | static int nl80211_get_macaddr(struct i802_bss *bss) |
| 740 | { |
| 741 | struct nl_msg *msg; |
| 742 | struct wiphy_idx_data data = { |
| 743 | .macaddr = bss->addr, |
| 744 | }; |
| 745 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 746 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 747 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 748 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 749 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data, |
| 750 | NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 751 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 752 | |
| 753 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 754 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
| 755 | struct nl80211_wiphy_data *w) |
| 756 | { |
| 757 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 758 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 759 | |
| 760 | msg = nlmsg_alloc(); |
| 761 | if (!msg) |
| 762 | return -1; |
| 763 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 764 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
| 765 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { |
| 766 | nlmsg_free(msg); |
| 767 | return -1; |
| 768 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 769 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 770 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL, |
| 771 | NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 772 | if (ret) { |
| 773 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " |
| 774 | "failed: ret=%d (%s)", |
| 775 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 776 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 777 | return ret; |
| 778 | } |
| 779 | |
| 780 | |
| 781 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) |
| 782 | { |
| 783 | struct nl80211_wiphy_data *w = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 784 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 785 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 786 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 787 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 788 | res = nl_recvmsgs(handle, w->nl_cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 789 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 790 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 791 | __func__, res); |
| 792 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | |
| 796 | static int process_beacon_event(struct nl_msg *msg, void *arg) |
| 797 | { |
| 798 | struct nl80211_wiphy_data *w = arg; |
| 799 | struct wpa_driver_nl80211_data *drv; |
| 800 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 801 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 802 | union wpa_event_data event; |
| 803 | |
| 804 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 805 | genlmsg_attrlen(gnlh, 0), NULL); |
| 806 | |
| 807 | if (gnlh->cmd != NL80211_CMD_FRAME) { |
| 808 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", |
| 809 | gnlh->cmd); |
| 810 | return NL_SKIP; |
| 811 | } |
| 812 | |
| 813 | if (!tb[NL80211_ATTR_FRAME]) |
| 814 | return NL_SKIP; |
| 815 | |
| 816 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, |
| 817 | wiphy_list) { |
| 818 | os_memset(&event, 0, sizeof(event)); |
| 819 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); |
| 820 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); |
| 821 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
| 822 | } |
| 823 | |
| 824 | return NL_SKIP; |
| 825 | } |
| 826 | |
| 827 | |
| 828 | static struct nl80211_wiphy_data * |
| 829 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) |
| 830 | { |
| 831 | static DEFINE_DL_LIST(nl80211_wiphys); |
| 832 | struct nl80211_wiphy_data *w; |
| 833 | int wiphy_idx, found = 0; |
| 834 | struct i802_bss *tmp_bss; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 835 | u8 channel; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 836 | |
| 837 | if (bss->wiphy_data != NULL) |
| 838 | return bss->wiphy_data; |
| 839 | |
| 840 | wiphy_idx = nl80211_get_wiphy_index(bss); |
| 841 | |
| 842 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { |
| 843 | if (w->wiphy_idx == wiphy_idx) |
| 844 | goto add; |
| 845 | } |
| 846 | |
| 847 | /* alloc new one */ |
| 848 | w = os_zalloc(sizeof(*w)); |
| 849 | if (w == NULL) |
| 850 | return NULL; |
| 851 | w->wiphy_idx = wiphy_idx; |
| 852 | dl_list_init(&w->bsss); |
| 853 | dl_list_init(&w->drvs); |
| 854 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 855 | /* Beacon frames not supported in IEEE 802.11ad */ |
| 856 | if (ieee80211_freq_to_chan(bss->freq, &channel) != |
| 857 | HOSTAPD_MODE_IEEE80211AD) { |
| 858 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 859 | if (!w->nl_cb) { |
| 860 | os_free(w); |
| 861 | return NULL; |
| 862 | } |
| 863 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 864 | no_seq_check, NULL); |
| 865 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 866 | process_beacon_event, w); |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 867 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 868 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, |
| 869 | "wiphy beacons"); |
| 870 | if (w->nl_beacons == NULL) { |
| 871 | os_free(w); |
| 872 | return NULL; |
| 873 | } |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 874 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 875 | if (nl80211_register_beacons(bss->drv, w)) { |
| 876 | nl_destroy_handles(&w->nl_beacons); |
| 877 | os_free(w); |
| 878 | return NULL; |
| 879 | } |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 880 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 881 | nl80211_register_eloop_read(&w->nl_beacons, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 882 | nl80211_recv_beacons, w, 0); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 883 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 884 | |
| 885 | dl_list_add(&nl80211_wiphys, &w->list); |
| 886 | |
| 887 | add: |
| 888 | /* drv entry for this bss already there? */ |
| 889 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 890 | if (tmp_bss->drv == bss->drv) { |
| 891 | found = 1; |
| 892 | break; |
| 893 | } |
| 894 | } |
| 895 | /* if not add it */ |
| 896 | if (!found) |
| 897 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); |
| 898 | |
| 899 | dl_list_add(&w->bsss, &bss->wiphy_list); |
| 900 | bss->wiphy_data = w; |
| 901 | return w; |
| 902 | } |
| 903 | |
| 904 | |
| 905 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) |
| 906 | { |
| 907 | struct nl80211_wiphy_data *w = bss->wiphy_data; |
| 908 | struct i802_bss *tmp_bss; |
| 909 | int found = 0; |
| 910 | |
| 911 | if (w == NULL) |
| 912 | return; |
| 913 | bss->wiphy_data = NULL; |
| 914 | dl_list_del(&bss->wiphy_list); |
| 915 | |
| 916 | /* still any for this drv present? */ |
| 917 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 918 | if (tmp_bss->drv == bss->drv) { |
| 919 | found = 1; |
| 920 | break; |
| 921 | } |
| 922 | } |
| 923 | /* if not remove it */ |
| 924 | if (!found) |
| 925 | dl_list_del(&bss->drv->wiphy_list); |
| 926 | |
| 927 | if (!dl_list_empty(&w->bsss)) |
| 928 | return; |
| 929 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 930 | if (w->nl_beacons) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 931 | nl80211_destroy_eloop_handle(&w->nl_beacons, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 932 | |
| 933 | nl_cb_put(w->nl_cb); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 934 | dl_list_del(&w->list); |
| 935 | os_free(w); |
| 936 | } |
| 937 | |
| 938 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 939 | static unsigned int nl80211_get_ifindex(void *priv) |
| 940 | { |
| 941 | struct i802_bss *bss = priv; |
| 942 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 943 | |
| 944 | return drv->ifindex; |
| 945 | } |
| 946 | |
| 947 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 948 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
| 949 | { |
| 950 | struct i802_bss *bss = priv; |
| 951 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 952 | if (!drv->associated) |
| 953 | return -1; |
| 954 | os_memcpy(bssid, drv->bssid, ETH_ALEN); |
| 955 | return 0; |
| 956 | } |
| 957 | |
| 958 | |
| 959 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
| 960 | { |
| 961 | struct i802_bss *bss = priv; |
| 962 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 963 | if (!drv->associated) |
| 964 | return -1; |
| 965 | os_memcpy(ssid, drv->ssid, drv->ssid_len); |
| 966 | return drv->ssid_len; |
| 967 | } |
| 968 | |
| 969 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 970 | static void wpa_driver_nl80211_event_newlink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 971 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 972 | int ifindex, const char *ifname) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 973 | { |
| 974 | union wpa_event_data event; |
| 975 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 976 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 977 | if (if_nametoindex(drv->first_bss->ifname) == 0) { |
| 978 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", |
| 979 | drv->first_bss->ifname); |
| 980 | return; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 981 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 982 | if (!drv->if_removed) |
| 983 | return; |
| 984 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", |
| 985 | drv->first_bss->ifname); |
| 986 | drv->if_removed = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 987 | } |
| 988 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 989 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 990 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 991 | os_strlcpy(event.interface_status.ifname, ifname, |
| 992 | sizeof(event.interface_status.ifname)); |
| 993 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 994 | if (drv) |
| 995 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 996 | else |
| 997 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 998 | &event); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 999 | } |
| 1000 | |
| 1001 | |
| 1002 | static void wpa_driver_nl80211_event_dellink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1003 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 1004 | int ifindex, const char *ifname) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1005 | { |
| 1006 | union wpa_event_data event; |
| 1007 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1008 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1009 | if (drv->if_removed) { |
| 1010 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", |
| 1011 | ifname); |
| 1012 | return; |
| 1013 | } |
| 1014 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
| 1015 | ifname); |
| 1016 | drv->if_removed = 1; |
| 1017 | } else { |
| 1018 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", |
| 1019 | ifname); |
| 1020 | } |
| 1021 | |
| 1022 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1023 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1024 | os_strlcpy(event.interface_status.ifname, ifname, |
| 1025 | sizeof(event.interface_status.ifname)); |
| 1026 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1027 | if (drv) |
| 1028 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 1029 | else |
| 1030 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 1031 | &event); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | |
| 1035 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
| 1036 | u8 *buf, size_t len) |
| 1037 | { |
| 1038 | int attrlen, rta_len; |
| 1039 | struct rtattr *attr; |
| 1040 | |
| 1041 | attrlen = len; |
| 1042 | attr = (struct rtattr *) buf; |
| 1043 | |
| 1044 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
| 1045 | while (RTA_OK(attr, attrlen)) { |
| 1046 | if (attr->rta_type == IFLA_IFNAME) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1047 | if (os_strcmp(((char *) attr) + rta_len, |
| 1048 | drv->first_bss->ifname) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1049 | return 1; |
| 1050 | else |
| 1051 | break; |
| 1052 | } |
| 1053 | attr = RTA_NEXT(attr, attrlen); |
| 1054 | } |
| 1055 | |
| 1056 | return 0; |
| 1057 | } |
| 1058 | |
| 1059 | |
| 1060 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, |
| 1061 | int ifindex, u8 *buf, size_t len) |
| 1062 | { |
| 1063 | if (drv->ifindex == ifindex) |
| 1064 | return 1; |
| 1065 | |
| 1066 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1067 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1068 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
| 1069 | "interface"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1070 | if (wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL) < 0) |
| 1071 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1072 | return 1; |
| 1073 | } |
| 1074 | |
| 1075 | return 0; |
| 1076 | } |
| 1077 | |
| 1078 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1079 | static struct wpa_driver_nl80211_data * |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1080 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len, |
| 1081 | int *init_failed) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1082 | { |
| 1083 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1084 | int res; |
| 1085 | |
| 1086 | if (init_failed) |
| 1087 | *init_failed = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1088 | dl_list_for_each(drv, &global->interfaces, |
| 1089 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1090 | res = wpa_driver_nl80211_own_ifindex(drv, idx, buf, len); |
| 1091 | if (res < 0) { |
| 1092 | wpa_printf(MSG_DEBUG, |
| 1093 | "nl80211: Found matching own interface, but failed to complete reinitialization"); |
| 1094 | if (init_failed) |
| 1095 | *init_failed = 1; |
| 1096 | return drv; |
| 1097 | } |
| 1098 | if (res > 0 || have_ifidx(drv, idx, IFIDX_ANY)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1099 | return drv; |
| 1100 | } |
| 1101 | return NULL; |
| 1102 | } |
| 1103 | |
| 1104 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1105 | static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1106 | int ifindex, int notify) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1107 | { |
| 1108 | struct i802_bss *bss; |
| 1109 | u8 addr[ETH_ALEN]; |
| 1110 | |
| 1111 | bss = get_bss_ifindex(drv, ifindex); |
| 1112 | if (bss && |
| 1113 | linux_get_ifhwaddr(drv->global->ioctl_sock, |
| 1114 | bss->ifname, addr) < 0) { |
| 1115 | wpa_printf(MSG_DEBUG, |
| 1116 | "nl80211: %s: failed to re-read MAC address", |
| 1117 | bss->ifname); |
| 1118 | } else if (bss && os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { |
| 1119 | wpa_printf(MSG_DEBUG, |
| 1120 | "nl80211: Own MAC address on ifindex %d (%s) changed from " |
| 1121 | MACSTR " to " MACSTR, |
| 1122 | ifindex, bss->ifname, |
| 1123 | MAC2STR(bss->addr), MAC2STR(addr)); |
| 1124 | os_memcpy(bss->addr, addr, ETH_ALEN); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1125 | if (notify) |
| 1126 | wpa_supplicant_event(drv->ctx, |
| 1127 | EVENT_INTERFACE_MAC_CHANGED, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1132 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
| 1133 | struct ifinfomsg *ifi, |
| 1134 | u8 *buf, size_t len) |
| 1135 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1136 | struct nl80211_global *global = ctx; |
| 1137 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1138 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1139 | struct rtattr *attr; |
| 1140 | u32 brid = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1141 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1142 | char ifname[IFNAMSIZ + 1]; |
| 1143 | char extra[100], *pos, *end; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1144 | int init_failed; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1145 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1146 | extra[0] = '\0'; |
| 1147 | pos = extra; |
| 1148 | end = pos + sizeof(extra); |
| 1149 | ifname[0] = '\0'; |
| 1150 | |
| 1151 | attrlen = len; |
| 1152 | attr = (struct rtattr *) buf; |
| 1153 | while (RTA_OK(attr, attrlen)) { |
| 1154 | switch (attr->rta_type) { |
| 1155 | case IFLA_IFNAME: |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1156 | if (RTA_PAYLOAD(attr) > IFNAMSIZ) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1157 | break; |
| 1158 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1159 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1160 | break; |
| 1161 | case IFLA_MASTER: |
| 1162 | brid = nla_get_u32((struct nlattr *) attr); |
| 1163 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1164 | break; |
| 1165 | case IFLA_WIRELESS: |
| 1166 | pos += os_snprintf(pos, end - pos, " wext"); |
| 1167 | break; |
| 1168 | case IFLA_OPERSTATE: |
| 1169 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1170 | nla_get_u32((struct nlattr *) attr)); |
| 1171 | break; |
| 1172 | case IFLA_LINKMODE: |
| 1173 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1174 | nla_get_u32((struct nlattr *) attr)); |
| 1175 | break; |
| 1176 | } |
| 1177 | attr = RTA_NEXT(attr, attrlen); |
| 1178 | } |
| 1179 | extra[sizeof(extra) - 1] = '\0'; |
| 1180 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1181 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1182 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1183 | ifi->ifi_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1184 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1185 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1186 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1187 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1188 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1189 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, &init_failed); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1190 | if (!drv) |
| 1191 | goto event_newlink; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1192 | if (init_failed) |
| 1193 | return; /* do not update interface state */ |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1194 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1195 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1196 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1197 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1198 | linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1199 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1200 | "event since interface %s is up", namebuf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1201 | drv->ignore_if_down_event = 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1202 | /* Re-read MAC address as it may have changed */ |
| 1203 | nl80211_refresh_mac(drv, ifi->ifi_index, 1); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1204 | return; |
| 1205 | } |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1206 | wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", |
| 1207 | namebuf, ifname); |
| 1208 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 1209 | wpa_printf(MSG_DEBUG, |
| 1210 | "nl80211: Not the main interface (%s) - do not indicate interface down", |
| 1211 | drv->first_bss->ifname); |
| 1212 | } else if (drv->ignore_if_down_event) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1213 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1214 | "event generated by mode change"); |
| 1215 | drv->ignore_if_down_event = 0; |
| 1216 | } else { |
| 1217 | drv->if_disabled = 1; |
| 1218 | wpa_supplicant_event(drv->ctx, |
| 1219 | EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1220 | |
| 1221 | /* |
| 1222 | * Try to get drv again, since it may be removed as |
| 1223 | * part of the EVENT_INTERFACE_DISABLED handling for |
| 1224 | * dynamic interfaces |
| 1225 | */ |
| 1226 | drv = nl80211_find_drv(global, ifi->ifi_index, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1227 | buf, len, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1228 | if (!drv) |
| 1229 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1230 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1231 | } |
| 1232 | |
| 1233 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 1234 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1235 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1236 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1237 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1238 | "event since interface %s is down", |
| 1239 | namebuf); |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 1240 | return; |
| 1241 | } |
| 1242 | wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)", |
| 1243 | namebuf, ifname); |
| 1244 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 1245 | wpa_printf(MSG_DEBUG, |
| 1246 | "nl80211: Not the main interface (%s) - do not indicate interface up", |
| 1247 | drv->first_bss->ifname); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1248 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1249 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1250 | "event since interface %s does not exist", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1251 | drv->first_bss->ifname); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1252 | } else if (drv->if_removed) { |
| 1253 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1254 | "event since interface %s is marked " |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1255 | "removed", drv->first_bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1256 | } else { |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1257 | /* Re-read MAC address as it may have changed */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1258 | nl80211_refresh_mac(drv, ifi->ifi_index, 0); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1259 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1260 | drv->if_disabled = 0; |
| 1261 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, |
| 1262 | NULL); |
| 1263 | } |
Sunil Ravi | 9077544 | 2020-09-24 11:53:19 -0700 | [diff] [blame] | 1264 | } else if (ifi->ifi_flags & IFF_UP) { |
| 1265 | /* Re-read MAC address as it may have changed */ |
| 1266 | nl80211_refresh_mac(drv, ifi->ifi_index, 1); |
| 1267 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | /* |
| 1271 | * Some drivers send the association event before the operup event--in |
| 1272 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() |
| 1273 | * fails. This will hit us when wpa_supplicant does not need to do |
| 1274 | * IEEE 802.1X authentication |
| 1275 | */ |
| 1276 | if (drv->operstate == 1 && |
| 1277 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1278 | !(ifi->ifi_flags & IFF_RUNNING)) { |
| 1279 | 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] | 1280 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1281 | -1, IF_OPER_UP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1284 | event_newlink: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1285 | if (ifname[0]) |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1286 | wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index, |
| 1287 | ifname); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1288 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1289 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1290 | struct i802_bss *bss; |
| 1291 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1292 | /* device has been added to bridge */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1293 | if (!if_indextoname(brid, namebuf)) { |
| 1294 | wpa_printf(MSG_DEBUG, |
| 1295 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1296 | brid); |
| 1297 | return; |
| 1298 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1299 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
| 1300 | brid, namebuf); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1301 | add_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1302 | |
| 1303 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 1304 | if (os_strcmp(ifname, bss->ifname) == 0) { |
| 1305 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); |
| 1306 | break; |
| 1307 | } |
| 1308 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1309 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | |
| 1313 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
| 1314 | struct ifinfomsg *ifi, |
| 1315 | u8 *buf, size_t len) |
| 1316 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1317 | struct nl80211_global *global = ctx; |
| 1318 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1319 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1320 | struct rtattr *attr; |
| 1321 | u32 brid = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1322 | char ifname[IFNAMSIZ + 1]; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1323 | char extra[100], *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1324 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1325 | extra[0] = '\0'; |
| 1326 | pos = extra; |
| 1327 | end = pos + sizeof(extra); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1328 | ifname[0] = '\0'; |
| 1329 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1330 | attrlen = len; |
| 1331 | attr = (struct rtattr *) buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1332 | while (RTA_OK(attr, attrlen)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1333 | switch (attr->rta_type) { |
| 1334 | case IFLA_IFNAME: |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1335 | if (RTA_PAYLOAD(attr) > IFNAMSIZ) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1336 | break; |
| 1337 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1338 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1339 | break; |
| 1340 | case IFLA_MASTER: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1341 | brid = nla_get_u32((struct nlattr *) attr); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1342 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1343 | break; |
| 1344 | case IFLA_OPERSTATE: |
| 1345 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1346 | nla_get_u32((struct nlattr *) attr)); |
| 1347 | break; |
| 1348 | case IFLA_LINKMODE: |
| 1349 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1350 | nla_get_u32((struct nlattr *) attr)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1351 | break; |
| 1352 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1353 | attr = RTA_NEXT(attr, attrlen); |
| 1354 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1355 | extra[sizeof(extra) - 1] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1356 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1357 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1358 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1359 | ifi->ifi_flags, |
| 1360 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1361 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1362 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1363 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1364 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1365 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1366 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1367 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1368 | /* device has been removed from bridge */ |
| 1369 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1370 | |
| 1371 | if (!if_indextoname(brid, namebuf)) { |
| 1372 | wpa_printf(MSG_DEBUG, |
| 1373 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1374 | brid); |
| 1375 | } else { |
| 1376 | wpa_printf(MSG_DEBUG, |
| 1377 | "nl80211: Remove ifindex %u for bridge %s", |
| 1378 | brid, namebuf); |
| 1379 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1380 | del_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1381 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1382 | |
| 1383 | if (ifi->ifi_family != AF_BRIDGE || !brid) |
| 1384 | wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index, |
| 1385 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1386 | } |
| 1387 | |
| 1388 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1389 | struct nl80211_get_assoc_freq_arg { |
| 1390 | struct wpa_driver_nl80211_data *drv; |
| 1391 | unsigned int assoc_freq; |
| 1392 | unsigned int ibss_freq; |
| 1393 | u8 assoc_bssid[ETH_ALEN]; |
| 1394 | u8 assoc_ssid[SSID_MAX_LEN]; |
| 1395 | u8 assoc_ssid_len; |
| 1396 | }; |
| 1397 | |
| 1398 | static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg) |
| 1399 | { |
| 1400 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1401 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1402 | struct nlattr *bss[NL80211_BSS_MAX + 1]; |
| 1403 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { |
| 1404 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, |
| 1405 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, |
| 1406 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, |
| 1407 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
| 1408 | }; |
| 1409 | struct nl80211_get_assoc_freq_arg *ctx = arg; |
| 1410 | enum nl80211_bss_status status; |
| 1411 | |
| 1412 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1413 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1414 | if (!tb[NL80211_ATTR_BSS] || |
| 1415 | nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], |
| 1416 | bss_policy) || |
| 1417 | !bss[NL80211_BSS_STATUS]) |
| 1418 | return NL_SKIP; |
| 1419 | |
| 1420 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); |
| 1421 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1422 | bss[NL80211_BSS_FREQUENCY]) { |
| 1423 | ctx->assoc_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1424 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", |
| 1425 | ctx->assoc_freq); |
| 1426 | } |
| 1427 | if (status == NL80211_BSS_STATUS_IBSS_JOINED && |
| 1428 | bss[NL80211_BSS_FREQUENCY]) { |
| 1429 | ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1430 | wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz", |
| 1431 | ctx->ibss_freq); |
| 1432 | } |
| 1433 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1434 | bss[NL80211_BSS_BSSID]) { |
| 1435 | os_memcpy(ctx->assoc_bssid, |
| 1436 | nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN); |
| 1437 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " |
| 1438 | MACSTR, MAC2STR(ctx->assoc_bssid)); |
| 1439 | } |
| 1440 | |
| 1441 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1442 | bss[NL80211_BSS_INFORMATION_ELEMENTS]) { |
| 1443 | const u8 *ie, *ssid; |
| 1444 | size_t ie_len; |
| 1445 | |
| 1446 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1447 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1448 | ssid = get_ie(ie, ie_len, WLAN_EID_SSID); |
| 1449 | if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) { |
| 1450 | ctx->assoc_ssid_len = ssid[1]; |
| 1451 | os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]); |
| 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | return NL_SKIP; |
| 1456 | } |
| 1457 | |
| 1458 | |
| 1459 | 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] | 1460 | { |
| 1461 | struct nl_msg *msg; |
| 1462 | int ret; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1463 | struct nl80211_get_assoc_freq_arg arg; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1464 | int count = 0; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1465 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1466 | try_again: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1467 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1468 | os_memset(&arg, 0, sizeof(arg)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1469 | arg.drv = drv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1470 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1471 | &arg, NULL, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1472 | if (ret == -EAGAIN) { |
| 1473 | count++; |
| 1474 | if (count >= 10) { |
| 1475 | wpa_printf(MSG_INFO, |
| 1476 | "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid"); |
| 1477 | } else { |
| 1478 | wpa_printf(MSG_DEBUG, |
| 1479 | "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid - try again"); |
| 1480 | goto try_again; |
| 1481 | } |
| 1482 | } |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1483 | if (ret == 0) { |
| 1484 | os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len); |
| 1485 | return arg.assoc_ssid_len; |
| 1486 | } |
| 1487 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)", |
| 1488 | ret, strerror(-ret)); |
| 1489 | return ret; |
| 1490 | } |
| 1491 | |
| 1492 | |
| 1493 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
| 1494 | { |
| 1495 | struct nl_msg *msg; |
| 1496 | int ret; |
| 1497 | struct nl80211_get_assoc_freq_arg arg; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1498 | int count = 0; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1499 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1500 | try_again: |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1501 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
| 1502 | os_memset(&arg, 0, sizeof(arg)); |
| 1503 | arg.drv = drv; |
| 1504 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1505 | &arg, NULL, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1506 | if (ret == -EAGAIN) { |
| 1507 | count++; |
| 1508 | if (count >= 10) { |
| 1509 | wpa_printf(MSG_INFO, |
| 1510 | "nl80211: Failed to receive consistent scan result dump for get_assoc_freq"); |
| 1511 | } else { |
| 1512 | wpa_printf(MSG_DEBUG, |
| 1513 | "nl80211: Failed to receive consistent scan result dump for get_assoc_freq - try again"); |
| 1514 | goto try_again; |
| 1515 | } |
| 1516 | } |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1517 | if (ret == 0) { |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1518 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
| 1519 | arg.ibss_freq : arg.assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1520 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1521 | "associated BSS from scan results: %u MHz", freq); |
| 1522 | if (freq) |
| 1523 | drv->assoc_freq = freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1524 | return drv->assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1525 | } |
| 1526 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
| 1527 | "(%s)", ret, strerror(-ret)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1528 | return drv->assoc_freq; |
| 1529 | } |
| 1530 | |
| 1531 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1532 | static int get_link_signal(struct nl_msg *msg, void *arg) |
| 1533 | { |
| 1534 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1535 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1536 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; |
| 1537 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { |
| 1538 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1539 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1540 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1541 | }; |
| 1542 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
| 1543 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 1544 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 1545 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 1546 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, |
| 1547 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 1548 | }; |
| 1549 | struct wpa_signal_info *sig_change = arg; |
| 1550 | |
| 1551 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1552 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1553 | if (!tb[NL80211_ATTR_STA_INFO] || |
| 1554 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, |
| 1555 | tb[NL80211_ATTR_STA_INFO], policy)) |
| 1556 | return NL_SKIP; |
| 1557 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) |
| 1558 | return NL_SKIP; |
| 1559 | |
| 1560 | sig_change->current_signal = |
| 1561 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); |
| 1562 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1563 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
| 1564 | sig_change->avg_signal = |
| 1565 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); |
| 1566 | else |
| 1567 | sig_change->avg_signal = 0; |
| 1568 | |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1569 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
| 1570 | sig_change->avg_beacon_signal = |
| 1571 | (s8) |
| 1572 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); |
| 1573 | else |
| 1574 | sig_change->avg_beacon_signal = 0; |
| 1575 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1576 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
| 1577 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, |
| 1578 | sinfo[NL80211_STA_INFO_TX_BITRATE], |
| 1579 | rate_policy)) { |
| 1580 | sig_change->current_txrate = 0; |
| 1581 | } else { |
| 1582 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { |
| 1583 | sig_change->current_txrate = |
| 1584 | nla_get_u16(rinfo[ |
| 1585 | NL80211_RATE_INFO_BITRATE]) * 100; |
| 1586 | } |
| 1587 | } |
| 1588 | } |
| 1589 | |
| 1590 | return NL_SKIP; |
| 1591 | } |
| 1592 | |
| 1593 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1594 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
| 1595 | struct wpa_signal_info *sig) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1596 | { |
| 1597 | struct nl_msg *msg; |
| 1598 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1599 | sig->current_signal = -WPA_INVALID_NOISE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1600 | sig->current_txrate = 0; |
| 1601 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1602 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
| 1603 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) { |
| 1604 | nlmsg_free(msg); |
| 1605 | return -ENOBUFS; |
| 1606 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1607 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1608 | 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] | 1609 | } |
| 1610 | |
| 1611 | |
| 1612 | static int get_link_noise(struct nl_msg *msg, void *arg) |
| 1613 | { |
| 1614 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1615 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1616 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 1617 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 1618 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 1619 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 1620 | }; |
| 1621 | struct wpa_signal_info *sig_change = arg; |
| 1622 | |
| 1623 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1624 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1625 | |
| 1626 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 1627 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); |
| 1628 | return NL_SKIP; |
| 1629 | } |
| 1630 | |
| 1631 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 1632 | tb[NL80211_ATTR_SURVEY_INFO], |
| 1633 | survey_policy)) { |
| 1634 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " |
| 1635 | "attributes!"); |
| 1636 | return NL_SKIP; |
| 1637 | } |
| 1638 | |
| 1639 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 1640 | return NL_SKIP; |
| 1641 | |
| 1642 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 1643 | sig_change->frequency) |
| 1644 | return NL_SKIP; |
| 1645 | |
| 1646 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 1647 | return NL_SKIP; |
| 1648 | |
| 1649 | sig_change->current_noise = |
| 1650 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 1651 | |
| 1652 | return NL_SKIP; |
| 1653 | } |
| 1654 | |
| 1655 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1656 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
| 1657 | struct wpa_signal_info *sig_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1658 | { |
| 1659 | struct nl_msg *msg; |
| 1660 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1661 | sig_change->current_noise = WPA_INVALID_NOISE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1662 | sig_change->frequency = drv->assoc_freq; |
| 1663 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1664 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1665 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change, |
| 1666 | NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1670 | static int get_channel_info(struct nl_msg *msg, void *arg) |
| 1671 | { |
| 1672 | struct nlattr *tb[NL80211_ATTR_MAX + 1] = { 0 }; |
| 1673 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1674 | struct wpa_channel_info *chan_info = arg; |
| 1675 | |
| 1676 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1677 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1678 | |
| 1679 | os_memset(chan_info, 0, sizeof(struct wpa_channel_info)); |
| 1680 | chan_info->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 1681 | |
| 1682 | if (tb[NL80211_ATTR_WIPHY_FREQ]) |
| 1683 | chan_info->frequency = |
| 1684 | nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]); |
| 1685 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) |
| 1686 | chan_info->chanwidth = convert2width( |
| 1687 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 1688 | if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1689 | enum nl80211_channel_type ct = |
| 1690 | nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1691 | |
| 1692 | switch (ct) { |
| 1693 | case NL80211_CHAN_HT40MINUS: |
| 1694 | chan_info->sec_channel = -1; |
| 1695 | break; |
| 1696 | case NL80211_CHAN_HT40PLUS: |
| 1697 | chan_info->sec_channel = 1; |
| 1698 | break; |
| 1699 | default: |
| 1700 | chan_info->sec_channel = 0; |
| 1701 | break; |
| 1702 | } |
| 1703 | } |
| 1704 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 1705 | chan_info->center_frq1 = |
| 1706 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 1707 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 1708 | chan_info->center_frq2 = |
| 1709 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 1710 | |
| 1711 | if (chan_info->center_frq2) { |
| 1712 | u8 seg1_idx = 0; |
| 1713 | |
| 1714 | if (ieee80211_freq_to_chan(chan_info->center_frq2, &seg1_idx) != |
| 1715 | NUM_HOSTAPD_MODES) |
| 1716 | chan_info->seg1_idx = seg1_idx; |
| 1717 | } |
| 1718 | |
| 1719 | return NL_SKIP; |
| 1720 | } |
| 1721 | |
| 1722 | |
| 1723 | static int nl80211_channel_info(void *priv, struct wpa_channel_info *ci) |
| 1724 | { |
| 1725 | struct i802_bss *bss = priv; |
| 1726 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1727 | struct nl_msg *msg; |
| 1728 | |
| 1729 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1730 | 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] | 1731 | } |
| 1732 | |
| 1733 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1734 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
| 1735 | void *handle) |
| 1736 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1737 | struct nl_cb *cb = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1738 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1739 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1740 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1741 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1742 | res = nl_recvmsgs(handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 1743 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1744 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 1745 | __func__, res); |
| 1746 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1747 | } |
| 1748 | |
| 1749 | |
| 1750 | /** |
| 1751 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain |
| 1752 | * @priv: driver_nl80211 private data |
| 1753 | * @alpha2_arg: country to which to switch to |
| 1754 | * Returns: 0 on success, -1 on failure |
| 1755 | * |
| 1756 | * This asks nl80211 to set the regulatory domain for given |
| 1757 | * country ISO / IEC alpha2. |
| 1758 | */ |
| 1759 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) |
| 1760 | { |
| 1761 | struct i802_bss *bss = priv; |
| 1762 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1763 | char alpha2[3]; |
| 1764 | struct nl_msg *msg; |
| 1765 | |
| 1766 | msg = nlmsg_alloc(); |
| 1767 | if (!msg) |
| 1768 | return -ENOMEM; |
| 1769 | |
| 1770 | alpha2[0] = alpha2_arg[0]; |
| 1771 | alpha2[1] = alpha2_arg[1]; |
| 1772 | alpha2[2] = '\0'; |
| 1773 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1774 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
| 1775 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { |
| 1776 | nlmsg_free(msg); |
| 1777 | return -EINVAL; |
| 1778 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1779 | if (send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1780 | return -EINVAL; |
| 1781 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1782 | } |
| 1783 | |
| 1784 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1785 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
| 1786 | { |
| 1787 | char *alpha2 = arg; |
| 1788 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 1789 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1790 | |
| 1791 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1792 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1793 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { |
| 1794 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); |
| 1795 | return NL_SKIP; |
| 1796 | } |
| 1797 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); |
| 1798 | return NL_SKIP; |
| 1799 | } |
| 1800 | |
| 1801 | |
| 1802 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) |
| 1803 | { |
| 1804 | struct i802_bss *bss = priv; |
| 1805 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1806 | struct nl_msg *msg; |
| 1807 | int ret; |
| 1808 | |
| 1809 | msg = nlmsg_alloc(); |
| 1810 | if (!msg) |
| 1811 | return -ENOMEM; |
| 1812 | |
| 1813 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
| 1814 | alpha2[0] = '\0'; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 1815 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2, |
| 1816 | NULL, NULL); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1817 | if (!alpha2[0]) |
| 1818 | ret = -1; |
| 1819 | |
| 1820 | return ret; |
| 1821 | } |
| 1822 | |
| 1823 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1824 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1825 | { |
| 1826 | int ret; |
| 1827 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1828 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1829 | if (global->nl_cb == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1830 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 1831 | "callbacks"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1832 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1833 | } |
| 1834 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1835 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
| 1836 | if (global->nl == NULL) |
| 1837 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1838 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1839 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
| 1840 | if (global->nl80211_id < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1841 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
| 1842 | "found"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1843 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1844 | } |
| 1845 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1846 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
| 1847 | if (global->nl_event == NULL) |
| 1848 | goto err; |
| 1849 | |
| 1850 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1851 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1852 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1853 | if (ret < 0) { |
| 1854 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1855 | "membership for scan events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1856 | ret, nl_geterror(ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1857 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1858 | } |
| 1859 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1860 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1861 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1862 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1863 | if (ret < 0) { |
| 1864 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1865 | "membership for mlme events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1866 | ret, nl_geterror(ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1867 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1868 | } |
| 1869 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1870 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1871 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1872 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1873 | if (ret < 0) { |
| 1874 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1875 | "membership for regulatory events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1876 | ret, nl_geterror(ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1877 | /* Continue without regulatory events */ |
| 1878 | } |
| 1879 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1880 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
| 1881 | if (ret >= 0) |
| 1882 | ret = nl_socket_add_membership(global->nl_event, ret); |
| 1883 | if (ret < 0) { |
| 1884 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1885 | "membership for vendor events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1886 | ret, nl_geterror(ret)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1887 | /* Continue without vendor events */ |
| 1888 | } |
| 1889 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1890 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1891 | no_seq_check, NULL); |
| 1892 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1893 | process_global_event, global); |
| 1894 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1895 | nl80211_register_eloop_read(&global->nl_event, |
| 1896 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1897 | global->nl_cb, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1898 | |
| 1899 | return 0; |
| 1900 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1901 | err: |
| 1902 | nl_destroy_handles(&global->nl_event); |
| 1903 | nl_destroy_handles(&global->nl); |
| 1904 | nl_cb_put(global->nl_cb); |
| 1905 | global->nl_cb = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1906 | return -1; |
| 1907 | } |
| 1908 | |
| 1909 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1910 | static void nl80211_check_global(struct nl80211_global *global) |
| 1911 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1912 | struct nl_sock *handle; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1913 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; |
| 1914 | int ret; |
| 1915 | unsigned int i; |
| 1916 | |
| 1917 | /* |
| 1918 | * Try to re-add memberships to handle case of cfg80211 getting reloaded |
| 1919 | * and all registration having been cleared. |
| 1920 | */ |
| 1921 | handle = (void *) (((intptr_t) global->nl_event) ^ |
| 1922 | ELOOP_SOCKET_INVALID); |
| 1923 | |
| 1924 | for (i = 0; groups[i]; i++) { |
| 1925 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); |
| 1926 | if (ret >= 0) |
| 1927 | ret = nl_socket_add_membership(handle, ret); |
| 1928 | if (ret < 0) { |
| 1929 | wpa_printf(MSG_INFO, |
| 1930 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1931 | groups[i], ret, nl_geterror(ret)); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1932 | } |
| 1933 | } |
| 1934 | } |
| 1935 | |
| 1936 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1937 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
| 1938 | { |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1939 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1940 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1941 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1942 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1943 | /* |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1944 | * rtnetlink ifdown handler will report interfaces other than the P2P |
| 1945 | * Device interface as disabled. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1946 | */ |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1947 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 1948 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | |
| 1952 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) |
| 1953 | { |
| 1954 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1955 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1956 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1957 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
| 1958 | "after rfkill unblock"); |
| 1959 | return; |
| 1960 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1961 | |
| 1962 | if (is_p2p_net_interface(drv->nlmode)) |
| 1963 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
| 1964 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1965 | /* |
| 1966 | * rtnetlink ifup handler will report interfaces other than the P2P |
| 1967 | * Device interface as enabled. |
| 1968 | */ |
| 1969 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 1970 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1974 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
| 1975 | void *eloop_ctx, |
| 1976 | void *handle) |
| 1977 | { |
| 1978 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 1979 | u8 data[2048]; |
| 1980 | struct msghdr msg; |
| 1981 | struct iovec entry; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1982 | u8 control[512]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1983 | struct cmsghdr *cmsg; |
| 1984 | int res, found_ee = 0, found_wifi = 0, acked = 0; |
| 1985 | union wpa_event_data event; |
| 1986 | |
| 1987 | memset(&msg, 0, sizeof(msg)); |
| 1988 | msg.msg_iov = &entry; |
| 1989 | msg.msg_iovlen = 1; |
| 1990 | entry.iov_base = data; |
| 1991 | entry.iov_len = sizeof(data); |
| 1992 | msg.msg_control = &control; |
| 1993 | msg.msg_controllen = sizeof(control); |
| 1994 | |
| 1995 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); |
| 1996 | /* if error or not fitting 802.3 header, return */ |
| 1997 | if (res < 14) |
| 1998 | return; |
| 1999 | |
| 2000 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
| 2001 | { |
| 2002 | if (cmsg->cmsg_level == SOL_SOCKET && |
| 2003 | cmsg->cmsg_type == SCM_WIFI_STATUS) { |
| 2004 | int *ack; |
| 2005 | |
| 2006 | found_wifi = 1; |
| 2007 | ack = (void *)CMSG_DATA(cmsg); |
| 2008 | acked = *ack; |
| 2009 | } |
| 2010 | |
| 2011 | if (cmsg->cmsg_level == SOL_PACKET && |
| 2012 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { |
| 2013 | struct sock_extended_err *err = |
| 2014 | (struct sock_extended_err *)CMSG_DATA(cmsg); |
| 2015 | |
| 2016 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) |
| 2017 | found_ee = 1; |
| 2018 | } |
| 2019 | } |
| 2020 | |
| 2021 | if (!found_ee || !found_wifi) |
| 2022 | return; |
| 2023 | |
| 2024 | memset(&event, 0, sizeof(event)); |
| 2025 | event.eapol_tx_status.dst = data; |
| 2026 | event.eapol_tx_status.data = data + 14; |
| 2027 | event.eapol_tx_status.data_len = res - 14; |
| 2028 | event.eapol_tx_status.ack = acked; |
| 2029 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); |
| 2030 | } |
| 2031 | |
| 2032 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 2033 | static int nl80211_init_connect_handle(struct i802_bss *bss) |
| 2034 | { |
| 2035 | if (bss->nl_connect) { |
| 2036 | wpa_printf(MSG_DEBUG, |
| 2037 | "nl80211: Connect handle already created (nl_connect=%p)", |
| 2038 | bss->nl_connect); |
| 2039 | return -1; |
| 2040 | } |
| 2041 | |
| 2042 | bss->nl_connect = nl_create_handle(bss->nl_cb, "connect"); |
| 2043 | if (!bss->nl_connect) |
| 2044 | return -1; |
| 2045 | nl80211_register_eloop_read(&bss->nl_connect, |
| 2046 | wpa_driver_nl80211_event_receive, |
| 2047 | bss->nl_cb, 1); |
| 2048 | return 0; |
| 2049 | } |
| 2050 | |
| 2051 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2052 | static int nl80211_init_bss(struct i802_bss *bss) |
| 2053 | { |
| 2054 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 2055 | if (!bss->nl_cb) |
| 2056 | return -1; |
| 2057 | |
| 2058 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 2059 | no_seq_check, NULL); |
| 2060 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 2061 | process_bss_event, bss); |
| 2062 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 2063 | nl80211_init_connect_handle(bss); |
| 2064 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2065 | return 0; |
| 2066 | } |
| 2067 | |
| 2068 | |
| 2069 | static void nl80211_destroy_bss(struct i802_bss *bss) |
| 2070 | { |
| 2071 | nl_cb_put(bss->nl_cb); |
| 2072 | bss->nl_cb = NULL; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 2073 | |
| 2074 | if (bss->nl_connect) |
| 2075 | nl80211_destroy_eloop_handle(&bss->nl_connect, 1); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2076 | } |
| 2077 | |
| 2078 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2079 | static void |
| 2080 | wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv) |
| 2081 | { |
| 2082 | struct rfkill_config *rcfg; |
| 2083 | |
| 2084 | if (drv->rfkill) |
| 2085 | return; |
| 2086 | |
| 2087 | rcfg = os_zalloc(sizeof(*rcfg)); |
| 2088 | if (!rcfg) |
| 2089 | return; |
| 2090 | |
| 2091 | rcfg->ctx = drv; |
| 2092 | |
| 2093 | /* rfkill uses netdev sysfs for initialization. However, P2P Device is |
| 2094 | * not associated with a netdev, so use the name of some other interface |
| 2095 | * sharing the same wiphy as the P2P Device interface. |
| 2096 | * |
| 2097 | * Note: This is valid, as a P2P Device interface is always dynamically |
| 2098 | * created and is created only once another wpa_s interface was added. |
| 2099 | */ |
| 2100 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 2101 | struct nl80211_global *global = drv->global; |
| 2102 | struct wpa_driver_nl80211_data *tmp1; |
| 2103 | |
| 2104 | dl_list_for_each(tmp1, &global->interfaces, |
| 2105 | struct wpa_driver_nl80211_data, list) { |
| 2106 | if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx || |
| 2107 | !tmp1->rfkill) |
| 2108 | continue; |
| 2109 | |
| 2110 | wpa_printf(MSG_DEBUG, |
| 2111 | "nl80211: Use (%s) to initialize P2P Device rfkill", |
| 2112 | tmp1->first_bss->ifname); |
| 2113 | os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname, |
| 2114 | sizeof(rcfg->ifname)); |
| 2115 | break; |
| 2116 | } |
| 2117 | } else { |
| 2118 | os_strlcpy(rcfg->ifname, drv->first_bss->ifname, |
| 2119 | sizeof(rcfg->ifname)); |
| 2120 | } |
| 2121 | |
| 2122 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; |
| 2123 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; |
| 2124 | drv->rfkill = rfkill_init(rcfg); |
| 2125 | if (!drv->rfkill) { |
| 2126 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
| 2127 | os_free(rcfg); |
| 2128 | } |
| 2129 | } |
| 2130 | |
| 2131 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2132 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
| 2133 | void *global_priv, int hostapd, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2134 | const u8 *set_addr, |
| 2135 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2136 | { |
| 2137 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2138 | struct i802_bss *bss; |
| 2139 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2140 | if (global_priv == NULL) |
| 2141 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2142 | drv = os_zalloc(sizeof(*drv)); |
| 2143 | if (drv == NULL) |
| 2144 | return NULL; |
| 2145 | drv->global = global_priv; |
| 2146 | drv->ctx = ctx; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2147 | drv->hostapd = !!hostapd; |
| 2148 | drv->eapol_sock = -1; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 2149 | |
| 2150 | /* |
| 2151 | * There is no driver capability flag for this, so assume it is |
| 2152 | * supported and disable this on first attempt to use if the driver |
| 2153 | * rejects the command due to missing support. |
| 2154 | */ |
| 2155 | drv->set_rekey_offload = 1; |
| 2156 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2157 | drv->num_if_indices = ARRAY_SIZE(drv->default_if_indices); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2158 | drv->if_indices = drv->default_if_indices; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2159 | |
| 2160 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); |
| 2161 | if (!drv->first_bss) { |
| 2162 | os_free(drv); |
| 2163 | return NULL; |
| 2164 | } |
| 2165 | bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2166 | bss->drv = drv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2167 | bss->ctx = ctx; |
| 2168 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2169 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
| 2170 | drv->monitor_ifidx = -1; |
| 2171 | drv->monitor_sock = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2172 | drv->eapol_tx_sock = -1; |
| 2173 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2174 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2175 | if (nl80211_init_bss(bss)) |
| 2176 | goto failed; |
| 2177 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2178 | 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] | 2179 | goto failed; |
| 2180 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2181 | if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_TX_STATUS) { |
| 2182 | drv->control_port_ap = 1; |
| 2183 | goto skip_wifi_status; |
| 2184 | } |
| 2185 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2186 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
| 2187 | if (drv->eapol_tx_sock < 0) |
| 2188 | goto failed; |
| 2189 | |
| 2190 | if (drv->data_tx_status) { |
| 2191 | int enabled = 1; |
| 2192 | |
| 2193 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, |
| 2194 | &enabled, sizeof(enabled)) < 0) { |
| 2195 | wpa_printf(MSG_DEBUG, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2196 | "nl80211: wifi status sockopt failed: %s", |
| 2197 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2198 | drv->data_tx_status = 0; |
| 2199 | if (!drv->use_monitor) |
| 2200 | drv->capa.flags &= |
| 2201 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
| 2202 | } else { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2203 | eloop_register_read_sock( |
| 2204 | drv->eapol_tx_sock, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2205 | wpa_driver_nl80211_handle_eapol_tx_status, |
| 2206 | drv, NULL); |
| 2207 | } |
| 2208 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2209 | skip_wifi_status: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2210 | |
| 2211 | if (drv->global) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2212 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2213 | dl_list_add(&drv->global->interfaces, &drv->list); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2214 | drv->in_interface_list = 1; |
| 2215 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2216 | |
| 2217 | return bss; |
| 2218 | |
| 2219 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2220 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2221 | return NULL; |
| 2222 | } |
| 2223 | |
| 2224 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2225 | /** |
| 2226 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface |
| 2227 | * @ctx: context to be used when calling wpa_supplicant functions, |
| 2228 | * e.g., wpa_supplicant_event() |
| 2229 | * @ifname: interface name, e.g., wlan0 |
| 2230 | * @global_priv: private driver global data from global_init() |
| 2231 | * Returns: Pointer to private data, %NULL on failure |
| 2232 | */ |
| 2233 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
| 2234 | void *global_priv) |
| 2235 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2236 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
| 2237 | NULL); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2238 | } |
| 2239 | |
| 2240 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2241 | static int nl80211_register_frame(struct i802_bss *bss, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2242 | struct nl_sock *nl_handle, |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2243 | u16 type, const u8 *match, size_t match_len, |
| 2244 | bool multicast) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2245 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2246 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2247 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2248 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2249 | char buf[30]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2250 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2251 | buf[0] = '\0'; |
| 2252 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2253 | wpa_printf(MSG_DEBUG, |
| 2254 | "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s multicast=%d", |
| 2255 | type, fc2str(type), nl_handle, buf, multicast); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2256 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2257 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_FRAME)) || |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2258 | (multicast && nla_put_flag(msg, NL80211_ATTR_RECEIVE_MULTICAST)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2259 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
| 2260 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { |
| 2261 | nlmsg_free(msg); |
| 2262 | return -1; |
| 2263 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2264 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2265 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL, |
| 2266 | NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2267 | if (ret) { |
| 2268 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
| 2269 | "failed (type=%u): ret=%d (%s)", |
| 2270 | type, ret, strerror(-ret)); |
| 2271 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", |
| 2272 | match, match_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2273 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2274 | return ret; |
| 2275 | } |
| 2276 | |
| 2277 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2278 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
| 2279 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2280 | if (bss->nl_mgmt) { |
| 2281 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
| 2282 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
| 2283 | return -1; |
| 2284 | } |
| 2285 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2286 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2287 | if (bss->nl_mgmt == NULL) |
| 2288 | return -1; |
| 2289 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2290 | return 0; |
| 2291 | } |
| 2292 | |
| 2293 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2294 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
| 2295 | { |
| 2296 | nl80211_register_eloop_read(&bss->nl_mgmt, |
| 2297 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2298 | bss->nl_cb, 0); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2299 | } |
| 2300 | |
| 2301 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2302 | static int nl80211_register_action_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2303 | const u8 *match, size_t match_len) |
| 2304 | { |
| 2305 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2306 | return nl80211_register_frame(bss, bss->nl_mgmt, |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2307 | type, match, match_len, false); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2308 | } |
| 2309 | |
| 2310 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2311 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2312 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2313 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2314 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2315 | int ret = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2316 | |
| 2317 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2318 | return -1; |
| 2319 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
| 2320 | "handle %p", bss->nl_mgmt); |
| 2321 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2322 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2323 | /* register for any AUTH message */ |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2324 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0, false); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2325 | } else if ((drv->capa.flags & WPA_DRIVER_FLAGS_SAE) && |
| 2326 | !(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
| 2327 | /* register for SAE Authentication frames */ |
| 2328 | nl80211_register_frame(bss, bss->nl_mgmt, type, |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2329 | (u8 *) "\x03\x00", 2, false); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2330 | } |
| 2331 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2332 | #ifdef CONFIG_INTERWORKING |
| 2333 | /* QoS Map Configure */ |
| 2334 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2335 | ret = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2336 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2337 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2338 | /* GAS Initial Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2339 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2340 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2341 | /* GAS Initial Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2342 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2343 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2344 | /* GAS Comeback Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2345 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2346 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2347 | /* GAS Comeback Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2348 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2349 | ret = -1; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2350 | /* Protected GAS Initial Request */ |
| 2351 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) |
| 2352 | ret = -1; |
| 2353 | /* Protected GAS Initial Response */ |
| 2354 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) |
| 2355 | ret = -1; |
| 2356 | /* Protected GAS Comeback Request */ |
| 2357 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) |
| 2358 | ret = -1; |
| 2359 | /* Protected GAS Comeback Response */ |
| 2360 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) |
| 2361 | ret = -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2362 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2363 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2364 | /* P2P Public Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2365 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2366 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
| 2367 | 6) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2368 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2369 | /* P2P Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2370 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2371 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
| 2372 | 5) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2373 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2374 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2375 | #ifdef CONFIG_DPP |
| 2376 | /* DPP Public Action */ |
| 2377 | if (nl80211_register_action_frame(bss, |
| 2378 | (u8 *) "\x04\x09\x50\x6f\x9a\x1a", |
| 2379 | 6) < 0) |
| 2380 | ret = -1; |
| 2381 | #endif /* CONFIG_DPP */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2382 | #ifdef CONFIG_OCV |
| 2383 | /* SA Query Request */ |
| 2384 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x00", 2) < 0) |
| 2385 | ret = -1; |
| 2386 | #endif /* CONFIG_OCV */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2387 | /* SA Query Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2388 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2389 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2390 | #ifdef CONFIG_TDLS |
| 2391 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { |
| 2392 | /* TDLS Discovery Response */ |
| 2393 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
| 2394 | 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2395 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2396 | } |
| 2397 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2398 | #ifdef CONFIG_FST |
| 2399 | /* FST Action frames */ |
| 2400 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2401 | ret = -1; |
| 2402 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2403 | |
| 2404 | /* FT Action frames */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2405 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2406 | ret = -1; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2407 | else if (!drv->has_driver_key_mgmt) { |
| 2408 | int i; |
| 2409 | |
| 2410 | /* Update supported AKMs only if the driver doesn't advertize |
| 2411 | * any AKM capabilities. */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2412 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | |
| 2413 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; |
| 2414 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2415 | /* Update per interface supported AKMs */ |
| 2416 | for (i = 0; i < WPA_IF_MAX; i++) |
| 2417 | drv->capa.key_mgmt_iftype[i] = drv->capa.key_mgmt; |
| 2418 | } |
| 2419 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2420 | /* WNM - BSS Transition Management Request */ |
| 2421 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2422 | ret = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2423 | /* WNM-Sleep Mode Response */ |
| 2424 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2425 | ret = -1; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2426 | #ifdef CONFIG_WNM |
| 2427 | /* WNM - Collocated Interference Request */ |
| 2428 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x0b", 2) < 0) |
| 2429 | ret = -1; |
| 2430 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2431 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2432 | #ifdef CONFIG_HS20 |
| 2433 | /* WNM-Notification */ |
| 2434 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2435 | ret = -1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2436 | #endif /* CONFIG_HS20 */ |
| 2437 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2438 | /* WMM-AC ADDTS Response */ |
| 2439 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) |
| 2440 | ret = -1; |
| 2441 | |
| 2442 | /* WMM-AC DELTS */ |
| 2443 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) |
| 2444 | ret = -1; |
| 2445 | |
| 2446 | /* Radio Measurement - Neighbor Report Response */ |
| 2447 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) |
| 2448 | ret = -1; |
| 2449 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2450 | /* Radio Measurement - Radio Measurement Request */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2451 | if (!drv->no_rrm && |
| 2452 | nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2453 | ret = -1; |
| 2454 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2455 | /* Radio Measurement - Link Measurement Request */ |
| 2456 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && |
| 2457 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) |
| 2458 | ret = -1; |
| 2459 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2460 | /* Robust AV MSCS Response */ |
| 2461 | if (nl80211_register_action_frame(bss, (u8 *) "\x13\x05", 2) < 0) |
| 2462 | ret = -1; |
| 2463 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2464 | nl80211_mgmt_handle_register_eloop(bss); |
| 2465 | |
| 2466 | return ret; |
| 2467 | } |
| 2468 | |
| 2469 | |
| 2470 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
| 2471 | { |
| 2472 | int ret = 0; |
| 2473 | |
| 2474 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2475 | return -1; |
| 2476 | |
| 2477 | wpa_printf(MSG_DEBUG, |
| 2478 | "nl80211: Subscribe to mgmt frames with mesh handle %p", |
| 2479 | bss->nl_mgmt); |
| 2480 | |
| 2481 | /* Auth frames for mesh SAE */ |
| 2482 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2483 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2484 | (WLAN_FC_STYPE_AUTH << 4), |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2485 | NULL, 0, false) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2486 | ret = -1; |
| 2487 | |
| 2488 | /* Mesh peering open */ |
| 2489 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) |
| 2490 | ret = -1; |
| 2491 | /* Mesh peering confirm */ |
| 2492 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) |
| 2493 | ret = -1; |
| 2494 | /* Mesh peering close */ |
| 2495 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) |
| 2496 | ret = -1; |
| 2497 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2498 | nl80211_mgmt_handle_register_eloop(bss); |
| 2499 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2500 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2501 | } |
| 2502 | |
| 2503 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2504 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
| 2505 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2506 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2507 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2508 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2509 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2510 | ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL, |
| 2511 | NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2512 | if (ret) { |
| 2513 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " |
| 2514 | "failed: ret=%d (%s)", |
| 2515 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2516 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2517 | return ret; |
| 2518 | } |
| 2519 | |
| 2520 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2521 | static int nl80211_action_subscribe_ap(struct i802_bss *bss) |
| 2522 | { |
| 2523 | int ret = 0; |
| 2524 | |
| 2525 | /* Public Action frames */ |
| 2526 | if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0) |
| 2527 | ret = -1; |
| 2528 | /* RRM Measurement Report */ |
| 2529 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0) |
| 2530 | ret = -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2531 | /* RRM Link Measurement Report */ |
| 2532 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0) |
| 2533 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2534 | /* RRM Neighbor Report Request */ |
| 2535 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0) |
| 2536 | ret = -1; |
| 2537 | /* FT Action frames */ |
| 2538 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
| 2539 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2540 | /* SA Query */ |
| 2541 | if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0) |
| 2542 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2543 | /* Protected Dual of Public Action */ |
| 2544 | if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0) |
| 2545 | ret = -1; |
| 2546 | /* WNM */ |
| 2547 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0) |
| 2548 | ret = -1; |
| 2549 | /* WMM */ |
| 2550 | if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0) |
| 2551 | ret = -1; |
| 2552 | #ifdef CONFIG_FST |
| 2553 | /* FST Action frames */ |
| 2554 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2555 | ret = -1; |
| 2556 | #endif /* CONFIG_FST */ |
| 2557 | /* Vendor-specific */ |
| 2558 | if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0) |
| 2559 | ret = -1; |
| 2560 | |
| 2561 | return ret; |
| 2562 | } |
| 2563 | |
| 2564 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2565 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
| 2566 | { |
| 2567 | static const int stypes[] = { |
| 2568 | WLAN_FC_STYPE_AUTH, |
| 2569 | WLAN_FC_STYPE_ASSOC_REQ, |
| 2570 | WLAN_FC_STYPE_REASSOC_REQ, |
| 2571 | WLAN_FC_STYPE_DISASSOC, |
| 2572 | WLAN_FC_STYPE_DEAUTH, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2573 | WLAN_FC_STYPE_PROBE_REQ, |
| 2574 | /* Beacon doesn't work as mac80211 doesn't currently allow |
| 2575 | * it, but it wouldn't really be the right thing anyway as |
| 2576 | * it isn't per interface ... maybe just dump the scan |
| 2577 | * results periodically for OLBC? |
| 2578 | */ |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2579 | /* WLAN_FC_STYPE_BEACON, */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2580 | }; |
| 2581 | unsigned int i; |
| 2582 | |
| 2583 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2584 | return -1; |
| 2585 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2586 | "handle %p", bss->nl_mgmt); |
| 2587 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2588 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2589 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2590 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2591 | (stypes[i] << 4), |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2592 | NULL, 0, false) < 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2593 | goto out_err; |
| 2594 | } |
| 2595 | } |
| 2596 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2597 | if (nl80211_action_subscribe_ap(bss)) |
| 2598 | goto out_err; |
| 2599 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2600 | if (nl80211_register_spurious_class3(bss)) |
| 2601 | goto out_err; |
| 2602 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2603 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2604 | return 0; |
| 2605 | |
| 2606 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2607 | nl_destroy_handles(&bss->nl_mgmt); |
| 2608 | return -1; |
| 2609 | } |
| 2610 | |
| 2611 | |
| 2612 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
| 2613 | { |
| 2614 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2615 | return -1; |
| 2616 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2617 | "handle %p (device SME)", bss->nl_mgmt); |
| 2618 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2619 | if (nl80211_action_subscribe_ap(bss)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2620 | goto out_err; |
| 2621 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 2622 | if (bss->drv->device_ap_sme) { |
| 2623 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
| 2624 | |
| 2625 | /* Register for all Authentication frames */ |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2626 | if (nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0, |
| 2627 | false) < 0) |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 2628 | wpa_printf(MSG_DEBUG, |
| 2629 | "nl80211: Failed to subscribe to handle Authentication frames - SAE offload may not work"); |
| 2630 | } |
| 2631 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2632 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2633 | return 0; |
| 2634 | |
| 2635 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2636 | nl_destroy_handles(&bss->nl_mgmt); |
| 2637 | return -1; |
| 2638 | } |
| 2639 | |
| 2640 | |
| 2641 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
| 2642 | { |
| 2643 | if (bss->nl_mgmt == NULL) |
| 2644 | return; |
| 2645 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
| 2646 | "(%s)", bss->nl_mgmt, reason); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2647 | nl80211_destroy_eloop_handle(&bss->nl_mgmt, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2648 | |
| 2649 | nl80211_put_wiphy_data_ap(bss); |
| 2650 | } |
| 2651 | |
| 2652 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2653 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
| 2654 | { |
| 2655 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); |
| 2656 | } |
| 2657 | |
| 2658 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2659 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
| 2660 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2661 | struct nl_msg *msg; |
| 2662 | int ret; |
| 2663 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2664 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2665 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2666 | |
| 2667 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", |
| 2668 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2669 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2670 | } |
| 2671 | |
| 2672 | |
| 2673 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
| 2674 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2675 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2676 | int ret; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2677 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2678 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
| 2679 | NL80211_CMD_STOP_P2P_DEVICE); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2680 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2681 | |
| 2682 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
| 2683 | start ? "Start" : "Stop", |
| 2684 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2685 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2686 | return ret; |
| 2687 | } |
| 2688 | |
| 2689 | |
| 2690 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
| 2691 | { |
| 2692 | enum nl80211_iftype nlmode; |
| 2693 | |
| 2694 | nlmode = nl80211_get_ifmode(bss); |
| 2695 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2696 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, |
| 2697 | bss->ifname, up); |
| 2698 | } |
| 2699 | |
| 2700 | /* P2P Device has start/stop which is equivalent */ |
| 2701 | return nl80211_set_p2pdev(bss, up); |
| 2702 | } |
| 2703 | |
| 2704 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2705 | #ifdef CONFIG_TESTING_OPTIONS |
| 2706 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) |
| 2707 | { |
| 2708 | /* struct wpa_driver_nl80211_data *drv = arg; */ |
| 2709 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 2710 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2711 | |
| 2712 | |
| 2713 | wpa_printf(MSG_DEBUG, |
| 2714 | "nl80211: QCA vendor test command response received"); |
| 2715 | |
| 2716 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2717 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2718 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { |
| 2719 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); |
| 2720 | return NL_SKIP; |
| 2721 | } |
| 2722 | |
| 2723 | wpa_hexdump(MSG_DEBUG, |
| 2724 | "nl80211: Received QCA vendor test command response", |
| 2725 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), |
| 2726 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); |
| 2727 | |
| 2728 | return NL_SKIP; |
| 2729 | } |
| 2730 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2731 | |
| 2732 | |
| 2733 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) |
| 2734 | { |
| 2735 | #ifdef CONFIG_TESTING_OPTIONS |
| 2736 | struct nl_msg *msg; |
| 2737 | struct nlattr *params; |
| 2738 | int ret; |
| 2739 | |
| 2740 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2741 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2742 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2743 | QCA_NL80211_VENDOR_SUBCMD_TEST) || |
| 2744 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 2745 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { |
| 2746 | nlmsg_free(msg); |
| 2747 | return; |
| 2748 | } |
| 2749 | nla_nest_end(msg, params); |
| 2750 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2751 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv, |
| 2752 | NULL, NULL); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2753 | wpa_printf(MSG_DEBUG, |
| 2754 | "nl80211: QCA vendor test command returned %d (%s)", |
| 2755 | ret, strerror(-ret)); |
| 2756 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2757 | } |
| 2758 | |
| 2759 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2760 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2761 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2762 | const u8 *set_addr, int first, |
| 2763 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2764 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2765 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2766 | int send_rfkill_event = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2767 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2768 | |
| 2769 | drv->ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2770 | bss->ifindex = drv->ifindex; |
| 2771 | bss->wdev_id = drv->global->if_add_wdevid; |
| 2772 | bss->wdev_id_set = drv->global->if_add_wdevid_set; |
| 2773 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2774 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
| 2775 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2776 | drv->global->if_add_wdevid_set = 0; |
| 2777 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2778 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2779 | bss->static_ap = 1; |
| 2780 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 2781 | if (first && |
| 2782 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && |
| 2783 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) |
| 2784 | drv->start_iface_up = 1; |
| 2785 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2786 | if (wpa_driver_nl80211_capa(drv)) |
| 2787 | return -1; |
| 2788 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2789 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
| 2790 | return -1; |
| 2791 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2792 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
| 2793 | bss->ifname, drv->phyname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2794 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2795 | if (set_addr && |
| 2796 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || |
| 2797 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2798 | set_addr))) |
| 2799 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2800 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2801 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2802 | drv->start_mode_ap = 1; |
| 2803 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2804 | if (drv->hostapd || bss->static_ap) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2805 | nlmode = NL80211_IFTYPE_AP; |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 2806 | else if (bss->if_dynamic || |
| 2807 | nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2808 | nlmode = nl80211_get_ifmode(bss); |
| 2809 | else |
| 2810 | nlmode = NL80211_IFTYPE_STATION; |
| 2811 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2812 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2813 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2814 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2815 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2816 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2817 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2818 | nl80211_get_macaddr(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2819 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2820 | wpa_driver_nl80211_drv_init_rfkill(drv); |
| 2821 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2822 | if (!rfkill_is_blocked(drv->rfkill)) { |
| 2823 | int ret = i802_set_iface_flags(bss, 1); |
| 2824 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2825 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
| 2826 | "interface '%s' UP", bss->ifname); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2827 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2828 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2829 | |
| 2830 | if (is_p2p_net_interface(nlmode)) |
| 2831 | nl80211_disable_11b_rates(bss->drv, |
| 2832 | bss->drv->ifindex, 1); |
| 2833 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2834 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2835 | return ret; |
| 2836 | } else { |
| 2837 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " |
| 2838 | "interface '%s' due to rfkill", bss->ifname); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2839 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 2840 | drv->if_disabled = 1; |
| 2841 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2842 | send_rfkill_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2843 | } |
| 2844 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2845 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2846 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
| 2847 | 1, IF_OPER_DORMANT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2848 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2849 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2850 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2851 | bss->addr)) |
| 2852 | return -1; |
| 2853 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); |
| 2854 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2855 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2856 | if (send_rfkill_event) { |
| 2857 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, |
| 2858 | drv, drv->ctx); |
| 2859 | } |
| 2860 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2861 | if (drv->vendor_cmd_test_avail) |
| 2862 | qca_vendor_test(drv); |
| 2863 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2864 | return 0; |
| 2865 | } |
| 2866 | |
| 2867 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2868 | static int wpa_driver_nl80211_del_beacon(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2869 | { |
| 2870 | struct nl_msg *msg; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2871 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2872 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2873 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
| 2874 | drv->ifindex); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2875 | nl80211_put_wiphy_data_ap(bss); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2876 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 2877 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2878 | } |
| 2879 | |
| 2880 | |
| 2881 | /** |
| 2882 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2883 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2884 | * |
| 2885 | * Shut down driver interface and processing of driver events. Free |
| 2886 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). |
| 2887 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2888 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2889 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2890 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2891 | unsigned int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2892 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2893 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
| 2894 | bss->ifname, drv->disabled_11b_rates); |
| 2895 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2896 | bss->in_deinit = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2897 | if (drv->data_tx_status) |
| 2898 | eloop_unregister_read_sock(drv->eapol_tx_sock); |
| 2899 | if (drv->eapol_tx_sock >= 0) |
| 2900 | close(drv->eapol_tx_sock); |
| 2901 | |
| 2902 | if (bss->nl_preq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2903 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 2904 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2905 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 2906 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2907 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2908 | "interface %s from bridge %s: %s", |
| 2909 | bss->ifname, bss->brname, strerror(errno)); |
| 2910 | } |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 2911 | |
| 2912 | if (drv->rtnl_sk) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2913 | nl_socket_free(drv->rtnl_sk); |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 2914 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2915 | if (bss->added_bridge) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2916 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
| 2917 | 0) < 0) |
| 2918 | wpa_printf(MSG_INFO, |
| 2919 | "nl80211: Could not set bridge %s down", |
| 2920 | bss->brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2921 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2922 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2923 | "bridge %s: %s", |
| 2924 | bss->brname, strerror(errno)); |
| 2925 | } |
| 2926 | |
| 2927 | nl80211_remove_monitor_interface(drv); |
| 2928 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2929 | if (is_ap_interface(drv->nlmode)) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2930 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2931 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2932 | if (drv->eapol_sock >= 0) { |
| 2933 | eloop_unregister_read_sock(drv->eapol_sock); |
| 2934 | close(drv->eapol_sock); |
| 2935 | } |
| 2936 | |
| 2937 | if (drv->if_indices != drv->default_if_indices) |
| 2938 | os_free(drv->if_indices); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2939 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2940 | if (drv->disabled_11b_rates) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2941 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 2942 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2943 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
| 2944 | IF_OPER_UP); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 2945 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2946 | rfkill_deinit(drv->rfkill); |
| 2947 | |
| 2948 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 2949 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2950 | if (!drv->start_iface_up) |
| 2951 | (void) i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2952 | |
| 2953 | if (drv->addr_changed) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2954 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 2955 | 0) < 0) { |
| 2956 | wpa_printf(MSG_DEBUG, |
| 2957 | "nl80211: Could not set interface down to restore permanent MAC address"); |
| 2958 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2959 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2960 | drv->perm_addr) < 0) { |
| 2961 | wpa_printf(MSG_DEBUG, |
| 2962 | "nl80211: Could not restore permanent MAC address"); |
| 2963 | } |
| 2964 | } |
| 2965 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2966 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2967 | if (!drv->hostapd || !drv->start_mode_ap) |
| 2968 | wpa_driver_nl80211_set_mode(bss, |
| 2969 | NL80211_IFTYPE_STATION); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2970 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2971 | } else { |
| 2972 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
| 2973 | nl80211_del_p2pdev(bss); |
| 2974 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2975 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2976 | nl80211_destroy_bss(drv->first_bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2977 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2978 | os_free(drv->filter_ssids); |
| 2979 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2980 | os_free(drv->auth_ie); |
| 2981 | |
| 2982 | if (drv->in_interface_list) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2983 | dl_list_del(&drv->list); |
| 2984 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2985 | os_free(drv->extended_capa); |
| 2986 | os_free(drv->extended_capa_mask); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2987 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 2988 | os_free(drv->iface_ext_capa[i].ext_capa); |
| 2989 | os_free(drv->iface_ext_capa[i].ext_capa_mask); |
| 2990 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2991 | os_free(drv->first_bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2992 | os_free(drv); |
| 2993 | } |
| 2994 | |
| 2995 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2996 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
| 2997 | { |
| 2998 | switch (alg) { |
| 2999 | case WPA_ALG_WEP: |
| 3000 | if (key_len == 5) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3001 | return RSN_CIPHER_SUITE_WEP40; |
| 3002 | return RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3003 | case WPA_ALG_TKIP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3004 | return RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3005 | case WPA_ALG_CCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3006 | return RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3007 | case WPA_ALG_GCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3008 | return RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3009 | case WPA_ALG_CCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3010 | return RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3011 | case WPA_ALG_GCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3012 | return RSN_CIPHER_SUITE_GCMP_256; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3013 | case WPA_ALG_BIP_CMAC_128: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3014 | return RSN_CIPHER_SUITE_AES_128_CMAC; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3015 | case WPA_ALG_BIP_GMAC_128: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3016 | return RSN_CIPHER_SUITE_BIP_GMAC_128; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3017 | case WPA_ALG_BIP_GMAC_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3018 | return RSN_CIPHER_SUITE_BIP_GMAC_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3019 | case WPA_ALG_BIP_CMAC_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3020 | return RSN_CIPHER_SUITE_BIP_CMAC_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3021 | case WPA_ALG_SMS4: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3022 | return RSN_CIPHER_SUITE_SMS4; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3023 | case WPA_ALG_KRK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3024 | return RSN_CIPHER_SUITE_KRK; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3025 | case WPA_ALG_NONE: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3026 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", |
| 3027 | alg); |
| 3028 | return 0; |
| 3029 | } |
| 3030 | |
| 3031 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", |
| 3032 | alg); |
| 3033 | return 0; |
| 3034 | } |
| 3035 | |
| 3036 | |
| 3037 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) |
| 3038 | { |
| 3039 | switch (cipher) { |
| 3040 | case WPA_CIPHER_CCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3041 | return RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3042 | case WPA_CIPHER_GCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3043 | return RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3044 | case WPA_CIPHER_CCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3045 | return RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3046 | case WPA_CIPHER_GCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3047 | return RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3048 | case WPA_CIPHER_TKIP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3049 | return RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3050 | case WPA_CIPHER_WEP104: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3051 | return RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3052 | case WPA_CIPHER_WEP40: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3053 | return RSN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 3054 | case WPA_CIPHER_GTK_NOT_USED: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3055 | return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3056 | } |
| 3057 | |
| 3058 | return 0; |
| 3059 | } |
| 3060 | |
| 3061 | |
| 3062 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], |
| 3063 | int max_suites) |
| 3064 | { |
| 3065 | int num_suites = 0; |
| 3066 | |
| 3067 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3068 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3069 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3070 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3071 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3072 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3073 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3074 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3075 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3076 | suites[num_suites++] = RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3077 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3078 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3079 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3080 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3081 | |
| 3082 | return num_suites; |
| 3083 | } |
| 3084 | |
| 3085 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3086 | static int wpa_key_mgmt_to_suites(unsigned int key_mgmt_suites, u32 suites[], |
| 3087 | int max_suites) |
| 3088 | { |
| 3089 | int num_suites = 0; |
| 3090 | |
| 3091 | #define __AKM(a, b) \ |
| 3092 | if (num_suites < max_suites && \ |
| 3093 | (key_mgmt_suites & (WPA_KEY_MGMT_ ## a))) \ |
| 3094 | suites[num_suites++] = (RSN_AUTH_KEY_MGMT_ ## b) |
| 3095 | __AKM(IEEE8021X, UNSPEC_802_1X); |
| 3096 | __AKM(PSK, PSK_OVER_802_1X); |
| 3097 | __AKM(FT_IEEE8021X, FT_802_1X); |
| 3098 | __AKM(FT_PSK, FT_PSK); |
| 3099 | __AKM(IEEE8021X_SHA256, 802_1X_SHA256); |
| 3100 | __AKM(PSK_SHA256, PSK_SHA256); |
| 3101 | __AKM(SAE, SAE); |
| 3102 | __AKM(FT_SAE, FT_SAE); |
| 3103 | __AKM(CCKM, CCKM); |
| 3104 | __AKM(OSEN, OSEN); |
| 3105 | __AKM(IEEE8021X_SUITE_B, 802_1X_SUITE_B); |
| 3106 | __AKM(IEEE8021X_SUITE_B_192, 802_1X_SUITE_B_192); |
| 3107 | __AKM(FILS_SHA256, FILS_SHA256); |
| 3108 | __AKM(FILS_SHA384, FILS_SHA384); |
| 3109 | __AKM(FT_FILS_SHA256, FT_FILS_SHA256); |
| 3110 | __AKM(FT_FILS_SHA384, FT_FILS_SHA384); |
| 3111 | __AKM(OWE, OWE); |
| 3112 | __AKM(DPP, DPP); |
| 3113 | __AKM(FT_IEEE8021X_SHA384, FT_802_1X_SHA384); |
| 3114 | #undef __AKM |
| 3115 | |
| 3116 | return num_suites; |
| 3117 | } |
| 3118 | |
Ajay Davanageri | b921bb8 | 2020-09-16 12:49:08 +0530 | [diff] [blame] | 3119 | #ifdef CONFIG_DRIVER_NL80211_BRCM |
| 3120 | static int wpa_driver_do_broadcom_acs(void *priv, struct drv_acs_params |
| 3121 | *params) |
| 3122 | { |
| 3123 | struct i802_bss *bss = priv; |
| 3124 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3125 | struct nl_msg *msg; |
| 3126 | struct nlattr *data; |
| 3127 | int freq_list_len; |
| 3128 | int ret = 0; |
| 3129 | do { |
| 3130 | freq_list_len = |
| 3131 | int_array_len(params->freq_list); |
| 3132 | wpa_printf(MSG_DEBUG, "%s: freq_list_len=%d", |
| 3133 | __FUNCTION__, freq_list_len); |
| 3134 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR); |
| 3135 | if (!msg) { |
| 3136 | wpa_printf(MSG_ERROR, "%s: *errof, no memory for msg", __FUNCTION__); |
| 3137 | return ret; |
| 3138 | } |
| 3139 | if ((nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM))) { |
| 3140 | wpa_printf(MSG_ERROR, "%s: *errof, NL80211_ATTR_VENDOR_ID", |
| 3141 | __FUNCTION__); |
| 3142 | nlmsg_free(msg); |
| 3143 | return ret; |
| 3144 | } |
| 3145 | |
| 3146 | if ((nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, BRCM_VENDOR_SCMD_ACS))) { |
| 3147 | wpa_printf(MSG_ERROR, "%s: *errof, NL80211_ATTR_VENDOR_SUBCMD", |
| 3148 | __FUNCTION__); |
| 3149 | nlmsg_free(msg); |
| 3150 | return ret; |
| 3151 | } |
| 3152 | if (!(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA))) { |
| 3153 | wpa_printf(MSG_ERROR, "%s: *errof, NL80211_ATTR_VENDOR_DATA", __FUNCTION__); |
| 3154 | nlmsg_free(msg); |
| 3155 | return ret; |
| 3156 | } |
| 3157 | if ((nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_HW_MODE, params->hw_mode))) { |
| 3158 | wpa_printf(MSG_ERROR, "%s: *errof, BRCM_VENDOR_ATTR_ACS_HW_MODE", |
| 3159 | __FUNCTION__); |
| 3160 | nlmsg_free(msg); |
| 3161 | return ret; |
| 3162 | } |
| 3163 | if ((nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_HT_ENABLED, params->ht_enabled))) { |
| 3164 | wpa_printf(MSG_ERROR, "%s: *errof, BRCM_VENDOR_ATTR_ACS_HT_ENABLED", |
| 3165 | __FUNCTION__); |
| 3166 | nlmsg_free(msg); |
| 3167 | return ret; |
| 3168 | } |
| 3169 | if ((nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_HT40_ENABLED, params->ht40_enabled))) { |
| 3170 | wpa_printf(MSG_ERROR, "%s: *errof, BRCM_VENDOR_ATTR_ACS_HT40_ENABLED", |
| 3171 | __FUNCTION__); |
| 3172 | nlmsg_free(msg); |
| 3173 | return ret; |
| 3174 | } |
| 3175 | if ((nla_put_u8(msg, BRCM_VENDOR_ATTR_ACS_VHT_ENABLED, params->vht_enabled))) { |
| 3176 | wpa_printf(MSG_ERROR, "%s: *errof, BRCM_VENDOR_ATTR_ACS_VHT_ENABLED", |
| 3177 | __FUNCTION__); |
| 3178 | nlmsg_free(msg); |
| 3179 | return ret; |
| 3180 | } |
| 3181 | if ((nla_put_u16(msg, BRCM_VENDOR_ATTR_ACS_CHWIDTH, params->ch_width))) { |
| 3182 | wpa_printf(MSG_ERROR, "%s: *errof, BRCM_VENDOR_ATTR_ACS_CHWIDTH", |
| 3183 | __FUNCTION__); |
| 3184 | nlmsg_free(msg); |
| 3185 | return ret; |
| 3186 | } |
| 3187 | wpa_printf(MSG_DEBUG, "%s: ht40=%d, ch_width=%d\n", |
| 3188 | __FUNCTION__, params->ht40_enabled, params->ch_width); |
| 3189 | if ((freq_list_len > 0) && (nla_put(msg, BRCM_VENDOR_ATTR_ACS_FREQ_LIST, |
| 3190 | sizeof(int) * freq_list_len, params->freq_list))) { |
| 3191 | wpa_printf(MSG_ERROR, "%s: *error, BRCM_VENDOR_ATTR_ACS_FREQ_LIST," |
| 3192 | "list_len=%d\n", __FUNCTION__, freq_list_len); |
| 3193 | nlmsg_free(msg); |
| 3194 | return ret; |
| 3195 | } |
| 3196 | nla_nest_end(msg, data); |
| 3197 | wpa_printf(MSG_DEBUG, "nl80211: ACS Params: HW_MODE: %d HT: %d HT40:" |
| 3198 | " %d VHT: %d BW: %d\n", |
| 3199 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
| 3200 | params->vht_enabled, params->ch_width); |
Ahmed ElArabawy | 73c89ee | 2020-10-22 16:09:08 -0700 | [diff] [blame] | 3201 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Ajay Davanageri | b921bb8 | 2020-09-16 12:49:08 +0530 | [diff] [blame] | 3202 | if (ret) { |
| 3203 | wpa_printf(MSG_ERROR, "nl80211: Failed to invoke vendor" |
| 3204 | " driver ACS function: %s\n", |
| 3205 | strerror(errno)); |
| 3206 | } |
| 3207 | } while (0); |
| 3208 | return ret; |
| 3209 | } |
| 3210 | #endif /* CONFIG_DRIVER_NL80211_BRCM */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3211 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3212 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3213 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 3214 | const u8 *key, size_t key_len) |
| 3215 | { |
| 3216 | struct nl_msg *msg; |
| 3217 | int ret; |
| 3218 | |
| 3219 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
| 3220 | return 0; |
| 3221 | |
| 3222 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 3223 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 3224 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 3225 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || |
| 3226 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { |
| 3227 | nl80211_nlmsg_clear(msg); |
| 3228 | nlmsg_free(msg); |
| 3229 | return -1; |
| 3230 | } |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3231 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3232 | if (ret) { |
| 3233 | wpa_printf(MSG_DEBUG, |
| 3234 | "nl80211: Key management set key failed: ret=%d (%s)", |
| 3235 | ret, strerror(-ret)); |
| 3236 | } |
| 3237 | |
| 3238 | return ret; |
| 3239 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3240 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3241 | |
| 3242 | |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3243 | #ifdef CONFIG_DRIVER_NL80211_BRCM |
| 3244 | static int key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 3245 | const u8 *key, size_t key_len) |
| 3246 | { |
| 3247 | struct nl_msg *msg; |
| 3248 | int ret; |
| 3249 | struct nlattr *params; |
| 3250 | |
| 3251 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 3252 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) || |
| 3253 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 3254 | BRCM_VENDOR_SUBCMD_SET_PMK) || |
| 3255 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 3256 | nla_put(msg, BRCM_ATTR_DRIVER_KEY_PMK, key_len, key)) { |
| 3257 | nl80211_nlmsg_clear(msg); |
| 3258 | nlmsg_free(msg); |
| 3259 | return -ENOBUFS; |
| 3260 | } |
| 3261 | nla_nest_end(msg, params); |
| 3262 | |
| 3263 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1, NULL, NULL); |
| 3264 | if (ret) { |
| 3265 | wpa_printf(MSG_DEBUG, "nl80211: Key mgmt set key failed: ret=%d (%s)", |
| 3266 | ret, strerror(-ret)); |
| 3267 | } |
| 3268 | |
| 3269 | return ret; |
| 3270 | } |
| 3271 | #endif /* CONFIG_DRIVER_NL80211_BRCM */ |
| 3272 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3273 | static int nl80211_set_pmk(struct wpa_driver_nl80211_data *drv, |
| 3274 | const u8 *key, size_t key_len, |
| 3275 | const u8 *addr) |
| 3276 | { |
| 3277 | struct nl_msg *msg = NULL; |
| 3278 | int ret; |
| 3279 | |
| 3280 | /* |
| 3281 | * If the authenticator address is not set, assume it is |
| 3282 | * the current BSSID. |
| 3283 | */ |
| 3284 | if (!addr && drv->associated) |
| 3285 | addr = drv->bssid; |
| 3286 | else if (!addr) |
| 3287 | return -1; |
| 3288 | |
| 3289 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK to the driver for " MACSTR, |
| 3290 | MAC2STR(addr)); |
| 3291 | wpa_hexdump_key(MSG_DEBUG, "nl80211: PMK", key, key_len); |
| 3292 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_PMK); |
| 3293 | if (!msg || |
| 3294 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 3295 | nla_put(msg, NL80211_ATTR_PMK, key_len, key)) { |
| 3296 | nl80211_nlmsg_clear(msg); |
| 3297 | nlmsg_free(msg); |
| 3298 | return -ENOBUFS; |
| 3299 | } |
| 3300 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3301 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1, NULL, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3302 | if (ret) { |
| 3303 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK failed: ret=%d (%s)", |
| 3304 | ret, strerror(-ret)); |
| 3305 | } |
| 3306 | |
| 3307 | return ret; |
| 3308 | } |
| 3309 | |
| 3310 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3311 | static int wpa_driver_nl80211_set_key(struct i802_bss *bss, |
| 3312 | struct wpa_driver_set_key_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3313 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3314 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3315 | int ifindex; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3316 | struct nl_msg *msg; |
| 3317 | struct nl_msg *key_msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3318 | int ret; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3319 | int skip_set_key = 1; |
| 3320 | const char *ifname = params->ifname; |
| 3321 | enum wpa_alg alg = params->alg; |
| 3322 | const u8 *addr = params->addr; |
| 3323 | int key_idx = params->key_idx; |
| 3324 | int set_tx = params->set_tx; |
| 3325 | const u8 *seq = params->seq; |
| 3326 | size_t seq_len = params->seq_len; |
| 3327 | const u8 *key = params->key; |
| 3328 | size_t key_len = params->key_len; |
| 3329 | int vlan_id = params->vlan_id; |
| 3330 | enum key_flag key_flag = params->key_flag; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3331 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3332 | /* Ignore for P2P Device */ |
| 3333 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 3334 | return 0; |
| 3335 | |
| 3336 | ifindex = if_nametoindex(ifname); |
| 3337 | 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] | 3338 | "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] | 3339 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3340 | (unsigned long) seq_len, (unsigned long) key_len, key_flag); |
| 3341 | |
| 3342 | if (check_key_flag(key_flag)) { |
| 3343 | wpa_printf(MSG_DEBUG, "%s: invalid key_flag", __func__); |
| 3344 | return -EINVAL; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 3345 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3346 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3347 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3348 | if ((key_flag & KEY_FLAG_PMK) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3349 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { |
| 3350 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
| 3351 | __func__); |
| 3352 | ret = issue_key_mgmt_set_key(drv, key, key_len); |
| 3353 | return ret; |
| 3354 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3355 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3356 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3357 | if (key_flag & KEY_FLAG_PMK) { |
| 3358 | if (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) |
| 3359 | return nl80211_set_pmk(drv, key, key_len, addr); |
Mir Ali | 677e748 | 2020-11-12 19:49:02 +0530 | [diff] [blame] | 3360 | #ifdef CONFIG_DRIVER_NL80211_BRCM |
| 3361 | if (drv->vendor_set_pmk) { |
Jay Patel | 731adae | 2021-02-17 14:55:58 -0800 | [diff] [blame^] | 3362 | 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] | 3363 | return key_mgmt_set_key(drv, key, key_len); |
| 3364 | } |
| 3365 | #endif /* CONFIG_DRIVER_NL80211_BRCM */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3366 | /* The driver does not have any offload mechanism for PMK, so |
| 3367 | * there is no need to configure this key. */ |
| 3368 | return 0; |
| 3369 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3370 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3371 | ret = -ENOBUFS; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3372 | key_msg = nlmsg_alloc(); |
| 3373 | if (!key_msg) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3374 | return ret; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3375 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3376 | if ((key_flag & KEY_FLAG_PAIRWISE_MASK) == |
| 3377 | KEY_FLAG_PAIRWISE_RX_TX_MODIFY) { |
| 3378 | wpa_printf(MSG_DEBUG, |
| 3379 | "nl80211: SET_KEY (pairwise RX/TX modify)"); |
| 3380 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
| 3381 | if (!msg) |
| 3382 | goto fail2; |
| 3383 | } else if (alg == WPA_ALG_NONE && (key_flag & KEY_FLAG_RX_TX)) { |
| 3384 | wpa_printf(MSG_DEBUG, "%s: invalid key_flag to delete key", |
| 3385 | __func__); |
| 3386 | ret = -EINVAL; |
| 3387 | goto fail2; |
| 3388 | } else if (alg == WPA_ALG_NONE) { |
| 3389 | wpa_printf(MSG_DEBUG, "nl80211: DEL_KEY"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3390 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
| 3391 | if (!msg) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3392 | goto fail2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3393 | } else { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3394 | u32 suite; |
| 3395 | |
| 3396 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3397 | if (!suite) { |
| 3398 | ret = -EINVAL; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3399 | goto fail2; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3400 | } |
| 3401 | wpa_printf(MSG_DEBUG, "nl80211: NEW_KEY"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3402 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3403 | if (!msg) |
| 3404 | goto fail2; |
| 3405 | if (nla_put(key_msg, NL80211_KEY_DATA, key_len, key) || |
| 3406 | nla_put_u32(key_msg, NL80211_KEY_CIPHER, suite)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3407 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3408 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3409 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3410 | if (seq && seq_len) { |
| 3411 | if (nla_put(key_msg, NL80211_KEY_SEQ, seq_len, seq)) |
| 3412 | goto fail; |
| 3413 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", |
| 3414 | seq, seq_len); |
| 3415 | } |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3416 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3417 | |
| 3418 | if (addr && !is_broadcast_ether_addr(addr)) { |
| 3419 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3420 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 3421 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3422 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3423 | if ((key_flag & KEY_FLAG_PAIRWISE_MASK) == |
| 3424 | KEY_FLAG_PAIRWISE_RX || |
| 3425 | (key_flag & KEY_FLAG_PAIRWISE_MASK) == |
| 3426 | KEY_FLAG_PAIRWISE_RX_TX_MODIFY) { |
| 3427 | if (nla_put_u8(key_msg, NL80211_KEY_MODE, |
| 3428 | key_flag == KEY_FLAG_PAIRWISE_RX ? |
| 3429 | NL80211_KEY_NO_TX : NL80211_KEY_SET_TX)) |
| 3430 | goto fail; |
| 3431 | } else if ((key_flag & KEY_FLAG_GROUP_MASK) == |
| 3432 | KEY_FLAG_GROUP_RX) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3433 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3434 | if (nla_put_u32(key_msg, NL80211_KEY_TYPE, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3435 | NL80211_KEYTYPE_GROUP)) |
| 3436 | goto fail; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3437 | } else if (!(key_flag & KEY_FLAG_PAIRWISE)) { |
| 3438 | wpa_printf(MSG_DEBUG, |
| 3439 | " key_flag missing PAIRWISE when setting a pairwise key"); |
| 3440 | ret = -EINVAL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3441 | goto fail; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3442 | } else if (alg == WPA_ALG_WEP && |
| 3443 | (key_flag & KEY_FLAG_RX_TX) == KEY_FLAG_RX_TX) { |
| 3444 | wpa_printf(MSG_DEBUG, " unicast WEP key"); |
| 3445 | skip_set_key = 0; |
| 3446 | } else { |
| 3447 | wpa_printf(MSG_DEBUG, " pairwise key"); |
| 3448 | } |
| 3449 | } else if ((key_flag & KEY_FLAG_PAIRWISE) || |
| 3450 | !(key_flag & KEY_FLAG_GROUP)) { |
| 3451 | wpa_printf(MSG_DEBUG, |
| 3452 | " invalid key_flag for a broadcast key"); |
| 3453 | ret = -EINVAL; |
| 3454 | goto fail; |
| 3455 | } else { |
| 3456 | wpa_printf(MSG_DEBUG, " broadcast key"); |
| 3457 | if (key_flag & KEY_FLAG_DEFAULT) |
| 3458 | skip_set_key = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3459 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3460 | if (nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) || |
| 3461 | nla_put_nested(msg, NL80211_ATTR_KEY, key_msg)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3462 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3463 | nl80211_nlmsg_clear(key_msg); |
| 3464 | nlmsg_free(key_msg); |
| 3465 | key_msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3466 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3467 | if (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) { |
| 3468 | wpa_printf(MSG_DEBUG, "nl80211: VLAN ID %d", vlan_id); |
| 3469 | if (nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) |
| 3470 | goto fail; |
| 3471 | } |
| 3472 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3473 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL, |
| 3474 | NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3475 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
| 3476 | ret = 0; |
| 3477 | if (ret) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3478 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3479 | ret, strerror(-ret)); |
| 3480 | |
| 3481 | /* |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3482 | * 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] | 3483 | * we're done here. |
| 3484 | */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3485 | if (ret || skip_set_key) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3486 | return ret; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3487 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_SET_KEY - default key"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3488 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3489 | ret = -ENOBUFS; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3490 | key_msg = nlmsg_alloc(); |
| 3491 | if (!key_msg) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3492 | return ret; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3493 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3494 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3495 | if (!msg) |
| 3496 | goto fail2; |
| 3497 | if (!key_msg || |
| 3498 | nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) || |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3499 | nla_put_flag(key_msg, wpa_alg_bip(alg) ? |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3500 | (key_idx == 6 || key_idx == 7 ? |
| 3501 | NL80211_KEY_DEFAULT_BEACON : |
| 3502 | NL80211_KEY_DEFAULT_MGMT) : |
| 3503 | NL80211_KEY_DEFAULT)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3504 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3505 | if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3506 | struct nlattr *types; |
| 3507 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3508 | types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3509 | if (!types || |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3510 | nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3511 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3512 | nla_nest_end(key_msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3513 | } else if (addr) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3514 | struct nlattr *types; |
| 3515 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3516 | types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3517 | if (!types || |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3518 | nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3519 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3520 | nla_nest_end(key_msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3521 | } |
| 3522 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3523 | if (nla_put_nested(msg, NL80211_ATTR_KEY, key_msg)) |
| 3524 | goto fail; |
| 3525 | nl80211_nlmsg_clear(key_msg); |
| 3526 | nlmsg_free(key_msg); |
| 3527 | key_msg = NULL; |
| 3528 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3529 | if (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) { |
| 3530 | wpa_printf(MSG_DEBUG, "nl80211: set_key default - VLAN ID %d", |
| 3531 | vlan_id); |
| 3532 | if (nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) |
| 3533 | goto fail; |
| 3534 | } |
| 3535 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3536 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3537 | if (ret) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3538 | wpa_printf(MSG_DEBUG, |
| 3539 | "nl80211: set_key default failed; err=%d %s", |
| 3540 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3541 | return ret; |
| 3542 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3543 | fail: |
| 3544 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3545 | nlmsg_free(msg); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3546 | fail2: |
| 3547 | nl80211_nlmsg_clear(key_msg); |
| 3548 | nlmsg_free(key_msg); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3549 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3550 | } |
| 3551 | |
| 3552 | |
| 3553 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
| 3554 | int key_idx, int defkey, |
| 3555 | const u8 *seq, size_t seq_len, |
| 3556 | const u8 *key, size_t key_len) |
| 3557 | { |
| 3558 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3559 | u32 suite; |
| 3560 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3561 | if (!key_attr) |
| 3562 | return -1; |
| 3563 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3564 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 3565 | if (!suite) |
| 3566 | return -1; |
| 3567 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3568 | if (defkey && wpa_alg_bip(alg)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3569 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) |
| 3570 | return -1; |
| 3571 | } else if (defkey) { |
| 3572 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) |
| 3573 | return -1; |
| 3574 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3575 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3576 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3577 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3578 | (seq && seq_len && |
| 3579 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || |
| 3580 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) |
| 3581 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3582 | |
| 3583 | nla_nest_end(msg, key_attr); |
| 3584 | |
| 3585 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3586 | } |
| 3587 | |
| 3588 | |
| 3589 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
| 3590 | struct nl_msg *msg) |
| 3591 | { |
| 3592 | int i, privacy = 0; |
| 3593 | struct nlattr *nl_keys, *nl_key; |
| 3594 | |
| 3595 | for (i = 0; i < 4; i++) { |
| 3596 | if (!params->wep_key[i]) |
| 3597 | continue; |
| 3598 | privacy = 1; |
| 3599 | break; |
| 3600 | } |
| 3601 | if (params->wps == WPS_MODE_PRIVACY) |
| 3602 | privacy = 1; |
| 3603 | if (params->pairwise_suite && |
| 3604 | params->pairwise_suite != WPA_CIPHER_NONE) |
| 3605 | privacy = 1; |
| 3606 | |
| 3607 | if (!privacy) |
| 3608 | return 0; |
| 3609 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3610 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 3611 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3612 | |
| 3613 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); |
| 3614 | if (!nl_keys) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3615 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3616 | |
| 3617 | for (i = 0; i < 4; i++) { |
| 3618 | if (!params->wep_key[i]) |
| 3619 | continue; |
| 3620 | |
| 3621 | nl_key = nla_nest_start(msg, i); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3622 | if (!nl_key || |
| 3623 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], |
| 3624 | params->wep_key[i]) || |
| 3625 | nla_put_u32(msg, NL80211_KEY_CIPHER, |
| 3626 | params->wep_key_len[i] == 5 ? |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3627 | RSN_CIPHER_SUITE_WEP40 : |
| 3628 | RSN_CIPHER_SUITE_WEP104) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3629 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
| 3630 | (i == params->wep_tx_keyidx && |
| 3631 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) |
| 3632 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3633 | |
| 3634 | nla_nest_end(msg, nl_key); |
| 3635 | } |
| 3636 | nla_nest_end(msg, nl_keys); |
| 3637 | |
| 3638 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3639 | } |
| 3640 | |
| 3641 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3642 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 3643 | const u8 *addr, int cmd, u16 reason_code, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3644 | int local_state_change, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3645 | struct nl_sock *nl_connect) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3646 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3647 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3648 | struct nl_msg *msg; |
| 3649 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3650 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
| 3651 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
| 3652 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 3653 | (local_state_change && |
| 3654 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { |
| 3655 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3656 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3657 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3658 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3659 | if (nl_connect) |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3660 | ret = send_and_recv(drv->global, nl_connect, msg, NULL, NULL, |
| 3661 | NULL, NULL); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3662 | else |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3663 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3664 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3665 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 3666 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", |
| 3667 | reason_code, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3668 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3669 | return ret; |
| 3670 | } |
| 3671 | |
| 3672 | |
| 3673 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3674 | u16 reason_code, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3675 | struct nl_sock *nl_connect) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3676 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3677 | int ret; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3678 | int drv_associated = drv->associated; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3679 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3680 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3681 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3682 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3683 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3684 | reason_code, 0, nl_connect); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3685 | /* |
| 3686 | * For locally generated disconnect, supplicant already generates a |
| 3687 | * DEAUTH event, so ignore the event from NL80211. |
| 3688 | */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3689 | drv->ignore_next_local_disconnect = drv_associated && (ret == 0); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3690 | |
| 3691 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3692 | } |
| 3693 | |
| 3694 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3695 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3696 | const u8 *addr, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3697 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3698 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3699 | int ret; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3700 | int drv_associated = drv->associated; |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3701 | |
| 3702 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3703 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3704 | return nl80211_leave_ibss(drv, 1); |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3705 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3706 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3707 | return wpa_driver_nl80211_disconnect(drv, reason_code, |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 3708 | get_connect_handle(bss)); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3709 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3710 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
| 3711 | __func__, MAC2STR(addr), reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3712 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3713 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 3714 | reason_code, 0, get_connect_handle(bss)); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3715 | /* |
| 3716 | * For locally generated deauthenticate, supplicant already generates a |
| 3717 | * DEAUTH event, so ignore the event from NL80211. |
| 3718 | */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3719 | drv->ignore_next_local_deauth = drv_associated && (ret == 0); |
| 3720 | |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3721 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3722 | } |
| 3723 | |
| 3724 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3725 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
| 3726 | struct wpa_driver_auth_params *params) |
| 3727 | { |
| 3728 | int i; |
| 3729 | |
| 3730 | drv->auth_freq = params->freq; |
| 3731 | drv->auth_alg = params->auth_alg; |
| 3732 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; |
| 3733 | drv->auth_local_state_change = params->local_state_change; |
| 3734 | drv->auth_p2p = params->p2p; |
| 3735 | |
| 3736 | if (params->bssid) |
| 3737 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); |
| 3738 | else |
| 3739 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); |
| 3740 | |
| 3741 | if (params->ssid) { |
| 3742 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); |
| 3743 | drv->auth_ssid_len = params->ssid_len; |
| 3744 | } else |
| 3745 | drv->auth_ssid_len = 0; |
| 3746 | |
| 3747 | |
| 3748 | os_free(drv->auth_ie); |
| 3749 | drv->auth_ie = NULL; |
| 3750 | drv->auth_ie_len = 0; |
| 3751 | if (params->ie) { |
| 3752 | drv->auth_ie = os_malloc(params->ie_len); |
| 3753 | if (drv->auth_ie) { |
| 3754 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); |
| 3755 | drv->auth_ie_len = params->ie_len; |
| 3756 | } |
| 3757 | } |
| 3758 | |
| 3759 | for (i = 0; i < 4; i++) { |
| 3760 | if (params->wep_key[i] && params->wep_key_len[i] && |
| 3761 | params->wep_key_len[i] <= 16) { |
| 3762 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], |
| 3763 | params->wep_key_len[i]); |
| 3764 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; |
| 3765 | } else |
| 3766 | drv->auth_wep_key_len[i] = 0; |
| 3767 | } |
| 3768 | } |
| 3769 | |
| 3770 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3771 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
| 3772 | { |
| 3773 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3774 | |
| 3775 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) |
| 3776 | return; |
| 3777 | |
| 3778 | /* |
| 3779 | * Looks like we failed to unmask 11b rates previously. This could |
| 3780 | * happen, e.g., if the interface was down at the point in time when a |
| 3781 | * P2P group was terminated. |
| 3782 | */ |
| 3783 | wpa_printf(MSG_DEBUG, |
| 3784 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", |
| 3785 | bss->ifname); |
| 3786 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 3787 | } |
| 3788 | |
| 3789 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3790 | static enum nl80211_auth_type get_nl_auth_type(int wpa_auth_alg) |
| 3791 | { |
| 3792 | if (wpa_auth_alg & WPA_AUTH_ALG_OPEN) |
| 3793 | return NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 3794 | if (wpa_auth_alg & WPA_AUTH_ALG_SHARED) |
| 3795 | return NL80211_AUTHTYPE_SHARED_KEY; |
| 3796 | if (wpa_auth_alg & WPA_AUTH_ALG_LEAP) |
| 3797 | return NL80211_AUTHTYPE_NETWORK_EAP; |
| 3798 | if (wpa_auth_alg & WPA_AUTH_ALG_FT) |
| 3799 | return NL80211_AUTHTYPE_FT; |
| 3800 | if (wpa_auth_alg & WPA_AUTH_ALG_SAE) |
| 3801 | return NL80211_AUTHTYPE_SAE; |
| 3802 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS) |
| 3803 | return NL80211_AUTHTYPE_FILS_SK; |
| 3804 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS_SK_PFS) |
| 3805 | return NL80211_AUTHTYPE_FILS_SK_PFS; |
| 3806 | |
| 3807 | return NL80211_AUTHTYPE_MAX; |
| 3808 | } |
| 3809 | |
| 3810 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3811 | static int wpa_driver_nl80211_authenticate( |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3812 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3813 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3814 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3815 | int ret = -1, i; |
| 3816 | struct nl_msg *msg; |
| 3817 | enum nl80211_auth_type type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3818 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3819 | int count = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3820 | int is_retry; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3821 | struct wpa_driver_set_key_params p; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3822 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3823 | nl80211_unmask_11b_rates(bss); |
| 3824 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3825 | is_retry = drv->retry_auth; |
| 3826 | drv->retry_auth = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3827 | drv->ignore_deauth_event = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3828 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3829 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3830 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3831 | if (params->bssid) |
| 3832 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 3833 | else |
| 3834 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3835 | /* FIX: IBSS mode */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3836 | nlmode = params->p2p ? |
| 3837 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 3838 | if (drv->nlmode != nlmode && |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3839 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3840 | return -1; |
| 3841 | |
| 3842 | retry: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3843 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
| 3844 | drv->ifindex); |
| 3845 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3846 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
| 3847 | if (!msg) |
| 3848 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3849 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3850 | os_memset(&p, 0, sizeof(p)); |
| 3851 | p.ifname = bss->ifname; |
| 3852 | p.alg = WPA_ALG_WEP; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3853 | for (i = 0; i < 4; i++) { |
| 3854 | if (!params->wep_key[i]) |
| 3855 | continue; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3856 | p.key_idx = i; |
| 3857 | p.set_tx = i == params->wep_tx_keyidx; |
| 3858 | p.key = params->wep_key[i]; |
| 3859 | p.key_len = params->wep_key_len[i]; |
| 3860 | p.key_flag = i == params->wep_tx_keyidx ? |
| 3861 | KEY_FLAG_GROUP_RX_TX_DEFAULT : |
| 3862 | KEY_FLAG_GROUP_RX_TX; |
| 3863 | wpa_driver_nl80211_set_key(bss, &p); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3864 | if (params->wep_tx_keyidx != i) |
| 3865 | continue; |
| 3866 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3867 | params->wep_key[i], params->wep_key_len[i])) |
| 3868 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3869 | } |
| 3870 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3871 | if (params->bssid) { |
| 3872 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 3873 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3874 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 3875 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3876 | } |
| 3877 | if (params->freq) { |
| 3878 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3879 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
| 3880 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3881 | } |
| 3882 | if (params->ssid) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3883 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
| 3884 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3885 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 3886 | params->ssid)) |
| 3887 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3888 | } |
| 3889 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3890 | if (params->ie && |
| 3891 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) |
| 3892 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3893 | if (params->auth_data) { |
| 3894 | wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data, |
| 3895 | params->auth_data_len); |
| 3896 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len, |
| 3897 | params->auth_data)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3898 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3899 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3900 | type = get_nl_auth_type(params->auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3901 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3902 | if (type == NL80211_AUTHTYPE_MAX || |
| 3903 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3904 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3905 | if (params->local_state_change) { |
| 3906 | wpa_printf(MSG_DEBUG, " * Local state change only"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3907 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
| 3908 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3909 | } |
| 3910 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 3911 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3912 | msg = NULL; |
| 3913 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3914 | wpa_dbg(drv->ctx, MSG_DEBUG, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3915 | "nl80211: MLME command failed (auth): count=%d ret=%d (%s)", |
| 3916 | count, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3917 | count++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3918 | if ((ret == -EALREADY || ret == -EEXIST) && count == 1 && |
| 3919 | params->bssid && !params->local_state_change) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3920 | /* |
| 3921 | * mac80211 does not currently accept new |
| 3922 | * authentication if we are already authenticated. As a |
| 3923 | * workaround, force deauthentication and try again. |
| 3924 | */ |
| 3925 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " |
| 3926 | "after forced deauthentication"); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3927 | drv->ignore_deauth_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3928 | wpa_driver_nl80211_deauthenticate( |
| 3929 | bss, params->bssid, |
| 3930 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 3931 | nlmsg_free(msg); |
| 3932 | goto retry; |
| 3933 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3934 | |
| 3935 | if (ret == -ENOENT && params->freq && !is_retry) { |
| 3936 | /* |
| 3937 | * cfg80211 has likely expired the BSS entry even |
| 3938 | * though it was previously available in our internal |
| 3939 | * BSS table. To recover quickly, start a single |
| 3940 | * channel scan on the specified channel. |
| 3941 | */ |
| 3942 | struct wpa_driver_scan_params scan; |
| 3943 | int freqs[2]; |
| 3944 | |
| 3945 | os_memset(&scan, 0, sizeof(scan)); |
| 3946 | scan.num_ssids = 1; |
| 3947 | if (params->ssid) { |
| 3948 | scan.ssids[0].ssid = params->ssid; |
| 3949 | scan.ssids[0].ssid_len = params->ssid_len; |
| 3950 | } |
| 3951 | freqs[0] = params->freq; |
| 3952 | freqs[1] = 0; |
| 3953 | scan.freqs = freqs; |
| 3954 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " |
| 3955 | "channel scan to refresh cfg80211 BSS " |
| 3956 | "entry"); |
| 3957 | ret = wpa_driver_nl80211_scan(bss, &scan); |
| 3958 | if (ret == 0) { |
| 3959 | nl80211_copy_auth_params(drv, params); |
| 3960 | drv->scan_for_auth = 1; |
| 3961 | } |
| 3962 | } else if (is_retry) { |
| 3963 | /* |
| 3964 | * Need to indicate this with an event since the return |
| 3965 | * value from the retry is not delivered to core code. |
| 3966 | */ |
| 3967 | union wpa_event_data event; |
| 3968 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " |
| 3969 | "failed"); |
| 3970 | os_memset(&event, 0, sizeof(event)); |
| 3971 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, |
| 3972 | ETH_ALEN); |
| 3973 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, |
| 3974 | &event); |
| 3975 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3976 | } else { |
| 3977 | wpa_printf(MSG_DEBUG, |
| 3978 | "nl80211: Authentication request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3979 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3980 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3981 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3982 | nlmsg_free(msg); |
| 3983 | return ret; |
| 3984 | } |
| 3985 | |
| 3986 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3987 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3988 | { |
| 3989 | struct wpa_driver_auth_params params; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3990 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3991 | int i; |
| 3992 | |
| 3993 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); |
| 3994 | |
| 3995 | os_memset(¶ms, 0, sizeof(params)); |
| 3996 | params.freq = drv->auth_freq; |
| 3997 | params.auth_alg = drv->auth_alg; |
| 3998 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; |
| 3999 | params.local_state_change = drv->auth_local_state_change; |
| 4000 | params.p2p = drv->auth_p2p; |
| 4001 | |
| 4002 | if (!is_zero_ether_addr(drv->auth_bssid_)) |
| 4003 | params.bssid = drv->auth_bssid_; |
| 4004 | |
| 4005 | if (drv->auth_ssid_len) { |
| 4006 | params.ssid = drv->auth_ssid; |
| 4007 | params.ssid_len = drv->auth_ssid_len; |
| 4008 | } |
| 4009 | |
| 4010 | params.ie = drv->auth_ie; |
| 4011 | params.ie_len = drv->auth_ie_len; |
| 4012 | |
| 4013 | for (i = 0; i < 4; i++) { |
| 4014 | if (drv->auth_wep_key_len[i]) { |
| 4015 | params.wep_key[i] = drv->auth_wep_key[i]; |
| 4016 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; |
| 4017 | } |
| 4018 | } |
| 4019 | |
| 4020 | drv->retry_auth = 1; |
| 4021 | return wpa_driver_nl80211_authenticate(bss, ¶ms); |
| 4022 | } |
| 4023 | |
| 4024 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 4025 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
| 4026 | size_t data_len, int noack, |
| 4027 | unsigned int freq, int no_cck, |
| 4028 | int offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4029 | unsigned int wait_time, |
| 4030 | const u16 *csa_offs, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4031 | size_t csa_offs_len, int no_encrypt) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4032 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4033 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4034 | struct ieee80211_mgmt *mgmt; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4035 | int encrypt = !no_encrypt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4036 | u16 fc; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4037 | int use_cookie = 1; |
| 4038 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4039 | |
| 4040 | mgmt = (struct ieee80211_mgmt *) data; |
| 4041 | fc = le_to_host16(mgmt->frame_control); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4042 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da=" MACSTR |
| 4043 | " 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] | 4044 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4045 | no_encrypt, fc, fc2str(fc), drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4046 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4047 | if ((is_sta_interface(drv->nlmode) || |
| 4048 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4049 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 4050 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { |
| 4051 | /* |
| 4052 | * The use of last_mgmt_freq is a bit of a hack, |
| 4053 | * but it works due to the single-threaded nature |
| 4054 | * of wpa_supplicant. |
| 4055 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4056 | if (freq == 0) { |
| 4057 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", |
| 4058 | drv->last_mgmt_freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4059 | freq = drv->last_mgmt_freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4060 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4061 | wait_time = 0; |
| 4062 | use_cookie = 0; |
| 4063 | no_cck = 1; |
| 4064 | offchanok = 1; |
| 4065 | goto send_frame_cmd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4066 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4067 | |
| 4068 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4069 | if (freq == 0) { |
| 4070 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", |
| 4071 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4072 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4073 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4074 | if ((int) freq == bss->freq) |
| 4075 | wait_time = 0; |
| 4076 | goto send_frame_cmd; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 4077 | } |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 4078 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4079 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 4080 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 4081 | /* |
| 4082 | * Only one of the authentication frame types is encrypted. |
| 4083 | * In order for static WEP encryption to work properly (i.e., |
| 4084 | * to not encrypt the frame), we need to tell mac80211 about |
| 4085 | * the frames that must not be encrypted. |
| 4086 | */ |
| 4087 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 4088 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); |
| 4089 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
| 4090 | encrypt = 0; |
| 4091 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4092 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4093 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_STATION && |
| 4094 | (drv->capa.flags & WPA_DRIVER_FLAGS_SAE) && |
| 4095 | !(drv->capa.flags & WPA_DRIVER_FLAGS_SME) && |
| 4096 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 4097 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 4098 | freq = nl80211_get_assoc_freq(drv); |
| 4099 | wpa_printf(MSG_DEBUG, |
| 4100 | "nl80211: send_mlme - Use assoc_freq=%u for external auth", |
| 4101 | freq); |
| 4102 | } |
| 4103 | |
| 4104 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 4105 | freq = nl80211_get_assoc_freq(drv); |
| 4106 | wpa_printf(MSG_DEBUG, |
| 4107 | "nl80211: send_mlme - Use assoc_freq=%u for IBSS", |
| 4108 | freq); |
| 4109 | } |
| 4110 | if (freq == 0) { |
| 4111 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - Use bss->freq=%u", |
| 4112 | bss->freq); |
| 4113 | freq = bss->freq; |
| 4114 | } |
| 4115 | |
| 4116 | if (drv->use_monitor) { |
| 4117 | wpa_printf(MSG_DEBUG, |
| 4118 | "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor", |
| 4119 | freq, bss->freq); |
| 4120 | return nl80211_send_monitor(drv, data, data_len, encrypt, |
| 4121 | noack); |
| 4122 | } |
| 4123 | |
| 4124 | if (noack || WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT || |
| 4125 | WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION) |
| 4126 | use_cookie = 0; |
| 4127 | send_frame_cmd: |
| 4128 | #ifdef CONFIG_TESTING_OPTIONS |
| 4129 | if (no_encrypt && !encrypt && !drv->use_monitor) { |
| 4130 | wpa_printf(MSG_DEBUG, |
| 4131 | "nl80211: Request to send an unencrypted frame - use a monitor interface for this"); |
| 4132 | if (nl80211_create_monitor_interface(drv) < 0) |
| 4133 | return -1; |
| 4134 | res = nl80211_send_monitor(drv, data, data_len, encrypt, |
| 4135 | noack); |
| 4136 | nl80211_remove_monitor_interface(drv); |
| 4137 | return res; |
| 4138 | } |
| 4139 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 4140 | |
| 4141 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame_cmd"); |
| 4142 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, data_len, |
| 4143 | use_cookie, no_cck, noack, offchanok, |
| 4144 | csa_offs, csa_offs_len); |
| 4145 | |
| 4146 | return res; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4147 | } |
| 4148 | |
| 4149 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4150 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
| 4151 | { |
| 4152 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 4153 | u8 rates_len = 0; |
| 4154 | int i; |
| 4155 | |
| 4156 | if (!basic_rates) |
| 4157 | return 0; |
| 4158 | |
| 4159 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) |
| 4160 | rates[rates_len++] = basic_rates[i] / 5; |
| 4161 | |
| 4162 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); |
| 4163 | } |
| 4164 | |
| 4165 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4166 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
| 4167 | int slot, int ht_opmode, int ap_isolate, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4168 | const int *basic_rates) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4169 | { |
| 4170 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4171 | struct nl_msg *msg; |
| 4172 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4173 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
| 4174 | (cts >= 0 && |
| 4175 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || |
| 4176 | (preamble >= 0 && |
| 4177 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || |
| 4178 | (slot >= 0 && |
| 4179 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || |
| 4180 | (ht_opmode >= 0 && |
| 4181 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || |
| 4182 | (ap_isolate >= 0 && |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4183 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
| 4184 | nl80211_put_basic_rates(msg, basic_rates)) { |
| 4185 | nlmsg_free(msg); |
| 4186 | return -ENOBUFS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4187 | } |
| 4188 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4189 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4190 | } |
| 4191 | |
| 4192 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4193 | static int wpa_driver_nl80211_set_acl(void *priv, |
| 4194 | struct hostapd_acl_params *params) |
| 4195 | { |
| 4196 | struct i802_bss *bss = priv; |
| 4197 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4198 | struct nl_msg *msg; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4199 | struct nl_msg *acl; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4200 | unsigned int i; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4201 | int ret; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4202 | |
| 4203 | if (!(drv->capa.max_acl_mac_addrs)) |
| 4204 | return -ENOTSUP; |
| 4205 | |
| 4206 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) |
| 4207 | return -ENOTSUP; |
| 4208 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4209 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
| 4210 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); |
| 4211 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4212 | acl = nlmsg_alloc(); |
| 4213 | if (!acl) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4214 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4215 | for (i = 0; i < params->num_mac_acl; i++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4216 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { |
| 4217 | nlmsg_free(acl); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4218 | return -ENOMEM; |
| 4219 | } |
| 4220 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4221 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4222 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
| 4223 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
| 4224 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : |
| 4225 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || |
| 4226 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
| 4227 | nlmsg_free(msg); |
| 4228 | nlmsg_free(acl); |
| 4229 | return -ENOMEM; |
| 4230 | } |
| 4231 | nlmsg_free(acl); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4232 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4233 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4234 | if (ret) { |
| 4235 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", |
| 4236 | ret, strerror(-ret)); |
| 4237 | } |
| 4238 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4239 | return ret; |
| 4240 | } |
| 4241 | |
| 4242 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4243 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
| 4244 | { |
| 4245 | if (beacon_int > 0) { |
| 4246 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); |
| 4247 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 4248 | beacon_int); |
| 4249 | } |
| 4250 | |
| 4251 | return 0; |
| 4252 | } |
| 4253 | |
| 4254 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4255 | static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period) |
| 4256 | { |
| 4257 | if (dtim_period > 0) { |
| 4258 | wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period); |
| 4259 | return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); |
| 4260 | } |
| 4261 | |
| 4262 | return 0; |
| 4263 | } |
| 4264 | |
| 4265 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4266 | #ifdef CONFIG_MESH |
| 4267 | static int nl80211_set_mesh_config(void *priv, |
| 4268 | struct wpa_driver_mesh_bss_params *params) |
| 4269 | { |
| 4270 | struct i802_bss *bss = priv; |
| 4271 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4272 | struct nl_msg *msg; |
| 4273 | int ret; |
| 4274 | |
| 4275 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG); |
| 4276 | if (!msg) |
| 4277 | return -1; |
| 4278 | |
| 4279 | ret = nl80211_put_mesh_config(msg, params); |
| 4280 | if (ret < 0) { |
| 4281 | nlmsg_free(msg); |
| 4282 | return ret; |
| 4283 | } |
| 4284 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4285 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4286 | if (ret) { |
| 4287 | wpa_printf(MSG_ERROR, |
| 4288 | "nl80211: Mesh config set failed: %d (%s)", |
| 4289 | ret, strerror(-ret)); |
| 4290 | return ret; |
| 4291 | } |
| 4292 | return 0; |
| 4293 | } |
| 4294 | #endif /* CONFIG_MESH */ |
| 4295 | |
| 4296 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4297 | static int nl80211_put_beacon_rate(struct nl_msg *msg, const u64 flags, |
| 4298 | struct wpa_driver_ap_params *params) |
| 4299 | { |
| 4300 | struct nlattr *bands, *band; |
| 4301 | struct nl80211_txrate_vht vht_rate; |
| 4302 | |
| 4303 | if (!params->freq || |
| 4304 | (params->beacon_rate == 0 && |
| 4305 | params->rate_type == BEACON_RATE_LEGACY)) |
| 4306 | return 0; |
| 4307 | |
| 4308 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 4309 | if (!bands) |
| 4310 | return -1; |
| 4311 | |
| 4312 | switch (params->freq->mode) { |
| 4313 | case HOSTAPD_MODE_IEEE80211B: |
| 4314 | case HOSTAPD_MODE_IEEE80211G: |
| 4315 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
| 4316 | break; |
| 4317 | case HOSTAPD_MODE_IEEE80211A: |
| 4318 | band = nla_nest_start(msg, NL80211_BAND_5GHZ); |
| 4319 | break; |
| 4320 | case HOSTAPD_MODE_IEEE80211AD: |
| 4321 | band = nla_nest_start(msg, NL80211_BAND_60GHZ); |
| 4322 | break; |
| 4323 | default: |
| 4324 | return 0; |
| 4325 | } |
| 4326 | |
| 4327 | if (!band) |
| 4328 | return -1; |
| 4329 | |
| 4330 | os_memset(&vht_rate, 0, sizeof(vht_rate)); |
| 4331 | |
| 4332 | switch (params->rate_type) { |
| 4333 | case BEACON_RATE_LEGACY: |
| 4334 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) { |
| 4335 | wpa_printf(MSG_INFO, |
| 4336 | "nl80211: Driver does not support setting Beacon frame rate (legacy)"); |
| 4337 | return -1; |
| 4338 | } |
| 4339 | |
| 4340 | if (nla_put_u8(msg, NL80211_TXRATE_LEGACY, |
| 4341 | (u8) params->beacon_rate / 5) || |
| 4342 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || |
| 4343 | (params->freq->vht_enabled && |
| 4344 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4345 | &vht_rate))) |
| 4346 | return -1; |
| 4347 | |
| 4348 | wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)", |
| 4349 | params->beacon_rate); |
| 4350 | break; |
| 4351 | case BEACON_RATE_HT: |
| 4352 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) { |
| 4353 | wpa_printf(MSG_INFO, |
| 4354 | "nl80211: Driver does not support setting Beacon frame rate (HT)"); |
| 4355 | return -1; |
| 4356 | } |
| 4357 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || |
| 4358 | nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) || |
| 4359 | (params->freq->vht_enabled && |
| 4360 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4361 | &vht_rate))) |
| 4362 | return -1; |
| 4363 | wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u", |
| 4364 | params->beacon_rate); |
| 4365 | break; |
| 4366 | case BEACON_RATE_VHT: |
| 4367 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) { |
| 4368 | wpa_printf(MSG_INFO, |
| 4369 | "nl80211: Driver does not support setting Beacon frame rate (VHT)"); |
| 4370 | return -1; |
| 4371 | } |
| 4372 | vht_rate.mcs[0] = BIT(params->beacon_rate); |
| 4373 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL)) |
| 4374 | return -1; |
| 4375 | if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL)) |
| 4376 | return -1; |
| 4377 | if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4378 | &vht_rate)) |
| 4379 | return -1; |
| 4380 | wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u", |
| 4381 | params->beacon_rate); |
| 4382 | break; |
| 4383 | } |
| 4384 | |
| 4385 | nla_nest_end(msg, band); |
| 4386 | nla_nest_end(msg, bands); |
| 4387 | |
| 4388 | return 0; |
| 4389 | } |
| 4390 | |
| 4391 | |
| 4392 | static int nl80211_set_multicast_to_unicast(struct i802_bss *bss, |
| 4393 | int multicast_to_unicast) |
| 4394 | { |
| 4395 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4396 | struct nl_msg *msg; |
| 4397 | int ret; |
| 4398 | |
| 4399 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST); |
| 4400 | if (!msg || |
| 4401 | (multicast_to_unicast && |
| 4402 | nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) { |
| 4403 | wpa_printf(MSG_ERROR, |
| 4404 | "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s", |
| 4405 | bss->ifname); |
| 4406 | nlmsg_free(msg); |
| 4407 | return -ENOBUFS; |
| 4408 | } |
| 4409 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4410 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4411 | |
| 4412 | switch (ret) { |
| 4413 | case 0: |
| 4414 | wpa_printf(MSG_DEBUG, |
| 4415 | "nl80211: multicast to unicast %s on interface %s", |
| 4416 | multicast_to_unicast ? "enabled" : "disabled", |
| 4417 | bss->ifname); |
| 4418 | break; |
| 4419 | case -EOPNOTSUPP: |
| 4420 | if (!multicast_to_unicast) |
| 4421 | break; |
| 4422 | wpa_printf(MSG_INFO, |
| 4423 | "nl80211: multicast to unicast not supported on interface %s", |
| 4424 | bss->ifname); |
| 4425 | break; |
| 4426 | default: |
| 4427 | wpa_printf(MSG_ERROR, |
| 4428 | "nl80211: %s multicast to unicast failed with %d (%s) on interface %s", |
| 4429 | multicast_to_unicast ? "enabling" : "disabling", |
| 4430 | ret, strerror(-ret), bss->ifname); |
| 4431 | break; |
| 4432 | } |
| 4433 | |
| 4434 | return ret; |
| 4435 | } |
| 4436 | |
| 4437 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4438 | static int wpa_driver_nl80211_set_ap(void *priv, |
| 4439 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4440 | { |
| 4441 | struct i802_bss *bss = priv; |
| 4442 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4443 | struct nl_msg *msg; |
| 4444 | u8 cmd = NL80211_CMD_NEW_BEACON; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4445 | int ret = -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4446 | int beacon_set; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4447 | int num_suites; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4448 | u32 suites[20], suite; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4449 | u32 ver; |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4450 | #ifdef CONFIG_MESH |
| 4451 | struct wpa_driver_mesh_bss_params mesh_params; |
| 4452 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4453 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4454 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4455 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4456 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
| 4457 | beacon_set); |
| 4458 | if (beacon_set) |
| 4459 | cmd = NL80211_CMD_SET_BEACON; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4460 | else if (!drv->device_ap_sme && !drv->use_monitor && |
| 4461 | !nl80211_get_wiphy_data_ap(bss)) |
| 4462 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4463 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4464 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
| 4465 | params->head, params->head_len); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4466 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
| 4467 | params->tail, params->tail_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4468 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4469 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4470 | wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate); |
| 4471 | wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4472 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4473 | wpa_printf(MSG_DEBUG, "nl80211: ssid=%s", |
| 4474 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4475 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 4476 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
| 4477 | params->head) || |
| 4478 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, |
| 4479 | params->tail) || |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4480 | nl80211_put_beacon_int(msg, params->beacon_int) || |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4481 | nl80211_put_beacon_rate(msg, drv->capa.flags, params) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4482 | nl80211_put_dtim_period(msg, params->dtim_period) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4483 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 4484 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4485 | if (params->proberesp && params->proberesp_len) { |
| 4486 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", |
| 4487 | params->proberesp, params->proberesp_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4488 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
| 4489 | params->proberesp)) |
| 4490 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4491 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4492 | switch (params->hide_ssid) { |
| 4493 | case NO_SSID_HIDING: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4494 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4495 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 4496 | NL80211_HIDDEN_SSID_NOT_IN_USE)) |
| 4497 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4498 | break; |
| 4499 | case HIDDEN_SSID_ZERO_LEN: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4500 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4501 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 4502 | NL80211_HIDDEN_SSID_ZERO_LEN)) |
| 4503 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4504 | break; |
| 4505 | case HIDDEN_SSID_ZERO_CONTENTS: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4506 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4507 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 4508 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) |
| 4509 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4510 | break; |
| 4511 | } |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4512 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4513 | if (params->privacy && |
| 4514 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 4515 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4516 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4517 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
| 4518 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { |
| 4519 | /* Leave out the attribute */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4520 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
| 4521 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 4522 | NL80211_AUTHTYPE_SHARED_KEY)) |
| 4523 | goto fail; |
| 4524 | } else { |
| 4525 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 4526 | NL80211_AUTHTYPE_OPEN_SYSTEM)) |
| 4527 | goto fail; |
| 4528 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4529 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4530 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4531 | ver = 0; |
| 4532 | if (params->wpa_version & WPA_PROTO_WPA) |
| 4533 | ver |= NL80211_WPA_VERSION_1; |
| 4534 | if (params->wpa_version & WPA_PROTO_RSN) |
| 4535 | ver |= NL80211_WPA_VERSION_2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4536 | if (ver && |
| 4537 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 4538 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4539 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4540 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
| 4541 | params->key_mgmt_suites); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4542 | num_suites = wpa_key_mgmt_to_suites(params->key_mgmt_suites, |
| 4543 | suites, ARRAY_SIZE(suites)); |
| 4544 | if (num_suites > NL80211_MAX_NR_AKM_SUITES) |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4545 | wpa_printf(MSG_DEBUG, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4546 | "nl80211: Not enough room for all AKM suites (num_suites=%d > NL80211_MAX_NR_AKM_SUITES)", |
| 4547 | num_suites); |
| 4548 | else if (num_suites && |
| 4549 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), |
| 4550 | suites)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4551 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4552 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4553 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4554 | (!params->pairwise_ciphers || |
| 4555 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) && |
| 4556 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 4557 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4558 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4559 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4560 | if (drv->device_ap_sme && |
| 4561 | (params->key_mgmt_suites & WPA_KEY_MGMT_SAE) && |
| 4562 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) |
| 4563 | goto fail; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 4564 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4565 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
| 4566 | params->pairwise_ciphers); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4567 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
| 4568 | suites, ARRAY_SIZE(suites)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4569 | if (num_suites && |
| 4570 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 4571 | num_suites * sizeof(u32), suites)) |
| 4572 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4573 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4574 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
| 4575 | params->group_cipher); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4576 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4577 | if (suite && |
| 4578 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) |
| 4579 | goto fail; |
| 4580 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4581 | if (params->beacon_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4582 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
| 4583 | params->beacon_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4584 | if (nla_put(msg, NL80211_ATTR_IE, |
| 4585 | wpabuf_len(params->beacon_ies), |
| 4586 | wpabuf_head(params->beacon_ies))) |
| 4587 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4588 | } |
| 4589 | if (params->proberesp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4590 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
| 4591 | params->proberesp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4592 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 4593 | wpabuf_len(params->proberesp_ies), |
| 4594 | wpabuf_head(params->proberesp_ies))) |
| 4595 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4596 | } |
| 4597 | if (params->assocresp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4598 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
| 4599 | params->assocresp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4600 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 4601 | wpabuf_len(params->assocresp_ies), |
| 4602 | wpabuf_head(params->assocresp_ies))) |
| 4603 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4604 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4605 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4606 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4607 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
| 4608 | params->ap_max_inactivity); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4609 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
| 4610 | params->ap_max_inactivity)) |
| 4611 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4612 | } |
| 4613 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4614 | #ifdef CONFIG_P2P |
| 4615 | if (params->p2p_go_ctwindow > 0) { |
| 4616 | if (drv->p2p_go_ctwindow_supported) { |
| 4617 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", |
| 4618 | params->p2p_go_ctwindow); |
| 4619 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, |
| 4620 | params->p2p_go_ctwindow)) |
| 4621 | goto fail; |
| 4622 | } else { |
| 4623 | wpa_printf(MSG_INFO, |
| 4624 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); |
| 4625 | } |
| 4626 | } |
| 4627 | #endif /* CONFIG_P2P */ |
| 4628 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4629 | if (params->pbss) { |
| 4630 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); |
| 4631 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 4632 | goto fail; |
| 4633 | } |
| 4634 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4635 | if (params->ftm_responder) { |
| 4636 | struct nlattr *ftm; |
| 4637 | |
| 4638 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_FTM_RESPONDER)) { |
| 4639 | ret = -ENOTSUP; |
| 4640 | goto fail; |
| 4641 | } |
| 4642 | |
| 4643 | ftm = nla_nest_start(msg, NL80211_ATTR_FTM_RESPONDER); |
| 4644 | if (!ftm || |
| 4645 | nla_put_flag(msg, NL80211_FTM_RESP_ATTR_ENABLED) || |
| 4646 | (params->lci && |
| 4647 | nla_put(msg, NL80211_FTM_RESP_ATTR_LCI, |
| 4648 | wpabuf_len(params->lci), |
| 4649 | wpabuf_head(params->lci))) || |
| 4650 | (params->civic && |
| 4651 | nla_put(msg, NL80211_FTM_RESP_ATTR_CIVICLOC, |
| 4652 | wpabuf_len(params->civic), |
| 4653 | wpabuf_head(params->civic)))) |
| 4654 | goto fail; |
| 4655 | nla_nest_end(msg, ftm); |
| 4656 | } |
| 4657 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4658 | #ifdef CONFIG_IEEE80211AX |
| 4659 | if (params->he_spr) { |
| 4660 | struct nlattr *spr; |
| 4661 | |
| 4662 | spr = nla_nest_start(msg, NL80211_ATTR_HE_OBSS_PD); |
| 4663 | wpa_printf(MSG_DEBUG, "nl80211: he_spr=%d", params->he_spr); |
| 4664 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4665 | if (!spr || |
| 4666 | nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4667 | params->he_spr_srg_obss_pd_min_offset) || |
| 4668 | nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET, |
| 4669 | params->he_spr_srg_obss_pd_max_offset)) |
| 4670 | goto fail; |
| 4671 | |
| 4672 | nla_nest_end(msg, spr); |
| 4673 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4674 | |
| 4675 | if (params->freq && params->freq->he_enabled) { |
| 4676 | struct nlattr *bss_color; |
| 4677 | |
| 4678 | bss_color = nla_nest_start(msg, NL80211_ATTR_HE_BSS_COLOR); |
| 4679 | if (!bss_color || |
| 4680 | (params->he_bss_color_disabled && |
| 4681 | nla_put_flag(msg, NL80211_HE_BSS_COLOR_ATTR_DISABLED)) || |
| 4682 | (params->he_bss_color_partial && |
| 4683 | nla_put_flag(msg, NL80211_HE_BSS_COLOR_ATTR_PARTIAL)) || |
| 4684 | nla_put_u8(msg, NL80211_HE_BSS_COLOR_ATTR_COLOR, |
| 4685 | params->he_bss_color)) |
| 4686 | goto fail; |
| 4687 | nla_nest_end(msg, bss_color); |
| 4688 | } |
| 4689 | |
| 4690 | if (params->twt_responder) { |
| 4691 | wpa_printf(MSG_DEBUG, "nl80211: twt_responder=%d", |
| 4692 | params->twt_responder); |
| 4693 | if (nla_put_flag(msg, NL80211_ATTR_TWT_RESPONDER)) |
| 4694 | goto fail; |
| 4695 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4696 | #endif /* CONFIG_IEEE80211AX */ |
| 4697 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4698 | ret = send_and_recv_msgs_owner(drv, msg, get_connect_handle(bss), 1, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4699 | NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4700 | if (ret) { |
| 4701 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", |
| 4702 | ret, strerror(-ret)); |
| 4703 | } else { |
| 4704 | bss->beacon_set = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4705 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
| 4706 | params->short_slot_time, params->ht_opmode, |
| 4707 | params->isolate, params->basic_rates); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4708 | nl80211_set_multicast_to_unicast(bss, |
| 4709 | params->multicast_to_unicast); |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4710 | if (beacon_set && params->freq && |
| 4711 | params->freq->bandwidth != bss->bandwidth) { |
| 4712 | wpa_printf(MSG_DEBUG, |
| 4713 | "nl80211: Update BSS %s bandwidth: %d -> %d", |
| 4714 | bss->ifname, bss->bandwidth, |
| 4715 | params->freq->bandwidth); |
| 4716 | ret = nl80211_set_channel(bss, params->freq, 1); |
| 4717 | if (ret) { |
| 4718 | wpa_printf(MSG_DEBUG, |
| 4719 | "nl80211: Frequency set failed: %d (%s)", |
| 4720 | ret, strerror(-ret)); |
| 4721 | } else { |
| 4722 | wpa_printf(MSG_DEBUG, |
| 4723 | "nl80211: Frequency set succeeded for ht2040 coex"); |
| 4724 | bss->bandwidth = params->freq->bandwidth; |
| 4725 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4726 | } else if (!beacon_set && params->freq) { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4727 | /* |
| 4728 | * cfg80211 updates the driver on frequence change in AP |
| 4729 | * mode only at the point when beaconing is started, so |
| 4730 | * set the initial value here. |
| 4731 | */ |
| 4732 | bss->bandwidth = params->freq->bandwidth; |
| 4733 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4734 | } |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4735 | |
| 4736 | #ifdef CONFIG_MESH |
| 4737 | if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) { |
| 4738 | os_memset(&mesh_params, 0, sizeof(mesh_params)); |
| 4739 | mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE; |
| 4740 | mesh_params.ht_opmode = params->ht_opmode; |
| 4741 | ret = nl80211_set_mesh_config(priv, &mesh_params); |
| 4742 | if (ret < 0) |
| 4743 | return ret; |
| 4744 | } |
| 4745 | #endif /* CONFIG_MESH */ |
| 4746 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4747 | return ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4748 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4749 | nlmsg_free(msg); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4750 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4751 | } |
| 4752 | |
| 4753 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4754 | static int nl80211_put_freq_params(struct nl_msg *msg, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4755 | const struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4756 | { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4757 | enum hostapd_hw_mode hw_mode; |
| 4758 | int is_24ghz; |
| 4759 | u8 channel; |
| 4760 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4761 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4762 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
| 4763 | return -ENOBUFS; |
| 4764 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4765 | wpa_printf(MSG_DEBUG, " * he_enabled=%d", freq->he_enabled); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4766 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
| 4767 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); |
| 4768 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4769 | hw_mode = ieee80211_freq_to_chan(freq->freq, &channel); |
| 4770 | is_24ghz = hw_mode == HOSTAPD_MODE_IEEE80211G || |
| 4771 | hw_mode == HOSTAPD_MODE_IEEE80211B; |
| 4772 | |
| 4773 | if (freq->vht_enabled || (freq->he_enabled && !is_24ghz)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4774 | enum nl80211_chan_width cw; |
| 4775 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4776 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4777 | switch (freq->bandwidth) { |
| 4778 | case 20: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4779 | cw = NL80211_CHAN_WIDTH_20; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4780 | break; |
| 4781 | case 40: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4782 | cw = NL80211_CHAN_WIDTH_40; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4783 | break; |
| 4784 | case 80: |
| 4785 | if (freq->center_freq2) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4786 | cw = NL80211_CHAN_WIDTH_80P80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4787 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4788 | cw = NL80211_CHAN_WIDTH_80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4789 | break; |
| 4790 | case 160: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4791 | cw = NL80211_CHAN_WIDTH_160; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4792 | break; |
| 4793 | default: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4794 | return -EINVAL; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4795 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4796 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4797 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
| 4798 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", |
| 4799 | freq->center_freq1); |
| 4800 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", |
| 4801 | freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4802 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
| 4803 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, |
| 4804 | freq->center_freq1) || |
| 4805 | (freq->center_freq2 && |
| 4806 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 4807 | freq->center_freq2))) |
| 4808 | return -ENOBUFS; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4809 | } else if (freq->ht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4810 | enum nl80211_channel_type ct; |
| 4811 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4812 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
| 4813 | freq->sec_channel_offset); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4814 | switch (freq->sec_channel_offset) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4815 | case -1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4816 | ct = NL80211_CHAN_HT40MINUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4817 | break; |
| 4818 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4819 | ct = NL80211_CHAN_HT40PLUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4820 | break; |
| 4821 | default: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4822 | ct = NL80211_CHAN_HT20; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4823 | break; |
| 4824 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4825 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4826 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4827 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
| 4828 | return -ENOBUFS; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4829 | } else if (freq->edmg.channels && freq->edmg.bw_config) { |
| 4830 | wpa_printf(MSG_DEBUG, |
| 4831 | " * EDMG configuration: channels=0x%x bw_config=%d", |
| 4832 | freq->edmg.channels, freq->edmg.bw_config); |
| 4833 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS, |
| 4834 | freq->edmg.channels) || |
| 4835 | nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG, |
| 4836 | freq->edmg.bw_config)) |
| 4837 | return -1; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4838 | } else { |
| 4839 | wpa_printf(MSG_DEBUG, " * channel_type=%d", |
| 4840 | NL80211_CHAN_NO_HT); |
| 4841 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 4842 | NL80211_CHAN_NO_HT)) |
| 4843 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4844 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4845 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4846 | } |
| 4847 | |
| 4848 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4849 | static int nl80211_set_channel(struct i802_bss *bss, |
| 4850 | struct hostapd_freq_params *freq, int set_chan) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4851 | { |
| 4852 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4853 | struct nl_msg *msg; |
| 4854 | int ret; |
| 4855 | |
| 4856 | wpa_printf(MSG_DEBUG, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4857 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, he_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
| 4858 | freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4859 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4860 | |
| 4861 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
| 4862 | NL80211_CMD_SET_WIPHY); |
| 4863 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { |
| 4864 | nlmsg_free(msg); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4865 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4866 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4867 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 4868 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4869 | if (ret == 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4870 | bss->freq = freq->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4871 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4872 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4873 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4874 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4875 | return -1; |
| 4876 | } |
| 4877 | |
| 4878 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4879 | static u32 sta_flags_nl80211(int flags) |
| 4880 | { |
| 4881 | u32 f = 0; |
| 4882 | |
| 4883 | if (flags & WPA_STA_AUTHORIZED) |
| 4884 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 4885 | if (flags & WPA_STA_WMM) |
| 4886 | f |= BIT(NL80211_STA_FLAG_WME); |
| 4887 | if (flags & WPA_STA_SHORT_PREAMBLE) |
| 4888 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
| 4889 | if (flags & WPA_STA_MFP) |
| 4890 | f |= BIT(NL80211_STA_FLAG_MFP); |
| 4891 | if (flags & WPA_STA_TDLS_PEER) |
| 4892 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4893 | if (flags & WPA_STA_AUTHENTICATED) |
| 4894 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4895 | if (flags & WPA_STA_ASSOCIATED) |
| 4896 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4897 | |
| 4898 | return f; |
| 4899 | } |
| 4900 | |
| 4901 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4902 | #ifdef CONFIG_MESH |
| 4903 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) |
| 4904 | { |
| 4905 | switch (state) { |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4906 | case PLINK_IDLE: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4907 | return NL80211_PLINK_LISTEN; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4908 | case PLINK_OPN_SNT: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4909 | return NL80211_PLINK_OPN_SNT; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4910 | case PLINK_OPN_RCVD: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4911 | return NL80211_PLINK_OPN_RCVD; |
| 4912 | case PLINK_CNF_RCVD: |
| 4913 | return NL80211_PLINK_CNF_RCVD; |
| 4914 | case PLINK_ESTAB: |
| 4915 | return NL80211_PLINK_ESTAB; |
| 4916 | case PLINK_HOLDING: |
| 4917 | return NL80211_PLINK_HOLDING; |
| 4918 | case PLINK_BLOCKED: |
| 4919 | return NL80211_PLINK_BLOCKED; |
| 4920 | default: |
| 4921 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", |
| 4922 | state); |
| 4923 | } |
| 4924 | return -1; |
| 4925 | } |
| 4926 | #endif /* CONFIG_MESH */ |
| 4927 | |
| 4928 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4929 | static int wpa_driver_nl80211_sta_add(void *priv, |
| 4930 | struct hostapd_sta_add_params *params) |
| 4931 | { |
| 4932 | struct i802_bss *bss = priv; |
| 4933 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4934 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4935 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4936 | int ret = -ENOBUFS; |
| 4937 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4938 | if ((params->flags & WPA_STA_TDLS_PEER) && |
| 4939 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 4940 | return -EOPNOTSUPP; |
| 4941 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4942 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
| 4943 | params->set ? "Set" : "Add", MAC2STR(params->addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4944 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
| 4945 | NL80211_CMD_NEW_STATION); |
| 4946 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) |
| 4947 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4948 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4949 | /* |
| 4950 | * Set the below properties only in one of the following cases: |
| 4951 | * 1. New station is added, already associated. |
| 4952 | * 2. Set WPA_STA_TDLS_PEER station. |
| 4953 | * 3. Set an already added unassociated station, if driver supports |
| 4954 | * full AP client state. (Set these properties after station became |
| 4955 | * associated will be rejected by the driver). |
| 4956 | */ |
| 4957 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
| 4958 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 4959 | (params->flags & WPA_STA_ASSOCIATED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4960 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
| 4961 | params->supp_rates, params->supp_rates_len); |
| 4962 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
| 4963 | params->capability); |
| 4964 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, |
| 4965 | params->supp_rates_len, params->supp_rates) || |
| 4966 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, |
| 4967 | params->capability)) |
| 4968 | goto fail; |
| 4969 | |
| 4970 | if (params->ht_capabilities) { |
| 4971 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
| 4972 | (u8 *) params->ht_capabilities, |
| 4973 | sizeof(*params->ht_capabilities)); |
| 4974 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
| 4975 | sizeof(*params->ht_capabilities), |
| 4976 | params->ht_capabilities)) |
| 4977 | goto fail; |
| 4978 | } |
| 4979 | |
| 4980 | if (params->vht_capabilities) { |
| 4981 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
| 4982 | (u8 *) params->vht_capabilities, |
| 4983 | sizeof(*params->vht_capabilities)); |
| 4984 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
| 4985 | sizeof(*params->vht_capabilities), |
| 4986 | params->vht_capabilities)) |
| 4987 | goto fail; |
| 4988 | } |
| 4989 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4990 | if (params->he_capab) { |
| 4991 | wpa_hexdump(MSG_DEBUG, " * he_capab", |
| 4992 | params->he_capab, params->he_capab_len); |
| 4993 | if (nla_put(msg, NL80211_ATTR_HE_CAPABILITY, |
| 4994 | params->he_capab_len, params->he_capab)) |
| 4995 | goto fail; |
| 4996 | } |
| 4997 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4998 | if (params->ext_capab) { |
| 4999 | wpa_hexdump(MSG_DEBUG, " * ext_capab", |
| 5000 | params->ext_capab, params->ext_capab_len); |
| 5001 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
| 5002 | params->ext_capab_len, params->ext_capab)) |
| 5003 | goto fail; |
| 5004 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5005 | |
| 5006 | if (is_ap_interface(drv->nlmode) && |
| 5007 | nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS, |
| 5008 | params->support_p2p_ps ? |
| 5009 | NL80211_P2P_PS_SUPPORTED : |
| 5010 | NL80211_P2P_PS_UNSUPPORTED)) |
| 5011 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5012 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5013 | if (!params->set) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 5014 | if (params->aid) { |
| 5015 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5016 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
| 5017 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 5018 | } else { |
| 5019 | /* |
| 5020 | * cfg80211 validates that AID is non-zero, so we have |
| 5021 | * to make this a non-zero value for the TDLS case where |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5022 | * a dummy STA entry is used for now and for a station |
| 5023 | * that is still not associated. |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 5024 | */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5025 | wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)", |
| 5026 | (params->flags & WPA_STA_TDLS_PEER) ? |
| 5027 | "TDLS" : "UNASSOC_STA"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5028 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
| 5029 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 5030 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5031 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 5032 | params->listen_interval); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5033 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 5034 | params->listen_interval)) |
| 5035 | goto fail; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5036 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
| 5037 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5038 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
| 5039 | goto fail; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5040 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 5041 | (params->flags & WPA_STA_ASSOCIATED)) { |
| 5042 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
| 5043 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 5044 | params->listen_interval); |
| 5045 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || |
| 5046 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 5047 | params->listen_interval)) |
| 5048 | goto fail; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5049 | } |
| 5050 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 5051 | if (params->vht_opmode_enabled) { |
| 5052 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5053 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
| 5054 | params->vht_opmode)) |
| 5055 | goto fail; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5056 | } |
| 5057 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5058 | if (params->supp_channels) { |
| 5059 | wpa_hexdump(MSG_DEBUG, " * supported channels", |
| 5060 | params->supp_channels, params->supp_channels_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5061 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
| 5062 | params->supp_channels_len, params->supp_channels)) |
| 5063 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5064 | } |
| 5065 | |
| 5066 | if (params->supp_oper_classes) { |
| 5067 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", |
| 5068 | params->supp_oper_classes, |
| 5069 | params->supp_oper_classes_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5070 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
| 5071 | params->supp_oper_classes_len, |
| 5072 | params->supp_oper_classes)) |
| 5073 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 5074 | } |
| 5075 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5076 | os_memset(&upd, 0, sizeof(upd)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5077 | upd.set = sta_flags_nl80211(params->flags); |
| 5078 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5079 | |
| 5080 | /* |
| 5081 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH |
| 5082 | * flags, as nl80211 driver moves a new station, by default, into |
| 5083 | * associated state. |
| 5084 | * |
| 5085 | * On the other hand, if the driver supports that feature and the |
| 5086 | * station is added in unauthenticated state, set the |
| 5087 | * authenticated/associated bits in the mask to prevent moving this |
| 5088 | * station to associated state before it is actually associated. |
| 5089 | * |
| 5090 | * This is irrelevant for mesh mode where the station is added to the |
| 5091 | * driver as authenticated already, and ASSOCIATED isn't part of the |
| 5092 | * nl80211 API. |
| 5093 | */ |
| 5094 | if (!is_mesh_interface(drv->nlmode)) { |
| 5095 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { |
| 5096 | wpa_printf(MSG_DEBUG, |
| 5097 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); |
| 5098 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 5099 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); |
| 5100 | } else if (!params->set && |
| 5101 | !(params->flags & WPA_STA_TDLS_PEER)) { |
| 5102 | if (!(params->flags & WPA_STA_AUTHENTICATED)) |
| 5103 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
| 5104 | if (!(params->flags & WPA_STA_ASSOCIATED)) |
| 5105 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 5106 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 5107 | #ifdef CONFIG_MESH |
| 5108 | } else { |
| 5109 | if (params->plink_state == PLINK_ESTAB && params->peer_aid) { |
| 5110 | ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID, |
| 5111 | params->peer_aid); |
| 5112 | if (ret) |
| 5113 | goto fail; |
| 5114 | } |
| 5115 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5116 | } |
| 5117 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5118 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
| 5119 | upd.set, upd.mask); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5120 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 5121 | goto fail; |
| 5122 | |
| 5123 | #ifdef CONFIG_MESH |
| 5124 | if (params->plink_state && |
| 5125 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, |
| 5126 | sta_plink_state_nl80211(params->plink_state))) |
| 5127 | goto fail; |
| 5128 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5129 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5130 | if ((!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
| 5131 | FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) && |
| 5132 | (params->flags & WPA_STA_WMM)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5133 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 5134 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 5135 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5136 | if (!wme || |
| 5137 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 5138 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || |
| 5139 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, |
| 5140 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
| 5141 | WMM_QOSINFO_STA_SP_MASK)) |
| 5142 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5143 | nla_nest_end(msg, wme); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5144 | } |
| 5145 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5146 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5147 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5148 | if (ret) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5149 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
| 5150 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, |
| 5151 | strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5152 | if (ret == -EEXIST) |
| 5153 | ret = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5154 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5155 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5156 | return ret; |
| 5157 | } |
| 5158 | |
| 5159 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5160 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
| 5161 | { |
| 5162 | #ifdef CONFIG_LIBNL3_ROUTE |
| 5163 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5164 | struct rtnl_neigh *rn; |
| 5165 | struct nl_addr *nl_addr; |
| 5166 | int err; |
| 5167 | |
| 5168 | rn = rtnl_neigh_alloc(); |
| 5169 | if (!rn) |
| 5170 | return; |
| 5171 | |
| 5172 | rtnl_neigh_set_family(rn, AF_BRIDGE); |
| 5173 | rtnl_neigh_set_ifindex(rn, bss->ifindex); |
| 5174 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); |
| 5175 | if (!nl_addr) { |
| 5176 | rtnl_neigh_put(rn); |
| 5177 | return; |
| 5178 | } |
| 5179 | rtnl_neigh_set_lladdr(rn, nl_addr); |
| 5180 | |
| 5181 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 5182 | if (err < 0) { |
| 5183 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " |
| 5184 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), |
| 5185 | bss->ifindex, nl_geterror(err)); |
| 5186 | } else { |
| 5187 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " |
| 5188 | MACSTR, MAC2STR(addr)); |
| 5189 | } |
| 5190 | |
| 5191 | nl_addr_put(nl_addr); |
| 5192 | rtnl_neigh_put(rn); |
| 5193 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 5194 | } |
| 5195 | |
| 5196 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5197 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
| 5198 | int deauth, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5199 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5200 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5201 | struct nl_msg *msg; |
| 5202 | int ret; |
| 5203 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5204 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
| 5205 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 5206 | (deauth == 0 && |
| 5207 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 5208 | WLAN_FC_STYPE_DISASSOC)) || |
| 5209 | (deauth == 1 && |
| 5210 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 5211 | WLAN_FC_STYPE_DEAUTH)) || |
| 5212 | (reason_code && |
| 5213 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { |
| 5214 | nlmsg_free(msg); |
| 5215 | return -ENOBUFS; |
| 5216 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5217 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5218 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5219 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
| 5220 | " --> %d (%s)", |
| 5221 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5222 | |
| 5223 | if (drv->rtnl_sk) |
| 5224 | rtnl_neigh_delete_fdb_entry(bss, addr); |
| 5225 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5226 | if (ret == -ENOENT) |
| 5227 | return 0; |
| 5228 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5229 | } |
| 5230 | |
| 5231 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5232 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5233 | { |
| 5234 | struct nl_msg *msg; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5235 | struct wpa_driver_nl80211_data *drv2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5236 | |
| 5237 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
| 5238 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5239 | /* stop listening for EAPOL on this interface */ |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5240 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 5241 | struct wpa_driver_nl80211_data, list) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5242 | { |
| 5243 | del_ifidx(drv2, ifidx, IFIDX_ANY); |
| 5244 | /* Remove all bridges learned for this iface */ |
| 5245 | del_ifidx(drv2, IFIDX_ANY, ifidx); |
| 5246 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5247 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5248 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5249 | if (send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5250 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5251 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
| 5252 | } |
| 5253 | |
| 5254 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5255 | const char * nl80211_iftype_str(enum nl80211_iftype mode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5256 | { |
| 5257 | switch (mode) { |
| 5258 | case NL80211_IFTYPE_ADHOC: |
| 5259 | return "ADHOC"; |
| 5260 | case NL80211_IFTYPE_STATION: |
| 5261 | return "STATION"; |
| 5262 | case NL80211_IFTYPE_AP: |
| 5263 | return "AP"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 5264 | case NL80211_IFTYPE_AP_VLAN: |
| 5265 | return "AP_VLAN"; |
| 5266 | case NL80211_IFTYPE_WDS: |
| 5267 | return "WDS"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5268 | case NL80211_IFTYPE_MONITOR: |
| 5269 | return "MONITOR"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 5270 | case NL80211_IFTYPE_MESH_POINT: |
| 5271 | return "MESH_POINT"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5272 | case NL80211_IFTYPE_P2P_CLIENT: |
| 5273 | return "P2P_CLIENT"; |
| 5274 | case NL80211_IFTYPE_P2P_GO: |
| 5275 | return "P2P_GO"; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5276 | case NL80211_IFTYPE_P2P_DEVICE: |
| 5277 | return "P2P_DEVICE"; |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 5278 | case NL80211_IFTYPE_OCB: |
| 5279 | return "OCB"; |
| 5280 | case NL80211_IFTYPE_NAN: |
| 5281 | return "NAN"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5282 | default: |
| 5283 | return "unknown"; |
| 5284 | } |
| 5285 | } |
| 5286 | |
| 5287 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5288 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
| 5289 | const char *ifname, |
| 5290 | enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5291 | const u8 *addr, int wds, |
| 5292 | int (*handler)(struct nl_msg *, void *), |
| 5293 | void *arg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5294 | { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5295 | struct nl_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5296 | int ifidx; |
| 5297 | int ret = -ENOBUFS; |
| 5298 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5299 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
| 5300 | iftype, nl80211_iftype_str(iftype)); |
| 5301 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5302 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
| 5303 | if (!msg || |
| 5304 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
| 5305 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) |
| 5306 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5307 | |
| 5308 | if (iftype == NL80211_IFTYPE_MONITOR) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5309 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5310 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5311 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5312 | if (!flags || |
| 5313 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) |
| 5314 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5315 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5316 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5317 | } else if (wds) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5318 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
| 5319 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5320 | } |
| 5321 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 5322 | /* |
| 5323 | * Tell cfg80211 that the interface belongs to the socket that created |
| 5324 | * it, and the interface should be deleted when the socket is closed. |
| 5325 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5326 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 5327 | goto fail; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 5328 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5329 | ret = send_and_recv_msgs(drv, msg, handler, arg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5330 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5331 | if (ret) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5332 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5333 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5334 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
| 5335 | ifname, ret, strerror(-ret)); |
| 5336 | return ret; |
| 5337 | } |
| 5338 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5339 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
| 5340 | return 0; |
| 5341 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5342 | ifidx = if_nametoindex(ifname); |
| 5343 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
| 5344 | ifname, ifidx); |
| 5345 | |
| 5346 | if (ifidx <= 0) |
| 5347 | return -1; |
| 5348 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5349 | /* |
| 5350 | * Some virtual interfaces need to process EAPOL packets and events on |
| 5351 | * the parent interface. This is used mainly with hostapd. |
| 5352 | */ |
| 5353 | if (drv->hostapd || |
| 5354 | iftype == NL80211_IFTYPE_AP_VLAN || |
| 5355 | iftype == NL80211_IFTYPE_WDS || |
| 5356 | iftype == NL80211_IFTYPE_MONITOR) { |
| 5357 | /* start listening for EAPOL on this interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5358 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5359 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5360 | |
| 5361 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5362 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5363 | nl80211_remove_iface(drv, ifidx); |
| 5364 | return -1; |
| 5365 | } |
| 5366 | |
| 5367 | return ifidx; |
| 5368 | } |
| 5369 | |
| 5370 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5371 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
| 5372 | const char *ifname, enum nl80211_iftype iftype, |
| 5373 | const u8 *addr, int wds, |
| 5374 | int (*handler)(struct nl_msg *, void *), |
| 5375 | void *arg, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5376 | { |
| 5377 | int ret; |
| 5378 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5379 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
| 5380 | arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5381 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5382 | /* if error occurred and interface exists already */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5383 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5384 | if (use_existing) { |
| 5385 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", |
| 5386 | ifname); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5387 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
| 5388 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 5389 | addr) < 0 && |
| 5390 | (linux_set_iface_flags(drv->global->ioctl_sock, |
| 5391 | ifname, 0) < 0 || |
| 5392 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 5393 | addr) < 0 || |
| 5394 | linux_set_iface_flags(drv->global->ioctl_sock, |
| 5395 | ifname, 1) < 0)) |
| 5396 | return -1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5397 | return -ENFILE; |
| 5398 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5399 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
| 5400 | |
| 5401 | /* Try to remove the interface that was already there. */ |
| 5402 | nl80211_remove_iface(drv, if_nametoindex(ifname)); |
| 5403 | |
| 5404 | /* Try to create the interface again */ |
| 5405 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5406 | wds, handler, arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5407 | } |
| 5408 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5409 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
| 5410 | wpa_printf(MSG_DEBUG, |
| 5411 | "nl80211: Interface %s created for P2P - disable 11b rates", |
| 5412 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5413 | nl80211_disable_11b_rates(drv, ret, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5414 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5415 | |
| 5416 | return ret; |
| 5417 | } |
| 5418 | |
| 5419 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5420 | static int nl80211_setup_ap(struct i802_bss *bss) |
| 5421 | { |
| 5422 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5423 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5424 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 5425 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5426 | |
| 5427 | /* |
| 5428 | * Disable Probe Request reporting unless we need it in this way for |
| 5429 | * devices that include the AP SME, in the other case (unless using |
| 5430 | * monitor iface) we'll get it through the nl_mgmt socket instead. |
| 5431 | */ |
| 5432 | if (!drv->device_ap_sme) |
| 5433 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 5434 | |
| 5435 | if (!drv->device_ap_sme && !drv->use_monitor) |
| 5436 | if (nl80211_mgmt_subscribe_ap(bss)) |
| 5437 | return -1; |
| 5438 | |
| 5439 | if (drv->device_ap_sme && !drv->use_monitor) |
| 5440 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5441 | wpa_printf(MSG_DEBUG, |
| 5442 | "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] | 5443 | |
| 5444 | if (!drv->device_ap_sme && drv->use_monitor && |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 5445 | nl80211_create_monitor_interface(drv) && |
| 5446 | !drv->device_ap_sme) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5447 | return -1; |
| 5448 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5449 | if (drv->device_ap_sme && |
| 5450 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { |
| 5451 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " |
| 5452 | "Probe Request frame reporting in AP mode"); |
| 5453 | /* Try to survive without this */ |
| 5454 | } |
| 5455 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5456 | return 0; |
| 5457 | } |
| 5458 | |
| 5459 | |
| 5460 | static void nl80211_teardown_ap(struct i802_bss *bss) |
| 5461 | { |
| 5462 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5463 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5464 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 5465 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5466 | if (drv->device_ap_sme) { |
| 5467 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 5468 | if (!drv->use_monitor) |
| 5469 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); |
| 5470 | } else if (drv->use_monitor) |
| 5471 | nl80211_remove_monitor_interface(drv); |
| 5472 | else |
| 5473 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
| 5474 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5475 | nl80211_put_wiphy_data_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5476 | bss->beacon_set = 0; |
| 5477 | } |
| 5478 | |
| 5479 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5480 | static int nl80211_tx_control_port(void *priv, const u8 *dest, |
| 5481 | u16 proto, const u8 *buf, size_t len, |
| 5482 | int no_encrypt) |
| 5483 | { |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5484 | struct nl80211_ack_ext_arg ext_arg; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5485 | struct i802_bss *bss = priv; |
| 5486 | struct nl_msg *msg; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5487 | u64 cookie = 0; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5488 | int ret; |
| 5489 | |
| 5490 | wpa_printf(MSG_DEBUG, |
| 5491 | "nl80211: Send over control port dest=" MACSTR |
| 5492 | " proto=0x%04x len=%u no_encrypt=%d", |
| 5493 | MAC2STR(dest), proto, (unsigned int) len, no_encrypt); |
| 5494 | |
| 5495 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CONTROL_PORT_FRAME); |
| 5496 | if (!msg || |
| 5497 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || |
| 5498 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dest) || |
| 5499 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 5500 | (no_encrypt && |
| 5501 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) { |
| 5502 | nlmsg_free(msg); |
| 5503 | return -ENOBUFS; |
| 5504 | } |
| 5505 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5506 | os_memset(&ext_arg, 0, sizeof(struct nl80211_ack_ext_arg)); |
| 5507 | ext_arg.ext_data = &cookie; |
| 5508 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL, |
| 5509 | ack_handler_cookie, &ext_arg); |
| 5510 | if (ret) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5511 | wpa_printf(MSG_DEBUG, |
| 5512 | "nl80211: tx_control_port failed: ret=%d (%s)", |
| 5513 | ret, strerror(-ret)); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5514 | } else { |
| 5515 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5516 | |
| 5517 | wpa_printf(MSG_DEBUG, |
| 5518 | "nl80211: tx_control_port cookie=0x%llx", |
| 5519 | (long long unsigned int) cookie); |
| 5520 | drv->eapol_tx_cookie = cookie; |
| 5521 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5522 | |
| 5523 | return ret; |
| 5524 | } |
| 5525 | |
| 5526 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5527 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
| 5528 | const u8 *addr, const u8 *data, |
| 5529 | size_t data_len) |
| 5530 | { |
| 5531 | struct sockaddr_ll ll; |
| 5532 | int ret; |
| 5533 | |
| 5534 | if (bss->drv->eapol_tx_sock < 0) { |
| 5535 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); |
| 5536 | return -1; |
| 5537 | } |
| 5538 | |
| 5539 | os_memset(&ll, 0, sizeof(ll)); |
| 5540 | ll.sll_family = AF_PACKET; |
| 5541 | ll.sll_ifindex = bss->ifindex; |
| 5542 | ll.sll_protocol = htons(ETH_P_PAE); |
| 5543 | ll.sll_halen = ETH_ALEN; |
| 5544 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); |
| 5545 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, |
| 5546 | (struct sockaddr *) &ll, sizeof(ll)); |
| 5547 | if (ret < 0) |
| 5548 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", |
| 5549 | strerror(errno)); |
| 5550 | |
| 5551 | return ret; |
| 5552 | } |
| 5553 | |
| 5554 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5555 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 5556 | |
| 5557 | static int wpa_driver_nl80211_hapd_send_eapol( |
| 5558 | void *priv, const u8 *addr, const u8 *data, |
| 5559 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
| 5560 | { |
| 5561 | struct i802_bss *bss = priv; |
| 5562 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5563 | struct ieee80211_hdr *hdr; |
| 5564 | size_t len; |
| 5565 | u8 *pos; |
| 5566 | int res; |
| 5567 | int qos = flags & WPA_STA_WMM; |
Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 5568 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 5569 | /* For now, disable EAPOL TX over control port in AP mode by default |
| 5570 | * since it does not provide TX status notifications. */ |
| 5571 | if (drv->control_port_ap && |
| 5572 | (drv->capa.flags & WPA_DRIVER_FLAGS_CONTROL_PORT)) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5573 | return nl80211_tx_control_port(bss, addr, ETH_P_EAPOL, |
| 5574 | data, data_len, !encrypt); |
| 5575 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5576 | if (drv->device_ap_sme || !drv->use_monitor) |
| 5577 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
| 5578 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5579 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
| 5580 | data_len; |
| 5581 | hdr = os_zalloc(len); |
| 5582 | if (hdr == NULL) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5583 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
| 5584 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5585 | return -1; |
| 5586 | } |
| 5587 | |
| 5588 | hdr->frame_control = |
| 5589 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); |
| 5590 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 5591 | if (encrypt) |
| 5592 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); |
| 5593 | if (qos) { |
| 5594 | hdr->frame_control |= |
| 5595 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); |
| 5596 | } |
| 5597 | |
| 5598 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 5599 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 5600 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 5601 | pos = (u8 *) (hdr + 1); |
| 5602 | |
| 5603 | if (qos) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 5604 | /* Set highest priority in QoS header */ |
| 5605 | pos[0] = 7; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5606 | pos[1] = 0; |
| 5607 | pos += 2; |
| 5608 | } |
| 5609 | |
| 5610 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); |
| 5611 | pos += sizeof(rfc1042_header); |
| 5612 | WPA_PUT_BE16(pos, ETH_P_PAE); |
| 5613 | pos += 2; |
| 5614 | memcpy(pos, data, data_len); |
| 5615 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5616 | res = nl80211_send_monitor(drv, hdr, len, encrypt, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5617 | if (res < 0) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5618 | wpa_printf(MSG_ERROR, |
| 5619 | "hapd_send_eapol - packet len: %lu - failed", |
| 5620 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5621 | } |
| 5622 | os_free(hdr); |
| 5623 | |
| 5624 | return res; |
| 5625 | } |
| 5626 | |
| 5627 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5628 | 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] | 5629 | unsigned int total_flags, |
| 5630 | unsigned int flags_or, |
| 5631 | unsigned int flags_and) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5632 | { |
| 5633 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5634 | struct nl_msg *msg; |
| 5635 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5636 | struct nl80211_sta_flag_update upd; |
| 5637 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5638 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
| 5639 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", |
| 5640 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, |
| 5641 | !!(total_flags & WPA_STA_AUTHORIZED)); |
| 5642 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5643 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5644 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 5645 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5646 | |
| 5647 | /* |
| 5648 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This |
| 5649 | * can be removed eventually. |
| 5650 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5651 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5652 | if (!flags || |
| 5653 | ((total_flags & WPA_STA_AUTHORIZED) && |
| 5654 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || |
| 5655 | ((total_flags & WPA_STA_WMM) && |
| 5656 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || |
| 5657 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && |
| 5658 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || |
| 5659 | ((total_flags & WPA_STA_MFP) && |
| 5660 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || |
| 5661 | ((total_flags & WPA_STA_TDLS_PEER) && |
| 5662 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) |
| 5663 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5664 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5665 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5666 | |
| 5667 | os_memset(&upd, 0, sizeof(upd)); |
| 5668 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); |
| 5669 | upd.set = sta_flags_nl80211(flags_or); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5670 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 5671 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5672 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5673 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5674 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5675 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5676 | return -ENOBUFS; |
| 5677 | } |
| 5678 | |
| 5679 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5680 | static int driver_nl80211_sta_set_airtime_weight(void *priv, const u8 *addr, |
| 5681 | unsigned int weight) |
| 5682 | { |
| 5683 | struct i802_bss *bss = priv; |
| 5684 | struct nl_msg *msg; |
| 5685 | |
| 5686 | wpa_printf(MSG_DEBUG, |
| 5687 | "nl80211: Set STA airtime weight - ifname=%s addr=" MACSTR |
| 5688 | " weight=%u", bss->ifname, MAC2STR(addr), weight); |
| 5689 | |
| 5690 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5691 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 5692 | nla_put_u16(msg, NL80211_ATTR_AIRTIME_WEIGHT, weight)) |
| 5693 | goto fail; |
| 5694 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5695 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5696 | fail: |
| 5697 | nlmsg_free(msg); |
| 5698 | return -ENOBUFS; |
| 5699 | } |
| 5700 | |
| 5701 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5702 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
| 5703 | struct wpa_driver_associate_params *params) |
| 5704 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5705 | enum nl80211_iftype nlmode, old_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5706 | |
| 5707 | if (params->p2p) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5708 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
| 5709 | "group (GO)"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5710 | nlmode = NL80211_IFTYPE_P2P_GO; |
| 5711 | } else |
| 5712 | nlmode = NL80211_IFTYPE_AP; |
| 5713 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5714 | old_mode = drv->nlmode; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5715 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5716 | nl80211_remove_monitor_interface(drv); |
| 5717 | return -1; |
| 5718 | } |
| 5719 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5720 | if (params->freq.freq && |
| 5721 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5722 | if (old_mode != nlmode) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5723 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5724 | nl80211_remove_monitor_interface(drv); |
| 5725 | return -1; |
| 5726 | } |
| 5727 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5728 | return 0; |
| 5729 | } |
| 5730 | |
| 5731 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5732 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 5733 | int reset_mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5734 | { |
| 5735 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5736 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5737 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5738 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 5739 | ret = send_and_recv_msgs_owner(drv, msg, |
| 5740 | get_connect_handle(drv->first_bss), 1, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5741 | NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5742 | if (ret) { |
| 5743 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " |
| 5744 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5745 | } else { |
| 5746 | wpa_printf(MSG_DEBUG, |
| 5747 | "nl80211: Leave IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5748 | } |
| 5749 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5750 | if (reset_mode && |
| 5751 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 5752 | NL80211_IFTYPE_STATION)) { |
| 5753 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 5754 | "station mode"); |
| 5755 | } |
| 5756 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5757 | return ret; |
| 5758 | } |
| 5759 | |
| 5760 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5761 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
| 5762 | struct wpa_driver_associate_params *params) |
| 5763 | { |
| 5764 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) |
| 5765 | return -1; |
| 5766 | |
| 5767 | if (params->htcaps && params->htcaps_mask) { |
| 5768 | int sz = sizeof(struct ieee80211_ht_capabilities); |
| 5769 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); |
| 5770 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", |
| 5771 | params->htcaps_mask, sz); |
| 5772 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, |
| 5773 | params->htcaps) || |
| 5774 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 5775 | params->htcaps_mask)) |
| 5776 | return -1; |
| 5777 | } |
| 5778 | |
| 5779 | #ifdef CONFIG_VHT_OVERRIDES |
| 5780 | if (params->disable_vht) { |
| 5781 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
| 5782 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) |
| 5783 | return -1; |
| 5784 | } |
| 5785 | |
| 5786 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 5787 | int sz = sizeof(struct ieee80211_vht_capabilities); |
| 5788 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); |
| 5789 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", |
| 5790 | params->vhtcaps_mask, sz); |
| 5791 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, |
| 5792 | params->vhtcaps) || |
| 5793 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 5794 | params->vhtcaps_mask)) |
| 5795 | return -1; |
| 5796 | } |
| 5797 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 5798 | |
| 5799 | return 0; |
| 5800 | } |
| 5801 | |
| 5802 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5803 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
| 5804 | struct wpa_driver_associate_params *params) |
| 5805 | { |
| 5806 | struct nl_msg *msg; |
| 5807 | int ret = -1; |
| 5808 | int count = 0; |
| 5809 | |
| 5810 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); |
| 5811 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5812 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5813 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 5814 | "IBSS mode"); |
| 5815 | return -1; |
| 5816 | } |
| 5817 | |
| 5818 | retry: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5819 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
| 5820 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
| 5821 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5822 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5823 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
| 5824 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5825 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 5826 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5827 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 5828 | drv->ssid_len = params->ssid_len; |
| 5829 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5830 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
| 5831 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5832 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5833 | |
| 5834 | ret = nl80211_set_conn_keys(params, msg); |
| 5835 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5836 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5837 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5838 | if (params->bssid && params->fixed_bssid) { |
| 5839 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, |
| 5840 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5841 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 5842 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5843 | } |
| 5844 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5845 | if (params->fixed_freq) { |
| 5846 | wpa_printf(MSG_DEBUG, " * fixed_freq"); |
| 5847 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) |
| 5848 | goto fail; |
| 5849 | } |
| 5850 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5851 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 5852 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 5853 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
| 5854 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5855 | wpa_printf(MSG_DEBUG, " * control port"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5856 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 5857 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5858 | } |
| 5859 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5860 | if (params->wpa_ie) { |
| 5861 | wpa_hexdump(MSG_DEBUG, |
| 5862 | " * Extra IEs for Beacon/Probe Response frames", |
| 5863 | params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5864 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 5865 | params->wpa_ie)) |
| 5866 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5867 | } |
| 5868 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 5869 | ret = nl80211_ht_vht_overrides(msg, params); |
| 5870 | if (ret < 0) |
| 5871 | goto fail; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5872 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 5873 | ret = send_and_recv_msgs_owner(drv, msg, |
| 5874 | get_connect_handle(drv->first_bss), 1, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 5875 | NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5876 | msg = NULL; |
| 5877 | if (ret) { |
| 5878 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", |
| 5879 | ret, strerror(-ret)); |
| 5880 | count++; |
| 5881 | if (ret == -EALREADY && count == 1) { |
| 5882 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " |
| 5883 | "forced leave"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5884 | nl80211_leave_ibss(drv, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5885 | nlmsg_free(msg); |
| 5886 | goto retry; |
| 5887 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5888 | } else { |
| 5889 | wpa_printf(MSG_DEBUG, |
| 5890 | "nl80211: Join IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5891 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5892 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5893 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5894 | nlmsg_free(msg); |
| 5895 | return ret; |
| 5896 | } |
| 5897 | |
| 5898 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5899 | static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data *drv, |
| 5900 | struct wpa_driver_associate_params *params, |
| 5901 | struct nl_msg *msg) |
| 5902 | { |
| 5903 | if (params->fils_erp_username_len) { |
| 5904 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP EMSKname/username", |
| 5905 | params->fils_erp_username, |
| 5906 | params->fils_erp_username_len); |
| 5907 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_USERNAME, |
| 5908 | params->fils_erp_username_len, |
| 5909 | params->fils_erp_username)) |
| 5910 | return -1; |
| 5911 | } |
| 5912 | |
| 5913 | if (params->fils_erp_realm_len) { |
| 5914 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP Realm", |
| 5915 | params->fils_erp_realm, |
| 5916 | params->fils_erp_realm_len); |
| 5917 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_REALM, |
| 5918 | params->fils_erp_realm_len, params->fils_erp_realm)) |
| 5919 | return -1; |
| 5920 | } |
| 5921 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5922 | if (params->fils_erp_rrk_len) { |
Vinita S. Maloo | 3a5b441 | 2020-05-19 17:43:22 +0530 | [diff] [blame] | 5923 | wpa_printf(MSG_DEBUG, " * FILS ERP next seq %u", |
| 5924 | params->fils_erp_next_seq_num); |
| 5925 | if (nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 5926 | params->fils_erp_next_seq_num)) |
| 5927 | return -1; |
| 5928 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5929 | wpa_printf(MSG_DEBUG, " * FILS ERP rRK (len=%lu)", |
| 5930 | (unsigned long) params->fils_erp_rrk_len); |
| 5931 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_RRK, |
| 5932 | params->fils_erp_rrk_len, params->fils_erp_rrk)) |
| 5933 | return -1; |
| 5934 | } |
| 5935 | |
| 5936 | return 0; |
| 5937 | } |
| 5938 | |
| 5939 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5940 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
| 5941 | struct wpa_driver_associate_params *params, |
| 5942 | struct nl_msg *msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5943 | { |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5944 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 5945 | return -1; |
| 5946 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5947 | if (params->bssid) { |
| 5948 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 5949 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5950 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 5951 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5952 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5953 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5954 | if (params->bssid_hint) { |
| 5955 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, |
| 5956 | MAC2STR(params->bssid_hint)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5957 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
| 5958 | params->bssid_hint)) |
| 5959 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5960 | } |
| 5961 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5962 | if (params->freq.freq) { |
| 5963 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5964 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 5965 | params->freq.freq)) |
| 5966 | return -1; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5967 | drv->assoc_freq = params->freq.freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5968 | } else |
| 5969 | drv->assoc_freq = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5970 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5971 | if (params->freq_hint) { |
| 5972 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5973 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
| 5974 | params->freq_hint)) |
| 5975 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5976 | } |
| 5977 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5978 | if (params->freq.edmg.channels && params->freq.edmg.bw_config) { |
| 5979 | wpa_printf(MSG_DEBUG, |
| 5980 | " * EDMG configuration: channels=0x%x bw_config=%d", |
| 5981 | params->freq.edmg.channels, |
| 5982 | params->freq.edmg.bw_config); |
| 5983 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS, |
| 5984 | params->freq.edmg.channels) || |
| 5985 | nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG, |
| 5986 | params->freq.edmg.bw_config)) |
| 5987 | return -1; |
| 5988 | } |
| 5989 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5990 | if (params->bg_scan_period >= 0) { |
| 5991 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 5992 | params->bg_scan_period); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5993 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 5994 | params->bg_scan_period)) |
| 5995 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5996 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5997 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5998 | if (params->ssid) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5999 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
| 6000 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6001 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 6002 | params->ssid)) |
| 6003 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6004 | if (params->ssid_len > sizeof(drv->ssid)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6005 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6006 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 6007 | drv->ssid_len = params->ssid_len; |
| 6008 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6009 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6010 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6011 | if (params->wpa_ie && |
| 6012 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) |
| 6013 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6014 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6015 | if (params->wpa_proto) { |
| 6016 | enum nl80211_wpa_versions ver = 0; |
| 6017 | |
| 6018 | if (params->wpa_proto & WPA_PROTO_WPA) |
| 6019 | ver |= NL80211_WPA_VERSION_1; |
| 6020 | if (params->wpa_proto & WPA_PROTO_RSN) |
| 6021 | ver |= NL80211_WPA_VERSION_2; |
| 6022 | |
| 6023 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6024 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 6025 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6026 | } |
| 6027 | |
| 6028 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
| 6029 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
| 6030 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6031 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 6032 | cipher)) |
| 6033 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6034 | } |
| 6035 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 6036 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
| 6037 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { |
| 6038 | /* |
| 6039 | * This is likely to work even though many drivers do not |
| 6040 | * advertise support for operations without GTK. |
| 6041 | */ |
| 6042 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); |
| 6043 | } else if (params->group_suite != WPA_CIPHER_NONE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6044 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
| 6045 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6046 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
| 6047 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6048 | } |
| 6049 | |
| 6050 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 6051 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 6052 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || |
| 6053 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6054 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 6055 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
| 6056 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6057 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6058 | params->key_mgmt_suite == WPA_KEY_MGMT_SAE || |
| 6059 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 6060 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6061 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6062 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X_SHA384 || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6063 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA256 || |
| 6064 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA384 || |
| 6065 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA256 || |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6066 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA384 || |
| 6067 | params->key_mgmt_suite == WPA_KEY_MGMT_OWE || |
| 6068 | params->key_mgmt_suite == WPA_KEY_MGMT_DPP) { |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6069 | int mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6070 | |
| 6071 | switch (params->key_mgmt_suite) { |
| 6072 | case WPA_KEY_MGMT_CCKM: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6073 | mgmt = RSN_AUTH_KEY_MGMT_CCKM; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6074 | break; |
| 6075 | case WPA_KEY_MGMT_IEEE8021X: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6076 | mgmt = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6077 | break; |
| 6078 | case WPA_KEY_MGMT_FT_IEEE8021X: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6079 | mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6080 | break; |
| 6081 | case WPA_KEY_MGMT_FT_PSK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6082 | mgmt = RSN_AUTH_KEY_MGMT_FT_PSK; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6083 | break; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 6084 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6085 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SHA256; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 6086 | break; |
| 6087 | case WPA_KEY_MGMT_PSK_SHA256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6088 | mgmt = RSN_AUTH_KEY_MGMT_PSK_SHA256; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 6089 | break; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6090 | case WPA_KEY_MGMT_OSEN: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6091 | mgmt = RSN_AUTH_KEY_MGMT_OSEN; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6092 | break; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6093 | case WPA_KEY_MGMT_SAE: |
| 6094 | mgmt = RSN_AUTH_KEY_MGMT_SAE; |
| 6095 | break; |
| 6096 | case WPA_KEY_MGMT_FT_SAE: |
| 6097 | mgmt = RSN_AUTH_KEY_MGMT_FT_SAE; |
| 6098 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6099 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6100 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6101 | break; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 6102 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6103 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 6104 | break; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6105 | case WPA_KEY_MGMT_FT_IEEE8021X_SHA384: |
| 6106 | mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384; |
| 6107 | break; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6108 | case WPA_KEY_MGMT_FILS_SHA256: |
| 6109 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA256; |
| 6110 | break; |
| 6111 | case WPA_KEY_MGMT_FILS_SHA384: |
| 6112 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA384; |
| 6113 | break; |
| 6114 | case WPA_KEY_MGMT_FT_FILS_SHA256: |
| 6115 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256; |
| 6116 | break; |
| 6117 | case WPA_KEY_MGMT_FT_FILS_SHA384: |
| 6118 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384; |
| 6119 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6120 | case WPA_KEY_MGMT_OWE: |
| 6121 | mgmt = RSN_AUTH_KEY_MGMT_OWE; |
| 6122 | break; |
| 6123 | case WPA_KEY_MGMT_DPP: |
| 6124 | mgmt = RSN_AUTH_KEY_MGMT_DPP; |
| 6125 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6126 | case WPA_KEY_MGMT_PSK: |
| 6127 | default: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 6128 | mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6129 | break; |
| 6130 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 6131 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6132 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
| 6133 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6134 | } |
| 6135 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 6136 | if (params->req_handshake_offload && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6137 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)) { |
| 6138 | wpa_printf(MSG_DEBUG, " * WANT_1X_4WAY_HS"); |
| 6139 | if (nla_put_flag(msg, NL80211_ATTR_WANT_1X_4WAY_HS)) |
| 6140 | return -1; |
| 6141 | } |
| 6142 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6143 | /* Add PSK in case of 4-way handshake offload */ |
| 6144 | if (params->psk && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6145 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6146 | wpa_hexdump_key(MSG_DEBUG, " * PSK", params->psk, 32); |
| 6147 | if (nla_put(msg, NL80211_ATTR_PMK, 32, params->psk)) |
| 6148 | return -1; |
| 6149 | } |
| 6150 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6151 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 6152 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6153 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 6154 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 6155 | (params->pairwise_suite == WPA_CIPHER_NONE || |
| 6156 | params->pairwise_suite == WPA_CIPHER_WEP104 || |
| 6157 | params->pairwise_suite == WPA_CIPHER_WEP40) && |
| 6158 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 6159 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
| 6160 | return -1; |
| 6161 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6162 | if (params->rrm_used) { |
| 6163 | u32 drv_rrm_flags = drv->capa.rrm_flags; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 6164 | if ((!((drv_rrm_flags & |
| 6165 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && |
| 6166 | (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && |
| 6167 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6168 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
| 6169 | return -1; |
| 6170 | } |
| 6171 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6172 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6173 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6174 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6175 | if (params->p2p) |
| 6176 | wpa_printf(MSG_DEBUG, " * P2P group"); |
| 6177 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6178 | if (params->pbss) { |
| 6179 | wpa_printf(MSG_DEBUG, " * PBSS"); |
| 6180 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 6181 | return -1; |
| 6182 | } |
| 6183 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 6184 | drv->connect_reassoc = 0; |
| 6185 | if (params->prev_bssid) { |
| 6186 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, |
| 6187 | MAC2STR(params->prev_bssid)); |
| 6188 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
| 6189 | params->prev_bssid)) |
| 6190 | return -1; |
| 6191 | drv->connect_reassoc = 1; |
| 6192 | } |
| 6193 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6194 | if ((params->auth_alg & WPA_AUTH_ALG_FILS) && |
| 6195 | nl80211_put_fils_connect_params(drv, params, msg) != 0) |
| 6196 | return -1; |
| 6197 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 6198 | if ((params->key_mgmt_suite == WPA_KEY_MGMT_SAE || |
| 6199 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6200 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) && |
| 6201 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) |
| 6202 | return -1; |
| 6203 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6204 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6205 | } |
| 6206 | |
| 6207 | |
| 6208 | static int wpa_driver_nl80211_try_connect( |
| 6209 | struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6210 | struct wpa_driver_associate_params *params, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6211 | struct nl_sock *nl_connect) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6212 | { |
| 6213 | struct nl_msg *msg; |
| 6214 | enum nl80211_auth_type type; |
| 6215 | int ret; |
| 6216 | int algs; |
| 6217 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6218 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6219 | if (params->req_key_mgmt_offload && params->psk && |
| 6220 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 6221 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
| 6222 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { |
| 6223 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); |
| 6224 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); |
| 6225 | if (ret) |
| 6226 | return ret; |
| 6227 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6228 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6229 | |
| 6230 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
| 6231 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6232 | if (!msg) |
| 6233 | return -1; |
| 6234 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6235 | ret = nl80211_connect_common(drv, params, msg); |
| 6236 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6237 | goto fail; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6238 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6239 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 6240 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 6241 | goto fail; |
| 6242 | |
| 6243 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_OPTIONAL && |
| 6244 | (drv->capa.flags & WPA_DRIVER_FLAGS_MFP_OPTIONAL) && |
| 6245 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_OPTIONAL)) |
| 6246 | goto fail; |
| 6247 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6248 | algs = 0; |
| 6249 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 6250 | algs++; |
| 6251 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 6252 | algs++; |
| 6253 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 6254 | algs++; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6255 | if (params->auth_alg & WPA_AUTH_ALG_FILS) |
| 6256 | algs++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6257 | if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 6258 | algs++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6259 | if (algs > 1) { |
| 6260 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " |
| 6261 | "selection"); |
| 6262 | goto skip_auth_type; |
| 6263 | } |
| 6264 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6265 | type = get_nl_auth_type(params->auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6266 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6267 | if (type == NL80211_AUTHTYPE_MAX || |
| 6268 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6269 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6270 | |
| 6271 | skip_auth_type: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6272 | ret = nl80211_set_conn_keys(params, msg); |
| 6273 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6274 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6275 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 6276 | ret = send_and_recv_msgs_owner(drv, msg, nl_connect, 1, NULL, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6277 | (void *) -1, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6278 | msg = NULL; |
| 6279 | if (ret) { |
| 6280 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " |
| 6281 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6282 | } else { |
| 6283 | wpa_printf(MSG_DEBUG, |
| 6284 | "nl80211: Connect request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6285 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6286 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6287 | fail: |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6288 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6289 | nlmsg_free(msg); |
| 6290 | return ret; |
| 6291 | |
| 6292 | } |
| 6293 | |
| 6294 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6295 | static int wpa_driver_nl80211_connect( |
| 6296 | struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6297 | struct wpa_driver_associate_params *params, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6298 | struct nl_sock *nl_connect) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6299 | { |
Jithu Jance | a7c60b4 | 2014-12-03 18:54:40 +0530 | [diff] [blame] | 6300 | int ret; |
| 6301 | |
| 6302 | /* Store the connection attempted bssid for future use */ |
| 6303 | if (params->bssid) |
| 6304 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 6305 | else |
| 6306 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
| 6307 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6308 | ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6309 | if (ret == -EALREADY) { |
| 6310 | /* |
| 6311 | * cfg80211 does not currently accept new connections if |
| 6312 | * we are already connected. As a workaround, force |
| 6313 | * disconnection and try again. |
| 6314 | */ |
| 6315 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " |
| 6316 | "disconnecting before reassociation " |
| 6317 | "attempt"); |
| 6318 | if (wpa_driver_nl80211_disconnect( |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6319 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID, nl_connect)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6320 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6321 | ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6322 | } |
| 6323 | return ret; |
| 6324 | } |
| 6325 | |
| 6326 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6327 | static int wpa_driver_nl80211_associate( |
| 6328 | void *priv, struct wpa_driver_associate_params *params) |
| 6329 | { |
| 6330 | struct i802_bss *bss = priv; |
| 6331 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6332 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6333 | struct nl_msg *msg; |
| 6334 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6335 | nl80211_unmask_11b_rates(bss); |
| 6336 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6337 | if (params->mode == IEEE80211_MODE_AP) |
| 6338 | return wpa_driver_nl80211_ap(drv, params); |
| 6339 | |
| 6340 | if (params->mode == IEEE80211_MODE_IBSS) |
| 6341 | return wpa_driver_nl80211_ibss(drv, params); |
| 6342 | |
| 6343 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6344 | enum nl80211_iftype nlmode = params->p2p ? |
| 6345 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 6346 | |
| 6347 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6348 | return -1; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 6349 | if (params->key_mgmt_suite == WPA_KEY_MGMT_SAE || |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 6350 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE) |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6351 | bss->use_nl_connect = 1; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 6352 | else |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6353 | bss->use_nl_connect = 0; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6354 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 6355 | return wpa_driver_nl80211_connect(drv, params, |
| 6356 | get_connect_handle(bss)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6357 | } |
| 6358 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6359 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6360 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6361 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
| 6362 | drv->ifindex); |
| 6363 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6364 | if (!msg) |
| 6365 | return -1; |
| 6366 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6367 | ret = nl80211_connect_common(drv, params, msg); |
| 6368 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6369 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6370 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6371 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 6372 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 6373 | goto fail; |
| 6374 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 6375 | if (params->fils_kek) { |
| 6376 | wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)", |
| 6377 | (unsigned int) params->fils_kek_len); |
| 6378 | if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len, |
| 6379 | params->fils_kek)) |
| 6380 | goto fail; |
| 6381 | } |
| 6382 | if (params->fils_nonces) { |
| 6383 | wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)", |
| 6384 | params->fils_nonces, |
| 6385 | params->fils_nonces_len); |
| 6386 | if (nla_put(msg, NL80211_ATTR_FILS_NONCES, |
| 6387 | params->fils_nonces_len, params->fils_nonces)) |
| 6388 | goto fail; |
| 6389 | } |
| 6390 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 6391 | ret = send_and_recv_msgs_owner(drv, msg, |
| 6392 | get_connect_handle(drv->first_bss), 1, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6393 | NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6394 | msg = NULL; |
| 6395 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6396 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 6397 | "nl80211: MLME command failed (assoc): ret=%d (%s)", |
| 6398 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6399 | nl80211_dump_scan(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6400 | } else { |
| 6401 | wpa_printf(MSG_DEBUG, |
| 6402 | "nl80211: Association request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6403 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6404 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6405 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6406 | nlmsg_free(msg); |
| 6407 | return ret; |
| 6408 | } |
| 6409 | |
| 6410 | |
| 6411 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6412 | int ifindex, enum nl80211_iftype mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6413 | { |
| 6414 | struct nl_msg *msg; |
| 6415 | int ret = -ENOBUFS; |
| 6416 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6417 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
| 6418 | ifindex, mode, nl80211_iftype_str(mode)); |
| 6419 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6420 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 6421 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) |
| 6422 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6423 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6424 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6425 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6426 | if (!ret) |
| 6427 | return 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6428 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6429 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6430 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
| 6431 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); |
| 6432 | return ret; |
| 6433 | } |
| 6434 | |
| 6435 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6436 | static int wpa_driver_nl80211_set_mode_impl( |
| 6437 | struct i802_bss *bss, |
| 6438 | enum nl80211_iftype nlmode, |
| 6439 | struct hostapd_freq_params *desired_freq_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6440 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6441 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6442 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6443 | int i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6444 | int was_ap = is_ap_interface(drv->nlmode); |
| 6445 | int res; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6446 | int mode_switch_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6447 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 6448 | if (TEST_FAIL()) |
| 6449 | return -1; |
| 6450 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6451 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 6452 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) |
| 6453 | mode_switch_res = 0; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6454 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6455 | if (mode_switch_res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6456 | drv->nlmode = nlmode; |
| 6457 | ret = 0; |
| 6458 | goto done; |
| 6459 | } |
| 6460 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6461 | if (mode_switch_res == -ENODEV) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6462 | return -1; |
| 6463 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6464 | if (nlmode == drv->nlmode) { |
| 6465 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
| 6466 | "requested mode - ignore error"); |
| 6467 | ret = 0; |
| 6468 | goto done; /* Already in the requested mode */ |
| 6469 | } |
| 6470 | |
| 6471 | /* mac80211 doesn't allow mode changes while the device is up, so |
| 6472 | * take the device down, try to set the mode again, and bring the |
| 6473 | * device back up. |
| 6474 | */ |
| 6475 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
| 6476 | "interface down"); |
| 6477 | for (i = 0; i < 10; i++) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6478 | res = i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6479 | if (res == -EACCES || res == -ENODEV) |
| 6480 | break; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6481 | if (res != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6482 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
| 6483 | "interface down"); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6484 | os_sleep(0, 100000); |
| 6485 | continue; |
| 6486 | } |
| 6487 | |
| 6488 | /* |
| 6489 | * Setting the mode will fail for some drivers if the phy is |
| 6490 | * on a frequency that the mode is disallowed in. |
| 6491 | */ |
| 6492 | if (desired_freq_params) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6493 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6494 | if (res) { |
| 6495 | wpa_printf(MSG_DEBUG, |
| 6496 | "nl80211: Failed to set frequency on interface"); |
| 6497 | } |
| 6498 | } |
| 6499 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 6500 | if (i == 0 && was_ap && !is_ap_interface(nlmode) && |
| 6501 | bss->brname[0] && |
| 6502 | (bss->added_if_into_bridge || bss->already_in_bridge)) { |
| 6503 | wpa_printf(MSG_DEBUG, |
| 6504 | "nl80211: Remove AP interface %s temporarily from the bridge %s to allow its mode to be set to STATION", |
| 6505 | bss->ifname, bss->brname); |
| 6506 | if (linux_br_del_if(drv->global->ioctl_sock, |
| 6507 | bss->brname, bss->ifname) < 0) |
| 6508 | wpa_printf(MSG_INFO, |
| 6509 | "nl80211: Failed to remove interface %s from bridge %s: %s", |
| 6510 | bss->ifname, bss->brname, |
| 6511 | strerror(errno)); |
| 6512 | } |
| 6513 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6514 | /* Try to set the mode again while the interface is down */ |
| 6515 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 6516 | if (mode_switch_res == -EBUSY) { |
| 6517 | wpa_printf(MSG_DEBUG, |
| 6518 | "nl80211: Delaying mode set while interface going down"); |
| 6519 | os_sleep(0, 100000); |
| 6520 | continue; |
| 6521 | } |
| 6522 | ret = mode_switch_res; |
| 6523 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6524 | } |
| 6525 | |
| 6526 | if (!ret) { |
| 6527 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " |
| 6528 | "interface is down"); |
| 6529 | drv->nlmode = nlmode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6530 | drv->ignore_if_down_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6531 | } |
| 6532 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6533 | /* Bring the interface back up */ |
| 6534 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); |
| 6535 | if (res != 0) { |
| 6536 | wpa_printf(MSG_DEBUG, |
| 6537 | "nl80211: Failed to set interface up after switching mode"); |
| 6538 | ret = -1; |
| 6539 | } |
| 6540 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6541 | done: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6542 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6543 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " |
| 6544 | "from %d failed", nlmode, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6545 | return ret; |
| 6546 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6547 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6548 | if (is_p2p_net_interface(nlmode)) { |
| 6549 | wpa_printf(MSG_DEBUG, |
| 6550 | "nl80211: Interface %s mode change to P2P - disable 11b rates", |
| 6551 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6552 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6553 | } else if (drv->disabled_11b_rates) { |
| 6554 | wpa_printf(MSG_DEBUG, |
| 6555 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", |
| 6556 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6557 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6558 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6559 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6560 | if (is_ap_interface(nlmode)) { |
| 6561 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
| 6562 | /* Setup additional AP mode functionality if needed */ |
| 6563 | if (nl80211_setup_ap(bss)) |
| 6564 | return -1; |
| 6565 | } else if (was_ap) { |
| 6566 | /* Remove additional AP mode functionality */ |
| 6567 | nl80211_teardown_ap(bss); |
| 6568 | } else { |
| 6569 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
| 6570 | } |
| 6571 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6572 | if (is_mesh_interface(nlmode) && |
| 6573 | nl80211_mgmt_subscribe_mesh(bss)) |
| 6574 | return -1; |
| 6575 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6576 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6577 | !is_mesh_interface(nlmode) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6578 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 6579 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " |
| 6580 | "frame processing - ignore for now"); |
| 6581 | |
| 6582 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6583 | } |
| 6584 | |
| 6585 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 6586 | void nl80211_restore_ap_mode(struct i802_bss *bss) |
| 6587 | { |
| 6588 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6589 | int was_ap = is_ap_interface(drv->nlmode); |
| 6590 | |
| 6591 | wpa_driver_nl80211_set_mode(bss, drv->ap_scan_as_station); |
| 6592 | if (!was_ap && is_ap_interface(drv->ap_scan_as_station) && |
| 6593 | bss->brname[0] && |
| 6594 | (bss->added_if_into_bridge || bss->already_in_bridge)) { |
| 6595 | wpa_printf(MSG_DEBUG, |
| 6596 | "nl80211: Add AP interface %s back into the bridge %s", |
| 6597 | bss->ifname, bss->brname); |
| 6598 | if (linux_br_add_if(drv->global->ioctl_sock, bss->brname, |
| 6599 | bss->ifname) < 0) { |
| 6600 | wpa_printf(MSG_WARNING, |
| 6601 | "nl80211: Failed to add interface %s into bridge %s: %s", |
| 6602 | bss->ifname, bss->brname, strerror(errno)); |
| 6603 | } |
| 6604 | } |
| 6605 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
| 6606 | } |
| 6607 | |
| 6608 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6609 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 6610 | enum nl80211_iftype nlmode) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6611 | { |
| 6612 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); |
| 6613 | } |
| 6614 | |
| 6615 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6616 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 6617 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6618 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6619 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6620 | freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6621 | } |
| 6622 | |
| 6623 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6624 | static int wpa_driver_nl80211_get_capa(void *priv, |
| 6625 | struct wpa_driver_capa *capa) |
| 6626 | { |
| 6627 | struct i802_bss *bss = priv; |
| 6628 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 6629 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6630 | if (!drv->has_capability) |
| 6631 | return -1; |
| 6632 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 6633 | if (drv->extended_capa && drv->extended_capa_mask) { |
| 6634 | capa->extended_capa = drv->extended_capa; |
| 6635 | capa->extended_capa_mask = drv->extended_capa_mask; |
| 6636 | capa->extended_capa_len = drv->extended_capa_len; |
| 6637 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6638 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6639 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6640 | } |
| 6641 | |
| 6642 | |
| 6643 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) |
| 6644 | { |
| 6645 | struct i802_bss *bss = priv; |
| 6646 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6647 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6648 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
| 6649 | bss->ifname, drv->operstate, state, |
| 6650 | state ? "UP" : "DORMANT"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6651 | drv->operstate = state; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6652 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6653 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
| 6654 | } |
| 6655 | |
| 6656 | |
| 6657 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) |
| 6658 | { |
| 6659 | struct i802_bss *bss = priv; |
| 6660 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6661 | struct nl_msg *msg; |
| 6662 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6663 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6664 | |
| 6665 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { |
| 6666 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); |
| 6667 | return 0; |
| 6668 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6669 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6670 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
| 6671 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); |
| 6672 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6673 | os_memset(&upd, 0, sizeof(upd)); |
| 6674 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 6675 | if (authorized) |
| 6676 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6677 | |
| 6678 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 6679 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
| 6680 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { |
| 6681 | nlmsg_free(msg); |
| 6682 | return -ENOBUFS; |
| 6683 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6684 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6685 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6686 | if (!ret) |
| 6687 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6688 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
| 6689 | ret, strerror(-ret)); |
| 6690 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6691 | } |
| 6692 | |
| 6693 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6694 | /* Set kernel driver on given frequency (MHz) */ |
| 6695 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6696 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6697 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 6698 | return nl80211_set_channel(bss, freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6699 | } |
| 6700 | |
| 6701 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6702 | static inline int min_int(int a, int b) |
| 6703 | { |
| 6704 | if (a < b) |
| 6705 | return a; |
| 6706 | return b; |
| 6707 | } |
| 6708 | |
| 6709 | |
| 6710 | static int get_key_handler(struct nl_msg *msg, void *arg) |
| 6711 | { |
| 6712 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6713 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6714 | |
| 6715 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6716 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6717 | |
| 6718 | /* |
| 6719 | * TODO: validate the key index and mac address! |
| 6720 | * Otherwise, there's a race condition as soon as |
| 6721 | * the kernel starts sending key notifications. |
| 6722 | */ |
| 6723 | |
| 6724 | if (tb[NL80211_ATTR_KEY_SEQ]) |
| 6725 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 6726 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6727 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6728 | return NL_SKIP; |
| 6729 | } |
| 6730 | |
| 6731 | |
| 6732 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, |
| 6733 | int idx, u8 *seq) |
| 6734 | { |
| 6735 | struct i802_bss *bss = priv; |
| 6736 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6737 | struct nl_msg *msg; |
| 6738 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6739 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
| 6740 | NL80211_CMD_GET_KEY); |
| 6741 | if (!msg || |
| 6742 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 6743 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
| 6744 | nlmsg_free(msg); |
| 6745 | return -ENOBUFS; |
| 6746 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6747 | |
| 6748 | memset(seq, 0, 6); |
| 6749 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6750 | 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] | 6751 | } |
| 6752 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6753 | |
| 6754 | static int i802_set_rts(void *priv, int rts) |
| 6755 | { |
| 6756 | struct i802_bss *bss = priv; |
| 6757 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6758 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6759 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6760 | u32 val; |
| 6761 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6762 | if (rts >= 2347 || rts == -1) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6763 | val = (u32) -1; |
| 6764 | else |
| 6765 | val = rts; |
| 6766 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6767 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 6768 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
| 6769 | nlmsg_free(msg); |
| 6770 | return -ENOBUFS; |
| 6771 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6772 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6773 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6774 | if (!ret) |
| 6775 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6776 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
| 6777 | "%d (%s)", rts, ret, strerror(-ret)); |
| 6778 | return ret; |
| 6779 | } |
| 6780 | |
| 6781 | |
| 6782 | static int i802_set_frag(void *priv, int frag) |
| 6783 | { |
| 6784 | struct i802_bss *bss = priv; |
| 6785 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6786 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6787 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6788 | u32 val; |
| 6789 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6790 | if (frag >= 2346 || frag == -1) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6791 | val = (u32) -1; |
| 6792 | else |
| 6793 | val = frag; |
| 6794 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6795 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 6796 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
| 6797 | nlmsg_free(msg); |
| 6798 | return -ENOBUFS; |
| 6799 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6800 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6801 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6802 | if (!ret) |
| 6803 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6804 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
| 6805 | "%d: %d (%s)", frag, ret, strerror(-ret)); |
| 6806 | return ret; |
| 6807 | } |
| 6808 | |
| 6809 | |
| 6810 | static int i802_flush(void *priv) |
| 6811 | { |
| 6812 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6813 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6814 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6815 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6816 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
| 6817 | bss->ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6818 | |
| 6819 | /* |
| 6820 | * XXX: FIX! this needs to flush all VLANs too |
| 6821 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6822 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 6823 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6824 | if (res) { |
| 6825 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " |
| 6826 | "(%s)", res, strerror(-res)); |
| 6827 | } |
| 6828 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6829 | } |
| 6830 | |
| 6831 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6832 | static void get_sta_tid_stats(struct hostap_sta_driver_data *data, |
| 6833 | struct nlattr *attr) |
| 6834 | { |
| 6835 | struct nlattr *tid_stats[NL80211_TID_STATS_MAX + 1], *tidattr; |
| 6836 | struct nlattr *txq_stats[NL80211_TXQ_STATS_MAX + 1]; |
| 6837 | static struct nla_policy txq_stats_policy[NL80211_TXQ_STATS_MAX + 1] = { |
| 6838 | [NL80211_TXQ_STATS_BACKLOG_BYTES] = { .type = NLA_U32 }, |
| 6839 | [NL80211_TXQ_STATS_BACKLOG_PACKETS] = { .type = NLA_U32 }, |
| 6840 | }; |
| 6841 | int rem; |
| 6842 | |
| 6843 | nla_for_each_nested(tidattr, attr, rem) { |
| 6844 | if (nla_parse_nested(tid_stats, NL80211_TID_STATS_MAX, |
| 6845 | tidattr, NULL) != 0 || |
| 6846 | !tid_stats[NL80211_TID_STATS_TXQ_STATS] || |
| 6847 | nla_parse_nested(txq_stats, NL80211_TXQ_STATS_MAX, |
| 6848 | tid_stats[NL80211_TID_STATS_TXQ_STATS], |
| 6849 | txq_stats_policy) != 0) |
| 6850 | continue; |
| 6851 | /* sum the backlogs over all TIDs for station */ |
| 6852 | if (txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]) |
| 6853 | data->backlog_bytes += nla_get_u32( |
| 6854 | txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]); |
| 6855 | if (txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]) |
| 6856 | data->backlog_bytes += nla_get_u32( |
| 6857 | txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]); |
| 6858 | } |
| 6859 | } |
| 6860 | |
| 6861 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6862 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
| 6863 | { |
| 6864 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6865 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6866 | struct hostap_sta_driver_data *data = arg; |
| 6867 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; |
| 6868 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
| 6869 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, |
| 6870 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, |
| 6871 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, |
| 6872 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
| 6873 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 6874 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6875 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
| 6876 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6877 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6878 | [NL80211_STA_INFO_ACK_SIGNAL] = { .type = NLA_U8 }, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6879 | [NL80211_STA_INFO_RX_DURATION] = { .type = NLA_U64 }, |
| 6880 | [NL80211_STA_INFO_TX_DURATION] = { .type = NLA_U64 }, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6881 | }; |
| 6882 | struct nlattr *rate[NL80211_RATE_INFO_MAX + 1]; |
| 6883 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 6884 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 6885 | [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 }, |
| 6886 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 6887 | [NL80211_RATE_INFO_VHT_MCS] = { .type = NLA_U8 }, |
| 6888 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 6889 | [NL80211_RATE_INFO_VHT_NSS] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6890 | }; |
| 6891 | |
| 6892 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6893 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6894 | |
| 6895 | /* |
| 6896 | * TODO: validate the interface and mac address! |
| 6897 | * Otherwise, there's a race condition as soon as |
| 6898 | * the kernel starts sending station notifications. |
| 6899 | */ |
| 6900 | |
| 6901 | if (!tb[NL80211_ATTR_STA_INFO]) { |
| 6902 | wpa_printf(MSG_DEBUG, "sta stats missing!"); |
| 6903 | return NL_SKIP; |
| 6904 | } |
| 6905 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, |
| 6906 | tb[NL80211_ATTR_STA_INFO], |
| 6907 | stats_policy)) { |
| 6908 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); |
| 6909 | return NL_SKIP; |
| 6910 | } |
| 6911 | |
| 6912 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) |
| 6913 | data->inactive_msec = |
| 6914 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6915 | /* For backwards compatibility, fetch the 32-bit counters first. */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6916 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
| 6917 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); |
| 6918 | if (stats[NL80211_STA_INFO_TX_BYTES]) |
| 6919 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6920 | if (stats[NL80211_STA_INFO_RX_BYTES64] && |
| 6921 | stats[NL80211_STA_INFO_TX_BYTES64]) { |
| 6922 | /* |
| 6923 | * The driver supports 64-bit counters, so use them to override |
| 6924 | * the 32-bit values. |
| 6925 | */ |
| 6926 | data->rx_bytes = |
| 6927 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); |
| 6928 | data->tx_bytes = |
| 6929 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); |
| 6930 | data->bytes_64bit = 1; |
| 6931 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6932 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
| 6933 | data->rx_packets = |
| 6934 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); |
| 6935 | if (stats[NL80211_STA_INFO_TX_PACKETS]) |
| 6936 | data->tx_packets = |
| 6937 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6938 | if (stats[NL80211_STA_INFO_RX_DURATION]) |
| 6939 | data->rx_airtime = |
| 6940 | nla_get_u64(stats[NL80211_STA_INFO_RX_DURATION]); |
| 6941 | if (stats[NL80211_STA_INFO_TX_DURATION]) |
| 6942 | data->tx_airtime = |
| 6943 | nla_get_u64(stats[NL80211_STA_INFO_TX_DURATION]); |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 6944 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
| 6945 | data->tx_retry_failed = |
| 6946 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6947 | if (stats[NL80211_STA_INFO_SIGNAL]) |
| 6948 | data->signal = nla_get_u8(stats[NL80211_STA_INFO_SIGNAL]); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6949 | if (stats[NL80211_STA_INFO_ACK_SIGNAL]) { |
| 6950 | data->last_ack_rssi = |
| 6951 | nla_get_u8(stats[NL80211_STA_INFO_ACK_SIGNAL]); |
| 6952 | data->flags |= STA_DRV_DATA_LAST_ACK_RSSI; |
| 6953 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6954 | |
| 6955 | if (stats[NL80211_STA_INFO_TX_BITRATE] && |
| 6956 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, |
| 6957 | stats[NL80211_STA_INFO_TX_BITRATE], |
| 6958 | rate_policy) == 0) { |
| 6959 | if (rate[NL80211_RATE_INFO_BITRATE32]) |
| 6960 | data->current_tx_rate = |
| 6961 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); |
| 6962 | else if (rate[NL80211_RATE_INFO_BITRATE]) |
| 6963 | data->current_tx_rate = |
| 6964 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); |
| 6965 | |
| 6966 | if (rate[NL80211_RATE_INFO_MCS]) { |
| 6967 | data->tx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]); |
| 6968 | data->flags |= STA_DRV_DATA_TX_MCS; |
| 6969 | } |
| 6970 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { |
| 6971 | data->tx_vhtmcs = |
| 6972 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); |
| 6973 | data->flags |= STA_DRV_DATA_TX_VHT_MCS; |
| 6974 | } |
| 6975 | if (rate[NL80211_RATE_INFO_SHORT_GI]) |
| 6976 | data->flags |= STA_DRV_DATA_TX_SHORT_GI; |
| 6977 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { |
| 6978 | data->tx_vht_nss = |
| 6979 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); |
| 6980 | data->flags |= STA_DRV_DATA_TX_VHT_NSS; |
| 6981 | } |
| 6982 | } |
| 6983 | |
| 6984 | if (stats[NL80211_STA_INFO_RX_BITRATE] && |
| 6985 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, |
| 6986 | stats[NL80211_STA_INFO_RX_BITRATE], |
| 6987 | rate_policy) == 0) { |
| 6988 | if (rate[NL80211_RATE_INFO_BITRATE32]) |
| 6989 | data->current_rx_rate = |
| 6990 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); |
| 6991 | else if (rate[NL80211_RATE_INFO_BITRATE]) |
| 6992 | data->current_rx_rate = |
| 6993 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); |
| 6994 | |
| 6995 | if (rate[NL80211_RATE_INFO_MCS]) { |
| 6996 | data->rx_mcs = |
| 6997 | nla_get_u8(rate[NL80211_RATE_INFO_MCS]); |
| 6998 | data->flags |= STA_DRV_DATA_RX_MCS; |
| 6999 | } |
| 7000 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { |
| 7001 | data->rx_vhtmcs = |
| 7002 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); |
| 7003 | data->flags |= STA_DRV_DATA_RX_VHT_MCS; |
| 7004 | } |
| 7005 | if (rate[NL80211_RATE_INFO_SHORT_GI]) |
| 7006 | data->flags |= STA_DRV_DATA_RX_SHORT_GI; |
| 7007 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { |
| 7008 | data->rx_vht_nss = |
| 7009 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); |
| 7010 | data->flags |= STA_DRV_DATA_RX_VHT_NSS; |
| 7011 | } |
| 7012 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7013 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7014 | if (stats[NL80211_STA_INFO_TID_STATS]) |
| 7015 | get_sta_tid_stats(data, stats[NL80211_STA_INFO_TID_STATS]); |
| 7016 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7017 | return NL_SKIP; |
| 7018 | } |
| 7019 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7020 | static int i802_read_sta_data(struct i802_bss *bss, |
| 7021 | struct hostap_sta_driver_data *data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7022 | const u8 *addr) |
| 7023 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7024 | struct nl_msg *msg; |
| 7025 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7026 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
| 7027 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 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 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data, |
| 7033 | NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7034 | } |
| 7035 | |
| 7036 | |
| 7037 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
| 7038 | int cw_min, int cw_max, int burst_time) |
| 7039 | { |
| 7040 | struct i802_bss *bss = priv; |
| 7041 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7042 | struct nl_msg *msg; |
| 7043 | struct nlattr *txq, *params; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7044 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7045 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7046 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7047 | if (!msg) |
| 7048 | return -1; |
| 7049 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7050 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
| 7051 | if (!txq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7052 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7053 | |
| 7054 | /* We are only sending parameters for a single TXQ at a time */ |
| 7055 | params = nla_nest_start(msg, 1); |
| 7056 | if (!params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7057 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7058 | |
| 7059 | switch (queue) { |
| 7060 | case 0: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7061 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
| 7062 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7063 | break; |
| 7064 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7065 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
| 7066 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7067 | break; |
| 7068 | case 2: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7069 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
| 7070 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7071 | break; |
| 7072 | case 3: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7073 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
| 7074 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7075 | break; |
| 7076 | } |
| 7077 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
| 7078 | * 32 usec, so need to convert the value here. */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7079 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
| 7080 | (burst_time * 100 + 16) / 32) || |
| 7081 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || |
| 7082 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || |
| 7083 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) |
| 7084 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7085 | |
| 7086 | nla_nest_end(msg, params); |
| 7087 | |
| 7088 | nla_nest_end(msg, txq); |
| 7089 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7090 | res = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7091 | wpa_printf(MSG_DEBUG, |
| 7092 | "nl80211: TX queue param set: queue=%d aifs=%d cw_min=%d cw_max=%d burst_time=%d --> res=%d", |
| 7093 | queue, aifs, cw_min, cw_max, burst_time, res); |
| 7094 | if (res == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7095 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7096 | msg = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7097 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7098 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7099 | return -1; |
| 7100 | } |
| 7101 | |
| 7102 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7103 | 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] | 7104 | const char *ifname, int vlan_id) |
| 7105 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7106 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7107 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7108 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7109 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7110 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
| 7111 | ", ifname=%s[%d], vlan_id=%d)", |
| 7112 | bss->ifname, if_nametoindex(bss->ifname), |
| 7113 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7114 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 7115 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7116 | (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD) && |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7117 | nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7118 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { |
| 7119 | nlmsg_free(msg); |
| 7120 | return -ENOBUFS; |
| 7121 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7122 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7123 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7124 | if (ret < 0) { |
| 7125 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" |
| 7126 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", |
| 7127 | MAC2STR(addr), ifname, vlan_id, ret, |
| 7128 | strerror(-ret)); |
| 7129 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7130 | return ret; |
| 7131 | } |
| 7132 | |
| 7133 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7134 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
| 7135 | { |
| 7136 | struct hostap_sta_driver_data data; |
| 7137 | int ret; |
| 7138 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 7139 | os_memset(&data, 0, sizeof(data)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7140 | data.inactive_msec = (unsigned long) -1; |
| 7141 | ret = i802_read_sta_data(priv, &data, addr); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 7142 | if (ret == -ENOENT) |
| 7143 | return -ENOENT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7144 | if (ret || data.inactive_msec == (unsigned long) -1) |
| 7145 | return -1; |
| 7146 | return data.inactive_msec / 1000; |
| 7147 | } |
| 7148 | |
| 7149 | |
| 7150 | static int i802_sta_clear_stats(void *priv, const u8 *addr) |
| 7151 | { |
| 7152 | #if 0 |
| 7153 | /* TODO */ |
| 7154 | #endif |
| 7155 | return 0; |
| 7156 | } |
| 7157 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7158 | |
| 7159 | 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] | 7160 | u16 reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7161 | { |
| 7162 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7163 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7164 | struct ieee80211_mgmt mgmt; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 7165 | u8 channel; |
| 7166 | |
| 7167 | if (ieee80211_freq_to_chan(bss->freq, &channel) == |
| 7168 | HOSTAPD_MODE_IEEE80211AD) { |
| 7169 | /* Deauthentication is not used in DMG/IEEE 802.11ad; |
| 7170 | * disassociate the STA instead. */ |
| 7171 | return i802_sta_disassoc(priv, own_addr, addr, reason); |
| 7172 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7173 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7174 | if (is_mesh_interface(drv->nlmode)) |
| 7175 | return -1; |
| 7176 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7177 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7178 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7179 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7180 | memset(&mgmt, 0, sizeof(mgmt)); |
| 7181 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 7182 | WLAN_FC_STYPE_DEAUTH); |
| 7183 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 7184 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 7185 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 7186 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
| 7187 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 7188 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7189 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7190 | 0, NULL, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7191 | } |
| 7192 | |
| 7193 | |
| 7194 | 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] | 7195 | u16 reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7196 | { |
| 7197 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7198 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7199 | struct ieee80211_mgmt mgmt; |
| 7200 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7201 | if (is_mesh_interface(drv->nlmode)) |
| 7202 | return -1; |
| 7203 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7204 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7205 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7206 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7207 | memset(&mgmt, 0, sizeof(mgmt)); |
| 7208 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 7209 | WLAN_FC_STYPE_DISASSOC); |
| 7210 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 7211 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 7212 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 7213 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
| 7214 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 7215 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7216 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7217 | 0, NULL, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7218 | } |
| 7219 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7220 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7221 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
| 7222 | { |
| 7223 | char buf[200], *pos, *end; |
| 7224 | int i, res; |
| 7225 | |
| 7226 | pos = buf; |
| 7227 | end = pos + sizeof(buf); |
| 7228 | |
| 7229 | for (i = 0; i < drv->num_if_indices; i++) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7230 | if (!drv->if_indices[i].ifindex) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7231 | continue; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7232 | res = os_snprintf(pos, end - pos, " %d(%d)", |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7233 | drv->if_indices[i].ifindex, |
| 7234 | drv->if_indices[i].reason); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7235 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7236 | break; |
| 7237 | pos += res; |
| 7238 | } |
| 7239 | *pos = '\0'; |
| 7240 | |
| 7241 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", |
| 7242 | drv->num_if_indices, buf); |
| 7243 | } |
| 7244 | |
| 7245 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7246 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 7247 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7248 | { |
| 7249 | int i; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7250 | struct drv_nl80211_if_info *old; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7251 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7252 | wpa_printf(MSG_DEBUG, |
| 7253 | "nl80211: Add own interface ifindex %d (ifidx_reason %d)", |
| 7254 | ifidx, ifidx_reason); |
| 7255 | if (have_ifidx(drv, ifidx, ifidx_reason)) { |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7256 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
| 7257 | ifidx); |
| 7258 | return; |
| 7259 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7260 | for (i = 0; i < drv->num_if_indices; i++) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7261 | if (drv->if_indices[i].ifindex == 0) { |
| 7262 | drv->if_indices[i].ifindex = ifidx; |
| 7263 | drv->if_indices[i].reason = ifidx_reason; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7264 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7265 | return; |
| 7266 | } |
| 7267 | } |
| 7268 | |
| 7269 | if (drv->if_indices != drv->default_if_indices) |
| 7270 | old = drv->if_indices; |
| 7271 | else |
| 7272 | old = NULL; |
| 7273 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7274 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7275 | sizeof(*old)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7276 | if (!drv->if_indices) { |
| 7277 | if (!old) |
| 7278 | drv->if_indices = drv->default_if_indices; |
| 7279 | else |
| 7280 | drv->if_indices = old; |
| 7281 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
| 7282 | "interfaces"); |
| 7283 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); |
| 7284 | return; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7285 | } |
| 7286 | if (!old) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7287 | os_memcpy(drv->if_indices, drv->default_if_indices, |
| 7288 | sizeof(drv->default_if_indices)); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7289 | drv->if_indices[drv->num_if_indices].ifindex = ifidx; |
| 7290 | drv->if_indices[drv->num_if_indices].reason = ifidx_reason; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7291 | drv->num_if_indices++; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7292 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7293 | } |
| 7294 | |
| 7295 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7296 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 7297 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7298 | { |
| 7299 | int i; |
| 7300 | |
| 7301 | for (i = 0; i < drv->num_if_indices; i++) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7302 | if ((drv->if_indices[i].ifindex == ifidx || |
| 7303 | ifidx == IFIDX_ANY) && |
| 7304 | (drv->if_indices[i].reason == ifidx_reason || |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7305 | ifidx_reason == IFIDX_ANY)) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7306 | drv->if_indices[i].ifindex = 0; |
| 7307 | drv->if_indices[i].reason = 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7308 | break; |
| 7309 | } |
| 7310 | } |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7311 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7312 | } |
| 7313 | |
| 7314 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7315 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 7316 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7317 | { |
| 7318 | int i; |
| 7319 | |
| 7320 | for (i = 0; i < drv->num_if_indices; i++) |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7321 | if (drv->if_indices[i].ifindex == ifidx && |
| 7322 | (drv->if_indices[i].reason == ifidx_reason || |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7323 | ifidx_reason == IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7324 | return 1; |
| 7325 | |
| 7326 | return 0; |
| 7327 | } |
| 7328 | |
| 7329 | |
| 7330 | 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] | 7331 | const char *bridge_ifname, char *ifname_wds) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7332 | { |
| 7333 | struct i802_bss *bss = priv; |
| 7334 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7335 | char name[IFNAMSIZ + 1]; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7336 | union wpa_event_data event; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 7337 | int ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7338 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 7339 | ret = os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
| 7340 | if (ret >= (int) sizeof(name)) |
| 7341 | wpa_printf(MSG_WARNING, |
| 7342 | "nl80211: WDS interface name was truncated"); |
| 7343 | else if (ret < 0) |
| 7344 | return ret; |
| 7345 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7346 | if (ifname_wds) |
| 7347 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); |
| 7348 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7349 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
| 7350 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); |
| 7351 | if (val) { |
| 7352 | if (!if_nametoindex(name)) { |
| 7353 | if (nl80211_create_iface(drv, name, |
| 7354 | NL80211_IFTYPE_AP_VLAN, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7355 | bss->addr, 1, NULL, NULL, 0) < |
| 7356 | 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7357 | return -1; |
| 7358 | if (bridge_ifname && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7359 | linux_br_add_if(drv->global->ioctl_sock, |
| 7360 | bridge_ifname, name) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7361 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7362 | |
| 7363 | os_memset(&event, 0, sizeof(event)); |
| 7364 | event.wds_sta_interface.sta_addr = addr; |
| 7365 | event.wds_sta_interface.ifname = name; |
| 7366 | event.wds_sta_interface.istatus = INTERFACE_ADDED; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 7367 | wpa_supplicant_event(bss->ctx, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7368 | EVENT_WDS_STA_INTERFACE_STATUS, |
| 7369 | &event); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7370 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7371 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
| 7372 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " |
| 7373 | "interface %s up", name); |
| 7374 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7375 | return i802_set_sta_vlan(priv, addr, name, 0); |
| 7376 | } else { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7377 | if (bridge_ifname && |
| 7378 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, |
| 7379 | name) < 0) |
| 7380 | wpa_printf(MSG_INFO, |
| 7381 | "nl80211: Failed to remove interface %s from bridge %s: %s", |
| 7382 | name, bridge_ifname, strerror(errno)); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7383 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7384 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7385 | nl80211_remove_iface(drv, if_nametoindex(name)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7386 | os_memset(&event, 0, sizeof(event)); |
| 7387 | event.wds_sta_interface.sta_addr = addr; |
| 7388 | event.wds_sta_interface.ifname = name; |
| 7389 | event.wds_sta_interface.istatus = INTERFACE_REMOVED; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 7390 | wpa_supplicant_event(bss->ctx, EVENT_WDS_STA_INTERFACE_STATUS, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7391 | &event); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7392 | return 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7393 | } |
| 7394 | } |
| 7395 | |
| 7396 | |
| 7397 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
| 7398 | { |
| 7399 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 7400 | struct sockaddr_ll lladdr; |
| 7401 | unsigned char buf[3000]; |
| 7402 | int len; |
| 7403 | socklen_t fromlen = sizeof(lladdr); |
| 7404 | |
| 7405 | len = recvfrom(sock, buf, sizeof(buf), 0, |
| 7406 | (struct sockaddr *)&lladdr, &fromlen); |
| 7407 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7408 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
| 7409 | strerror(errno)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7410 | return; |
| 7411 | } |
| 7412 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7413 | if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7414 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
| 7415 | } |
| 7416 | |
| 7417 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7418 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
| 7419 | struct i802_bss *bss, |
| 7420 | const char *brname, const char *ifname) |
| 7421 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7422 | int br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7423 | char in_br[IFNAMSIZ]; |
| 7424 | |
| 7425 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7426 | br_ifindex = if_nametoindex(brname); |
| 7427 | if (br_ifindex == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7428 | /* |
| 7429 | * Bridge was configured, but the bridge device does |
| 7430 | * not exist. Try to add it now. |
| 7431 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7432 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7433 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
| 7434 | "bridge interface %s: %s", |
| 7435 | brname, strerror(errno)); |
| 7436 | return -1; |
| 7437 | } |
| 7438 | bss->added_bridge = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7439 | br_ifindex = if_nametoindex(brname); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7440 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7441 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7442 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7443 | |
| 7444 | if (linux_br_get(in_br, ifname) == 0) { |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 7445 | if (os_strcmp(in_br, brname) == 0) { |
| 7446 | bss->already_in_bridge = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7447 | return 0; /* already in the bridge */ |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 7448 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7449 | |
| 7450 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " |
| 7451 | "bridge %s", ifname, in_br); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7452 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
| 7453 | 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7454 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
| 7455 | "remove interface %s from bridge " |
| 7456 | "%s: %s", |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7457 | ifname, in_br, strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7458 | return -1; |
| 7459 | } |
| 7460 | } |
| 7461 | |
| 7462 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", |
| 7463 | ifname, brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7464 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7465 | wpa_printf(MSG_WARNING, |
| 7466 | "nl80211: Failed to add interface %s into bridge %s: %s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7467 | ifname, brname, strerror(errno)); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7468 | /* Try to continue without the interface being in a bridge. This |
| 7469 | * may be needed for some cases, e.g., with Open vSwitch, where |
| 7470 | * an external component will need to handle bridge |
| 7471 | * configuration. */ |
| 7472 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7473 | } |
| 7474 | bss->added_if_into_bridge = 1; |
| 7475 | |
| 7476 | return 0; |
| 7477 | } |
| 7478 | |
| 7479 | |
| 7480 | static void *i802_init(struct hostapd_data *hapd, |
| 7481 | struct wpa_init_params *params) |
| 7482 | { |
| 7483 | struct wpa_driver_nl80211_data *drv; |
| 7484 | struct i802_bss *bss; |
| 7485 | size_t i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7486 | char master_ifname[IFNAMSIZ]; |
| 7487 | int ifindex, br_ifindex = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7488 | int br_added = 0; |
| 7489 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7490 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
| 7491 | params->global_priv, 1, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7492 | params->bssid, params->driver_params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7493 | if (bss == NULL) |
| 7494 | return NULL; |
| 7495 | |
| 7496 | drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7497 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7498 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7499 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7500 | params->ifname, master_ifname); |
| 7501 | br_ifindex = if_nametoindex(master_ifname); |
| 7502 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 7503 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && |
| 7504 | linux_master_get(master_ifname, params->ifname) == 0) { |
| 7505 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", |
| 7506 | params->ifname, master_ifname); |
| 7507 | /* start listening for EAPOL on the master interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7508 | add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 7509 | |
| 7510 | /* check if master itself is under bridge */ |
| 7511 | if (linux_br_get(master_ifname, master_ifname) == 0) { |
| 7512 | wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s", |
| 7513 | master_ifname); |
| 7514 | br_ifindex = if_nametoindex(master_ifname); |
| 7515 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 7516 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7517 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7518 | master_ifname[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7519 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7520 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7521 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7522 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7523 | for (i = 0; i < params->num_bridge; i++) { |
| 7524 | if (params->bridge[i]) { |
| 7525 | ifindex = if_nametoindex(params->bridge[i]); |
| 7526 | if (ifindex) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7527 | add_ifidx(drv, ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7528 | if (ifindex == br_ifindex) |
| 7529 | br_added = 1; |
| 7530 | } |
| 7531 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7532 | |
| 7533 | /* start listening for EAPOL on the default AP interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7534 | add_ifidx(drv, drv->ifindex, IFIDX_ANY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7535 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7536 | if (params->num_bridge && params->bridge[0]) { |
| 7537 | if (i802_check_bridge(drv, bss, params->bridge[0], |
| 7538 | params->ifname) < 0) |
| 7539 | goto failed; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7540 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7541 | br_added = 1; |
| 7542 | } |
| 7543 | |
| 7544 | if (!br_added && br_ifindex && |
| 7545 | (params->num_bridge == 0 || !params->bridge[0])) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7546 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7547 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7548 | #ifdef CONFIG_LIBNL3_ROUTE |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 7549 | if (bss->added_if_into_bridge || bss->already_in_bridge) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7550 | int err; |
| 7551 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7552 | drv->rtnl_sk = nl_socket_alloc(); |
| 7553 | if (drv->rtnl_sk == NULL) { |
| 7554 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); |
| 7555 | goto failed; |
| 7556 | } |
| 7557 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7558 | err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE); |
| 7559 | if (err) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7560 | 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] | 7561 | nl_geterror(err)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7562 | goto failed; |
| 7563 | } |
| 7564 | } |
| 7565 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 7566 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 7567 | if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) { |
| 7568 | wpa_printf(MSG_DEBUG, |
| 7569 | "nl80211: Do not open EAPOL RX socket - using control port for RX"); |
| 7570 | goto skip_eapol_sock; |
| 7571 | } |
| 7572 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7573 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
| 7574 | if (drv->eapol_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7575 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
| 7576 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7577 | goto failed; |
| 7578 | } |
| 7579 | |
| 7580 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) |
| 7581 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7582 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7583 | goto failed; |
| 7584 | } |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 7585 | skip_eapol_sock: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7586 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7587 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 7588 | params->own_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7589 | goto failed; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7590 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7591 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7592 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
| 7593 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7594 | return bss; |
| 7595 | |
| 7596 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7597 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7598 | return NULL; |
| 7599 | } |
| 7600 | |
| 7601 | |
| 7602 | static void i802_deinit(void *priv) |
| 7603 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7604 | struct i802_bss *bss = priv; |
| 7605 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7606 | } |
| 7607 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7608 | |
| 7609 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
| 7610 | enum wpa_driver_if_type type) |
| 7611 | { |
| 7612 | switch (type) { |
| 7613 | case WPA_IF_STATION: |
| 7614 | return NL80211_IFTYPE_STATION; |
| 7615 | case WPA_IF_P2P_CLIENT: |
| 7616 | case WPA_IF_P2P_GROUP: |
| 7617 | return NL80211_IFTYPE_P2P_CLIENT; |
| 7618 | case WPA_IF_AP_VLAN: |
| 7619 | return NL80211_IFTYPE_AP_VLAN; |
| 7620 | case WPA_IF_AP_BSS: |
| 7621 | return NL80211_IFTYPE_AP; |
| 7622 | case WPA_IF_P2P_GO: |
| 7623 | return NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7624 | case WPA_IF_P2P_DEVICE: |
| 7625 | return NL80211_IFTYPE_P2P_DEVICE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7626 | case WPA_IF_MESH: |
| 7627 | return NL80211_IFTYPE_MESH_POINT; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7628 | default: |
| 7629 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7630 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7631 | } |
| 7632 | |
| 7633 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7634 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
| 7635 | { |
| 7636 | struct wpa_driver_nl80211_data *drv; |
| 7637 | dl_list_for_each(drv, &global->interfaces, |
| 7638 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7639 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7640 | return 1; |
| 7641 | } |
| 7642 | return 0; |
| 7643 | } |
| 7644 | |
| 7645 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7646 | 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] | 7647 | { |
| 7648 | unsigned int idx; |
| 7649 | |
| 7650 | if (!drv->global) |
| 7651 | return -1; |
| 7652 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7653 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7654 | for (idx = 0; idx < 64; idx++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7655 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7656 | new_addr[0] ^= idx << 2; |
| 7657 | if (!nl80211_addr_in_use(drv->global, new_addr)) |
| 7658 | break; |
| 7659 | } |
| 7660 | if (idx == 64) |
| 7661 | return -1; |
| 7662 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7663 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7664 | MACSTR, MAC2STR(new_addr)); |
| 7665 | |
| 7666 | return 0; |
| 7667 | } |
| 7668 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7669 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7670 | struct wdev_info { |
| 7671 | u64 wdev_id; |
| 7672 | int wdev_id_set; |
| 7673 | u8 macaddr[ETH_ALEN]; |
| 7674 | }; |
| 7675 | |
| 7676 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) |
| 7677 | { |
| 7678 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7679 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7680 | struct wdev_info *wi = arg; |
| 7681 | |
| 7682 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7683 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7684 | if (tb[NL80211_ATTR_WDEV]) { |
| 7685 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 7686 | wi->wdev_id_set = 1; |
| 7687 | } |
| 7688 | |
| 7689 | if (tb[NL80211_ATTR_MAC]) |
| 7690 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 7691 | ETH_ALEN); |
| 7692 | |
| 7693 | return NL_SKIP; |
| 7694 | } |
| 7695 | |
| 7696 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7697 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
| 7698 | const char *ifname, const u8 *addr, |
| 7699 | void *bss_ctx, void **drv_priv, |
| 7700 | char *force_ifname, u8 *if_addr, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7701 | const char *bridge, int use_existing, |
| 7702 | int setup_ap) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7703 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7704 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7705 | struct i802_bss *bss = priv; |
| 7706 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7707 | int ifidx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7708 | int added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7709 | |
| 7710 | if (addr) |
| 7711 | os_memcpy(if_addr, addr, ETH_ALEN); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7712 | nlmode = wpa_driver_nl80211_if_type(type); |
| 7713 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 7714 | struct wdev_info p2pdev_info; |
| 7715 | |
| 7716 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); |
| 7717 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
| 7718 | 0, nl80211_wdev_handler, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7719 | &p2pdev_info, use_existing); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7720 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
| 7721 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
| 7722 | ifname); |
| 7723 | return -1; |
| 7724 | } |
| 7725 | |
| 7726 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; |
| 7727 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 7728 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7729 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 7730 | os_memcpy(drv->global->p2p_perm_addr, p2pdev_info.macaddr, ETH_ALEN); |
| 7731 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7732 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", |
| 7733 | ifname, |
| 7734 | (long long unsigned int) p2pdev_info.wdev_id); |
| 7735 | } else { |
| 7736 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7737 | 0, NULL, NULL, use_existing); |
| 7738 | if (use_existing && ifidx == -ENFILE) { |
| 7739 | added = 0; |
| 7740 | ifidx = if_nametoindex(ifname); |
| 7741 | } else if (ifidx < 0) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7742 | return -1; |
| 7743 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7744 | } |
| 7745 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7746 | if (!addr) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 7747 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7748 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
| 7749 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 7750 | ifname, if_addr) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7751 | if (added) |
| 7752 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7753 | return -1; |
| 7754 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7755 | } |
| 7756 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7757 | if (!addr && |
| 7758 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 7759 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
| 7760 | type == WPA_IF_STATION)) { |
| 7761 | /* Enforce unique address */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7762 | u8 new_addr[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7763 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7764 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7765 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 7766 | if (added) |
| 7767 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7768 | return -1; |
| 7769 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7770 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7771 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 7772 | "for interface %s type %d", ifname, type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7773 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 7774 | if (added) |
| 7775 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7776 | return -1; |
| 7777 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7778 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7779 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 7780 | if (added) |
| 7781 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7782 | return -1; |
| 7783 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7784 | } |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 7785 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7786 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7787 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7788 | if (type == WPA_IF_AP_BSS && setup_ap) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7789 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
| 7790 | if (new_bss == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7791 | if (added) |
| 7792 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7793 | return -1; |
| 7794 | } |
| 7795 | |
| 7796 | if (bridge && |
| 7797 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { |
| 7798 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " |
| 7799 | "interface %s to a bridge %s", |
| 7800 | ifname, bridge); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7801 | if (added) |
| 7802 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7803 | os_free(new_bss); |
| 7804 | return -1; |
| 7805 | } |
| 7806 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7807 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
| 7808 | { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 7809 | if (added) |
| 7810 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7811 | os_free(new_bss); |
| 7812 | return -1; |
| 7813 | } |
| 7814 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7815 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7816 | new_bss->ifindex = ifidx; |
| 7817 | new_bss->drv = drv; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7818 | new_bss->next = drv->first_bss->next; |
| 7819 | new_bss->freq = drv->first_bss->freq; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7820 | new_bss->ctx = bss_ctx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7821 | new_bss->added_if = added; |
| 7822 | drv->first_bss->next = new_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7823 | if (drv_priv) |
| 7824 | *drv_priv = new_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7825 | nl80211_init_bss(new_bss); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7826 | |
| 7827 | /* Subscribe management frames for this WPA_IF_AP_BSS */ |
| 7828 | if (nl80211_setup_ap(new_bss)) |
| 7829 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7830 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7831 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7832 | if (drv->global) |
| 7833 | drv->global->if_add_ifindex = ifidx; |
| 7834 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7835 | /* |
| 7836 | * Some virtual interfaces need to process EAPOL packets and events on |
| 7837 | * the parent interface. This is used mainly with hostapd. |
| 7838 | */ |
| 7839 | if (ifidx > 0 && |
| 7840 | (drv->hostapd || |
| 7841 | nlmode == NL80211_IFTYPE_AP_VLAN || |
| 7842 | nlmode == NL80211_IFTYPE_WDS || |
| 7843 | nlmode == NL80211_IFTYPE_MONITOR)) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7844 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7845 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7846 | return 0; |
| 7847 | } |
| 7848 | |
| 7849 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7850 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7851 | enum wpa_driver_if_type type, |
| 7852 | const char *ifname) |
| 7853 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7854 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7855 | int ifindex = if_nametoindex(ifname); |
| 7856 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7857 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
| 7858 | __func__, type, ifname, ifindex, bss->added_if); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 7859 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7860 | nl80211_remove_iface(drv, ifindex); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 7861 | else if (ifindex > 0 && !bss->added_if) { |
| 7862 | struct wpa_driver_nl80211_data *drv2; |
| 7863 | dl_list_for_each(drv2, &drv->global->interfaces, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7864 | struct wpa_driver_nl80211_data, list) { |
| 7865 | del_ifidx(drv2, ifindex, IFIDX_ANY); |
| 7866 | del_ifidx(drv2, IFIDX_ANY, ifindex); |
| 7867 | } |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 7868 | } |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7869 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7870 | if (type != WPA_IF_AP_BSS) |
| 7871 | return 0; |
| 7872 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7873 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7874 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 7875 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7876 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 7877 | "interface %s from bridge %s: %s", |
| 7878 | bss->ifname, bss->brname, strerror(errno)); |
| 7879 | } |
| 7880 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7881 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7882 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 7883 | "bridge %s: %s", |
| 7884 | bss->brname, strerror(errno)); |
| 7885 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7886 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7887 | if (bss != drv->first_bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7888 | struct i802_bss *tbss; |
| 7889 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7890 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
| 7891 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7892 | if (tbss->next == bss) { |
| 7893 | tbss->next = bss->next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7894 | /* Unsubscribe management frames */ |
| 7895 | nl80211_teardown_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7896 | nl80211_destroy_bss(bss); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7897 | if (!bss->added_if) |
| 7898 | i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7899 | os_free(bss); |
| 7900 | bss = NULL; |
| 7901 | break; |
| 7902 | } |
| 7903 | } |
| 7904 | if (bss) |
| 7905 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " |
| 7906 | "BSS %p in the list", __func__, bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7907 | } else { |
| 7908 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
| 7909 | nl80211_teardown_ap(bss); |
| 7910 | if (!bss->added_if && !drv->first_bss->next) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 7911 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7912 | nl80211_destroy_bss(bss); |
| 7913 | if (!bss->added_if) |
| 7914 | i802_set_iface_flags(bss, 0); |
| 7915 | if (drv->first_bss->next) { |
| 7916 | drv->first_bss = drv->first_bss->next; |
| 7917 | drv->ctx = drv->first_bss->ctx; |
| 7918 | os_free(bss); |
| 7919 | } else { |
| 7920 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); |
| 7921 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7922 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7923 | |
| 7924 | return 0; |
| 7925 | } |
| 7926 | |
| 7927 | |
| 7928 | static int cookie_handler(struct nl_msg *msg, void *arg) |
| 7929 | { |
| 7930 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7931 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7932 | u64 *cookie = arg; |
| 7933 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7934 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7935 | if (tb[NL80211_ATTR_COOKIE]) |
| 7936 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 7937 | return NL_SKIP; |
| 7938 | } |
| 7939 | |
| 7940 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7941 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7942 | unsigned int freq, unsigned int wait, |
| 7943 | const u8 *buf, size_t buf_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7944 | int save_cookie, int no_cck, int no_ack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7945 | int offchanok, const u16 *csa_offs, |
| 7946 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7947 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7948 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7949 | struct nl_msg *msg; |
| 7950 | u64 cookie; |
| 7951 | int ret = -1; |
| 7952 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7953 | 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] | 7954 | "no_ack=%d offchanok=%d", |
| 7955 | freq, wait, no_cck, no_ack, offchanok); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7956 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7957 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7958 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
| 7959 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 7960 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || |
| 7961 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 7962 | drv->test_use_roc_tx) && |
| 7963 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || |
| 7964 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || |
| 7965 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7966 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
| 7967 | csa_offs_len * sizeof(u16), csa_offs)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7968 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
| 7969 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7970 | |
| 7971 | cookie = 0; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 7972 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7973 | msg = NULL; |
| 7974 | if (ret) { |
| 7975 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 7976 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
| 7977 | freq, wait); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7978 | } else { |
| 7979 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " |
| 7980 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
| 7981 | (long long unsigned int) cookie); |
| 7982 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7983 | if (save_cookie) |
| 7984 | drv->send_frame_cookie = no_ack ? (u64) -1 : cookie; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7985 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7986 | if (drv->num_send_frame_cookies == MAX_SEND_FRAME_COOKIES) { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7987 | wpa_printf(MSG_DEBUG, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7988 | "nl80211: Drop oldest pending send frame cookie 0x%llx", |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7989 | (long long unsigned int) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7990 | drv->send_frame_cookies[0]); |
| 7991 | os_memmove(&drv->send_frame_cookies[0], |
| 7992 | &drv->send_frame_cookies[1], |
| 7993 | (MAX_SEND_FRAME_COOKIES - 1) * |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7994 | sizeof(u64)); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7995 | drv->num_send_frame_cookies--; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7996 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7997 | drv->send_frame_cookies[drv->num_send_frame_cookies] = cookie; |
| 7998 | drv->num_send_frame_cookies++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7999 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8000 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8001 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8002 | nlmsg_free(msg); |
| 8003 | return ret; |
| 8004 | } |
| 8005 | |
| 8006 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8007 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
| 8008 | unsigned int freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8009 | unsigned int wait_time, |
| 8010 | const u8 *dst, const u8 *src, |
| 8011 | const u8 *bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8012 | const u8 *data, size_t data_len, |
| 8013 | int no_cck) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8014 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8015 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8016 | int ret = -1; |
| 8017 | u8 *buf; |
| 8018 | struct ieee80211_hdr *hdr; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8019 | int offchanok = 1; |
| 8020 | |
Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 8021 | if (is_ap_interface(drv->nlmode) && (int) freq == bss->freq && |
| 8022 | bss->beacon_set) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8023 | offchanok = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8024 | |
| 8025 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8026 | "freq=%u MHz wait=%d ms no_cck=%d offchanok=%d)", |
| 8027 | drv->ifindex, freq, wait_time, no_cck, offchanok); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8028 | |
| 8029 | buf = os_zalloc(24 + data_len); |
| 8030 | if (buf == NULL) |
| 8031 | return ret; |
| 8032 | os_memcpy(buf + 24, data, data_len); |
| 8033 | hdr = (struct ieee80211_hdr *) buf; |
| 8034 | hdr->frame_control = |
| 8035 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); |
| 8036 | os_memcpy(hdr->addr1, dst, ETH_ALEN); |
| 8037 | os_memcpy(hdr->addr2, src, ETH_ALEN); |
| 8038 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); |
| 8039 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 8040 | if (os_memcmp(bss->addr, src, ETH_ALEN) != 0) { |
| 8041 | wpa_printf(MSG_DEBUG, "nl80211: Use random TA " MACSTR, |
| 8042 | MAC2STR(src)); |
| 8043 | os_memcpy(bss->rand_addr, src, ETH_ALEN); |
| 8044 | } else { |
| 8045 | os_memset(bss->rand_addr, 0, ETH_ALEN); |
| 8046 | } |
| 8047 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8048 | if (is_ap_interface(drv->nlmode) && |
| 8049 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 8050 | (int) freq == bss->freq || drv->device_ap_sme || |
| 8051 | !drv->use_monitor)) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8052 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8053 | 0, freq, no_cck, offchanok, |
| 8054 | wait_time, NULL, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8055 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8056 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8057 | 24 + data_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8058 | 1, no_cck, 0, offchanok, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8059 | |
| 8060 | os_free(buf); |
| 8061 | return ret; |
| 8062 | } |
| 8063 | |
| 8064 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8065 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8066 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8067 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8068 | struct nl_msg *msg; |
| 8069 | int ret; |
| 8070 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 8071 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8072 | (long long unsigned int) cookie); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8073 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8074 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8075 | nlmsg_free(msg); |
| 8076 | return; |
| 8077 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8078 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8079 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8080 | if (ret) |
| 8081 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " |
| 8082 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8083 | } |
| 8084 | |
| 8085 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8086 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
| 8087 | { |
| 8088 | struct i802_bss *bss = priv; |
| 8089 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8090 | unsigned int i; |
| 8091 | u64 cookie; |
| 8092 | |
| 8093 | /* Cancel the last pending TX cookie */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8094 | nl80211_frame_wait_cancel(bss, drv->send_frame_cookie); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8095 | |
| 8096 | /* |
| 8097 | * Cancel the other pending TX cookies, if any. This is needed since |
| 8098 | * the driver may keep a list of all pending offchannel TX operations |
| 8099 | * and free up the radio only once they have expired or cancelled. |
| 8100 | */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8101 | for (i = drv->num_send_frame_cookies; i > 0; i--) { |
| 8102 | cookie = drv->send_frame_cookies[i - 1]; |
| 8103 | if (cookie != drv->send_frame_cookie) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8104 | nl80211_frame_wait_cancel(bss, cookie); |
| 8105 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8106 | drv->num_send_frame_cookies = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8107 | } |
| 8108 | |
| 8109 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8110 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
| 8111 | unsigned int duration) |
| 8112 | { |
| 8113 | struct i802_bss *bss = priv; |
| 8114 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8115 | struct nl_msg *msg; |
| 8116 | int ret; |
| 8117 | u64 cookie; |
| 8118 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8119 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
| 8120 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 8121 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { |
| 8122 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8123 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8124 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8125 | |
| 8126 | cookie = 0; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8127 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8128 | if (ret == 0) { |
| 8129 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " |
| 8130 | "0x%llx for freq=%u MHz duration=%u", |
| 8131 | (long long unsigned int) cookie, freq, duration); |
| 8132 | drv->remain_on_chan_cookie = cookie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8133 | drv->pending_remain_on_chan = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8134 | return 0; |
| 8135 | } |
| 8136 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " |
| 8137 | "(freq=%d duration=%u): %d (%s)", |
| 8138 | freq, duration, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8139 | return -1; |
| 8140 | } |
| 8141 | |
| 8142 | |
| 8143 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) |
| 8144 | { |
| 8145 | struct i802_bss *bss = priv; |
| 8146 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8147 | struct nl_msg *msg; |
| 8148 | int ret; |
| 8149 | |
| 8150 | if (!drv->pending_remain_on_chan) { |
| 8151 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " |
| 8152 | "to cancel"); |
| 8153 | return -1; |
| 8154 | } |
| 8155 | |
| 8156 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " |
| 8157 | "0x%llx", |
| 8158 | (long long unsigned int) drv->remain_on_chan_cookie); |
| 8159 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8160 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
| 8161 | if (!msg || |
| 8162 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
| 8163 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8164 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8165 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8166 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8167 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8168 | if (ret == 0) |
| 8169 | return 0; |
| 8170 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " |
| 8171 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8172 | return -1; |
| 8173 | } |
| 8174 | |
| 8175 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8176 | 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] | 8177 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8178 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 8179 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8180 | if (!report) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8181 | if (bss->nl_preq && drv->device_ap_sme && |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 8182 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
| 8183 | !bss->static_ap) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8184 | /* |
| 8185 | * Do not disable Probe Request reporting that was |
| 8186 | * enabled in nl80211_setup_ap(). |
| 8187 | */ |
| 8188 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " |
| 8189 | "Probe Request reporting nl_preq=%p while " |
| 8190 | "in AP mode", bss->nl_preq); |
| 8191 | } else if (bss->nl_preq) { |
| 8192 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
| 8193 | "reporting nl_preq=%p", bss->nl_preq); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8194 | nl80211_destroy_eloop_handle(&bss->nl_preq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8195 | } |
| 8196 | return 0; |
| 8197 | } |
| 8198 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8199 | if (bss->nl_preq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8200 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8201 | "already on! nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8202 | return 0; |
| 8203 | } |
| 8204 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8205 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
| 8206 | if (bss->nl_preq == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8207 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8208 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
| 8209 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8210 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8211 | if (nl80211_register_frame(bss, bss->nl_preq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8212 | (WLAN_FC_TYPE_MGMT << 2) | |
| 8213 | (WLAN_FC_STYPE_PROBE_REQ << 4), |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 8214 | NULL, 0, false) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8215 | goto out_err; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 8216 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8217 | nl80211_register_eloop_read(&bss->nl_preq, |
| 8218 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8219 | bss->nl_cb, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8220 | |
| 8221 | return 0; |
| 8222 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8223 | out_err: |
| 8224 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8225 | return -1; |
| 8226 | } |
| 8227 | |
| 8228 | |
| 8229 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 8230 | int ifindex, int disabled) |
| 8231 | { |
| 8232 | struct nl_msg *msg; |
| 8233 | struct nlattr *bands, *band; |
| 8234 | int ret; |
| 8235 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8236 | wpa_printf(MSG_DEBUG, |
| 8237 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", |
| 8238 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : |
| 8239 | "no NL80211_TXRATE_LEGACY constraint"); |
| 8240 | |
| 8241 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
| 8242 | NL80211_CMD_SET_TX_BITRATE_MASK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8243 | if (!msg) |
| 8244 | return -1; |
| 8245 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8246 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 8247 | if (!bands) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8248 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8249 | |
| 8250 | /* |
| 8251 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything |
| 8252 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS |
| 8253 | * rates. All 5 GHz rates are left enabled. |
| 8254 | */ |
| 8255 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8256 | if (!band || |
| 8257 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, |
| 8258 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) |
| 8259 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8260 | nla_nest_end(msg, band); |
| 8261 | |
| 8262 | nla_nest_end(msg, bands); |
| 8263 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8264 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8265 | if (ret) { |
| 8266 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " |
| 8267 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8268 | } else |
| 8269 | drv->disabled_11b_rates = disabled; |
| 8270 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8271 | return ret; |
| 8272 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8273 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8274 | nlmsg_free(msg); |
| 8275 | return -1; |
| 8276 | } |
| 8277 | |
| 8278 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8279 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
| 8280 | { |
| 8281 | struct i802_bss *bss = priv; |
| 8282 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8283 | if (!is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8284 | return -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8285 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8286 | bss->beacon_set = 0; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8287 | |
| 8288 | /* |
| 8289 | * If the P2P GO interface was dynamically added, then it is |
| 8290 | * possible that the interface change to station is not possible. |
| 8291 | */ |
| 8292 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) |
| 8293 | return 0; |
| 8294 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8295 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8296 | } |
| 8297 | |
| 8298 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8299 | static int wpa_driver_nl80211_stop_ap(void *priv) |
| 8300 | { |
| 8301 | struct i802_bss *bss = priv; |
| 8302 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8303 | if (!is_ap_interface(drv->nlmode)) |
| 8304 | return -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8305 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8306 | bss->beacon_set = 0; |
| 8307 | return 0; |
| 8308 | } |
| 8309 | |
| 8310 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8311 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
| 8312 | { |
| 8313 | struct i802_bss *bss = priv; |
| 8314 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8315 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) |
| 8316 | return -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8317 | |
| 8318 | /* |
| 8319 | * If the P2P Client interface was dynamically added, then it is |
| 8320 | * possible that the interface change to station is not possible. |
| 8321 | */ |
| 8322 | if (bss->if_dynamic) |
| 8323 | return 0; |
| 8324 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8325 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
| 8326 | } |
| 8327 | |
| 8328 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8329 | static void wpa_driver_nl80211_resume(void *priv) |
| 8330 | { |
| 8331 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8332 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8333 | |
| 8334 | if (i802_set_iface_flags(bss, 1)) |
| 8335 | 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] | 8336 | |
| 8337 | if (is_p2p_net_interface(nlmode)) |
| 8338 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8339 | } |
| 8340 | |
| 8341 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8342 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
| 8343 | { |
| 8344 | struct i802_bss *bss = priv; |
| 8345 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8346 | struct nl_msg *msg; |
| 8347 | struct nlattr *cqm; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8348 | |
| 8349 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " |
| 8350 | "hysteresis=%d", threshold, hysteresis); |
| 8351 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8352 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
| 8353 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
| 8354 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || |
| 8355 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { |
| 8356 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8357 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8358 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8359 | nla_nest_end(msg, cqm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8360 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8361 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8362 | } |
| 8363 | |
| 8364 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8365 | static int get_channel_width(struct nl_msg *msg, void *arg) |
| 8366 | { |
| 8367 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8368 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8369 | struct wpa_signal_info *sig_change = arg; |
| 8370 | |
| 8371 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8372 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8373 | |
| 8374 | sig_change->center_frq1 = -1; |
| 8375 | sig_change->center_frq2 = -1; |
| 8376 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 8377 | |
| 8378 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 8379 | sig_change->chanwidth = convert2width( |
| 8380 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 8381 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 8382 | sig_change->center_frq1 = |
| 8383 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 8384 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 8385 | sig_change->center_frq2 = |
| 8386 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 8387 | } |
| 8388 | |
| 8389 | return NL_SKIP; |
| 8390 | } |
| 8391 | |
| 8392 | |
| 8393 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, |
| 8394 | struct wpa_signal_info *sig) |
| 8395 | { |
| 8396 | struct nl_msg *msg; |
| 8397 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8398 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8399 | 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] | 8400 | } |
| 8401 | |
| 8402 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8403 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
| 8404 | { |
| 8405 | struct i802_bss *bss = priv; |
| 8406 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8407 | int res; |
| 8408 | |
| 8409 | os_memset(si, 0, sizeof(*si)); |
| 8410 | res = nl80211_get_link_signal(drv, si); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8411 | if (res) { |
| 8412 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && |
| 8413 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
| 8414 | return res; |
| 8415 | si->current_signal = 0; |
| 8416 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8417 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8418 | res = nl80211_get_channel_width(drv, si); |
| 8419 | if (res != 0) |
| 8420 | return res; |
| 8421 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8422 | return nl80211_get_link_noise(drv, si); |
| 8423 | } |
| 8424 | |
| 8425 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8426 | static int nl80211_set_param(void *priv, const char *param) |
| 8427 | { |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 8428 | struct i802_bss *bss = priv; |
| 8429 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8430 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8431 | if (param == NULL) |
| 8432 | return 0; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 8433 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8434 | |
| 8435 | #ifdef CONFIG_P2P |
| 8436 | if (os_strstr(param, "use_p2p_group_interface=1")) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8437 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 8438 | "interface"); |
| 8439 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 8440 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 8441 | } |
| 8442 | #endif /* CONFIG_P2P */ |
| 8443 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 8444 | if (os_strstr(param, "use_monitor=1")) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8445 | drv->use_monitor = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8446 | |
| 8447 | if (os_strstr(param, "force_connect_cmd=1")) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8448 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8449 | drv->force_connect_cmd = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8450 | } |
| 8451 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 8452 | if (os_strstr(param, "force_bss_selection=1")) |
| 8453 | drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
| 8454 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 8455 | if (os_strstr(param, "no_offchannel_tx=1")) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 8456 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 8457 | drv->test_use_roc_tx = 1; |
| 8458 | } |
| 8459 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 8460 | if (os_strstr(param, "control_port=0")) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8461 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_CONTROL_PORT; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8462 | drv->capa.flags2 &= ~(WPA_DRIVER_FLAGS2_CONTROL_PORT_RX | |
| 8463 | WPA_DRIVER_FLAGS2_CONTROL_PORT_TX_STATUS); |
| 8464 | drv->control_port_ap = 0; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 8465 | } |
| 8466 | |
| 8467 | if (os_strstr(param, "control_port_ap=1")) |
| 8468 | drv->control_port_ap = 1; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8469 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8470 | if (os_strstr(param, "control_port_ap=0")) { |
| 8471 | drv->capa.flags2 &= ~WPA_DRIVER_FLAGS2_CONTROL_PORT_TX_STATUS; |
| 8472 | drv->control_port_ap = 0; |
| 8473 | } |
| 8474 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8475 | if (os_strstr(param, "full_ap_client_state=0")) |
| 8476 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE; |
| 8477 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8478 | if (os_strstr(param, "no_rrm=1")) { |
| 8479 | drv->no_rrm = 1; |
| 8480 | |
| 8481 | if (!bss->in_deinit && !is_ap_interface(drv->nlmode) && |
| 8482 | !is_mesh_interface(drv->nlmode)) { |
| 8483 | nl80211_mgmt_unsubscribe(bss, "no_rrm=1"); |
| 8484 | if (nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 8485 | wpa_printf(MSG_DEBUG, |
| 8486 | "nl80211: Failed to re-register Action frame processing - ignore for now"); |
| 8487 | } |
| 8488 | } |
| 8489 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8490 | return 0; |
| 8491 | } |
| 8492 | |
| 8493 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 8494 | static void * nl80211_global_init(void *ctx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8495 | { |
| 8496 | struct nl80211_global *global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8497 | struct netlink_config *cfg; |
| 8498 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8499 | global = os_zalloc(sizeof(*global)); |
| 8500 | if (global == NULL) |
| 8501 | return NULL; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 8502 | global->ctx = ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8503 | global->ioctl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8504 | dl_list_init(&global->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8505 | global->if_add_ifindex = -1; |
| 8506 | |
| 8507 | cfg = os_zalloc(sizeof(*cfg)); |
| 8508 | if (cfg == NULL) |
| 8509 | goto err; |
| 8510 | |
| 8511 | cfg->ctx = global; |
| 8512 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; |
| 8513 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; |
| 8514 | global->netlink = netlink_init(cfg); |
| 8515 | if (global->netlink == NULL) { |
| 8516 | os_free(cfg); |
| 8517 | goto err; |
| 8518 | } |
| 8519 | |
| 8520 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
| 8521 | goto err; |
| 8522 | |
| 8523 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 8524 | if (global->ioctl_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8525 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
| 8526 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8527 | goto err; |
| 8528 | } |
| 8529 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8530 | return global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8531 | |
| 8532 | err: |
| 8533 | nl80211_global_deinit(global); |
| 8534 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8535 | } |
| 8536 | |
| 8537 | |
| 8538 | static void nl80211_global_deinit(void *priv) |
| 8539 | { |
| 8540 | struct nl80211_global *global = priv; |
| 8541 | if (global == NULL) |
| 8542 | return; |
| 8543 | if (!dl_list_empty(&global->interfaces)) { |
| 8544 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " |
| 8545 | "nl80211_global_deinit", |
| 8546 | dl_list_len(&global->interfaces)); |
| 8547 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8548 | |
| 8549 | if (global->netlink) |
| 8550 | netlink_deinit(global->netlink); |
| 8551 | |
| 8552 | nl_destroy_handles(&global->nl); |
| 8553 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8554 | if (global->nl_event) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8555 | nl80211_destroy_eloop_handle(&global->nl_event, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8556 | |
| 8557 | nl_cb_put(global->nl_cb); |
| 8558 | |
| 8559 | if (global->ioctl_sock >= 0) |
| 8560 | close(global->ioctl_sock); |
| 8561 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8562 | os_free(global); |
| 8563 | } |
| 8564 | |
| 8565 | |
| 8566 | static const char * nl80211_get_radio_name(void *priv) |
| 8567 | { |
| 8568 | struct i802_bss *bss = priv; |
| 8569 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8570 | return drv->phyname; |
| 8571 | } |
| 8572 | |
| 8573 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8574 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, |
| 8575 | struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8576 | { |
| 8577 | struct nl_msg *msg; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8578 | const size_t PMK_MAX_LEN = 48; /* current cfg80211 limit */ |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8579 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8580 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8581 | (params->pmkid && |
| 8582 | nla_put(msg, NL80211_ATTR_PMKID, 16, params->pmkid)) || |
| 8583 | (params->bssid && |
| 8584 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) || |
| 8585 | (params->ssid_len && |
| 8586 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || |
| 8587 | (params->fils_cache_id && |
| 8588 | nla_put(msg, NL80211_ATTR_FILS_CACHE_ID, 2, |
| 8589 | params->fils_cache_id)) || |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8590 | (params->pmk_lifetime && |
| 8591 | nla_put_u32(msg, NL80211_ATTR_PMK_LIFETIME, |
| 8592 | params->pmk_lifetime)) || |
| 8593 | (params->pmk_reauth_threshold && |
| 8594 | nla_put_u8(msg, NL80211_ATTR_PMK_REAUTH_THRESHOLD, |
| 8595 | params->pmk_reauth_threshold)) || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 8596 | (cmd != NL80211_CMD_DEL_PMKSA && |
| 8597 | params->pmk_len && params->pmk_len <= PMK_MAX_LEN && |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8598 | nla_put(msg, NL80211_ATTR_PMK, params->pmk_len, params->pmk))) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8599 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8600 | nlmsg_free(msg); |
| 8601 | return -ENOBUFS; |
| 8602 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8603 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8604 | return send_and_recv_msgs(bss->drv, msg, NULL, (void *) -1, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8605 | } |
| 8606 | |
| 8607 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8608 | static int nl80211_add_pmkid(void *priv, struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8609 | { |
| 8610 | struct i802_bss *bss = priv; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8611 | int ret; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8612 | |
| 8613 | if (params->bssid) |
| 8614 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, |
| 8615 | MAC2STR(params->bssid)); |
| 8616 | else if (params->fils_cache_id && params->ssid_len) { |
| 8617 | wpa_printf(MSG_DEBUG, |
| 8618 | "nl80211: Add PMKSA for cache id %02x%02x SSID %s", |
| 8619 | params->fils_cache_id[0], params->fils_cache_id[1], |
| 8620 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
| 8621 | } |
| 8622 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8623 | ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params); |
| 8624 | if (ret < 0) { |
| 8625 | wpa_printf(MSG_DEBUG, |
| 8626 | "nl80211: NL80211_CMD_SET_PMKSA failed: %d (%s)", |
| 8627 | ret, strerror(-ret)); |
| 8628 | } |
| 8629 | |
| 8630 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8631 | } |
| 8632 | |
| 8633 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8634 | static int nl80211_remove_pmkid(void *priv, struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8635 | { |
| 8636 | struct i802_bss *bss = priv; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8637 | int ret; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8638 | |
| 8639 | if (params->bssid) |
| 8640 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, |
| 8641 | MAC2STR(params->bssid)); |
| 8642 | else if (params->fils_cache_id && params->ssid_len) { |
| 8643 | wpa_printf(MSG_DEBUG, |
| 8644 | "nl80211: Delete PMKSA for cache id %02x%02x SSID %s", |
| 8645 | params->fils_cache_id[0], params->fils_cache_id[1], |
| 8646 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
| 8647 | } |
| 8648 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8649 | ret = nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, params); |
| 8650 | if (ret < 0) { |
| 8651 | wpa_printf(MSG_DEBUG, |
| 8652 | "nl80211: NL80211_CMD_DEL_PMKSA failed: %d (%s)", |
| 8653 | ret, strerror(-ret)); |
| 8654 | } |
| 8655 | |
| 8656 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8657 | } |
| 8658 | |
| 8659 | |
| 8660 | static int nl80211_flush_pmkid(void *priv) |
| 8661 | { |
| 8662 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8663 | struct nl_msg *msg; |
| 8664 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8665 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8666 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_FLUSH_PMKSA); |
| 8667 | if (!msg) |
| 8668 | return -ENOBUFS; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8669 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8670 | } |
| 8671 | |
| 8672 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8673 | static void clean_survey_results(struct survey_results *survey_results) |
| 8674 | { |
| 8675 | struct freq_survey *survey, *tmp; |
| 8676 | |
| 8677 | if (dl_list_empty(&survey_results->survey_list)) |
| 8678 | return; |
| 8679 | |
| 8680 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 8681 | struct freq_survey, list) { |
| 8682 | dl_list_del(&survey->list); |
| 8683 | os_free(survey); |
| 8684 | } |
| 8685 | } |
| 8686 | |
| 8687 | |
| 8688 | static void add_survey(struct nlattr **sinfo, u32 ifidx, |
| 8689 | struct dl_list *survey_list) |
| 8690 | { |
| 8691 | struct freq_survey *survey; |
| 8692 | |
| 8693 | survey = os_zalloc(sizeof(struct freq_survey)); |
| 8694 | if (!survey) |
| 8695 | return; |
| 8696 | |
| 8697 | survey->ifidx = ifidx; |
| 8698 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 8699 | survey->filled = 0; |
| 8700 | |
| 8701 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { |
| 8702 | survey->nf = (int8_t) |
| 8703 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 8704 | survey->filled |= SURVEY_HAS_NF; |
| 8705 | } |
| 8706 | |
| 8707 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { |
| 8708 | survey->channel_time = |
| 8709 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); |
| 8710 | survey->filled |= SURVEY_HAS_CHAN_TIME; |
| 8711 | } |
| 8712 | |
| 8713 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { |
| 8714 | survey->channel_time_busy = |
| 8715 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); |
| 8716 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; |
| 8717 | } |
| 8718 | |
| 8719 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { |
| 8720 | survey->channel_time_rx = |
| 8721 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); |
| 8722 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; |
| 8723 | } |
| 8724 | |
| 8725 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { |
| 8726 | survey->channel_time_tx = |
| 8727 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); |
| 8728 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; |
| 8729 | } |
| 8730 | |
| 8731 | 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)", |
| 8732 | survey->freq, |
| 8733 | survey->nf, |
| 8734 | (unsigned long int) survey->channel_time, |
| 8735 | (unsigned long int) survey->channel_time_busy, |
| 8736 | (unsigned long int) survey->channel_time_tx, |
| 8737 | (unsigned long int) survey->channel_time_rx, |
| 8738 | survey->filled); |
| 8739 | |
| 8740 | dl_list_add_tail(survey_list, &survey->list); |
| 8741 | } |
| 8742 | |
| 8743 | |
| 8744 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, |
| 8745 | unsigned int freq_filter) |
| 8746 | { |
| 8747 | if (!freq_filter) |
| 8748 | return 1; |
| 8749 | |
| 8750 | return freq_filter == surveyed_freq; |
| 8751 | } |
| 8752 | |
| 8753 | |
| 8754 | static int survey_handler(struct nl_msg *msg, void *arg) |
| 8755 | { |
| 8756 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8757 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8758 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 8759 | struct survey_results *survey_results; |
| 8760 | u32 surveyed_freq = 0; |
| 8761 | u32 ifidx; |
| 8762 | |
| 8763 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 8764 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 8765 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 8766 | }; |
| 8767 | |
| 8768 | survey_results = (struct survey_results *) arg; |
| 8769 | |
| 8770 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8771 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8772 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 8773 | if (!tb[NL80211_ATTR_IFINDEX]) |
| 8774 | return NL_SKIP; |
| 8775 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8776 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 8777 | |
| 8778 | if (!tb[NL80211_ATTR_SURVEY_INFO]) |
| 8779 | return NL_SKIP; |
| 8780 | |
| 8781 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 8782 | tb[NL80211_ATTR_SURVEY_INFO], |
| 8783 | survey_policy)) |
| 8784 | return NL_SKIP; |
| 8785 | |
| 8786 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { |
| 8787 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); |
| 8788 | return NL_SKIP; |
| 8789 | } |
| 8790 | |
| 8791 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 8792 | |
| 8793 | if (!check_survey_ok(sinfo, surveyed_freq, |
| 8794 | survey_results->freq_filter)) |
| 8795 | return NL_SKIP; |
| 8796 | |
| 8797 | if (survey_results->freq_filter && |
| 8798 | survey_results->freq_filter != surveyed_freq) { |
| 8799 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", |
| 8800 | surveyed_freq); |
| 8801 | return NL_SKIP; |
| 8802 | } |
| 8803 | |
| 8804 | add_survey(sinfo, ifidx, &survey_results->survey_list); |
| 8805 | |
| 8806 | return NL_SKIP; |
| 8807 | } |
| 8808 | |
| 8809 | |
| 8810 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) |
| 8811 | { |
| 8812 | struct i802_bss *bss = priv; |
| 8813 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8814 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8815 | int err; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8816 | union wpa_event_data data; |
| 8817 | struct survey_results *survey_results; |
| 8818 | |
| 8819 | os_memset(&data, 0, sizeof(data)); |
| 8820 | survey_results = &data.survey_results; |
| 8821 | |
| 8822 | dl_list_init(&survey_results->survey_list); |
| 8823 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8824 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8825 | if (!msg) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8826 | return -ENOBUFS; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8827 | |
| 8828 | if (freq) |
| 8829 | data.survey_results.freq_filter = freq; |
| 8830 | |
| 8831 | do { |
| 8832 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); |
| 8833 | err = send_and_recv_msgs(drv, msg, survey_handler, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8834 | survey_results, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8835 | } while (err > 0); |
| 8836 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8837 | if (err) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8838 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8839 | else |
| 8840 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8841 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8842 | clean_survey_results(survey_results); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8843 | return err; |
| 8844 | } |
| 8845 | |
| 8846 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 8847 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
| 8848 | const u8 *kck, size_t kck_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8849 | const u8 *replay_ctr) |
| 8850 | { |
| 8851 | struct i802_bss *bss = priv; |
| 8852 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8853 | struct nlattr *replay_nested; |
| 8854 | struct nl_msg *msg; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8855 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8856 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8857 | if (!drv->set_rekey_offload) |
| 8858 | return; |
| 8859 | |
| 8860 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8861 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
| 8862 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 8863 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8864 | (kck_len && nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8865 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
| 8866 | replay_ctr)) { |
| 8867 | nl80211_nlmsg_clear(msg); |
| 8868 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8869 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8870 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8871 | |
| 8872 | nla_nest_end(msg, replay_nested); |
| 8873 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8874 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1, NULL, NULL); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8875 | if (ret == -EOPNOTSUPP) { |
| 8876 | wpa_printf(MSG_DEBUG, |
| 8877 | "nl80211: Driver does not support rekey offload"); |
| 8878 | drv->set_rekey_offload = 0; |
| 8879 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8880 | } |
| 8881 | |
| 8882 | |
| 8883 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
| 8884 | const u8 *addr, int qos) |
| 8885 | { |
| 8886 | /* send data frame to poll STA and check whether |
| 8887 | * this frame is ACKed */ |
| 8888 | struct { |
| 8889 | struct ieee80211_hdr hdr; |
| 8890 | u16 qos_ctl; |
| 8891 | } STRUCT_PACKED nulldata; |
| 8892 | size_t size; |
| 8893 | |
| 8894 | /* Send data frame to poll STA and check whether this frame is ACKed */ |
| 8895 | |
| 8896 | os_memset(&nulldata, 0, sizeof(nulldata)); |
| 8897 | |
| 8898 | if (qos) { |
| 8899 | nulldata.hdr.frame_control = |
| 8900 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 8901 | WLAN_FC_STYPE_QOS_NULL); |
| 8902 | size = sizeof(nulldata); |
| 8903 | } else { |
| 8904 | nulldata.hdr.frame_control = |
| 8905 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 8906 | WLAN_FC_STYPE_NULLFUNC); |
| 8907 | size = sizeof(struct ieee80211_hdr); |
| 8908 | } |
| 8909 | |
| 8910 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 8911 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 8912 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 8913 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 8914 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8915 | 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] | 8916 | 0, 0, NULL, 0, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8917 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
| 8918 | "send poll frame"); |
| 8919 | } |
| 8920 | |
| 8921 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
| 8922 | int qos) |
| 8923 | { |
| 8924 | struct i802_bss *bss = priv; |
| 8925 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8926 | struct nl_msg *msg; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 8927 | u64 cookie; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8928 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8929 | |
| 8930 | if (!drv->poll_command_supported) { |
| 8931 | nl80211_send_null_frame(bss, own_addr, addr, qos); |
| 8932 | return; |
| 8933 | } |
| 8934 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8935 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
| 8936 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 8937 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8938 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8939 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8940 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8941 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie, NULL, NULL); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8942 | if (ret < 0) { |
| 8943 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " |
| 8944 | MACSTR " failed: ret=%d (%s)", |
| 8945 | MAC2STR(addr), ret, strerror(-ret)); |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 8946 | } else { |
| 8947 | wpa_printf(MSG_DEBUG, |
| 8948 | "nl80211: Client probe request addr=" MACSTR |
| 8949 | " cookie=%llu", MAC2STR(addr), |
| 8950 | (long long unsigned int) cookie); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8951 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8952 | } |
| 8953 | |
| 8954 | |
| 8955 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
| 8956 | { |
| 8957 | struct nl_msg *msg; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8958 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8959 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8960 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
| 8961 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
| 8962 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { |
| 8963 | nlmsg_free(msg); |
| 8964 | return -ENOBUFS; |
| 8965 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8966 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 8967 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL, NULL, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8968 | if (ret < 0) { |
| 8969 | wpa_printf(MSG_DEBUG, |
| 8970 | "nl80211: Setting PS state %s failed: %d (%s)", |
| 8971 | enabled ? "enabled" : "disabled", |
| 8972 | ret, strerror(-ret)); |
| 8973 | } |
| 8974 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8975 | } |
| 8976 | |
| 8977 | |
| 8978 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, |
| 8979 | int ctwindow) |
| 8980 | { |
| 8981 | struct i802_bss *bss = priv; |
| 8982 | |
| 8983 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " |
| 8984 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); |
| 8985 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8986 | if (opp_ps != -1 || ctwindow != -1) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8987 | #ifdef ANDROID_P2P |
| 8988 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8989 | #else /* ANDROID_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8990 | return -1; /* Not yet supported */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8991 | #endif /* ANDROID_P2P */ |
| 8992 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8993 | |
| 8994 | if (legacy_ps == -1) |
| 8995 | return 0; |
| 8996 | if (legacy_ps != 0 && legacy_ps != 1) |
| 8997 | return -1; /* Not yet supported */ |
| 8998 | |
| 8999 | return nl80211_set_power_save(bss, legacy_ps); |
| 9000 | } |
| 9001 | |
| 9002 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 9003 | static int nl80211_start_radar_detection(void *priv, |
| 9004 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9005 | { |
| 9006 | struct i802_bss *bss = priv; |
| 9007 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9008 | struct nl_msg *msg; |
| 9009 | int ret; |
| 9010 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 9011 | 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)", |
| 9012 | freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 9013 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 9014 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9015 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
| 9016 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " |
| 9017 | "detection"); |
| 9018 | return -1; |
| 9019 | } |
| 9020 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9021 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
| 9022 | nl80211_put_freq_params(msg, freq) < 0) { |
| 9023 | nlmsg_free(msg); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9024 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9025 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9026 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9027 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9028 | if (ret == 0) |
| 9029 | return 0; |
| 9030 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " |
| 9031 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9032 | return -1; |
| 9033 | } |
| 9034 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9035 | #ifdef CONFIG_TDLS |
| 9036 | |
| 9037 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, |
| 9038 | u8 dialog_token, u16 status_code, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 9039 | u32 peer_capab, int initiator, const u8 *buf, |
| 9040 | size_t len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9041 | { |
| 9042 | struct i802_bss *bss = priv; |
| 9043 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9044 | struct nl_msg *msg; |
| 9045 | |
| 9046 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 9047 | return -EOPNOTSUPP; |
| 9048 | |
| 9049 | if (!dst) |
| 9050 | return -EINVAL; |
| 9051 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9052 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
| 9053 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 9054 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || |
| 9055 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || |
| 9056 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) |
| 9057 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 9058 | if (peer_capab) { |
| 9059 | /* |
| 9060 | * The internal enum tdls_peer_capability definition is |
| 9061 | * currently identical with the nl80211 enum |
| 9062 | * nl80211_tdls_peer_capability, so no conversion is needed |
| 9063 | * here. |
| 9064 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9065 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
| 9066 | peer_capab)) |
| 9067 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 9068 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9069 | if ((initiator && |
| 9070 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || |
| 9071 | nla_put(msg, NL80211_ATTR_IE, len, buf)) |
| 9072 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9073 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9074 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9075 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9076 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9077 | nlmsg_free(msg); |
| 9078 | return -ENOBUFS; |
| 9079 | } |
| 9080 | |
| 9081 | |
| 9082 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) |
| 9083 | { |
| 9084 | struct i802_bss *bss = priv; |
| 9085 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9086 | struct nl_msg *msg; |
| 9087 | enum nl80211_tdls_operation nl80211_oper; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9088 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9089 | |
| 9090 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 9091 | return -EOPNOTSUPP; |
| 9092 | |
| 9093 | switch (oper) { |
| 9094 | case TDLS_DISCOVERY_REQ: |
| 9095 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; |
| 9096 | break; |
| 9097 | case TDLS_SETUP: |
| 9098 | nl80211_oper = NL80211_TDLS_SETUP; |
| 9099 | break; |
| 9100 | case TDLS_TEARDOWN: |
| 9101 | nl80211_oper = NL80211_TDLS_TEARDOWN; |
| 9102 | break; |
| 9103 | case TDLS_ENABLE_LINK: |
| 9104 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; |
| 9105 | break; |
| 9106 | case TDLS_DISABLE_LINK: |
| 9107 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; |
| 9108 | break; |
| 9109 | case TDLS_ENABLE: |
| 9110 | return 0; |
| 9111 | case TDLS_DISABLE: |
| 9112 | return 0; |
| 9113 | default: |
| 9114 | return -EINVAL; |
| 9115 | } |
| 9116 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9117 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
| 9118 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
| 9119 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
| 9120 | nlmsg_free(msg); |
| 9121 | return -ENOBUFS; |
| 9122 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9123 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9124 | res = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 9125 | wpa_printf(MSG_DEBUG, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR |
| 9126 | " --> res=%d (%s)", nl80211_oper, MAC2STR(peer), res, |
| 9127 | strerror(-res)); |
| 9128 | return res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9129 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9130 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9131 | |
| 9132 | static int |
| 9133 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, |
| 9134 | const struct hostapd_freq_params *params) |
| 9135 | { |
| 9136 | struct i802_bss *bss = priv; |
| 9137 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9138 | struct nl_msg *msg; |
| 9139 | int ret = -ENOBUFS; |
| 9140 | |
| 9141 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 9142 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 9143 | return -EOPNOTSUPP; |
| 9144 | |
| 9145 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR |
| 9146 | " oper_class=%u freq=%u", |
| 9147 | MAC2STR(addr), oper_class, params->freq); |
| 9148 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); |
| 9149 | if (!msg || |
| 9150 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 9151 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || |
| 9152 | (ret = nl80211_put_freq_params(msg, params))) { |
| 9153 | nlmsg_free(msg); |
| 9154 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); |
| 9155 | return ret; |
| 9156 | } |
| 9157 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9158 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9159 | } |
| 9160 | |
| 9161 | |
| 9162 | static int |
| 9163 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) |
| 9164 | { |
| 9165 | struct i802_bss *bss = priv; |
| 9166 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9167 | struct nl_msg *msg; |
| 9168 | |
| 9169 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 9170 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 9171 | return -EOPNOTSUPP; |
| 9172 | |
| 9173 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, |
| 9174 | MAC2STR(addr)); |
| 9175 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); |
| 9176 | if (!msg || |
| 9177 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 9178 | nlmsg_free(msg); |
| 9179 | wpa_printf(MSG_DEBUG, |
| 9180 | "nl80211: Could not build TDLS cancel chan switch"); |
| 9181 | return -ENOBUFS; |
| 9182 | } |
| 9183 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9184 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9185 | } |
| 9186 | |
| 9187 | #endif /* CONFIG TDLS */ |
| 9188 | |
| 9189 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9190 | static int driver_nl80211_set_key(void *priv, |
| 9191 | struct wpa_driver_set_key_params *params) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9192 | { |
| 9193 | struct i802_bss *bss = priv; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9194 | |
| 9195 | return wpa_driver_nl80211_set_key(bss, params); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9196 | } |
| 9197 | |
| 9198 | |
| 9199 | static int driver_nl80211_scan2(void *priv, |
| 9200 | struct wpa_driver_scan_params *params) |
| 9201 | { |
| 9202 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9203 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 9204 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9205 | |
| 9206 | /* |
| 9207 | * Do a vendor specific scan if possible. If only_new_results is |
| 9208 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush |
| 9209 | * cannot be achieved through a vendor scan. The below condition may |
| 9210 | * need to be modified if new scan flags are added in the future whose |
| 9211 | * functionality can only be achieved through a normal scan. |
| 9212 | */ |
| 9213 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) |
| 9214 | return wpa_driver_nl80211_vendor_scan(bss, params); |
| 9215 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9216 | return wpa_driver_nl80211_scan(bss, params); |
| 9217 | } |
| 9218 | |
| 9219 | |
| 9220 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 9221 | u16 reason_code) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9222 | { |
| 9223 | struct i802_bss *bss = priv; |
| 9224 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); |
| 9225 | } |
| 9226 | |
| 9227 | |
| 9228 | static int driver_nl80211_authenticate(void *priv, |
| 9229 | struct wpa_driver_auth_params *params) |
| 9230 | { |
| 9231 | struct i802_bss *bss = priv; |
| 9232 | return wpa_driver_nl80211_authenticate(bss, params); |
| 9233 | } |
| 9234 | |
| 9235 | |
| 9236 | static void driver_nl80211_deinit(void *priv) |
| 9237 | { |
| 9238 | struct i802_bss *bss = priv; |
| 9239 | wpa_driver_nl80211_deinit(bss); |
| 9240 | } |
| 9241 | |
| 9242 | |
| 9243 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, |
| 9244 | const char *ifname) |
| 9245 | { |
| 9246 | struct i802_bss *bss = priv; |
| 9247 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 9248 | } |
| 9249 | |
| 9250 | |
| 9251 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 9252 | size_t data_len, int noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9253 | unsigned int freq, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9254 | const u16 *csa_offs, size_t csa_offs_len, |
| 9255 | int no_encrypt, unsigned int wait) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9256 | { |
| 9257 | struct i802_bss *bss = priv; |
| 9258 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9259 | freq, 0, 0, wait, csa_offs, |
| 9260 | csa_offs_len, no_encrypt); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9261 | } |
| 9262 | |
| 9263 | |
| 9264 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) |
| 9265 | { |
| 9266 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9267 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9268 | } |
| 9269 | |
| 9270 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9271 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
| 9272 | const char *ifname, int vlan_id) |
| 9273 | { |
| 9274 | struct i802_bss *bss = priv; |
| 9275 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); |
| 9276 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9277 | |
| 9278 | |
| 9279 | static int driver_nl80211_read_sta_data(void *priv, |
| 9280 | struct hostap_sta_driver_data *data, |
| 9281 | const u8 *addr) |
| 9282 | { |
| 9283 | struct i802_bss *bss = priv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 9284 | |
| 9285 | os_memset(data, 0, sizeof(*data)); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9286 | return i802_read_sta_data(bss, data, addr); |
| 9287 | } |
| 9288 | |
| 9289 | |
| 9290 | static int driver_nl80211_send_action(void *priv, unsigned int freq, |
| 9291 | unsigned int wait_time, |
| 9292 | const u8 *dst, const u8 *src, |
| 9293 | const u8 *bssid, |
| 9294 | const u8 *data, size_t data_len, |
| 9295 | int no_cck) |
| 9296 | { |
| 9297 | struct i802_bss *bss = priv; |
| 9298 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, |
| 9299 | bssid, data, data_len, no_cck); |
| 9300 | } |
| 9301 | |
| 9302 | |
| 9303 | static int driver_nl80211_probe_req_report(void *priv, int report) |
| 9304 | { |
| 9305 | struct i802_bss *bss = priv; |
| 9306 | return wpa_driver_nl80211_probe_req_report(bss, report); |
| 9307 | } |
| 9308 | |
| 9309 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 9310 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
| 9311 | const u8 *ies, size_t ies_len) |
| 9312 | { |
| 9313 | int ret; |
| 9314 | struct nl_msg *msg; |
| 9315 | struct i802_bss *bss = priv; |
| 9316 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9317 | u16 mdid = WPA_GET_LE16(md); |
| 9318 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 9319 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9320 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
| 9321 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
| 9322 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { |
| 9323 | nlmsg_free(msg); |
| 9324 | return -ENOBUFS; |
| 9325 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 9326 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9327 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 9328 | if (ret) { |
| 9329 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " |
| 9330 | "err=%d (%s)", ret, strerror(-ret)); |
| 9331 | } |
| 9332 | |
| 9333 | return ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 9334 | } |
| 9335 | |
| 9336 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 9337 | static int nl80211_update_dh_ie(void *priv, const u8 *peer_mac, |
| 9338 | u16 reason_code, const u8 *ie, size_t ie_len) |
| 9339 | { |
| 9340 | int ret; |
| 9341 | struct nl_msg *msg; |
| 9342 | struct i802_bss *bss = priv; |
| 9343 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9344 | |
| 9345 | wpa_printf(MSG_DEBUG, "nl80211: Updating DH IE peer: " MACSTR |
| 9346 | " reason %u", MAC2STR(peer_mac), reason_code); |
| 9347 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UPDATE_OWE_INFO)) || |
| 9348 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer_mac) || |
| 9349 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, reason_code) || |
| 9350 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) { |
| 9351 | nlmsg_free(msg); |
| 9352 | return -ENOBUFS; |
| 9353 | } |
| 9354 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9355 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 9356 | if (ret) { |
| 9357 | wpa_printf(MSG_DEBUG, |
| 9358 | "nl80211: update_dh_ie failed err=%d (%s)", |
| 9359 | ret, strerror(-ret)); |
| 9360 | } |
| 9361 | |
| 9362 | return ret; |
| 9363 | } |
| 9364 | |
| 9365 | |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 9366 | static const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9367 | { |
| 9368 | struct i802_bss *bss = priv; |
| 9369 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9370 | |
| 9371 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 9372 | return NULL; |
| 9373 | |
| 9374 | return bss->addr; |
| 9375 | } |
| 9376 | |
| 9377 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9378 | static const char * scan_state_str(enum scan_states scan_state) |
| 9379 | { |
| 9380 | switch (scan_state) { |
| 9381 | case NO_SCAN: |
| 9382 | return "NO_SCAN"; |
| 9383 | case SCAN_REQUESTED: |
| 9384 | return "SCAN_REQUESTED"; |
| 9385 | case SCAN_STARTED: |
| 9386 | return "SCAN_STARTED"; |
| 9387 | case SCAN_COMPLETED: |
| 9388 | return "SCAN_COMPLETED"; |
| 9389 | case SCAN_ABORTED: |
| 9390 | return "SCAN_ABORTED"; |
| 9391 | case SCHED_SCAN_STARTED: |
| 9392 | return "SCHED_SCAN_STARTED"; |
| 9393 | case SCHED_SCAN_STOPPED: |
| 9394 | return "SCHED_SCAN_STOPPED"; |
| 9395 | case SCHED_SCAN_RESULTS: |
| 9396 | return "SCHED_SCAN_RESULTS"; |
| 9397 | } |
| 9398 | |
| 9399 | return "??"; |
| 9400 | } |
| 9401 | |
| 9402 | |
| 9403 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) |
| 9404 | { |
| 9405 | struct i802_bss *bss = priv; |
| 9406 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9407 | int res; |
| 9408 | char *pos, *end; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9409 | struct nl_msg *msg; |
| 9410 | char alpha2[3] = { 0, 0, 0 }; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9411 | |
| 9412 | pos = buf; |
| 9413 | end = buf + buflen; |
| 9414 | |
| 9415 | res = os_snprintf(pos, end - pos, |
| 9416 | "ifindex=%d\n" |
| 9417 | "ifname=%s\n" |
| 9418 | "brname=%s\n" |
| 9419 | "addr=" MACSTR "\n" |
| 9420 | "freq=%d\n" |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 9421 | "%s%s%s%s%s%s", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9422 | bss->ifindex, |
| 9423 | bss->ifname, |
| 9424 | bss->brname, |
| 9425 | MAC2STR(bss->addr), |
| 9426 | bss->freq, |
| 9427 | bss->beacon_set ? "beacon_set=1\n" : "", |
| 9428 | bss->added_if_into_bridge ? |
| 9429 | "added_if_into_bridge=1\n" : "", |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 9430 | bss->already_in_bridge ? "already_in_bridge=1\n" : "", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9431 | bss->added_bridge ? "added_bridge=1\n" : "", |
| 9432 | bss->in_deinit ? "in_deinit=1\n" : "", |
| 9433 | bss->if_dynamic ? "if_dynamic=1\n" : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9434 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9435 | return pos - buf; |
| 9436 | pos += res; |
| 9437 | |
| 9438 | if (bss->wdev_id_set) { |
| 9439 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", |
| 9440 | (unsigned long long) bss->wdev_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9441 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9442 | return pos - buf; |
| 9443 | pos += res; |
| 9444 | } |
| 9445 | |
| 9446 | res = os_snprintf(pos, end - pos, |
| 9447 | "phyname=%s\n" |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9448 | "perm_addr=" MACSTR "\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9449 | "drv_ifindex=%d\n" |
| 9450 | "operstate=%d\n" |
| 9451 | "scan_state=%s\n" |
| 9452 | "auth_bssid=" MACSTR "\n" |
| 9453 | "auth_attempt_bssid=" MACSTR "\n" |
| 9454 | "bssid=" MACSTR "\n" |
| 9455 | "prev_bssid=" MACSTR "\n" |
| 9456 | "associated=%d\n" |
| 9457 | "assoc_freq=%u\n" |
| 9458 | "monitor_sock=%d\n" |
| 9459 | "monitor_ifidx=%d\n" |
| 9460 | "monitor_refcount=%d\n" |
| 9461 | "last_mgmt_freq=%u\n" |
| 9462 | "eapol_tx_sock=%d\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9463 | "%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] | 9464 | drv->phyname, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9465 | MAC2STR(drv->perm_addr), |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9466 | drv->ifindex, |
| 9467 | drv->operstate, |
| 9468 | scan_state_str(drv->scan_state), |
| 9469 | MAC2STR(drv->auth_bssid), |
| 9470 | MAC2STR(drv->auth_attempt_bssid), |
| 9471 | MAC2STR(drv->bssid), |
| 9472 | MAC2STR(drv->prev_bssid), |
| 9473 | drv->associated, |
| 9474 | drv->assoc_freq, |
| 9475 | drv->monitor_sock, |
| 9476 | drv->monitor_ifidx, |
| 9477 | drv->monitor_refcount, |
| 9478 | drv->last_mgmt_freq, |
| 9479 | drv->eapol_tx_sock, |
| 9480 | drv->ignore_if_down_event ? |
| 9481 | "ignore_if_down_event=1\n" : "", |
| 9482 | drv->scan_complete_events ? |
| 9483 | "scan_complete_events=1\n" : "", |
| 9484 | drv->disabled_11b_rates ? |
| 9485 | "disabled_11b_rates=1\n" : "", |
| 9486 | drv->pending_remain_on_chan ? |
| 9487 | "pending_remain_on_chan=1\n" : "", |
| 9488 | drv->in_interface_list ? "in_interface_list=1\n" : "", |
| 9489 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", |
| 9490 | drv->poll_command_supported ? |
| 9491 | "poll_command_supported=1\n" : "", |
| 9492 | drv->data_tx_status ? "data_tx_status=1\n" : "", |
| 9493 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", |
| 9494 | drv->retry_auth ? "retry_auth=1\n" : "", |
| 9495 | drv->use_monitor ? "use_monitor=1\n" : "", |
| 9496 | drv->ignore_next_local_disconnect ? |
| 9497 | "ignore_next_local_disconnect=1\n" : "", |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 9498 | drv->ignore_next_local_deauth ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9499 | "ignore_next_local_deauth=1\n" : ""); |
| 9500 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9501 | return pos - buf; |
| 9502 | pos += res; |
| 9503 | |
| 9504 | if (drv->has_capability) { |
| 9505 | res = os_snprintf(pos, end - pos, |
| 9506 | "capa.key_mgmt=0x%x\n" |
| 9507 | "capa.enc=0x%x\n" |
| 9508 | "capa.auth=0x%x\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9509 | "capa.flags=0x%llx\n" |
| 9510 | "capa.rrm_flags=0x%x\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9511 | "capa.max_scan_ssids=%d\n" |
| 9512 | "capa.max_sched_scan_ssids=%d\n" |
| 9513 | "capa.sched_scan_supported=%d\n" |
| 9514 | "capa.max_match_sets=%d\n" |
| 9515 | "capa.max_remain_on_chan=%u\n" |
| 9516 | "capa.max_stations=%u\n" |
| 9517 | "capa.probe_resp_offloads=0x%x\n" |
| 9518 | "capa.max_acl_mac_addrs=%u\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9519 | "capa.num_multichan_concurrent=%u\n" |
| 9520 | "capa.mac_addr_rand_sched_scan_supported=%d\n" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9521 | "capa.mac_addr_rand_scan_supported=%d\n" |
| 9522 | "capa.conc_capab=%u\n" |
| 9523 | "capa.max_conc_chan_2_4=%u\n" |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9524 | "capa.max_conc_chan_5_0=%u\n" |
| 9525 | "capa.max_sched_scan_plans=%u\n" |
| 9526 | "capa.max_sched_scan_plan_interval=%u\n" |
| 9527 | "capa.max_sched_scan_plan_iterations=%u\n", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9528 | drv->capa.key_mgmt, |
| 9529 | drv->capa.enc, |
| 9530 | drv->capa.auth, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9531 | (unsigned long long) drv->capa.flags, |
| 9532 | drv->capa.rrm_flags, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9533 | drv->capa.max_scan_ssids, |
| 9534 | drv->capa.max_sched_scan_ssids, |
| 9535 | drv->capa.sched_scan_supported, |
| 9536 | drv->capa.max_match_sets, |
| 9537 | drv->capa.max_remain_on_chan, |
| 9538 | drv->capa.max_stations, |
| 9539 | drv->capa.probe_resp_offloads, |
| 9540 | drv->capa.max_acl_mac_addrs, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9541 | drv->capa.num_multichan_concurrent, |
| 9542 | drv->capa.mac_addr_rand_sched_scan_supported, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9543 | drv->capa.mac_addr_rand_scan_supported, |
| 9544 | drv->capa.conc_capab, |
| 9545 | drv->capa.max_conc_chan_2_4, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9546 | drv->capa.max_conc_chan_5_0, |
| 9547 | drv->capa.max_sched_scan_plans, |
| 9548 | drv->capa.max_sched_scan_plan_interval, |
| 9549 | drv->capa.max_sched_scan_plan_iterations); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9550 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9551 | return pos - buf; |
| 9552 | pos += res; |
| 9553 | } |
| 9554 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9555 | msg = nlmsg_alloc(); |
| 9556 | if (msg && |
| 9557 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG) && |
| 9558 | nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx) == 0) { |
| 9559 | if (send_and_recv_msgs(drv, msg, nl80211_get_country, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9560 | alpha2, NULL, NULL) == 0 && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9561 | alpha2[0]) { |
| 9562 | res = os_snprintf(pos, end - pos, "country=%s\n", |
| 9563 | alpha2); |
| 9564 | if (os_snprintf_error(end - pos, res)) |
| 9565 | return pos - buf; |
| 9566 | pos += res; |
| 9567 | } |
| 9568 | } else { |
| 9569 | nlmsg_free(msg); |
| 9570 | } |
| 9571 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9572 | return pos - buf; |
| 9573 | } |
| 9574 | |
| 9575 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9576 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
| 9577 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9578 | if ((settings->head && |
| 9579 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, |
| 9580 | settings->head_len, settings->head)) || |
| 9581 | (settings->tail && |
| 9582 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, |
| 9583 | settings->tail_len, settings->tail)) || |
| 9584 | (settings->beacon_ies && |
| 9585 | nla_put(msg, NL80211_ATTR_IE, |
| 9586 | settings->beacon_ies_len, settings->beacon_ies)) || |
| 9587 | (settings->proberesp_ies && |
| 9588 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 9589 | settings->proberesp_ies_len, settings->proberesp_ies)) || |
| 9590 | (settings->assocresp_ies && |
| 9591 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 9592 | settings->assocresp_ies_len, settings->assocresp_ies)) || |
| 9593 | (settings->probe_resp && |
| 9594 | nla_put(msg, NL80211_ATTR_PROBE_RESP, |
| 9595 | settings->probe_resp_len, settings->probe_resp))) |
| 9596 | return -ENOBUFS; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9597 | |
| 9598 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9599 | } |
| 9600 | |
| 9601 | |
| 9602 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) |
| 9603 | { |
| 9604 | struct nl_msg *msg; |
| 9605 | struct i802_bss *bss = priv; |
| 9606 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9607 | struct nlattr *beacon_csa; |
| 9608 | int ret = -ENOBUFS; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9609 | int csa_off_len = 0; |
| 9610 | int i; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9611 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 9612 | wpa_printf(MSG_DEBUG, "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d width=%d cf1=%d cf2=%d)", |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9613 | settings->cs_count, settings->block_tx, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 9614 | settings->freq_params.freq, settings->freq_params.bandwidth, |
| 9615 | settings->freq_params.center_freq1, |
| 9616 | settings->freq_params.center_freq2); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9617 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9618 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9619 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
| 9620 | return -EOPNOTSUPP; |
| 9621 | } |
| 9622 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9623 | if (drv->nlmode != NL80211_IFTYPE_AP && |
| 9624 | drv->nlmode != NL80211_IFTYPE_P2P_GO && |
| 9625 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9626 | return -EOPNOTSUPP; |
| 9627 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9628 | /* |
| 9629 | * Remove empty counters, assuming Probe Response and Beacon frame |
| 9630 | * counters match. This implementation assumes that there are only two |
| 9631 | * counters. |
| 9632 | */ |
| 9633 | if (settings->counter_offset_beacon[0] && |
| 9634 | !settings->counter_offset_beacon[1]) { |
| 9635 | csa_off_len = 1; |
| 9636 | } else if (settings->counter_offset_beacon[1] && |
| 9637 | !settings->counter_offset_beacon[0]) { |
| 9638 | csa_off_len = 1; |
| 9639 | settings->counter_offset_beacon[0] = |
| 9640 | settings->counter_offset_beacon[1]; |
| 9641 | settings->counter_offset_presp[0] = |
| 9642 | settings->counter_offset_presp[1]; |
| 9643 | } else if (settings->counter_offset_beacon[1] && |
| 9644 | settings->counter_offset_beacon[0]) { |
| 9645 | csa_off_len = 2; |
| 9646 | } else { |
| 9647 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); |
| 9648 | return -EINVAL; |
| 9649 | } |
| 9650 | |
| 9651 | /* Check CSA counters validity */ |
| 9652 | if (drv->capa.max_csa_counters && |
| 9653 | csa_off_len > drv->capa.max_csa_counters) { |
| 9654 | wpa_printf(MSG_ERROR, |
| 9655 | "nl80211: Too many CSA counters provided"); |
| 9656 | return -EINVAL; |
| 9657 | } |
| 9658 | |
| 9659 | if (!settings->beacon_csa.tail) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9660 | return -EINVAL; |
| 9661 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9662 | for (i = 0; i < csa_off_len; i++) { |
| 9663 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; |
| 9664 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; |
| 9665 | |
| 9666 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || |
| 9667 | (settings->beacon_csa.tail[csa_c_off_bcn] != |
| 9668 | settings->cs_count)) |
| 9669 | return -EINVAL; |
| 9670 | |
| 9671 | if (settings->beacon_csa.probe_resp && |
| 9672 | ((settings->beacon_csa.probe_resp_len <= |
| 9673 | csa_c_off_presp) || |
| 9674 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != |
| 9675 | settings->cs_count))) |
| 9676 | return -EINVAL; |
| 9677 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9678 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9679 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
| 9680 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
| 9681 | settings->cs_count) || |
| 9682 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || |
| 9683 | (settings->block_tx && |
| 9684 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9685 | goto error; |
| 9686 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9687 | /* beacon_after params */ |
| 9688 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 9689 | if (ret) |
| 9690 | goto error; |
| 9691 | |
| 9692 | /* beacon_csa params */ |
| 9693 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); |
| 9694 | if (!beacon_csa) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9695 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9696 | |
| 9697 | ret = set_beacon_data(msg, &settings->beacon_csa); |
| 9698 | if (ret) |
| 9699 | goto error; |
| 9700 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9701 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
| 9702 | csa_off_len * sizeof(u16), |
| 9703 | settings->counter_offset_beacon) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9704 | (settings->beacon_csa.probe_resp && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9705 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
| 9706 | csa_off_len * sizeof(u16), |
| 9707 | settings->counter_offset_presp))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9708 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9709 | |
| 9710 | nla_nest_end(msg, beacon_csa); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9711 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9712 | if (ret) { |
| 9713 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", |
| 9714 | ret, strerror(-ret)); |
| 9715 | } |
| 9716 | return ret; |
| 9717 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9718 | fail: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9719 | ret = -ENOBUFS; |
| 9720 | error: |
| 9721 | nlmsg_free(msg); |
| 9722 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); |
| 9723 | return ret; |
| 9724 | } |
| 9725 | |
| 9726 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9727 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
| 9728 | u8 user_priority, u16 admitted_time) |
| 9729 | { |
| 9730 | struct i802_bss *bss = priv; |
| 9731 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9732 | struct nl_msg *msg; |
| 9733 | int ret; |
| 9734 | |
| 9735 | wpa_printf(MSG_DEBUG, |
| 9736 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", |
| 9737 | tsid, admitted_time, user_priority); |
| 9738 | |
| 9739 | if (!is_sta_interface(drv->nlmode)) |
| 9740 | return -ENOTSUP; |
| 9741 | |
| 9742 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
| 9743 | if (!msg || |
| 9744 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 9745 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 9746 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || |
| 9747 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { |
| 9748 | nlmsg_free(msg); |
| 9749 | return -ENOBUFS; |
| 9750 | } |
| 9751 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9752 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9753 | if (ret) |
| 9754 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", |
| 9755 | ret, strerror(-ret)); |
| 9756 | return ret; |
| 9757 | } |
| 9758 | |
| 9759 | |
| 9760 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) |
| 9761 | { |
| 9762 | struct i802_bss *bss = priv; |
| 9763 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9764 | struct nl_msg *msg; |
| 9765 | int ret; |
| 9766 | |
| 9767 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); |
| 9768 | |
| 9769 | if (!is_sta_interface(drv->nlmode)) |
| 9770 | return -ENOTSUP; |
| 9771 | |
| 9772 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
| 9773 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 9774 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 9775 | nlmsg_free(msg); |
| 9776 | return -ENOBUFS; |
| 9777 | } |
| 9778 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9779 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9780 | if (ret) |
| 9781 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", |
| 9782 | ret, strerror(-ret)); |
| 9783 | return ret; |
| 9784 | } |
| 9785 | |
| 9786 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9787 | #ifdef CONFIG_TESTING_OPTIONS |
| 9788 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) |
| 9789 | { |
| 9790 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9791 | struct wpabuf *buf = arg; |
| 9792 | |
| 9793 | if (!buf) |
| 9794 | return NL_SKIP; |
| 9795 | |
| 9796 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { |
| 9797 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); |
| 9798 | return NL_SKIP; |
| 9799 | } |
| 9800 | |
| 9801 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), |
| 9802 | genlmsg_attrlen(gnlh, 0)); |
| 9803 | |
| 9804 | return NL_SKIP; |
| 9805 | } |
| 9806 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 9807 | |
| 9808 | |
| 9809 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
| 9810 | { |
| 9811 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9812 | struct nlattr *nl_vendor_reply, *nl; |
| 9813 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9814 | struct wpabuf *buf = arg; |
| 9815 | int rem; |
| 9816 | |
| 9817 | if (!buf) |
| 9818 | return NL_SKIP; |
| 9819 | |
| 9820 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9821 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9822 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; |
| 9823 | |
| 9824 | if (!nl_vendor_reply) |
| 9825 | return NL_SKIP; |
| 9826 | |
| 9827 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { |
| 9828 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); |
| 9829 | return NL_SKIP; |
| 9830 | } |
| 9831 | |
| 9832 | nla_for_each_nested(nl, nl_vendor_reply, rem) { |
| 9833 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); |
| 9834 | } |
| 9835 | |
| 9836 | return NL_SKIP; |
| 9837 | } |
| 9838 | |
| 9839 | |
| 9840 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, |
| 9841 | unsigned int subcmd, const u8 *data, |
| 9842 | size_t data_len, struct wpabuf *buf) |
| 9843 | { |
| 9844 | struct i802_bss *bss = priv; |
| 9845 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9846 | struct nl_msg *msg; |
| 9847 | int ret; |
| 9848 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9849 | #ifdef CONFIG_TESTING_OPTIONS |
| 9850 | if (vendor_id == 0xffffffff) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9851 | msg = nlmsg_alloc(); |
| 9852 | if (!msg) |
| 9853 | return -ENOMEM; |
| 9854 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9855 | nl80211_cmd(drv, msg, 0, subcmd); |
| 9856 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < |
| 9857 | 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9858 | goto fail; |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 9859 | /* This test vendor_cmd can be used with nl80211 commands that |
| 9860 | * need the connect nl_sock, so use the owner-setting variant |
| 9861 | * of send_and_recv_msgs(). */ |
| 9862 | ret = send_and_recv_msgs_owner(drv, msg, |
| 9863 | get_connect_handle(bss), 0, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9864 | cmd_reply_handler, buf, |
| 9865 | NULL, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9866 | if (ret) |
| 9867 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", |
| 9868 | ret); |
| 9869 | return ret; |
| 9870 | } |
| 9871 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 9872 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9873 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 9874 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
| 9875 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || |
| 9876 | (data && |
| 9877 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) |
| 9878 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9879 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9880 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf, |
| 9881 | NULL, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9882 | if (ret) |
| 9883 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", |
| 9884 | ret); |
| 9885 | return ret; |
| 9886 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9887 | fail: |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9888 | nlmsg_free(msg); |
| 9889 | return -ENOBUFS; |
| 9890 | } |
| 9891 | |
| 9892 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9893 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
| 9894 | u8 qos_map_set_len) |
| 9895 | { |
| 9896 | struct i802_bss *bss = priv; |
| 9897 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9898 | struct nl_msg *msg; |
| 9899 | int ret; |
| 9900 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9901 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
| 9902 | qos_map_set, qos_map_set_len); |
| 9903 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9904 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
| 9905 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
| 9906 | nlmsg_free(msg); |
| 9907 | return -ENOBUFS; |
| 9908 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9909 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9910 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9911 | if (ret) |
| 9912 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); |
| 9913 | |
| 9914 | return ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9915 | } |
| 9916 | |
| 9917 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9918 | static int get_wowlan_handler(struct nl_msg *msg, void *arg) |
| 9919 | { |
| 9920 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9921 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9922 | int *wowlan_enabled = arg; |
| 9923 | |
| 9924 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9925 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9926 | |
| 9927 | *wowlan_enabled = !!tb[NL80211_ATTR_WOWLAN_TRIGGERS]; |
| 9928 | |
| 9929 | return NL_SKIP; |
| 9930 | } |
| 9931 | |
| 9932 | |
| 9933 | static int nl80211_get_wowlan(void *priv) |
| 9934 | { |
| 9935 | struct i802_bss *bss = priv; |
| 9936 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9937 | struct nl_msg *msg; |
| 9938 | int wowlan_enabled; |
| 9939 | int ret; |
| 9940 | |
| 9941 | wpa_printf(MSG_DEBUG, "nl80211: Getting wowlan status"); |
| 9942 | |
| 9943 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_WOWLAN); |
| 9944 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9945 | ret = send_and_recv_msgs(drv, msg, get_wowlan_handler, &wowlan_enabled, |
| 9946 | NULL, NULL); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9947 | if (ret) { |
| 9948 | wpa_printf(MSG_DEBUG, "nl80211: Getting wowlan status failed"); |
| 9949 | return 0; |
| 9950 | } |
| 9951 | |
| 9952 | wpa_printf(MSG_DEBUG, "nl80211: wowlan is %s", |
| 9953 | wowlan_enabled ? "enabled" : "disabled"); |
| 9954 | |
| 9955 | return wowlan_enabled; |
| 9956 | } |
| 9957 | |
| 9958 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9959 | static int nl80211_set_wowlan(void *priv, |
| 9960 | const struct wowlan_triggers *triggers) |
| 9961 | { |
| 9962 | struct i802_bss *bss = priv; |
| 9963 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9964 | struct nl_msg *msg; |
| 9965 | struct nlattr *wowlan_triggers; |
| 9966 | int ret; |
| 9967 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9968 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
| 9969 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 9970 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9971 | !(wowlan_triggers = nla_nest_start(msg, |
| 9972 | NL80211_ATTR_WOWLAN_TRIGGERS)) || |
| 9973 | (triggers->any && |
| 9974 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 9975 | (triggers->disconnect && |
| 9976 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 9977 | (triggers->magic_pkt && |
| 9978 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 9979 | (triggers->gtk_rekey_failure && |
| 9980 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 9981 | (triggers->eap_identity_req && |
| 9982 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 9983 | (triggers->four_way_handshake && |
| 9984 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 9985 | (triggers->rfkill_release && |
| 9986 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { |
| 9987 | nlmsg_free(msg); |
| 9988 | return -ENOBUFS; |
| 9989 | } |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9990 | |
| 9991 | nla_nest_end(msg, wowlan_triggers); |
| 9992 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 9993 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9994 | if (ret) |
| 9995 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); |
| 9996 | |
| 9997 | return ret; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9998 | } |
| 9999 | |
| 10000 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10001 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10002 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
| 10003 | { |
| 10004 | struct i802_bss *bss = priv; |
| 10005 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10006 | struct nl_msg *msg; |
| 10007 | struct nlattr *params; |
| 10008 | |
| 10009 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); |
| 10010 | |
| 10011 | if (!drv->roaming_vendor_cmd_avail) { |
| 10012 | wpa_printf(MSG_DEBUG, |
| 10013 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); |
| 10014 | return -1; |
| 10015 | } |
| 10016 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10017 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10018 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10019 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10020 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || |
| 10021 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10022 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, |
| 10023 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : |
| 10024 | QCA_ROAMING_NOT_ALLOWED) || |
| 10025 | (bssid && |
| 10026 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { |
| 10027 | nlmsg_free(msg); |
| 10028 | return -1; |
| 10029 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10030 | nla_nest_end(msg, params); |
| 10031 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10032 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10033 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10034 | |
| 10035 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10036 | static int nl80211_disable_fils(void *priv, int disable) |
| 10037 | { |
| 10038 | struct i802_bss *bss = priv; |
| 10039 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10040 | struct nl_msg *msg; |
| 10041 | struct nlattr *params; |
| 10042 | |
| 10043 | wpa_printf(MSG_DEBUG, "nl80211: Disable FILS=%d", disable); |
| 10044 | |
| 10045 | if (!drv->set_wifi_conf_vendor_cmd_avail) |
| 10046 | return -1; |
| 10047 | |
| 10048 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10049 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10050 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10051 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) || |
| 10052 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10053 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS, |
| 10054 | disable)) { |
| 10055 | nlmsg_free(msg); |
| 10056 | return -1; |
| 10057 | } |
| 10058 | nla_nest_end(msg, params); |
| 10059 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10060 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10061 | } |
| 10062 | |
| 10063 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10064 | /* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */ |
| 10065 | #define WPA_SUPPLICANT_CLIENT_ID 1 |
| 10066 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10067 | static int nl80211_set_bssid_tmp_disallow(void *priv, unsigned int num_bssid, |
| 10068 | const u8 *bssid) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10069 | { |
| 10070 | struct i802_bss *bss = priv; |
| 10071 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10072 | struct nl_msg *msg; |
| 10073 | struct nlattr *params, *nlbssids, *attr; |
| 10074 | unsigned int i; |
| 10075 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10076 | wpa_printf(MSG_DEBUG, |
| 10077 | "nl80211: Set temporarily disallowed BSSIDs (num=%u)", |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10078 | num_bssid); |
| 10079 | |
| 10080 | if (!drv->roam_vendor_cmd_avail) |
| 10081 | return -1; |
| 10082 | |
| 10083 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10084 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10085 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10086 | QCA_NL80211_VENDOR_SUBCMD_ROAM) || |
| 10087 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10088 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 10089 | QCA_WLAN_VENDOR_ROAMING_SUBCMD_SET_BLACKLIST_BSSID) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10090 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID, |
| 10091 | WPA_SUPPLICANT_CLIENT_ID) || |
| 10092 | nla_put_u32(msg, |
| 10093 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID, |
| 10094 | num_bssid)) |
| 10095 | goto fail; |
| 10096 | |
| 10097 | nlbssids = nla_nest_start( |
| 10098 | msg, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS); |
| 10099 | if (!nlbssids) |
| 10100 | goto fail; |
| 10101 | |
| 10102 | for (i = 0; i < num_bssid; i++) { |
| 10103 | attr = nla_nest_start(msg, i); |
| 10104 | if (!attr) |
| 10105 | goto fail; |
| 10106 | if (nla_put(msg, |
| 10107 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID, |
| 10108 | ETH_ALEN, &bssid[i * ETH_ALEN])) |
| 10109 | goto fail; |
| 10110 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%u]: " MACSTR, i, |
| 10111 | MAC2STR(&bssid[i * ETH_ALEN])); |
| 10112 | nla_nest_end(msg, attr); |
| 10113 | } |
| 10114 | nla_nest_end(msg, nlbssids); |
| 10115 | nla_nest_end(msg, params); |
| 10116 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10117 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10118 | |
| 10119 | fail: |
| 10120 | nlmsg_free(msg); |
| 10121 | return -1; |
| 10122 | } |
| 10123 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 10124 | |
| 10125 | static int nl80211_add_sta_node(void *priv, const u8 *addr, u16 auth_alg) |
| 10126 | { |
| 10127 | struct i802_bss *bss = priv; |
| 10128 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10129 | struct nl_msg *msg; |
| 10130 | struct nlattr *params; |
| 10131 | |
| 10132 | if (!drv->add_sta_node_vendor_cmd_avail) |
| 10133 | return -EOPNOTSUPP; |
| 10134 | |
| 10135 | wpa_printf(MSG_DEBUG, "nl80211: Add STA node"); |
| 10136 | |
| 10137 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10138 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10139 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10140 | QCA_NL80211_VENDOR_SUBCMD_ADD_STA_NODE) || |
| 10141 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10142 | (addr && |
| 10143 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_MAC_ADDR, ETH_ALEN, |
| 10144 | addr)) || |
| 10145 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_AUTH_ALGO, |
| 10146 | auth_alg)) { |
| 10147 | nlmsg_free(msg); |
| 10148 | wpa_printf(MSG_ERROR, |
| 10149 | "%s: err in adding vendor_cmd and vendor_data", |
| 10150 | __func__); |
| 10151 | return -1; |
| 10152 | } |
| 10153 | nla_nest_end(msg, params); |
| 10154 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10155 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 10156 | } |
| 10157 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10158 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10159 | |
| 10160 | |
| 10161 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
| 10162 | { |
| 10163 | struct i802_bss *bss = priv; |
| 10164 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10165 | int new_addr = addr != NULL; |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 10166 | #ifdef CONFIG_DRIVER_NL80211_BRCM |
| 10167 | struct nl_msg *msg; |
| 10168 | struct nlattr *params; |
| 10169 | int ret; |
| 10170 | #endif /* CONFIG_DRIVER_NL80211_BRCM */ |
| 10171 | wpa_printf(MSG_DEBUG, "Enter: %s", __FUNCTION__); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10172 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10173 | if (TEST_FAIL()) |
| 10174 | return -1; |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 10175 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 10176 | #ifdef CONFIG_DRIVER_NL80211_BRCM |
| 10177 | if (!addr ) { |
| 10178 | addr = drv->global->p2p_perm_addr; |
| 10179 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10180 | |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 10181 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 10182 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_BRCM) || |
| 10183 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10184 | BRCM_VENDOR_SUBCMD_SET_MAC) || |
| 10185 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10186 | nla_put(msg, BRCM_ATTR_DRIVER_MAC_ADDR, ETH_ALEN, addr)) { |
| 10187 | wpa_printf(MSG_ERROR, "failed to put p2p randmac"); |
| 10188 | nl80211_nlmsg_clear(msg); |
| 10189 | nlmsg_free(msg); |
| 10190 | return -ENOBUFS; |
| 10191 | } |
| 10192 | nla_nest_end(msg, params); |
| 10193 | |
| 10194 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1, NULL, NULL); |
| 10195 | if (ret) { |
| 10196 | wpa_printf(MSG_ERROR, "nl80211: p2p set macaddr failed: ret=%d (%s)", |
| 10197 | ret, strerror(-ret)); |
| 10198 | } |
| 10199 | memcpy(bss->addr, addr, ETH_ALEN); |
| 10200 | return ret; |
| 10201 | #else |
| 10202 | return -ENOTSUP; |
| 10203 | #endif /* CONFIG_DRIVER_NL80211_BRCM */ |
| 10204 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10205 | if (!addr) |
| 10206 | addr = drv->perm_addr; |
| 10207 | |
| 10208 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) |
| 10209 | return -1; |
| 10210 | |
| 10211 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) |
| 10212 | { |
| 10213 | wpa_printf(MSG_DEBUG, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 10214 | "nl80211: failed to set_mac_addr for %s to " MACSTR, |
| 10215 | bss->ifname, MAC2STR(addr)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10216 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 10217 | 1) < 0) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10218 | wpa_printf(MSG_DEBUG, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 10219 | "nl80211: Could not restore interface UP after failed set_mac_addr"); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10220 | } |
| 10221 | return -1; |
| 10222 | } |
| 10223 | |
| 10224 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 10225 | bss->ifname, MAC2STR(addr)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10226 | drv->addr_changed = new_addr; |
| 10227 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 10228 | |
| 10229 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) |
| 10230 | { |
| 10231 | wpa_printf(MSG_DEBUG, |
Mir Ali | 8a8f100 | 2020-10-06 22:41:40 +0530 | [diff] [blame] | 10232 | "nl80211: Could not restore interface UP after set_mac_addr"); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10233 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10234 | return 0; |
| 10235 | } |
| 10236 | |
| 10237 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10238 | #ifdef CONFIG_MESH |
| 10239 | |
| 10240 | static int wpa_driver_nl80211_init_mesh(void *priv) |
| 10241 | { |
| 10242 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { |
| 10243 | wpa_printf(MSG_INFO, |
| 10244 | "nl80211: Failed to set interface into mesh mode"); |
| 10245 | return -1; |
| 10246 | } |
| 10247 | return 0; |
| 10248 | } |
| 10249 | |
| 10250 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 10251 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
| 10252 | size_t mesh_id_len) |
| 10253 | { |
| 10254 | if (mesh_id) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 10255 | wpa_printf(MSG_DEBUG, " * Mesh ID (SSID)=%s", |
| 10256 | wpa_ssid_txt(mesh_id, mesh_id_len)); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 10257 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); |
| 10258 | } |
| 10259 | |
| 10260 | return 0; |
| 10261 | } |
| 10262 | |
| 10263 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 10264 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
| 10265 | struct wpa_driver_mesh_bss_params *params) |
| 10266 | { |
| 10267 | struct nlattr *container; |
| 10268 | |
| 10269 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
| 10270 | if (!container) |
| 10271 | return -1; |
| 10272 | |
| 10273 | if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10274 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 10275 | params->auto_plinks)) || |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 10276 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) && |
| 10277 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10278 | params->max_peer_links)) || |
| 10279 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD) && |
| 10280 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 10281 | params->rssi_threshold))) |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 10282 | return -1; |
| 10283 | |
| 10284 | /* |
| 10285 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because |
| 10286 | * the timer could disconnect stations even in that case. |
| 10287 | */ |
| 10288 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) && |
| 10289 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 10290 | params->peer_link_timeout)) { |
| 10291 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); |
| 10292 | return -1; |
| 10293 | } |
| 10294 | |
| 10295 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) && |
| 10296 | nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) { |
| 10297 | wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE"); |
| 10298 | return -1; |
| 10299 | } |
| 10300 | |
| 10301 | nla_nest_end(msg, container); |
| 10302 | |
| 10303 | return 0; |
| 10304 | } |
| 10305 | |
| 10306 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 10307 | static int nl80211_join_mesh(struct i802_bss *bss, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10308 | struct wpa_driver_mesh_join_params *params) |
| 10309 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10310 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10311 | struct nl_msg *msg; |
| 10312 | struct nlattr *container; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 10313 | int ret = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10314 | |
| 10315 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
| 10316 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 10317 | if (!msg || |
| 10318 | nl80211_put_freq_params(msg, ¶ms->freq) || |
| 10319 | nl80211_put_basic_rates(msg, params->basic_rates) || |
| 10320 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 10321 | nl80211_put_beacon_int(msg, params->beacon_int) || |
| 10322 | nl80211_put_dtim_period(msg, params->dtim_period)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10323 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10324 | |
| 10325 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
| 10326 | |
| 10327 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); |
| 10328 | if (!container) |
| 10329 | goto fail; |
| 10330 | |
| 10331 | if (params->ies) { |
| 10332 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); |
| 10333 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
| 10334 | params->ies)) |
| 10335 | goto fail; |
| 10336 | } |
| 10337 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ |
| 10338 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { |
| 10339 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
| 10340 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) |
| 10341 | goto fail; |
| 10342 | } |
| 10343 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
| 10344 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) |
| 10345 | goto fail; |
| 10346 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && |
| 10347 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) |
| 10348 | goto fail; |
| 10349 | nla_nest_end(msg, container); |
| 10350 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 10351 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS; |
| 10352 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT; |
| 10353 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS; |
| 10354 | if (nl80211_put_mesh_config(msg, ¶ms->conf) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10355 | goto fail; |
| 10356 | |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 10357 | ret = send_and_recv_msgs_owner(drv, msg, get_connect_handle(bss), 1, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10358 | NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10359 | msg = NULL; |
| 10360 | if (ret) { |
| 10361 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", |
| 10362 | ret, strerror(-ret)); |
| 10363 | goto fail; |
| 10364 | } |
| 10365 | ret = 0; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 10366 | drv->assoc_freq = bss->freq = params->freq.freq; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10367 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
| 10368 | |
| 10369 | fail: |
| 10370 | nlmsg_free(msg); |
| 10371 | return ret; |
| 10372 | } |
| 10373 | |
| 10374 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 10375 | static int |
| 10376 | wpa_driver_nl80211_join_mesh(void *priv, |
| 10377 | struct wpa_driver_mesh_join_params *params) |
| 10378 | { |
| 10379 | struct i802_bss *bss = priv; |
| 10380 | int ret, timeout; |
| 10381 | |
| 10382 | timeout = params->conf.peer_link_timeout; |
| 10383 | |
| 10384 | /* Disable kernel inactivity timer */ |
| 10385 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) |
| 10386 | params->conf.peer_link_timeout = 0; |
| 10387 | |
| 10388 | ret = nl80211_join_mesh(bss, params); |
| 10389 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { |
| 10390 | wpa_printf(MSG_DEBUG, |
| 10391 | "nl80211: Mesh join retry for peer_link_timeout"); |
| 10392 | /* |
| 10393 | * Old kernel does not support setting |
| 10394 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds |
| 10395 | * into future from peer_link_timeout. |
| 10396 | */ |
| 10397 | params->conf.peer_link_timeout = timeout + 60; |
| 10398 | ret = nl80211_join_mesh(priv, params); |
| 10399 | } |
| 10400 | |
| 10401 | params->conf.peer_link_timeout = timeout; |
| 10402 | return ret; |
| 10403 | } |
| 10404 | |
| 10405 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10406 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
| 10407 | { |
| 10408 | struct i802_bss *bss = priv; |
| 10409 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10410 | struct nl_msg *msg; |
| 10411 | int ret; |
| 10412 | |
| 10413 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); |
| 10414 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 10415 | ret = send_and_recv_msgs_owner(drv, msg, get_connect_handle(bss), 0, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10416 | NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10417 | if (ret) { |
| 10418 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", |
| 10419 | ret, strerror(-ret)); |
| 10420 | } else { |
| 10421 | wpa_printf(MSG_DEBUG, |
| 10422 | "nl80211: mesh leave request send successfully"); |
| 10423 | } |
| 10424 | |
| 10425 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
| 10426 | NL80211_IFTYPE_STATION)) { |
| 10427 | wpa_printf(MSG_INFO, |
| 10428 | "nl80211: Failed to set interface into station mode"); |
| 10429 | } |
| 10430 | return ret; |
| 10431 | } |
| 10432 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 10433 | |
| 10434 | static int nl80211_probe_mesh_link(void *priv, const u8 *addr, const u8 *eth, |
| 10435 | size_t len) |
| 10436 | { |
| 10437 | struct i802_bss *bss = priv; |
| 10438 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10439 | struct nl_msg *msg; |
| 10440 | int ret; |
| 10441 | |
| 10442 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_PROBE_MESH_LINK); |
| 10443 | if (!msg || |
| 10444 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10445 | nla_put(msg, NL80211_ATTR_FRAME, len, eth)) { |
| 10446 | nlmsg_free(msg); |
| 10447 | return -ENOBUFS; |
| 10448 | } |
| 10449 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10450 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 10451 | if (ret) { |
| 10452 | wpa_printf(MSG_DEBUG, "nl80211: mesh link probe to " MACSTR |
| 10453 | " failed: ret=%d (%s)", |
| 10454 | MAC2STR(addr), ret, strerror(-ret)); |
| 10455 | } else { |
| 10456 | wpa_printf(MSG_DEBUG, "nl80211: Mesh link to " MACSTR |
| 10457 | " probed successfully", MAC2STR(addr)); |
| 10458 | } |
| 10459 | |
| 10460 | return ret; |
| 10461 | } |
| 10462 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10463 | #endif /* CONFIG_MESH */ |
| 10464 | |
| 10465 | |
| 10466 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
| 10467 | const u8 *ipaddr, int prefixlen, |
| 10468 | const u8 *addr) |
| 10469 | { |
| 10470 | #ifdef CONFIG_LIBNL3_ROUTE |
| 10471 | struct i802_bss *bss = priv; |
| 10472 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10473 | struct rtnl_neigh *rn; |
| 10474 | struct nl_addr *nl_ipaddr = NULL; |
| 10475 | struct nl_addr *nl_lladdr = NULL; |
| 10476 | int family, addrsize; |
| 10477 | int res; |
| 10478 | |
| 10479 | if (!ipaddr || prefixlen == 0 || !addr) |
| 10480 | return -EINVAL; |
| 10481 | |
| 10482 | if (bss->br_ifindex == 0) { |
| 10483 | wpa_printf(MSG_DEBUG, |
| 10484 | "nl80211: bridge must be set before adding an ip neigh to it"); |
| 10485 | return -1; |
| 10486 | } |
| 10487 | |
| 10488 | if (!drv->rtnl_sk) { |
| 10489 | wpa_printf(MSG_DEBUG, |
| 10490 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 10491 | return -1; |
| 10492 | } |
| 10493 | |
| 10494 | if (version == 4) { |
| 10495 | family = AF_INET; |
| 10496 | addrsize = 4; |
| 10497 | } else if (version == 6) { |
| 10498 | family = AF_INET6; |
| 10499 | addrsize = 16; |
| 10500 | } else { |
| 10501 | return -EINVAL; |
| 10502 | } |
| 10503 | |
| 10504 | rn = rtnl_neigh_alloc(); |
| 10505 | if (rn == NULL) |
| 10506 | return -ENOMEM; |
| 10507 | |
| 10508 | /* set the destination ip address for neigh */ |
| 10509 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 10510 | if (nl_ipaddr == NULL) { |
| 10511 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 10512 | res = -ENOMEM; |
| 10513 | goto errout; |
| 10514 | } |
| 10515 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); |
| 10516 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 10517 | if (res) { |
| 10518 | wpa_printf(MSG_DEBUG, |
| 10519 | "nl80211: neigh set destination addr failed"); |
| 10520 | goto errout; |
| 10521 | } |
| 10522 | |
| 10523 | /* set the corresponding lladdr for neigh */ |
| 10524 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); |
| 10525 | if (nl_lladdr == NULL) { |
| 10526 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); |
| 10527 | res = -ENOMEM; |
| 10528 | goto errout; |
| 10529 | } |
| 10530 | rtnl_neigh_set_lladdr(rn, nl_lladdr); |
| 10531 | |
| 10532 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 10533 | rtnl_neigh_set_state(rn, NUD_PERMANENT); |
| 10534 | |
| 10535 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); |
| 10536 | if (res) { |
| 10537 | wpa_printf(MSG_DEBUG, |
| 10538 | "nl80211: Adding bridge ip neigh failed: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10539 | nl_geterror(res)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10540 | } |
| 10541 | errout: |
| 10542 | if (nl_lladdr) |
| 10543 | nl_addr_put(nl_lladdr); |
| 10544 | if (nl_ipaddr) |
| 10545 | nl_addr_put(nl_ipaddr); |
| 10546 | if (rn) |
| 10547 | rtnl_neigh_put(rn); |
| 10548 | return res; |
| 10549 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 10550 | return -1; |
| 10551 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 10552 | } |
| 10553 | |
| 10554 | |
| 10555 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
| 10556 | const u8 *ipaddr) |
| 10557 | { |
| 10558 | #ifdef CONFIG_LIBNL3_ROUTE |
| 10559 | struct i802_bss *bss = priv; |
| 10560 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10561 | struct rtnl_neigh *rn; |
| 10562 | struct nl_addr *nl_ipaddr; |
| 10563 | int family, addrsize; |
| 10564 | int res; |
| 10565 | |
| 10566 | if (!ipaddr) |
| 10567 | return -EINVAL; |
| 10568 | |
| 10569 | if (version == 4) { |
| 10570 | family = AF_INET; |
| 10571 | addrsize = 4; |
| 10572 | } else if (version == 6) { |
| 10573 | family = AF_INET6; |
| 10574 | addrsize = 16; |
| 10575 | } else { |
| 10576 | return -EINVAL; |
| 10577 | } |
| 10578 | |
| 10579 | if (bss->br_ifindex == 0) { |
| 10580 | wpa_printf(MSG_DEBUG, |
| 10581 | "nl80211: bridge must be set to delete an ip neigh"); |
| 10582 | return -1; |
| 10583 | } |
| 10584 | |
| 10585 | if (!drv->rtnl_sk) { |
| 10586 | wpa_printf(MSG_DEBUG, |
| 10587 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 10588 | return -1; |
| 10589 | } |
| 10590 | |
| 10591 | rn = rtnl_neigh_alloc(); |
| 10592 | if (rn == NULL) |
| 10593 | return -ENOMEM; |
| 10594 | |
| 10595 | /* set the destination ip address for neigh */ |
| 10596 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 10597 | if (nl_ipaddr == NULL) { |
| 10598 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 10599 | res = -ENOMEM; |
| 10600 | goto errout; |
| 10601 | } |
| 10602 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 10603 | if (res) { |
| 10604 | wpa_printf(MSG_DEBUG, |
| 10605 | "nl80211: neigh set destination addr failed"); |
| 10606 | goto errout; |
| 10607 | } |
| 10608 | |
| 10609 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 10610 | |
| 10611 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 10612 | if (res) { |
| 10613 | wpa_printf(MSG_DEBUG, |
| 10614 | "nl80211: Deleting bridge ip neigh failed: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10615 | nl_geterror(res)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10616 | } |
| 10617 | errout: |
| 10618 | if (nl_ipaddr) |
| 10619 | nl_addr_put(nl_ipaddr); |
| 10620 | if (rn) |
| 10621 | rtnl_neigh_put(rn); |
| 10622 | return res; |
| 10623 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 10624 | return -1; |
| 10625 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 10626 | } |
| 10627 | |
| 10628 | |
| 10629 | static int linux_write_system_file(const char *path, unsigned int val) |
| 10630 | { |
| 10631 | char buf[50]; |
| 10632 | int fd, len; |
| 10633 | |
| 10634 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); |
| 10635 | if (os_snprintf_error(sizeof(buf), len)) |
| 10636 | return -1; |
| 10637 | |
| 10638 | fd = open(path, O_WRONLY); |
| 10639 | if (fd < 0) |
| 10640 | return -1; |
| 10641 | |
| 10642 | if (write(fd, buf, len) < 0) { |
| 10643 | wpa_printf(MSG_DEBUG, |
| 10644 | "nl80211: Failed to write Linux system file: %s with the value of %d", |
| 10645 | path, val); |
| 10646 | close(fd); |
| 10647 | return -1; |
| 10648 | } |
| 10649 | close(fd); |
| 10650 | |
| 10651 | return 0; |
| 10652 | } |
| 10653 | |
| 10654 | |
| 10655 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) |
| 10656 | { |
| 10657 | switch (attr) { |
| 10658 | case DRV_BR_PORT_ATTR_PROXYARP: |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 10659 | return "proxyarp_wifi"; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10660 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
| 10661 | return "hairpin_mode"; |
| 10662 | } |
| 10663 | |
| 10664 | return NULL; |
| 10665 | } |
| 10666 | |
| 10667 | |
| 10668 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, |
| 10669 | unsigned int val) |
| 10670 | { |
| 10671 | struct i802_bss *bss = priv; |
| 10672 | char path[128]; |
| 10673 | const char *attr_txt; |
| 10674 | |
| 10675 | attr_txt = drv_br_port_attr_str(attr); |
| 10676 | if (attr_txt == NULL) |
| 10677 | return -EINVAL; |
| 10678 | |
| 10679 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", |
| 10680 | bss->ifname, attr_txt); |
| 10681 | |
| 10682 | if (linux_write_system_file(path, val)) |
| 10683 | return -1; |
| 10684 | |
| 10685 | return 0; |
| 10686 | } |
| 10687 | |
| 10688 | |
| 10689 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
| 10690 | { |
| 10691 | switch (param) { |
| 10692 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 10693 | return "arp_accept"; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 10694 | default: |
| 10695 | return NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10696 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10697 | } |
| 10698 | |
| 10699 | |
| 10700 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, |
| 10701 | unsigned int val) |
| 10702 | { |
| 10703 | struct i802_bss *bss = priv; |
| 10704 | char path[128]; |
| 10705 | const char *param_txt; |
| 10706 | int ip_version = 4; |
| 10707 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 10708 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
| 10709 | os_snprintf(path, sizeof(path), |
| 10710 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", |
| 10711 | bss->brname); |
| 10712 | goto set_val; |
| 10713 | } |
| 10714 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10715 | param_txt = drv_br_net_param_str(param); |
| 10716 | if (param_txt == NULL) |
| 10717 | return -EINVAL; |
| 10718 | |
| 10719 | switch (param) { |
| 10720 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 10721 | ip_version = 4; |
| 10722 | break; |
| 10723 | default: |
| 10724 | return -EINVAL; |
| 10725 | } |
| 10726 | |
| 10727 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", |
| 10728 | ip_version, bss->brname, param_txt); |
| 10729 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 10730 | set_val: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10731 | if (linux_write_system_file(path, val)) |
| 10732 | return -1; |
| 10733 | |
| 10734 | return 0; |
| 10735 | } |
| 10736 | |
| 10737 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10738 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 10739 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10740 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
| 10741 | { |
| 10742 | switch (hw_mode) { |
| 10743 | case HOSTAPD_MODE_IEEE80211B: |
| 10744 | return QCA_ACS_MODE_IEEE80211B; |
| 10745 | case HOSTAPD_MODE_IEEE80211G: |
| 10746 | return QCA_ACS_MODE_IEEE80211G; |
| 10747 | case HOSTAPD_MODE_IEEE80211A: |
| 10748 | return QCA_ACS_MODE_IEEE80211A; |
| 10749 | case HOSTAPD_MODE_IEEE80211AD: |
| 10750 | return QCA_ACS_MODE_IEEE80211AD; |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 10751 | case HOSTAPD_MODE_IEEE80211ANY: |
| 10752 | return QCA_ACS_MODE_IEEE80211ANY; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10753 | default: |
| 10754 | return -1; |
| 10755 | } |
| 10756 | } |
| 10757 | |
| 10758 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 10759 | static int add_acs_ch_list(struct nl_msg *msg, const int *freq_list) |
| 10760 | { |
| 10761 | int num_channels = 0, num_freqs; |
| 10762 | u8 *ch_list; |
| 10763 | enum hostapd_hw_mode hw_mode; |
| 10764 | int ret = 0; |
| 10765 | int i; |
| 10766 | |
| 10767 | if (!freq_list) |
| 10768 | return 0; |
| 10769 | |
| 10770 | num_freqs = int_array_len(freq_list); |
| 10771 | ch_list = os_malloc(sizeof(u8) * num_freqs); |
| 10772 | if (!ch_list) |
| 10773 | return -1; |
| 10774 | |
| 10775 | for (i = 0; i < num_freqs; i++) { |
| 10776 | const int freq = freq_list[i]; |
| 10777 | |
| 10778 | if (freq == 0) |
| 10779 | break; |
| 10780 | /* Send 2.4 GHz and 5 GHz channels with |
| 10781 | * QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST to maintain backwards |
| 10782 | * compatibility. |
| 10783 | */ |
| 10784 | if (!(freq >= 2412 && freq <= 2484) && |
| 10785 | !(freq >= 5180 && freq <= 5900)) |
| 10786 | continue; |
| 10787 | hw_mode = ieee80211_freq_to_chan(freq, &ch_list[num_channels]); |
| 10788 | if (hw_mode != NUM_HOSTAPD_MODES) |
| 10789 | num_channels++; |
| 10790 | } |
| 10791 | |
| 10792 | if (num_channels) |
| 10793 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, |
| 10794 | num_channels, ch_list); |
| 10795 | |
| 10796 | os_free(ch_list); |
| 10797 | return ret; |
| 10798 | } |
| 10799 | |
| 10800 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10801 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
| 10802 | { |
| 10803 | int i, len, ret; |
| 10804 | u32 *freqs; |
| 10805 | |
| 10806 | if (!freq_list) |
| 10807 | return 0; |
| 10808 | len = int_array_len(freq_list); |
| 10809 | freqs = os_malloc(sizeof(u32) * len); |
| 10810 | if (!freqs) |
| 10811 | return -1; |
| 10812 | for (i = 0; i < len; i++) |
| 10813 | freqs[i] = freq_list[i]; |
| 10814 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, |
| 10815 | sizeof(u32) * len, freqs); |
| 10816 | os_free(freqs); |
| 10817 | return ret; |
| 10818 | } |
| 10819 | |
| 10820 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10821 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
| 10822 | { |
| 10823 | struct i802_bss *bss = priv; |
| 10824 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10825 | struct nl_msg *msg; |
| 10826 | struct nlattr *data; |
| 10827 | int ret; |
| 10828 | int mode; |
| 10829 | |
| 10830 | mode = hw_mode_to_qca_acs(params->hw_mode); |
| 10831 | if (mode < 0) |
| 10832 | return -1; |
| 10833 | |
| 10834 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10835 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10836 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10837 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || |
| 10838 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10839 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || |
| 10840 | (params->ht_enabled && |
| 10841 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || |
| 10842 | (params->ht40_enabled && |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 10843 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
| 10844 | (params->vht_enabled && |
| 10845 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || |
| 10846 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, |
| 10847 | params->ch_width) || |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 10848 | add_acs_ch_list(msg, params->freq_list) || |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10849 | add_acs_freq_list(msg, params->freq_list) || |
| 10850 | (params->edmg_enabled && |
| 10851 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_EDMG_ENABLED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10852 | nlmsg_free(msg); |
| 10853 | return -ENOBUFS; |
| 10854 | } |
| 10855 | nla_nest_end(msg, data); |
| 10856 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 10857 | wpa_printf(MSG_DEBUG, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10858 | "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] | 10859 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10860 | params->vht_enabled, params->ch_width, params->edmg_enabled); |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 10861 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10862 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10863 | if (ret) { |
| 10864 | wpa_printf(MSG_DEBUG, |
| 10865 | "nl80211: Failed to invoke driver ACS function: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10866 | strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10867 | } |
| 10868 | return ret; |
| 10869 | } |
| 10870 | |
| 10871 | |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 10872 | static int nl80211_set_band(void *priv, enum set_band band) |
| 10873 | { |
| 10874 | struct i802_bss *bss = priv; |
| 10875 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10876 | struct nl_msg *msg; |
| 10877 | struct nlattr *data; |
| 10878 | int ret; |
| 10879 | enum qca_set_band qca_band; |
| 10880 | |
| 10881 | if (!drv->setband_vendor_cmd_avail) |
| 10882 | return -1; |
| 10883 | |
| 10884 | switch (band) { |
| 10885 | case WPA_SETBAND_AUTO: |
| 10886 | qca_band = QCA_SETBAND_AUTO; |
| 10887 | break; |
| 10888 | case WPA_SETBAND_5G: |
| 10889 | qca_band = QCA_SETBAND_5G; |
| 10890 | break; |
| 10891 | case WPA_SETBAND_2G: |
| 10892 | qca_band = QCA_SETBAND_2G; |
| 10893 | break; |
| 10894 | default: |
| 10895 | return -1; |
| 10896 | } |
| 10897 | |
| 10898 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10899 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10900 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10901 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || |
| 10902 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10903 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) { |
| 10904 | nlmsg_free(msg); |
| 10905 | return -ENOBUFS; |
| 10906 | } |
| 10907 | nla_nest_end(msg, data); |
| 10908 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 10909 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 10910 | if (ret) { |
| 10911 | wpa_printf(MSG_DEBUG, |
| 10912 | "nl80211: Driver setband function failed: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10913 | strerror(-ret)); |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 10914 | } |
| 10915 | return ret; |
| 10916 | } |
| 10917 | |
| 10918 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10919 | struct nl80211_pcl { |
| 10920 | unsigned int num; |
| 10921 | unsigned int *freq_list; |
| 10922 | }; |
| 10923 | |
| 10924 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) |
| 10925 | { |
| 10926 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 10927 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 10928 | struct nl80211_pcl *param = arg; |
| 10929 | struct nlattr *nl_vend, *attr; |
| 10930 | enum qca_iface_type iface_type; |
| 10931 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 10932 | unsigned int num, max_num; |
| 10933 | u32 *freqs; |
| 10934 | |
| 10935 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 10936 | genlmsg_attrlen(gnlh, 0), NULL); |
| 10937 | |
| 10938 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; |
| 10939 | if (!nl_vend) |
| 10940 | return NL_SKIP; |
| 10941 | |
| 10942 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 10943 | nla_data(nl_vend), nla_len(nl_vend), NULL); |
| 10944 | |
| 10945 | attr = tb_vendor[ |
| 10946 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; |
| 10947 | if (!attr) { |
| 10948 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); |
| 10949 | param->num = 0; |
| 10950 | return NL_SKIP; |
| 10951 | } |
| 10952 | |
| 10953 | iface_type = (enum qca_iface_type) nla_get_u32(attr); |
| 10954 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", |
| 10955 | iface_type); |
| 10956 | |
| 10957 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; |
| 10958 | if (!attr) { |
| 10959 | wpa_printf(MSG_ERROR, |
| 10960 | "nl80211: preferred_freq_list couldn't be found"); |
| 10961 | param->num = 0; |
| 10962 | return NL_SKIP; |
| 10963 | } |
| 10964 | |
| 10965 | /* |
| 10966 | * param->num has the maximum number of entries for which there |
| 10967 | * is room in the freq_list provided by the caller. |
| 10968 | */ |
| 10969 | freqs = nla_data(attr); |
| 10970 | max_num = nla_len(attr) / sizeof(u32); |
| 10971 | if (max_num > param->num) |
| 10972 | max_num = param->num; |
| 10973 | for (num = 0; num < max_num; num++) |
| 10974 | param->freq_list[num] = freqs[num]; |
| 10975 | param->num = num; |
| 10976 | |
| 10977 | return NL_SKIP; |
| 10978 | } |
| 10979 | |
| 10980 | |
| 10981 | static int nl80211_get_pref_freq_list(void *priv, |
| 10982 | enum wpa_driver_if_type if_type, |
| 10983 | unsigned int *num, |
| 10984 | unsigned int *freq_list) |
| 10985 | { |
| 10986 | struct i802_bss *bss = priv; |
| 10987 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10988 | struct nl_msg *msg; |
| 10989 | int ret; |
| 10990 | unsigned int i; |
| 10991 | struct nlattr *params; |
| 10992 | struct nl80211_pcl param; |
| 10993 | enum qca_iface_type iface_type; |
| 10994 | |
| 10995 | if (!drv->get_pref_freq_list) |
| 10996 | return -1; |
| 10997 | |
| 10998 | switch (if_type) { |
| 10999 | case WPA_IF_STATION: |
| 11000 | iface_type = QCA_IFACE_TYPE_STA; |
| 11001 | break; |
| 11002 | case WPA_IF_AP_BSS: |
| 11003 | iface_type = QCA_IFACE_TYPE_AP; |
| 11004 | break; |
| 11005 | case WPA_IF_P2P_GO: |
| 11006 | iface_type = QCA_IFACE_TYPE_P2P_GO; |
| 11007 | break; |
| 11008 | case WPA_IF_P2P_CLIENT: |
| 11009 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; |
| 11010 | break; |
| 11011 | case WPA_IF_IBSS: |
| 11012 | iface_type = QCA_IFACE_TYPE_IBSS; |
| 11013 | break; |
| 11014 | case WPA_IF_TDLS: |
| 11015 | iface_type = QCA_IFACE_TYPE_TDLS; |
| 11016 | break; |
| 11017 | default: |
| 11018 | return -1; |
| 11019 | } |
| 11020 | |
| 11021 | param.num = *num; |
| 11022 | param.freq_list = freq_list; |
| 11023 | |
| 11024 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11025 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || |
| 11026 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11027 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11028 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || |
| 11029 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 11030 | nla_put_u32(msg, |
| 11031 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, |
| 11032 | iface_type)) { |
| 11033 | wpa_printf(MSG_ERROR, |
| 11034 | "%s: err in adding vendor_cmd and vendor_data", |
| 11035 | __func__); |
| 11036 | nlmsg_free(msg); |
| 11037 | return -1; |
| 11038 | } |
| 11039 | nla_nest_end(msg, params); |
| 11040 | |
| 11041 | os_memset(freq_list, 0, *num * sizeof(freq_list[0])); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11042 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m, |
| 11043 | NULL, NULL); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11044 | if (ret) { |
| 11045 | wpa_printf(MSG_ERROR, |
| 11046 | "%s: err in send_and_recv_msgs", __func__); |
| 11047 | return ret; |
| 11048 | } |
| 11049 | |
| 11050 | *num = param.num; |
| 11051 | |
| 11052 | for (i = 0; i < *num; i++) { |
| 11053 | wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d", |
| 11054 | i, freq_list[i]); |
| 11055 | } |
| 11056 | |
| 11057 | return 0; |
| 11058 | } |
| 11059 | |
| 11060 | |
| 11061 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
| 11062 | { |
| 11063 | struct i802_bss *bss = priv; |
| 11064 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11065 | struct nl_msg *msg; |
| 11066 | int ret; |
| 11067 | struct nlattr *params; |
| 11068 | |
| 11069 | if (!drv->set_prob_oper_freq) |
| 11070 | return -1; |
| 11071 | |
| 11072 | wpa_printf(MSG_DEBUG, |
| 11073 | "nl80211: Set P2P probable operating freq %u for ifindex %d", |
| 11074 | freq, bss->ifindex); |
| 11075 | |
| 11076 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11077 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11078 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11079 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || |
| 11080 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 11081 | nla_put_u32(msg, |
| 11082 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, |
| 11083 | QCA_IFACE_TYPE_P2P_CLIENT) || |
| 11084 | nla_put_u32(msg, |
| 11085 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, |
| 11086 | freq)) { |
| 11087 | wpa_printf(MSG_ERROR, |
| 11088 | "%s: err in adding vendor_cmd and vendor_data", |
| 11089 | __func__); |
| 11090 | nlmsg_free(msg); |
| 11091 | return -1; |
| 11092 | } |
| 11093 | nla_nest_end(msg, params); |
| 11094 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11095 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11096 | msg = NULL; |
| 11097 | if (ret) { |
| 11098 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", |
| 11099 | __func__); |
| 11100 | return ret; |
| 11101 | } |
| 11102 | nlmsg_free(msg); |
| 11103 | return 0; |
| 11104 | } |
| 11105 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 11106 | |
| 11107 | static int nl80211_p2p_lo_start(void *priv, unsigned int freq, |
| 11108 | unsigned int period, unsigned int interval, |
| 11109 | unsigned int count, const u8 *device_types, |
| 11110 | size_t dev_types_len, |
| 11111 | const u8 *ies, size_t ies_len) |
| 11112 | { |
| 11113 | struct i802_bss *bss = priv; |
| 11114 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11115 | struct nl_msg *msg; |
| 11116 | struct nlattr *container; |
| 11117 | int ret; |
| 11118 | |
| 11119 | wpa_printf(MSG_DEBUG, |
| 11120 | "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u", |
| 11121 | freq, period, interval, count); |
| 11122 | |
| 11123 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 11124 | return -1; |
| 11125 | |
| 11126 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11127 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11128 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11129 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START)) |
| 11130 | goto fail; |
| 11131 | |
| 11132 | container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 11133 | if (!container) |
| 11134 | goto fail; |
| 11135 | |
| 11136 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL, |
| 11137 | freq) || |
| 11138 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD, |
| 11139 | period) || |
| 11140 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL, |
| 11141 | interval) || |
| 11142 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT, |
| 11143 | count) || |
| 11144 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES, |
| 11145 | dev_types_len, device_types) || |
| 11146 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE, |
| 11147 | ies_len, ies)) |
| 11148 | goto fail; |
| 11149 | |
| 11150 | nla_nest_end(msg, container); |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11151 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 11152 | msg = NULL; |
| 11153 | if (ret) { |
| 11154 | wpa_printf(MSG_DEBUG, |
| 11155 | "nl80211: Failed to send P2P Listen offload vendor command"); |
| 11156 | goto fail; |
| 11157 | } |
| 11158 | |
| 11159 | return 0; |
| 11160 | |
| 11161 | fail: |
| 11162 | nlmsg_free(msg); |
| 11163 | return -1; |
| 11164 | } |
| 11165 | |
| 11166 | |
| 11167 | static int nl80211_p2p_lo_stop(void *priv) |
| 11168 | { |
| 11169 | struct i802_bss *bss = priv; |
| 11170 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11171 | struct nl_msg *msg; |
| 11172 | |
| 11173 | wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload"); |
| 11174 | |
| 11175 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 11176 | return -1; |
| 11177 | |
| 11178 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11179 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11180 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11181 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) { |
| 11182 | nlmsg_free(msg); |
| 11183 | return -1; |
| 11184 | } |
| 11185 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11186 | return send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 11187 | } |
| 11188 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 11189 | |
| 11190 | static int nl80211_set_tdls_mode(void *priv, int tdls_external_control) |
| 11191 | { |
| 11192 | struct i802_bss *bss = priv; |
| 11193 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11194 | struct nl_msg *msg; |
| 11195 | struct nlattr *params; |
| 11196 | int ret; |
| 11197 | u32 tdls_mode; |
| 11198 | |
| 11199 | wpa_printf(MSG_DEBUG, |
| 11200 | "nl80211: Set TDKS mode: tdls_external_control=%d", |
| 11201 | tdls_external_control); |
| 11202 | |
| 11203 | if (tdls_external_control == 1) |
| 11204 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT | |
| 11205 | QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL; |
| 11206 | else |
| 11207 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT; |
| 11208 | |
| 11209 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11210 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11211 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11212 | QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS)) |
| 11213 | goto fail; |
| 11214 | |
| 11215 | params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 11216 | if (!params) |
| 11217 | goto fail; |
| 11218 | |
| 11219 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE, |
| 11220 | tdls_mode)) |
| 11221 | goto fail; |
| 11222 | |
| 11223 | nla_nest_end(msg, params); |
| 11224 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11225 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 11226 | msg = NULL; |
| 11227 | if (ret) { |
| 11228 | wpa_printf(MSG_ERROR, |
| 11229 | "nl80211: Set TDLS mode failed: ret=%d (%s)", |
| 11230 | ret, strerror(-ret)); |
| 11231 | goto fail; |
| 11232 | } |
| 11233 | return 0; |
| 11234 | fail: |
| 11235 | nlmsg_free(msg); |
| 11236 | return -1; |
| 11237 | } |
| 11238 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11239 | |
| 11240 | #ifdef CONFIG_MBO |
| 11241 | |
| 11242 | static enum mbo_transition_reject_reason |
| 11243 | nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status) |
| 11244 | { |
| 11245 | switch (status) { |
| 11246 | case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED: |
| 11247 | return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS; |
| 11248 | case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED: |
| 11249 | return MBO_TRANSITION_REJECT_REASON_DELAY; |
| 11250 | case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY: |
| 11251 | return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY; |
| 11252 | case QCA_STATUS_REJECT_LOW_RSSI: |
| 11253 | return MBO_TRANSITION_REJECT_REASON_RSSI; |
| 11254 | case QCA_STATUS_REJECT_HIGH_INTERFERENCE: |
| 11255 | return MBO_TRANSITION_REJECT_REASON_INTERFERENCE; |
| 11256 | case QCA_STATUS_REJECT_UNKNOWN: |
| 11257 | default: |
| 11258 | return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED; |
| 11259 | } |
| 11260 | } |
| 11261 | |
| 11262 | |
| 11263 | static void nl80211_parse_btm_candidate_info(struct candidate_list *candidate, |
| 11264 | struct nlattr *tb[], int num) |
| 11265 | { |
| 11266 | enum qca_wlan_btm_candidate_status status; |
| 11267 | char buf[50]; |
| 11268 | |
| 11269 | os_memcpy(candidate->bssid, |
| 11270 | nla_data(tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID]), |
| 11271 | ETH_ALEN); |
| 11272 | |
| 11273 | status = nla_get_u32( |
| 11274 | tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]); |
| 11275 | candidate->is_accept = status == QCA_STATUS_ACCEPT; |
| 11276 | candidate->reject_reason = nl80211_mbo_reject_reason_mapping(status); |
| 11277 | |
| 11278 | if (candidate->is_accept) |
| 11279 | os_snprintf(buf, sizeof(buf), "Accepted"); |
| 11280 | else |
| 11281 | os_snprintf(buf, sizeof(buf), |
| 11282 | "Rejected, Reject_reason: %d", |
| 11283 | candidate->reject_reason); |
| 11284 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR " %s", |
| 11285 | num, MAC2STR(candidate->bssid), buf); |
| 11286 | } |
| 11287 | |
| 11288 | |
| 11289 | static int |
| 11290 | nl80211_get_bss_transition_status_handler(struct nl_msg *msg, void *arg) |
| 11291 | { |
| 11292 | struct wpa_bss_candidate_info *info = arg; |
| 11293 | struct candidate_list *candidate = info->candidates; |
| 11294 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 11295 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 11296 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1]; |
| 11297 | static struct nla_policy policy[ |
| 11298 | QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1] = { |
| 11299 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] = { |
| 11300 | .minlen = ETH_ALEN |
| 11301 | }, |
| 11302 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS] = { |
| 11303 | .type = NLA_U32, |
| 11304 | }, |
| 11305 | }; |
| 11306 | struct nlattr *attr; |
| 11307 | int rem; |
| 11308 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 11309 | u8 num; |
| 11310 | |
| 11311 | num = info->num; /* number of candidates sent to driver */ |
| 11312 | info->num = 0; |
| 11313 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 11314 | genlmsg_attrlen(gnlh, 0), NULL); |
| 11315 | |
| 11316 | if (!tb_msg[NL80211_ATTR_VENDOR_DATA] || |
| 11317 | nla_parse_nested(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 11318 | tb_msg[NL80211_ATTR_VENDOR_DATA], NULL) || |
| 11319 | !tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO]) |
| 11320 | return NL_SKIP; |
| 11321 | |
| 11322 | wpa_printf(MSG_DEBUG, |
| 11323 | "nl80211: WNM Candidate list received from driver"); |
| 11324 | nla_for_each_nested(attr, |
| 11325 | tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO], |
| 11326 | rem) { |
| 11327 | if (info->num >= num || |
| 11328 | nla_parse_nested( |
| 11329 | tb, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX, |
| 11330 | attr, policy) || |
| 11331 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] || |
| 11332 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]) |
| 11333 | break; |
| 11334 | |
| 11335 | nl80211_parse_btm_candidate_info(candidate, tb, info->num); |
| 11336 | |
| 11337 | candidate++; |
| 11338 | info->num++; |
| 11339 | } |
| 11340 | |
| 11341 | return NL_SKIP; |
| 11342 | } |
| 11343 | |
| 11344 | |
| 11345 | static struct wpa_bss_candidate_info * |
| 11346 | nl80211_get_bss_transition_status(void *priv, struct wpa_bss_trans_info *params) |
| 11347 | { |
| 11348 | struct i802_bss *bss = priv; |
| 11349 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11350 | struct nl_msg *msg; |
| 11351 | struct nlattr *attr, *attr1, *attr2; |
| 11352 | struct wpa_bss_candidate_info *info; |
| 11353 | u8 i; |
| 11354 | int ret; |
| 11355 | u8 *pos; |
| 11356 | |
| 11357 | if (!drv->fetch_bss_trans_status) |
| 11358 | return NULL; |
| 11359 | |
| 11360 | info = os_zalloc(sizeof(*info)); |
| 11361 | if (!info) |
| 11362 | return NULL; |
| 11363 | /* Allocate memory for number of candidates sent to driver */ |
| 11364 | info->candidates = os_calloc(params->n_candidates, |
| 11365 | sizeof(*info->candidates)); |
| 11366 | if (!info->candidates) { |
| 11367 | os_free(info); |
| 11368 | return NULL; |
| 11369 | } |
| 11370 | |
| 11371 | /* Copy the number of candidates being sent to driver. This is used in |
| 11372 | * nl80211_get_bss_transition_status_handler() to limit the number of |
| 11373 | * candidates that can be populated in info->candidates and will be |
| 11374 | * later overwritten with the actual number of candidates received from |
| 11375 | * the driver. |
| 11376 | */ |
| 11377 | info->num = params->n_candidates; |
| 11378 | |
| 11379 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11380 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11381 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11382 | QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS)) |
| 11383 | goto fail; |
| 11384 | |
| 11385 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 11386 | if (!attr) |
| 11387 | goto fail; |
| 11388 | |
| 11389 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON, |
| 11390 | params->mbo_transition_reason)) |
| 11391 | goto fail; |
| 11392 | |
| 11393 | attr1 = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO); |
| 11394 | if (!attr1) |
| 11395 | goto fail; |
| 11396 | |
| 11397 | wpa_printf(MSG_DEBUG, |
| 11398 | "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d", |
| 11399 | params->mbo_transition_reason, params->n_candidates); |
| 11400 | pos = params->bssid; |
| 11401 | for (i = 0; i < params->n_candidates; i++) { |
| 11402 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR, i, |
| 11403 | MAC2STR(pos)); |
| 11404 | attr2 = nla_nest_start(msg, i); |
| 11405 | if (!attr2 || |
| 11406 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID, |
| 11407 | ETH_ALEN, pos)) |
| 11408 | goto fail; |
| 11409 | pos += ETH_ALEN; |
| 11410 | nla_nest_end(msg, attr2); |
| 11411 | } |
| 11412 | |
| 11413 | nla_nest_end(msg, attr1); |
| 11414 | nla_nest_end(msg, attr); |
| 11415 | |
| 11416 | ret = send_and_recv_msgs(drv, msg, |
| 11417 | nl80211_get_bss_transition_status_handler, |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11418 | info, NULL, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11419 | msg = NULL; |
| 11420 | if (ret) { |
| 11421 | wpa_printf(MSG_ERROR, |
| 11422 | "nl80211: WNM Get BSS transition status failed: ret=%d (%s)", |
| 11423 | ret, strerror(-ret)); |
| 11424 | goto fail; |
| 11425 | } |
| 11426 | return info; |
| 11427 | |
| 11428 | fail: |
| 11429 | nlmsg_free(msg); |
| 11430 | os_free(info->candidates); |
| 11431 | os_free(info); |
| 11432 | return NULL; |
| 11433 | } |
| 11434 | |
| 11435 | |
| 11436 | /** |
| 11437 | * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow |
| 11438 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() |
| 11439 | * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore |
| 11440 | * Returns: 0 on success, -1 on failure |
| 11441 | */ |
| 11442 | static int nl80211_ignore_assoc_disallow(void *priv, int ignore_disallow) |
| 11443 | { |
| 11444 | struct i802_bss *bss = priv; |
| 11445 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11446 | struct nl_msg *msg; |
| 11447 | struct nlattr *attr; |
| 11448 | int ret = -1; |
| 11449 | |
| 11450 | if (!drv->set_wifi_conf_vendor_cmd_avail) |
| 11451 | return -1; |
| 11452 | |
| 11453 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11454 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11455 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11456 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) |
| 11457 | goto fail; |
| 11458 | |
| 11459 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 11460 | if (!attr) |
| 11461 | goto fail; |
| 11462 | |
| 11463 | wpa_printf(MSG_DEBUG, "nl80211: Set ignore_assoc_disallow %d", |
| 11464 | ignore_disallow); |
| 11465 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED, |
| 11466 | ignore_disallow)) |
| 11467 | goto fail; |
| 11468 | |
| 11469 | nla_nest_end(msg, attr); |
| 11470 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11471 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11472 | msg = NULL; |
| 11473 | if (ret) { |
| 11474 | wpa_printf(MSG_ERROR, |
| 11475 | "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)", |
| 11476 | ret, strerror(-ret)); |
| 11477 | goto fail; |
| 11478 | } |
| 11479 | |
| 11480 | fail: |
| 11481 | nlmsg_free(msg); |
| 11482 | return ret; |
| 11483 | } |
| 11484 | |
| 11485 | #endif /* CONFIG_MBO */ |
| 11486 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11487 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 11488 | |
| 11489 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11490 | static int nl80211_write_to_file(const char *name, unsigned int val) |
| 11491 | { |
| 11492 | int fd, len; |
| 11493 | char tmp[128]; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11494 | int ret = 0; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11495 | |
| 11496 | fd = open(name, O_RDWR); |
| 11497 | if (fd < 0) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11498 | int level; |
| 11499 | /* |
| 11500 | * Flags may not exist on older kernels, or while we're tearing |
| 11501 | * down a disappearing device. |
| 11502 | */ |
| 11503 | if (errno == ENOENT) { |
| 11504 | ret = 0; |
| 11505 | level = MSG_DEBUG; |
| 11506 | } else { |
| 11507 | ret = -1; |
| 11508 | level = MSG_ERROR; |
| 11509 | } |
| 11510 | wpa_printf(level, "nl80211: Failed to open %s: %s", |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11511 | name, strerror(errno)); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11512 | return ret; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11513 | } |
| 11514 | |
| 11515 | len = os_snprintf(tmp, sizeof(tmp), "%u\n", val); |
| 11516 | len = write(fd, tmp, len); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11517 | if (len < 0) { |
| 11518 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11519 | wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s", |
| 11520 | name, strerror(errno)); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11521 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11522 | close(fd); |
| 11523 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11524 | return ret; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11525 | } |
| 11526 | |
| 11527 | |
| 11528 | static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags) |
| 11529 | { |
| 11530 | struct i802_bss *bss = priv; |
| 11531 | char path[128]; |
| 11532 | int ret; |
| 11533 | |
| 11534 | wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x", |
| 11535 | filter_flags); |
| 11536 | |
| 11537 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 11538 | ret = os_snprintf(path, sizeof(path), |
| 11539 | "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast", |
| 11540 | bss->ifname); |
| 11541 | if (os_snprintf_error(sizeof(path), ret)) |
| 11542 | return -1; |
| 11543 | |
| 11544 | ret = nl80211_write_to_file(path, |
| 11545 | !!(filter_flags & |
| 11546 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 11547 | if (ret) { |
| 11548 | wpa_printf(MSG_ERROR, |
| 11549 | "nl80211: Failed to set IPv4 unicast in multicast filter"); |
| 11550 | return ret; |
| 11551 | } |
| 11552 | |
| 11553 | os_snprintf(path, sizeof(path), |
| 11554 | "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast", |
| 11555 | bss->ifname); |
| 11556 | ret = nl80211_write_to_file(path, |
| 11557 | !!(filter_flags & |
| 11558 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 11559 | |
| 11560 | if (ret) { |
| 11561 | wpa_printf(MSG_ERROR, |
| 11562 | "nl80211: Failed to set IPv6 unicast in multicast filter"); |
| 11563 | return ret; |
| 11564 | } |
| 11565 | |
| 11566 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 11567 | os_snprintf(path, sizeof(path), |
| 11568 | "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp", |
| 11569 | bss->ifname); |
| 11570 | ret = nl80211_write_to_file(path, |
| 11571 | !!(filter_flags & |
| 11572 | WPA_DATA_FRAME_FILTER_FLAG_ARP)); |
| 11573 | if (ret) { |
| 11574 | wpa_printf(MSG_ERROR, |
| 11575 | "nl80211: Failed set gratuitous ARP filter"); |
| 11576 | return ret; |
| 11577 | } |
| 11578 | |
| 11579 | /* Configure filtering of IPv6 NA frames */ |
| 11580 | os_snprintf(path, sizeof(path), |
| 11581 | "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na", |
| 11582 | bss->ifname); |
| 11583 | ret = nl80211_write_to_file(path, |
| 11584 | !!(filter_flags & |
| 11585 | WPA_DATA_FRAME_FILTER_FLAG_NA)); |
| 11586 | if (ret) { |
| 11587 | wpa_printf(MSG_ERROR, |
| 11588 | "nl80211: Failed to set unsolicited NA filter"); |
| 11589 | return ret; |
| 11590 | } |
| 11591 | |
| 11592 | return 0; |
| 11593 | } |
| 11594 | |
| 11595 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 11596 | static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type, |
| 11597 | const u8 **ext_capa, const u8 **ext_capa_mask, |
| 11598 | unsigned int *ext_capa_len) |
| 11599 | { |
| 11600 | struct i802_bss *bss = priv; |
| 11601 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11602 | enum nl80211_iftype nlmode; |
| 11603 | unsigned int i; |
| 11604 | |
| 11605 | if (!ext_capa || !ext_capa_mask || !ext_capa_len) |
| 11606 | return -1; |
| 11607 | |
| 11608 | nlmode = wpa_driver_nl80211_if_type(type); |
| 11609 | |
| 11610 | /* By default, use the per-radio values */ |
| 11611 | *ext_capa = drv->extended_capa; |
| 11612 | *ext_capa_mask = drv->extended_capa_mask; |
| 11613 | *ext_capa_len = drv->extended_capa_len; |
| 11614 | |
| 11615 | /* Replace the default value if a per-interface type value exists */ |
| 11616 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 11617 | if (nlmode == drv->iface_ext_capa[i].iftype) { |
| 11618 | *ext_capa = drv->iface_ext_capa[i].ext_capa; |
| 11619 | *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask; |
| 11620 | *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len; |
| 11621 | break; |
| 11622 | } |
| 11623 | } |
| 11624 | |
| 11625 | return 0; |
| 11626 | } |
| 11627 | |
| 11628 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11629 | static int nl80211_update_connection_params( |
| 11630 | void *priv, struct wpa_driver_associate_params *params, |
| 11631 | enum wpa_drv_update_connect_params_mask mask) |
| 11632 | { |
| 11633 | struct i802_bss *bss = priv; |
| 11634 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11635 | struct nl_msg *msg; |
| 11636 | int ret = -1; |
| 11637 | enum nl80211_auth_type type; |
| 11638 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11639 | /* Update Connection Params is intended for drivers that implement |
| 11640 | * internal SME and expect these updated connection params from |
| 11641 | * wpa_supplicant. Do not send this request for the drivers using |
| 11642 | * SME from wpa_supplicant. |
| 11643 | */ |
| 11644 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) |
| 11645 | return 0; |
| 11646 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11647 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS); |
| 11648 | if (!msg) |
| 11649 | goto fail; |
| 11650 | |
| 11651 | wpa_printf(MSG_DEBUG, "nl80211: Update connection params (ifindex=%d)", |
| 11652 | drv->ifindex); |
| 11653 | |
| 11654 | if ((mask & WPA_DRV_UPDATE_ASSOC_IES) && params->wpa_ie) { |
| 11655 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 11656 | params->wpa_ie)) |
| 11657 | goto fail; |
| 11658 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, |
| 11659 | params->wpa_ie_len); |
| 11660 | } |
| 11661 | |
| 11662 | if (mask & WPA_DRV_UPDATE_AUTH_TYPE) { |
| 11663 | type = get_nl_auth_type(params->auth_alg); |
| 11664 | if (type == NL80211_AUTHTYPE_MAX || |
| 11665 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 11666 | goto fail; |
| 11667 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
| 11668 | } |
| 11669 | |
| 11670 | if ((mask & WPA_DRV_UPDATE_FILS_ERP_INFO) && |
| 11671 | nl80211_put_fils_connect_params(drv, params, msg)) |
| 11672 | goto fail; |
| 11673 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11674 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11675 | msg = NULL; |
| 11676 | if (ret) |
| 11677 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 11678 | "nl80211: Update connect params command failed: ret=%d (%s)", |
| 11679 | ret, strerror(-ret)); |
| 11680 | |
| 11681 | fail: |
| 11682 | nlmsg_free(msg); |
| 11683 | return ret; |
| 11684 | } |
| 11685 | |
| 11686 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11687 | static int nl80211_send_external_auth_status(void *priv, |
| 11688 | struct external_auth *params) |
| 11689 | { |
| 11690 | struct i802_bss *bss = priv; |
| 11691 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11692 | struct nl_msg *msg = NULL; |
| 11693 | int ret = -1; |
| 11694 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 11695 | /* External auth command/status is intended for drivers that implement |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 11696 | * internal SME but want to offload authentication processing (e.g., |
| 11697 | * SAE) to hostapd/wpa_supplicant. Do not send the status to drivers |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 11698 | * which do not support AP SME or use wpa_supplicant/hostapd SME. |
| 11699 | */ |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 11700 | if ((is_ap_interface(drv->nlmode) && !bss->drv->device_ap_sme) || |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 11701 | (drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
| 11702 | return -1; |
| 11703 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11704 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 11705 | "nl80211: External auth status: %u", params->status); |
| 11706 | |
| 11707 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_EXTERNAL_AUTH); |
| 11708 | if (!msg || |
| 11709 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, params->status) || |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 11710 | (params->ssid && params->ssid_len && |
| 11711 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || |
| 11712 | (params->pmkid && |
| 11713 | nla_put(msg, NL80211_ATTR_PMKID, PMKID_LEN, params->pmkid)) || |
| 11714 | (params->bssid && |
| 11715 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid))) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11716 | goto fail; |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11717 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11718 | msg = NULL; |
| 11719 | if (ret) { |
| 11720 | wpa_printf(MSG_DEBUG, |
| 11721 | "nl80211: External Auth status update failed: ret=%d (%s)", |
| 11722 | ret, strerror(-ret)); |
| 11723 | goto fail; |
| 11724 | } |
| 11725 | fail: |
| 11726 | nlmsg_free(msg); |
| 11727 | return ret; |
| 11728 | } |
| 11729 | |
| 11730 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 11731 | static int nl80211_set_4addr_mode(void *priv, const char *bridge_ifname, |
| 11732 | int val) |
| 11733 | { |
| 11734 | struct i802_bss *bss = priv; |
| 11735 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11736 | struct nl_msg *msg; |
| 11737 | int ret = -ENOBUFS; |
| 11738 | |
| 11739 | wpa_printf(MSG_DEBUG, "nl80211: %s 4addr mode (bridge_ifname: %s)", |
| 11740 | val ? "Enable" : "Disable", bridge_ifname); |
| 11741 | |
| 11742 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 11743 | if (!msg || nla_put_u8(msg, NL80211_ATTR_4ADDR, val)) |
| 11744 | goto fail; |
| 11745 | |
| 11746 | if (bridge_ifname[0] && bss->added_if_into_bridge && !val) { |
| 11747 | if (linux_br_del_if(drv->global->ioctl_sock, |
| 11748 | bridge_ifname, bss->ifname)) { |
| 11749 | wpa_printf(MSG_ERROR, |
| 11750 | "nl80211: Failed to remove interface %s from bridge %s", |
| 11751 | bss->ifname, bridge_ifname); |
| 11752 | return -1; |
| 11753 | } |
| 11754 | bss->added_if_into_bridge = 0; |
| 11755 | } |
| 11756 | |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11757 | ret = send_and_recv_msgs(drv, msg, NULL, NULL, NULL, NULL); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 11758 | msg = NULL; |
| 11759 | if (!ret) { |
| 11760 | if (bridge_ifname[0] && val && |
| 11761 | i802_check_bridge(drv, bss, bridge_ifname, bss->ifname) < 0) |
| 11762 | return -1; |
| 11763 | return 0; |
| 11764 | } |
| 11765 | |
| 11766 | fail: |
| 11767 | nlmsg_free(msg); |
| 11768 | wpa_printf(MSG_ERROR, "nl80211: Failed to enable/disable 4addr"); |
| 11769 | |
| 11770 | return ret; |
| 11771 | } |
| 11772 | |
| 11773 | |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 11774 | #ifdef CONFIG_DPP |
| 11775 | static int nl80211_dpp_listen(void *priv, bool enable) |
| 11776 | { |
| 11777 | struct i802_bss *bss = priv; |
| 11778 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11779 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
| 11780 | struct nl_sock *handle; |
| 11781 | |
| 11782 | if (!drv->multicast_registrations || !bss->nl_mgmt) |
| 11783 | return 0; /* cannot do more than hope broadcast RX works */ |
| 11784 | |
| 11785 | wpa_printf(MSG_DEBUG, |
| 11786 | "nl80211: Update DPP Public Action frame registration (%s multicast RX)", |
| 11787 | enable ? "enable" : "disable"); |
| 11788 | handle = (void *) (((intptr_t) bss->nl_mgmt) ^ ELOOP_SOCKET_INVALID); |
| 11789 | return nl80211_register_frame(bss, handle, type, |
| 11790 | (u8 *) "\x04\x09\x50\x6f\x9a\x1a", 6, |
| 11791 | enable); |
| 11792 | } |
| 11793 | #endif /* CONFIG_DPP */ |
| 11794 | |
| 11795 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11796 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 11797 | .name = "nl80211", |
| 11798 | .desc = "Linux nl80211/cfg80211", |
| 11799 | .get_bssid = wpa_driver_nl80211_get_bssid, |
| 11800 | .get_ssid = wpa_driver_nl80211_get_ssid, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11801 | .set_key = driver_nl80211_set_key, |
| 11802 | .scan2 = driver_nl80211_scan2, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11803 | .sched_scan = wpa_driver_nl80211_sched_scan, |
| 11804 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11805 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 11806 | .abort_scan = wpa_driver_nl80211_abort_scan, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11807 | .deauthenticate = driver_nl80211_deauthenticate, |
| 11808 | .authenticate = driver_nl80211_authenticate, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11809 | .associate = wpa_driver_nl80211_associate, |
| 11810 | .global_init = nl80211_global_init, |
| 11811 | .global_deinit = nl80211_global_deinit, |
| 11812 | .init2 = wpa_driver_nl80211_init, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11813 | .deinit = driver_nl80211_deinit, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11814 | .get_capa = wpa_driver_nl80211_get_capa, |
| 11815 | .set_operstate = wpa_driver_nl80211_set_operstate, |
| 11816 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
| 11817 | .set_country = wpa_driver_nl80211_set_country, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 11818 | .get_country = wpa_driver_nl80211_get_country, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11819 | .set_ap = wpa_driver_nl80211_set_ap, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 11820 | .set_acl = wpa_driver_nl80211_set_acl, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11821 | .if_add = wpa_driver_nl80211_if_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11822 | .if_remove = driver_nl80211_if_remove, |
| 11823 | .send_mlme = driver_nl80211_send_mlme, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11824 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11825 | .sta_add = wpa_driver_nl80211_sta_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11826 | .sta_remove = driver_nl80211_sta_remove, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11827 | .tx_control_port = nl80211_tx_control_port, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11828 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
| 11829 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 11830 | .sta_set_airtime_weight = driver_nl80211_sta_set_airtime_weight, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11831 | .hapd_init = i802_init, |
| 11832 | .hapd_deinit = i802_deinit, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 11833 | .set_wds_sta = i802_set_wds_sta, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11834 | .get_seqnum = i802_get_seqnum, |
| 11835 | .flush = i802_flush, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11836 | .get_inact_sec = i802_get_inact_sec, |
| 11837 | .sta_clear_stats = i802_sta_clear_stats, |
| 11838 | .set_rts = i802_set_rts, |
| 11839 | .set_frag = i802_set_frag, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11840 | .set_tx_queue_params = i802_set_tx_queue_params, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11841 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11842 | .sta_deauth = i802_sta_deauth, |
| 11843 | .sta_disassoc = i802_sta_disassoc, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11844 | .read_sta_data = driver_nl80211_read_sta_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11845 | .set_freq = i802_set_freq, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11846 | .send_action = driver_nl80211_send_action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11847 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
| 11848 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
| 11849 | .cancel_remain_on_channel = |
| 11850 | wpa_driver_nl80211_cancel_remain_on_channel, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11851 | .probe_req_report = driver_nl80211_probe_req_report, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11852 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 11853 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11854 | .resume = wpa_driver_nl80211_resume, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11855 | .signal_monitor = nl80211_signal_monitor, |
| 11856 | .signal_poll = nl80211_signal_poll, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 11857 | .channel_info = nl80211_channel_info, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11858 | .set_param = nl80211_set_param, |
| 11859 | .get_radio_name = nl80211_get_radio_name, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 11860 | .add_pmkid = nl80211_add_pmkid, |
| 11861 | .remove_pmkid = nl80211_remove_pmkid, |
| 11862 | .flush_pmkid = nl80211_flush_pmkid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11863 | .set_rekey_info = nl80211_set_rekey_info, |
| 11864 | .poll_client = nl80211_poll_client, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11865 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 11866 | .start_dfs_cac = nl80211_start_radar_detection, |
| 11867 | .stop_ap = wpa_driver_nl80211_stop_ap, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11868 | #ifdef CONFIG_TDLS |
| 11869 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, |
| 11870 | .tdls_oper = nl80211_tdls_oper, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11871 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
| 11872 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11873 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 11874 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 11875 | .update_dh_ie = nl80211_update_dh_ie, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 11876 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 11877 | .get_survey = wpa_driver_nl80211_get_survey, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11878 | .status = wpa_driver_nl80211_status, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11879 | .switch_channel = nl80211_switch_channel, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11880 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 11881 | .set_noa = wpa_driver_set_p2p_noa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11882 | .get_noa = wpa_driver_get_p2p_noa, |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 11883 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 11884 | #endif /* ANDROID_P2P */ |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 11885 | #ifdef ANDROID |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 11886 | #ifndef ANDROID_LIB_STUB |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 11887 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 11888 | #endif /* !ANDROID_LIB_STUB */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 11889 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 11890 | .vendor_cmd = nl80211_vendor_cmd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11891 | .set_qos_map = nl80211_set_qos_map, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11892 | .get_wowlan = nl80211_get_wowlan, |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 11893 | .set_wowlan = nl80211_set_wowlan, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11894 | .set_mac_addr = nl80211_set_mac_addr, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11895 | #ifdef CONFIG_MESH |
| 11896 | .init_mesh = wpa_driver_nl80211_init_mesh, |
| 11897 | .join_mesh = wpa_driver_nl80211_join_mesh, |
| 11898 | .leave_mesh = wpa_driver_nl80211_leave_mesh, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 11899 | .probe_mesh_link = nl80211_probe_mesh_link, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11900 | #endif /* CONFIG_MESH */ |
| 11901 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
| 11902 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, |
| 11903 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
| 11904 | .br_set_net_param = wpa_driver_br_set_net_param, |
| 11905 | .add_tx_ts = nl80211_add_ts, |
| 11906 | .del_tx_ts = nl80211_del_ts, |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 11907 | .get_ifindex = nl80211_get_ifindex, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11908 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 11909 | .roaming = nl80211_roaming, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11910 | .disable_fils = nl80211_disable_fils, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11911 | .do_acs = wpa_driver_do_acs, |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11912 | .set_band = nl80211_set_band, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11913 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
| 11914 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 11915 | .p2p_lo_start = nl80211_p2p_lo_start, |
| 11916 | .p2p_lo_stop = nl80211_p2p_lo_stop, |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 11917 | .set_default_scan_ies = nl80211_set_default_scan_ies, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 11918 | .set_tdls_mode = nl80211_set_tdls_mode, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11919 | #ifdef CONFIG_MBO |
| 11920 | .get_bss_transition_status = nl80211_get_bss_transition_status, |
| 11921 | .ignore_assoc_disallow = nl80211_ignore_assoc_disallow, |
| 11922 | #endif /* CONFIG_MBO */ |
Hai Shalom | 899fcc7 | 2020-10-19 14:38:18 -0700 | [diff] [blame] | 11923 | .set_bssid_tmp_disallow = nl80211_set_bssid_tmp_disallow, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11924 | .add_sta_node = nl80211_add_sta_node, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11925 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11926 | .configure_data_frame_filters = nl80211_configure_data_frame_filters, |
Ajay Davanageri | b921bb8 | 2020-09-16 12:49:08 +0530 | [diff] [blame] | 11927 | #if defined(CONFIG_DRIVER_NL80211_BRCM) |
| 11928 | .do_acs = wpa_driver_do_broadcom_acs, |
| 11929 | #endif /* CONFIG_DRIVER_NL80211_BRCM */ |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 11930 | .get_ext_capab = nl80211_get_ext_capab, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11931 | .update_connect_params = nl80211_update_connection_params, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11932 | .send_external_auth_status = nl80211_send_external_auth_status, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 11933 | .set_4addr_mode = nl80211_set_4addr_mode, |
Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 11934 | #ifdef CONFIG_DPP |
| 11935 | .dpp_listen = nl80211_dpp_listen, |
| 11936 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11937 | }; |