| 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" | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 40 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 41 |  | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 42 | #ifndef NETLINK_CAP_ACK | 
|  | 43 | #define NETLINK_CAP_ACK 10 | 
|  | 44 | #endif /* NETLINK_CAP_ACK */ | 
| Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 45 | /* support for extack if compilation headers are too old */ | 
|  | 46 | #ifndef NETLINK_EXT_ACK | 
|  | 47 | #define NETLINK_EXT_ACK 11 | 
|  | 48 | enum nlmsgerr_attrs { | 
|  | 49 | NLMSGERR_ATTR_UNUSED, | 
|  | 50 | NLMSGERR_ATTR_MSG, | 
|  | 51 | NLMSGERR_ATTR_OFFS, | 
|  | 52 | NLMSGERR_ATTR_COOKIE, | 
|  | 53 |  | 
|  | 54 | __NLMSGERR_ATTR_MAX, | 
|  | 55 | NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1 | 
|  | 56 | }; | 
|  | 57 | #endif | 
|  | 58 | #ifndef NLM_F_CAPPED | 
|  | 59 | #define NLM_F_CAPPED 0x100 | 
|  | 60 | #endif | 
|  | 61 | #ifndef NLM_F_ACK_TLVS | 
|  | 62 | #define NLM_F_ACK_TLVS 0x200 | 
|  | 63 | #endif | 
|  | 64 | #ifndef SOL_NETLINK | 
|  | 65 | #define SOL_NETLINK 270 | 
|  | 66 | #endif | 
|  | 67 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 68 |  | 
| Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 69 | #ifdef ANDROID | 
|  | 70 | /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */ | 
| Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 71 | #undef nl_socket_set_nonblocking | 
|  | 72 | #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 73 |  | 
| Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 74 | #endif /* ANDROID */ | 
|  | 75 |  | 
|  | 76 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 77 | 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] | 78 | { | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 79 | struct nl_sock *handle; | 
| 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 | handle = nl_socket_alloc_cb(cb); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 82 | if (handle == NULL) { | 
|  | 83 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " | 
|  | 84 | "callbacks (%s)", dbg); | 
|  | 85 | return NULL; | 
|  | 86 | } | 
|  | 87 |  | 
|  | 88 | if (genl_connect(handle)) { | 
|  | 89 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " | 
|  | 90 | "netlink (%s)", dbg); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 91 | nl_socket_free(handle); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 92 | return NULL; | 
|  | 93 | } | 
|  | 94 |  | 
|  | 95 | return handle; | 
|  | 96 | } | 
|  | 97 |  | 
|  | 98 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 99 | static void nl_destroy_handles(struct nl_sock **handle) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 100 | { | 
|  | 101 | if (*handle == NULL) | 
|  | 102 | return; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 103 | nl_socket_free(*handle); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 104 | *handle = NULL; | 
|  | 105 | } | 
|  | 106 |  | 
|  | 107 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 108 | #if __WORDSIZE == 64 | 
|  | 109 | #define ELOOP_SOCKET_INVALID	(intptr_t) 0x8888888888888889ULL | 
|  | 110 | #else | 
|  | 111 | #define ELOOP_SOCKET_INVALID	(intptr_t) 0x88888889ULL | 
|  | 112 | #endif | 
|  | 113 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 114 | static void nl80211_register_eloop_read(struct nl_sock **handle, | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 115 | eloop_sock_handler handler, | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 116 | void *eloop_data, int persist) | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 117 | { | 
| Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 118 | /* | 
|  | 119 | * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB) | 
|  | 120 | * by default. It is possible to hit that limit in some cases where | 
|  | 121 | * operations are blocked, e.g., with a burst of Deauthentication frames | 
|  | 122 | * to hostapd and STA entry deletion. Try to increase the buffer to make | 
|  | 123 | * this less likely to occur. | 
|  | 124 | */ | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 125 | int err; | 
|  | 126 |  | 
|  | 127 | err = nl_socket_set_buffer_size(*handle, 262144, 0); | 
|  | 128 | if (err < 0) { | 
| Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 129 | wpa_printf(MSG_DEBUG, | 
|  | 130 | "nl80211: Could not set nl_socket RX buffer size: %s", | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 131 | nl_geterror(err)); | 
| Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 132 | /* continue anyway with the default (smaller) buffer */ | 
|  | 133 | } | 
| Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 134 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 135 | nl_socket_set_nonblocking(*handle); | 
|  | 136 | eloop_register_read_sock(nl_socket_get_fd(*handle), handler, | 
|  | 137 | eloop_data, *handle); | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 138 | if (!persist) | 
|  | 139 | *handle = (void *) (((intptr_t) *handle) ^ | 
|  | 140 | ELOOP_SOCKET_INVALID); | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 141 | } | 
|  | 142 |  | 
|  | 143 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 144 | static void nl80211_destroy_eloop_handle(struct nl_sock **handle, int persist) | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 145 | { | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 146 | if (!persist) | 
|  | 147 | *handle = (void *) (((intptr_t) *handle) ^ | 
|  | 148 | ELOOP_SOCKET_INVALID); | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 149 | eloop_unregister_read_sock(nl_socket_get_fd(*handle)); | 
|  | 150 | nl_destroy_handles(handle); | 
|  | 151 | } | 
|  | 152 |  | 
|  | 153 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 154 | static void nl80211_global_deinit(void *priv); | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 155 | static void nl80211_check_global(struct nl80211_global *global); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 156 |  | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 157 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); | 
| Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 158 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, | 
|  | 159 | struct hostapd_freq_params *freq); | 
| Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 160 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 161 | static int | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 162 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 163 | const u8 *set_addr, int first, | 
|  | 164 | const char *driver_params); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 165 | static int nl80211_send_frame_cmd(struct i802_bss *bss, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 166 | unsigned int freq, unsigned int wait, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 167 | const u8 *buf, size_t buf_len, | 
|  | 168 | int save_cookie, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 169 | int no_cck, int no_ack, int offchanok, | 
|  | 170 | const u16 *csa_offs, size_t csa_offs_len); | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 171 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, | 
|  | 172 | int report); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 173 |  | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 174 | #define IFIDX_ANY -1 | 
|  | 175 |  | 
|  | 176 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, | 
|  | 177 | int ifidx_reason); | 
|  | 178 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, | 
|  | 179 | int ifidx_reason); | 
|  | 180 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, | 
|  | 181 | int ifidx_reason); | 
| Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 182 |  | 
| Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 183 | static int nl80211_set_channel(struct i802_bss *bss, | 
|  | 184 | struct hostapd_freq_params *freq, int set_chan); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 185 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, | 
|  | 186 | int ifindex, int disabled); | 
|  | 187 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 188 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, | 
|  | 189 | int reset_mode); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 190 |  | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 191 | static int i802_set_iface_flags(struct i802_bss *bss, int up); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 192 | static int nl80211_set_param(void *priv, const char *param); | 
| Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 193 | #ifdef CONFIG_MESH | 
|  | 194 | static int nl80211_put_mesh_config(struct nl_msg *msg, | 
|  | 195 | struct wpa_driver_mesh_bss_params *params); | 
|  | 196 | #endif /* CONFIG_MESH */ | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 197 | 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] | 198 | u16 reason); | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 199 |  | 
|  | 200 |  | 
| Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 201 | /* Converts nl80211_chan_width to a common format */ | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 202 | enum chan_width convert2width(int width) | 
| Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 203 | { | 
|  | 204 | switch (width) { | 
|  | 205 | case NL80211_CHAN_WIDTH_20_NOHT: | 
|  | 206 | return CHAN_WIDTH_20_NOHT; | 
|  | 207 | case NL80211_CHAN_WIDTH_20: | 
|  | 208 | return CHAN_WIDTH_20; | 
|  | 209 | case NL80211_CHAN_WIDTH_40: | 
|  | 210 | return CHAN_WIDTH_40; | 
|  | 211 | case NL80211_CHAN_WIDTH_80: | 
|  | 212 | return CHAN_WIDTH_80; | 
|  | 213 | case NL80211_CHAN_WIDTH_80P80: | 
|  | 214 | return CHAN_WIDTH_80P80; | 
|  | 215 | case NL80211_CHAN_WIDTH_160: | 
|  | 216 | return CHAN_WIDTH_160; | 
|  | 217 | } | 
|  | 218 | return CHAN_WIDTH_UNKNOWN; | 
|  | 219 | } | 
|  | 220 |  | 
|  | 221 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 222 | int is_ap_interface(enum nl80211_iftype nlmode) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 223 | { | 
| Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 224 | return nlmode == NL80211_IFTYPE_AP || | 
|  | 225 | nlmode == NL80211_IFTYPE_P2P_GO; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 226 | } | 
|  | 227 |  | 
|  | 228 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 229 | int is_sta_interface(enum nl80211_iftype nlmode) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 230 | { | 
| Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 231 | return nlmode == NL80211_IFTYPE_STATION || | 
|  | 232 | nlmode == NL80211_IFTYPE_P2P_CLIENT; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 233 | } | 
|  | 234 |  | 
|  | 235 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 236 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 237 | { | 
| Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 238 | return nlmode == NL80211_IFTYPE_P2P_CLIENT || | 
|  | 239 | nlmode == NL80211_IFTYPE_P2P_GO; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 240 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 241 |  | 
|  | 242 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 243 | struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, | 
|  | 244 | int ifindex) | 
| Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 245 | { | 
|  | 246 | struct i802_bss *bss; | 
|  | 247 |  | 
|  | 248 | for (bss = drv->first_bss; bss; bss = bss->next) { | 
|  | 249 | if (bss->ifindex == ifindex) | 
|  | 250 | return bss; | 
|  | 251 | } | 
|  | 252 |  | 
|  | 253 | return NULL; | 
|  | 254 | } | 
|  | 255 |  | 
|  | 256 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 257 | static int is_mesh_interface(enum nl80211_iftype nlmode) | 
|  | 258 | { | 
|  | 259 | return nlmode == NL80211_IFTYPE_MESH_POINT; | 
|  | 260 | } | 
|  | 261 |  | 
|  | 262 |  | 
|  | 263 | void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 264 | { | 
|  | 265 | if (drv->associated) | 
|  | 266 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); | 
|  | 267 | drv->associated = 0; | 
|  | 268 | os_memset(drv->bssid, 0, ETH_ALEN); | 
| Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 269 | drv->first_bss->freq = 0; | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 270 | } | 
|  | 271 |  | 
|  | 272 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 273 | /* nl80211 code */ | 
|  | 274 | static int ack_handler(struct nl_msg *msg, void *arg) | 
|  | 275 | { | 
|  | 276 | int *err = arg; | 
|  | 277 | *err = 0; | 
|  | 278 | return NL_STOP; | 
|  | 279 | } | 
|  | 280 |  | 
|  | 281 | static int finish_handler(struct nl_msg *msg, void *arg) | 
|  | 282 | { | 
|  | 283 | int *ret = arg; | 
|  | 284 | *ret = 0; | 
|  | 285 | return NL_SKIP; | 
|  | 286 | } | 
|  | 287 |  | 
|  | 288 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, | 
|  | 289 | void *arg) | 
|  | 290 | { | 
| Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 291 | struct nlmsghdr *nlh = (struct nlmsghdr *) err - 1; | 
|  | 292 | int len = nlh->nlmsg_len; | 
|  | 293 | struct nlattr *attrs; | 
|  | 294 | struct nlattr *tb[NLMSGERR_ATTR_MAX + 1]; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 295 | int *ret = arg; | 
| Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 296 | int ack_len = sizeof(*nlh) + sizeof(int) + sizeof(*nlh); | 
|  | 297 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 298 | *ret = err->error; | 
| Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 299 |  | 
|  | 300 | if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS)) | 
|  | 301 | return NL_SKIP; | 
|  | 302 |  | 
|  | 303 | if (!(nlh->nlmsg_flags & NLM_F_CAPPED)) | 
|  | 304 | ack_len += err->msg.nlmsg_len - sizeof(*nlh); | 
|  | 305 |  | 
|  | 306 | if (len <= ack_len) | 
|  | 307 | return NL_STOP; | 
|  | 308 |  | 
|  | 309 | attrs = (void *) ((unsigned char *) nlh + ack_len); | 
|  | 310 | len -= ack_len; | 
|  | 311 |  | 
|  | 312 | nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, len, NULL); | 
|  | 313 | if (tb[NLMSGERR_ATTR_MSG]) { | 
|  | 314 | len = strnlen((char *) nla_data(tb[NLMSGERR_ATTR_MSG]), | 
|  | 315 | nla_len(tb[NLMSGERR_ATTR_MSG])); | 
|  | 316 | wpa_printf(MSG_ERROR, "nl80211: kernel reports: %*s", | 
|  | 317 | len, (char *) nla_data(tb[NLMSGERR_ATTR_MSG])); | 
|  | 318 | } | 
|  | 319 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 320 | return NL_SKIP; | 
|  | 321 | } | 
|  | 322 |  | 
|  | 323 |  | 
|  | 324 | static int no_seq_check(struct nl_msg *msg, void *arg) | 
|  | 325 | { | 
|  | 326 | return NL_OK; | 
|  | 327 | } | 
|  | 328 |  | 
|  | 329 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 330 | static void nl80211_nlmsg_clear(struct nl_msg *msg) | 
|  | 331 | { | 
|  | 332 | /* | 
|  | 333 | * Clear nlmsg data, e.g., to make sure key material is not left in | 
|  | 334 | * heap memory for unnecessarily long time. | 
|  | 335 | */ | 
|  | 336 | if (msg) { | 
|  | 337 | struct nlmsghdr *hdr = nlmsg_hdr(msg); | 
|  | 338 | void *data = nlmsg_data(hdr); | 
|  | 339 | /* | 
|  | 340 | * This would use nlmsg_datalen() or the older nlmsg_len() if | 
|  | 341 | * only libnl were to maintain a stable API.. Neither will work | 
|  | 342 | * with all released versions, so just calculate the length | 
|  | 343 | * here. | 
|  | 344 | */ | 
|  | 345 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; | 
|  | 346 |  | 
|  | 347 | os_memset(data, 0, len); | 
|  | 348 | } | 
|  | 349 | } | 
|  | 350 |  | 
|  | 351 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 352 | static int send_and_recv(struct nl80211_global *global, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 353 | struct nl_sock *nl_handle, struct nl_msg *msg, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 354 | int (*valid_handler)(struct nl_msg *, void *), | 
|  | 355 | void *valid_data) | 
|  | 356 | { | 
|  | 357 | struct nl_cb *cb; | 
| Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 358 | int err = -ENOMEM, opt; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 359 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 360 | if (!msg) | 
|  | 361 | return -ENOMEM; | 
|  | 362 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 363 | cb = nl_cb_clone(global->nl_cb); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 364 | if (!cb) | 
|  | 365 | goto out; | 
|  | 366 |  | 
| Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 367 | /* try to set NETLINK_EXT_ACK to 1, ignoring errors */ | 
|  | 368 | opt = 1; | 
|  | 369 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, | 
|  | 370 | NETLINK_EXT_ACK, &opt, sizeof(opt)); | 
|  | 371 |  | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 372 | /* try to set NETLINK_CAP_ACK to 1, ignoring errors */ | 
|  | 373 | opt = 1; | 
|  | 374 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, | 
|  | 375 | NETLINK_CAP_ACK, &opt, sizeof(opt)); | 
|  | 376 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 377 | err = nl_send_auto_complete(nl_handle, msg); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 378 | if (err < 0) { | 
|  | 379 | wpa_printf(MSG_INFO, | 
|  | 380 | "nl80211: nl_send_auto_complete() failed: %s", | 
|  | 381 | nl_geterror(err)); | 
|  | 382 | /* Need to convert libnl error code to an errno value. For now, | 
|  | 383 | * just hardcode this to EBADF; the real error reason is shown | 
|  | 384 | * in that error print above. */ | 
|  | 385 | err = -EBADF; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 386 | goto out; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 387 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 388 |  | 
|  | 389 | err = 1; | 
|  | 390 |  | 
|  | 391 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); | 
|  | 392 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); | 
|  | 393 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); | 
|  | 394 |  | 
|  | 395 | if (valid_handler) | 
|  | 396 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, | 
|  | 397 | valid_handler, valid_data); | 
|  | 398 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 399 | while (err > 0) { | 
|  | 400 | int res = nl_recvmsgs(nl_handle, cb); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 401 |  | 
|  | 402 | if (res == -NLE_DUMP_INTR) { | 
|  | 403 | /* Most likely one of the nl80211 dump routines hit a | 
|  | 404 | * case where internal results changed while the dump | 
|  | 405 | * was being sent. The most common known case for this | 
|  | 406 | * is scan results fetching while associated were every | 
|  | 407 | * received Beacon frame from the AP may end up | 
|  | 408 | * incrementing bss_generation. This | 
|  | 409 | * NL80211_CMD_GET_SCAN case tries again in the caller; | 
|  | 410 | * other cases (of which there are no known common ones) | 
|  | 411 | * will stop and return an error. */ | 
|  | 412 | wpa_printf(MSG_DEBUG, "nl80211: %s; convert to -EAGAIN", | 
|  | 413 | nl_geterror(res)); | 
|  | 414 | err = -EAGAIN; | 
|  | 415 | } else if (res < 0) { | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 416 | wpa_printf(MSG_INFO, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 417 | "nl80211: %s->nl_recvmsgs failed: %d (%s)", | 
|  | 418 | __func__, res, nl_geterror(res)); | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 419 | } | 
|  | 420 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 421 | out: | 
|  | 422 | nl_cb_put(cb); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 423 | if (!valid_handler && valid_data == (void *) -1) | 
|  | 424 | nl80211_nlmsg_clear(msg); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 425 | nlmsg_free(msg); | 
|  | 426 | return err; | 
|  | 427 | } | 
|  | 428 |  | 
|  | 429 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 430 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, | 
|  | 431 | struct nl_msg *msg, | 
|  | 432 | int (*valid_handler)(struct nl_msg *, void *), | 
|  | 433 | void *valid_data) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 434 | { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 435 | return send_and_recv(drv->global, drv->global->nl, msg, | 
|  | 436 | valid_handler, valid_data); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 437 | } | 
|  | 438 |  | 
|  | 439 |  | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 440 | /* Use this method to mark that it is necessary to own the connection/interface | 
|  | 441 | * for this operation. | 
|  | 442 | * handle may be set to NULL, to get the same behavior as send_and_recv_msgs(). | 
|  | 443 | * set_owner can be used to mark this socket for receiving control port frames. | 
|  | 444 | */ | 
|  | 445 | static int send_and_recv_msgs_owner(struct wpa_driver_nl80211_data *drv, | 
|  | 446 | struct nl_msg *msg, | 
|  | 447 | struct nl_sock *handle, int set_owner, | 
|  | 448 | int (*valid_handler)(struct nl_msg *, | 
|  | 449 | void *), | 
|  | 450 | void *valid_data) | 
|  | 451 | { | 
|  | 452 | /* Control port over nl80211 needs the flags and attributes below. | 
|  | 453 | * | 
|  | 454 | * The Linux kernel has initial checks for them (in nl80211.c) like: | 
|  | 455 | *     validate_pae_over_nl80211(...) | 
|  | 456 | * or final checks like: | 
|  | 457 | *     dev->ieee80211_ptr->conn_owner_nlportid != info->snd_portid | 
|  | 458 | * | 
|  | 459 | * Final operations (e.g., disassociate) don't need to set these | 
|  | 460 | * attributes, but they have to be performed on the socket, which has | 
|  | 461 | * the connection owner property set in the kernel. | 
|  | 462 | */ | 
|  | 463 | if ((drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) && | 
|  | 464 | handle && set_owner && | 
|  | 465 | (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_OVER_NL80211) || | 
|  | 466 | nla_put_flag(msg, NL80211_ATTR_SOCKET_OWNER) || | 
|  | 467 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || | 
|  | 468 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_PREAUTH))) | 
|  | 469 | return -1; | 
|  | 470 |  | 
|  | 471 | return send_and_recv(drv->global, handle ? handle : drv->global->nl, | 
|  | 472 | msg, valid_handler, valid_data); | 
|  | 473 | } | 
|  | 474 |  | 
|  | 475 |  | 
|  | 476 | struct nl_sock * get_connect_handle(struct i802_bss *bss) | 
|  | 477 | { | 
|  | 478 | if ((bss->drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) || | 
|  | 479 | bss->use_nl_connect) | 
|  | 480 | return bss->nl_connect; | 
|  | 481 |  | 
|  | 482 | return NULL; | 
|  | 483 | } | 
|  | 484 |  | 
|  | 485 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 486 | struct family_data { | 
|  | 487 | const char *group; | 
|  | 488 | int id; | 
|  | 489 | }; | 
|  | 490 |  | 
|  | 491 |  | 
|  | 492 | static int family_handler(struct nl_msg *msg, void *arg) | 
|  | 493 | { | 
|  | 494 | struct family_data *res = arg; | 
|  | 495 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; | 
|  | 496 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | 
|  | 497 | struct nlattr *mcgrp; | 
|  | 498 | int i; | 
|  | 499 |  | 
|  | 500 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | 
|  | 501 | genlmsg_attrlen(gnlh, 0), NULL); | 
|  | 502 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) | 
|  | 503 | return NL_SKIP; | 
|  | 504 |  | 
|  | 505 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { | 
|  | 506 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; | 
|  | 507 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), | 
|  | 508 | nla_len(mcgrp), NULL); | 
|  | 509 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || | 
|  | 510 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || | 
|  | 511 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), | 
|  | 512 | res->group, | 
|  | 513 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) | 
|  | 514 | continue; | 
|  | 515 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); | 
|  | 516 | break; | 
|  | 517 | }; | 
|  | 518 |  | 
|  | 519 | return NL_SKIP; | 
|  | 520 | } | 
|  | 521 |  | 
|  | 522 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 523 | static int nl_get_multicast_id(struct nl80211_global *global, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 524 | const char *family, const char *group) | 
|  | 525 | { | 
|  | 526 | struct nl_msg *msg; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 527 | int ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 528 | struct family_data res = { group, -ENOENT }; | 
|  | 529 |  | 
|  | 530 | msg = nlmsg_alloc(); | 
|  | 531 | if (!msg) | 
|  | 532 | return -ENOMEM; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 533 | if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), | 
|  | 534 | 0, 0, CTRL_CMD_GETFAMILY, 0) || | 
|  | 535 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { | 
|  | 536 | nlmsg_free(msg); | 
|  | 537 | return -1; | 
|  | 538 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 539 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 540 | ret = send_and_recv(global, global->nl, msg, family_handler, &res); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 541 | if (ret == 0) | 
|  | 542 | ret = res.id; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 543 | return ret; | 
|  | 544 | } | 
|  | 545 |  | 
|  | 546 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 547 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, | 
|  | 548 | struct nl_msg *msg, int flags, uint8_t cmd) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 549 | { | 
| Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 550 | if (TEST_FAIL()) | 
|  | 551 | return NULL; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 552 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, | 
|  | 553 | 0, flags, cmd, 0); | 
|  | 554 | } | 
|  | 555 |  | 
|  | 556 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 557 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) | 
|  | 558 | { | 
|  | 559 | if (bss->wdev_id_set) | 
|  | 560 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); | 
|  | 561 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); | 
|  | 562 | } | 
|  | 563 |  | 
|  | 564 |  | 
|  | 565 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) | 
|  | 566 | { | 
|  | 567 | struct nl_msg *msg; | 
|  | 568 |  | 
|  | 569 | msg = nlmsg_alloc(); | 
|  | 570 | if (!msg) | 
|  | 571 | return NULL; | 
|  | 572 |  | 
|  | 573 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || | 
|  | 574 | nl80211_set_iface_id(msg, bss) < 0) { | 
|  | 575 | nlmsg_free(msg); | 
|  | 576 | return NULL; | 
|  | 577 | } | 
|  | 578 |  | 
|  | 579 | return msg; | 
|  | 580 | } | 
|  | 581 |  | 
|  | 582 |  | 
|  | 583 | static struct nl_msg * | 
|  | 584 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, | 
|  | 585 | int flags, uint8_t cmd) | 
|  | 586 | { | 
|  | 587 | struct nl_msg *msg; | 
|  | 588 |  | 
|  | 589 | msg = nlmsg_alloc(); | 
|  | 590 | if (!msg) | 
|  | 591 | return NULL; | 
|  | 592 |  | 
|  | 593 | if (!nl80211_cmd(drv, msg, flags, cmd) || | 
|  | 594 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { | 
|  | 595 | nlmsg_free(msg); | 
|  | 596 | return NULL; | 
|  | 597 | } | 
|  | 598 |  | 
|  | 599 | return msg; | 
|  | 600 | } | 
|  | 601 |  | 
|  | 602 |  | 
|  | 603 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, | 
|  | 604 | uint8_t cmd) | 
|  | 605 | { | 
|  | 606 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); | 
|  | 607 | } | 
|  | 608 |  | 
|  | 609 |  | 
|  | 610 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) | 
|  | 611 | { | 
|  | 612 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); | 
|  | 613 | } | 
|  | 614 |  | 
|  | 615 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 616 | struct wiphy_idx_data { | 
|  | 617 | int wiphy_idx; | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 618 | enum nl80211_iftype nlmode; | 
|  | 619 | u8 *macaddr; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 620 | }; | 
|  | 621 |  | 
|  | 622 |  | 
|  | 623 | static int netdev_info_handler(struct nl_msg *msg, void *arg) | 
|  | 624 | { | 
|  | 625 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | 
|  | 626 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | 
|  | 627 | struct wiphy_idx_data *info = arg; | 
|  | 628 |  | 
|  | 629 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | 
|  | 630 | genlmsg_attrlen(gnlh, 0), NULL); | 
|  | 631 |  | 
|  | 632 | if (tb[NL80211_ATTR_WIPHY]) | 
|  | 633 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); | 
|  | 634 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 635 | if (tb[NL80211_ATTR_IFTYPE]) | 
|  | 636 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); | 
|  | 637 |  | 
|  | 638 | if (tb[NL80211_ATTR_MAC] && info->macaddr) | 
|  | 639 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), | 
|  | 640 | ETH_ALEN); | 
|  | 641 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 642 | return NL_SKIP; | 
|  | 643 | } | 
|  | 644 |  | 
|  | 645 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 646 | int nl80211_get_wiphy_index(struct i802_bss *bss) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 647 | { | 
|  | 648 | struct nl_msg *msg; | 
|  | 649 | struct wiphy_idx_data data = { | 
|  | 650 | .wiphy_idx = -1, | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 651 | .macaddr = NULL, | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 652 | }; | 
|  | 653 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 654 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) | 
|  | 655 | return -1; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 656 |  | 
|  | 657 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) | 
|  | 658 | return data.wiphy_idx; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 659 | return -1; | 
|  | 660 | } | 
|  | 661 |  | 
|  | 662 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 663 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) | 
|  | 664 | { | 
|  | 665 | struct nl_msg *msg; | 
|  | 666 | struct wiphy_idx_data data = { | 
|  | 667 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, | 
|  | 668 | .macaddr = NULL, | 
|  | 669 | }; | 
|  | 670 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 671 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) | 
|  | 672 | return NL80211_IFTYPE_UNSPECIFIED; | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 673 |  | 
|  | 674 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) | 
|  | 675 | return data.nlmode; | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 676 | return NL80211_IFTYPE_UNSPECIFIED; | 
|  | 677 | } | 
|  | 678 |  | 
|  | 679 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 680 | static int nl80211_get_macaddr(struct i802_bss *bss) | 
|  | 681 | { | 
|  | 682 | struct nl_msg *msg; | 
|  | 683 | struct wiphy_idx_data data = { | 
|  | 684 | .macaddr = bss->addr, | 
|  | 685 | }; | 
|  | 686 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 687 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) | 
|  | 688 | return -1; | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 689 |  | 
|  | 690 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data); | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 691 | } | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 692 |  | 
|  | 693 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 694 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, | 
|  | 695 | struct nl80211_wiphy_data *w) | 
|  | 696 | { | 
|  | 697 | struct nl_msg *msg; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 698 | int ret; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 699 |  | 
|  | 700 | msg = nlmsg_alloc(); | 
|  | 701 | if (!msg) | 
|  | 702 | return -1; | 
|  | 703 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 704 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || | 
|  | 705 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { | 
|  | 706 | nlmsg_free(msg); | 
|  | 707 | return -1; | 
|  | 708 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 709 |  | 
|  | 710 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 711 | if (ret) { | 
|  | 712 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " | 
|  | 713 | "failed: ret=%d (%s)", | 
|  | 714 | ret, strerror(-ret)); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 715 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 716 | return ret; | 
|  | 717 | } | 
|  | 718 |  | 
|  | 719 |  | 
|  | 720 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) | 
|  | 721 | { | 
|  | 722 | struct nl80211_wiphy_data *w = eloop_ctx; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 723 | int res; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 724 |  | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 725 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 726 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 727 | res = nl_recvmsgs(handle, w->nl_cb); | 
| Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 728 | if (res < 0) { | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 729 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", | 
|  | 730 | __func__, res); | 
|  | 731 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 732 | } | 
|  | 733 |  | 
|  | 734 |  | 
|  | 735 | static int process_beacon_event(struct nl_msg *msg, void *arg) | 
|  | 736 | { | 
|  | 737 | struct nl80211_wiphy_data *w = arg; | 
|  | 738 | struct wpa_driver_nl80211_data *drv; | 
|  | 739 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | 
|  | 740 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | 
|  | 741 | union wpa_event_data event; | 
|  | 742 |  | 
|  | 743 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | 
|  | 744 | genlmsg_attrlen(gnlh, 0), NULL); | 
|  | 745 |  | 
|  | 746 | if (gnlh->cmd != NL80211_CMD_FRAME) { | 
|  | 747 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", | 
|  | 748 | gnlh->cmd); | 
|  | 749 | return NL_SKIP; | 
|  | 750 | } | 
|  | 751 |  | 
|  | 752 | if (!tb[NL80211_ATTR_FRAME]) | 
|  | 753 | return NL_SKIP; | 
|  | 754 |  | 
|  | 755 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, | 
|  | 756 | wiphy_list) { | 
|  | 757 | os_memset(&event, 0, sizeof(event)); | 
|  | 758 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); | 
|  | 759 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); | 
|  | 760 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); | 
|  | 761 | } | 
|  | 762 |  | 
|  | 763 | return NL_SKIP; | 
|  | 764 | } | 
|  | 765 |  | 
|  | 766 |  | 
|  | 767 | static struct nl80211_wiphy_data * | 
|  | 768 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) | 
|  | 769 | { | 
|  | 770 | static DEFINE_DL_LIST(nl80211_wiphys); | 
|  | 771 | struct nl80211_wiphy_data *w; | 
|  | 772 | int wiphy_idx, found = 0; | 
|  | 773 | struct i802_bss *tmp_bss; | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 774 | u8 channel; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 775 |  | 
|  | 776 | if (bss->wiphy_data != NULL) | 
|  | 777 | return bss->wiphy_data; | 
|  | 778 |  | 
|  | 779 | wiphy_idx = nl80211_get_wiphy_index(bss); | 
|  | 780 |  | 
|  | 781 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { | 
|  | 782 | if (w->wiphy_idx == wiphy_idx) | 
|  | 783 | goto add; | 
|  | 784 | } | 
|  | 785 |  | 
|  | 786 | /* alloc new one */ | 
|  | 787 | w = os_zalloc(sizeof(*w)); | 
|  | 788 | if (w == NULL) | 
|  | 789 | return NULL; | 
|  | 790 | w->wiphy_idx = wiphy_idx; | 
|  | 791 | dl_list_init(&w->bsss); | 
|  | 792 | dl_list_init(&w->drvs); | 
|  | 793 |  | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 794 | /* Beacon frames not supported in IEEE 802.11ad */ | 
|  | 795 | if (ieee80211_freq_to_chan(bss->freq, &channel) != | 
|  | 796 | HOSTAPD_MODE_IEEE80211AD) { | 
|  | 797 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | 
|  | 798 | if (!w->nl_cb) { | 
|  | 799 | os_free(w); | 
|  | 800 | return NULL; | 
|  | 801 | } | 
|  | 802 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, | 
|  | 803 | no_seq_check, NULL); | 
|  | 804 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | 
|  | 805 | process_beacon_event, w); | 
| Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 806 |  | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 807 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, | 
|  | 808 | "wiphy beacons"); | 
|  | 809 | if (w->nl_beacons == NULL) { | 
|  | 810 | os_free(w); | 
|  | 811 | return NULL; | 
|  | 812 | } | 
| Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 813 |  | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 814 | if (nl80211_register_beacons(bss->drv, w)) { | 
|  | 815 | nl_destroy_handles(&w->nl_beacons); | 
|  | 816 | os_free(w); | 
|  | 817 | return NULL; | 
|  | 818 | } | 
| Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 819 |  | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 820 | nl80211_register_eloop_read(&w->nl_beacons, | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 821 | nl80211_recv_beacons, w, 0); | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 822 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 823 |  | 
|  | 824 | dl_list_add(&nl80211_wiphys, &w->list); | 
|  | 825 |  | 
|  | 826 | add: | 
|  | 827 | /* drv entry for this bss already there? */ | 
|  | 828 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | 
|  | 829 | if (tmp_bss->drv == bss->drv) { | 
|  | 830 | found = 1; | 
|  | 831 | break; | 
|  | 832 | } | 
|  | 833 | } | 
|  | 834 | /* if not add it */ | 
|  | 835 | if (!found) | 
|  | 836 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); | 
|  | 837 |  | 
|  | 838 | dl_list_add(&w->bsss, &bss->wiphy_list); | 
|  | 839 | bss->wiphy_data = w; | 
|  | 840 | return w; | 
|  | 841 | } | 
|  | 842 |  | 
|  | 843 |  | 
|  | 844 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) | 
|  | 845 | { | 
|  | 846 | struct nl80211_wiphy_data *w = bss->wiphy_data; | 
|  | 847 | struct i802_bss *tmp_bss; | 
|  | 848 | int found = 0; | 
|  | 849 |  | 
|  | 850 | if (w == NULL) | 
|  | 851 | return; | 
|  | 852 | bss->wiphy_data = NULL; | 
|  | 853 | dl_list_del(&bss->wiphy_list); | 
|  | 854 |  | 
|  | 855 | /* still any for this drv present? */ | 
|  | 856 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { | 
|  | 857 | if (tmp_bss->drv == bss->drv) { | 
|  | 858 | found = 1; | 
|  | 859 | break; | 
|  | 860 | } | 
|  | 861 | } | 
|  | 862 | /* if not remove it */ | 
|  | 863 | if (!found) | 
|  | 864 | dl_list_del(&bss->drv->wiphy_list); | 
|  | 865 |  | 
|  | 866 | if (!dl_list_empty(&w->bsss)) | 
|  | 867 | return; | 
|  | 868 |  | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 869 | if (w->nl_beacons) | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 870 | nl80211_destroy_eloop_handle(&w->nl_beacons, 0); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 871 |  | 
|  | 872 | nl_cb_put(w->nl_cb); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 873 | dl_list_del(&w->list); | 
|  | 874 | os_free(w); | 
|  | 875 | } | 
|  | 876 |  | 
|  | 877 |  | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 878 | static unsigned int nl80211_get_ifindex(void *priv) | 
|  | 879 | { | 
|  | 880 | struct i802_bss *bss = priv; | 
|  | 881 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 882 |  | 
|  | 883 | return drv->ifindex; | 
|  | 884 | } | 
|  | 885 |  | 
|  | 886 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 887 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) | 
|  | 888 | { | 
|  | 889 | struct i802_bss *bss = priv; | 
|  | 890 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 891 | if (!drv->associated) | 
|  | 892 | return -1; | 
|  | 893 | os_memcpy(bssid, drv->bssid, ETH_ALEN); | 
|  | 894 | return 0; | 
|  | 895 | } | 
|  | 896 |  | 
|  | 897 |  | 
|  | 898 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) | 
|  | 899 | { | 
|  | 900 | struct i802_bss *bss = priv; | 
|  | 901 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 902 | if (!drv->associated) | 
|  | 903 | return -1; | 
|  | 904 | os_memcpy(ssid, drv->ssid, drv->ssid_len); | 
|  | 905 | return drv->ssid_len; | 
|  | 906 | } | 
|  | 907 |  | 
|  | 908 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 909 | static void wpa_driver_nl80211_event_newlink( | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 910 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, | 
|  | 911 | int ifindex, const char *ifname) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 912 | { | 
|  | 913 | union wpa_event_data event; | 
|  | 914 |  | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 915 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 916 | if (if_nametoindex(drv->first_bss->ifname) == 0) { | 
|  | 917 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", | 
|  | 918 | drv->first_bss->ifname); | 
|  | 919 | return; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 920 | } | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 921 | if (!drv->if_removed) | 
|  | 922 | return; | 
|  | 923 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", | 
|  | 924 | drv->first_bss->ifname); | 
|  | 925 | drv->if_removed = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 926 | } | 
|  | 927 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 928 | os_memset(&event, 0, sizeof(event)); | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 929 | event.interface_status.ifindex = ifindex; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 930 | os_strlcpy(event.interface_status.ifname, ifname, | 
|  | 931 | sizeof(event.interface_status.ifname)); | 
|  | 932 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 933 | if (drv) | 
|  | 934 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); | 
|  | 935 | else | 
|  | 936 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, | 
|  | 937 | &event); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 938 | } | 
|  | 939 |  | 
|  | 940 |  | 
|  | 941 | static void wpa_driver_nl80211_event_dellink( | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 942 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, | 
|  | 943 | int ifindex, const char *ifname) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 944 | { | 
|  | 945 | union wpa_event_data event; | 
|  | 946 |  | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 947 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 948 | if (drv->if_removed) { | 
|  | 949 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", | 
|  | 950 | ifname); | 
|  | 951 | return; | 
|  | 952 | } | 
|  | 953 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", | 
|  | 954 | ifname); | 
|  | 955 | drv->if_removed = 1; | 
|  | 956 | } else { | 
|  | 957 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", | 
|  | 958 | ifname); | 
|  | 959 | } | 
|  | 960 |  | 
|  | 961 | os_memset(&event, 0, sizeof(event)); | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 962 | event.interface_status.ifindex = ifindex; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 963 | os_strlcpy(event.interface_status.ifname, ifname, | 
|  | 964 | sizeof(event.interface_status.ifname)); | 
|  | 965 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 966 | if (drv) | 
|  | 967 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); | 
|  | 968 | else | 
|  | 969 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, | 
|  | 970 | &event); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 971 | } | 
|  | 972 |  | 
|  | 973 |  | 
|  | 974 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, | 
|  | 975 | u8 *buf, size_t len) | 
|  | 976 | { | 
|  | 977 | int attrlen, rta_len; | 
|  | 978 | struct rtattr *attr; | 
|  | 979 |  | 
|  | 980 | attrlen = len; | 
|  | 981 | attr = (struct rtattr *) buf; | 
|  | 982 |  | 
|  | 983 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); | 
|  | 984 | while (RTA_OK(attr, attrlen)) { | 
|  | 985 | if (attr->rta_type == IFLA_IFNAME) { | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 986 | if (os_strcmp(((char *) attr) + rta_len, | 
|  | 987 | drv->first_bss->ifname) == 0) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 988 | return 1; | 
|  | 989 | else | 
|  | 990 | break; | 
|  | 991 | } | 
|  | 992 | attr = RTA_NEXT(attr, attrlen); | 
|  | 993 | } | 
|  | 994 |  | 
|  | 995 | return 0; | 
|  | 996 | } | 
|  | 997 |  | 
|  | 998 |  | 
|  | 999 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, | 
|  | 1000 | int ifindex, u8 *buf, size_t len) | 
|  | 1001 | { | 
|  | 1002 | if (drv->ifindex == ifindex) | 
|  | 1003 | return 1; | 
|  | 1004 |  | 
|  | 1005 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1006 | nl80211_check_global(drv->global); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1007 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " | 
|  | 1008 | "interface"); | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1009 | if (wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL) < 0) | 
|  | 1010 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1011 | return 1; | 
|  | 1012 | } | 
|  | 1013 |  | 
|  | 1014 | return 0; | 
|  | 1015 | } | 
|  | 1016 |  | 
|  | 1017 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1018 | static struct wpa_driver_nl80211_data * | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1019 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len, | 
|  | 1020 | int *init_failed) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1021 | { | 
|  | 1022 | struct wpa_driver_nl80211_data *drv; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1023 | int res; | 
|  | 1024 |  | 
|  | 1025 | if (init_failed) | 
|  | 1026 | *init_failed = 0; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1027 | dl_list_for_each(drv, &global->interfaces, | 
|  | 1028 | struct wpa_driver_nl80211_data, list) { | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1029 | res = wpa_driver_nl80211_own_ifindex(drv, idx, buf, len); | 
|  | 1030 | if (res < 0) { | 
|  | 1031 | wpa_printf(MSG_DEBUG, | 
|  | 1032 | "nl80211: Found matching own interface, but failed to complete reinitialization"); | 
|  | 1033 | if (init_failed) | 
|  | 1034 | *init_failed = 1; | 
|  | 1035 | return drv; | 
|  | 1036 | } | 
|  | 1037 | if (res > 0 || have_ifidx(drv, idx, IFIDX_ANY)) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1038 | return drv; | 
|  | 1039 | } | 
|  | 1040 | return NULL; | 
|  | 1041 | } | 
|  | 1042 |  | 
|  | 1043 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1044 | static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv, | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1045 | int ifindex, int notify) | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1046 | { | 
|  | 1047 | struct i802_bss *bss; | 
|  | 1048 | u8 addr[ETH_ALEN]; | 
|  | 1049 |  | 
|  | 1050 | bss = get_bss_ifindex(drv, ifindex); | 
|  | 1051 | if (bss && | 
|  | 1052 | linux_get_ifhwaddr(drv->global->ioctl_sock, | 
|  | 1053 | bss->ifname, addr) < 0) { | 
|  | 1054 | wpa_printf(MSG_DEBUG, | 
|  | 1055 | "nl80211: %s: failed to re-read MAC address", | 
|  | 1056 | bss->ifname); | 
|  | 1057 | } else if (bss && os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { | 
|  | 1058 | wpa_printf(MSG_DEBUG, | 
|  | 1059 | "nl80211: Own MAC address on ifindex %d (%s) changed from " | 
|  | 1060 | MACSTR " to " MACSTR, | 
|  | 1061 | ifindex, bss->ifname, | 
|  | 1062 | MAC2STR(bss->addr), MAC2STR(addr)); | 
|  | 1063 | os_memcpy(bss->addr, addr, ETH_ALEN); | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1064 | if (notify) | 
|  | 1065 | wpa_supplicant_event(drv->ctx, | 
|  | 1066 | EVENT_INTERFACE_MAC_CHANGED, NULL); | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1067 | } | 
|  | 1068 | } | 
|  | 1069 |  | 
|  | 1070 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1071 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, | 
|  | 1072 | struct ifinfomsg *ifi, | 
|  | 1073 | u8 *buf, size_t len) | 
|  | 1074 | { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1075 | struct nl80211_global *global = ctx; | 
|  | 1076 | struct wpa_driver_nl80211_data *drv; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1077 | int attrlen; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1078 | struct rtattr *attr; | 
|  | 1079 | u32 brid = 0; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1080 | char namebuf[IFNAMSIZ]; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1081 | char ifname[IFNAMSIZ + 1]; | 
|  | 1082 | char extra[100], *pos, *end; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1083 | int init_failed; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1084 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1085 | extra[0] = '\0'; | 
|  | 1086 | pos = extra; | 
|  | 1087 | end = pos + sizeof(extra); | 
|  | 1088 | ifname[0] = '\0'; | 
|  | 1089 |  | 
|  | 1090 | attrlen = len; | 
|  | 1091 | attr = (struct rtattr *) buf; | 
|  | 1092 | while (RTA_OK(attr, attrlen)) { | 
|  | 1093 | switch (attr->rta_type) { | 
|  | 1094 | case IFLA_IFNAME: | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1095 | if (RTA_PAYLOAD(attr) > IFNAMSIZ) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1096 | break; | 
|  | 1097 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); | 
|  | 1098 | ifname[RTA_PAYLOAD(attr)] = '\0'; | 
|  | 1099 | break; | 
|  | 1100 | case IFLA_MASTER: | 
|  | 1101 | brid = nla_get_u32((struct nlattr *) attr); | 
|  | 1102 | pos += os_snprintf(pos, end - pos, " master=%u", brid); | 
|  | 1103 | break; | 
|  | 1104 | case IFLA_WIRELESS: | 
|  | 1105 | pos += os_snprintf(pos, end - pos, " wext"); | 
|  | 1106 | break; | 
|  | 1107 | case IFLA_OPERSTATE: | 
|  | 1108 | pos += os_snprintf(pos, end - pos, " operstate=%u", | 
|  | 1109 | nla_get_u32((struct nlattr *) attr)); | 
|  | 1110 | break; | 
|  | 1111 | case IFLA_LINKMODE: | 
|  | 1112 | pos += os_snprintf(pos, end - pos, " linkmode=%u", | 
|  | 1113 | nla_get_u32((struct nlattr *) attr)); | 
|  | 1114 | break; | 
|  | 1115 | } | 
|  | 1116 | attr = RTA_NEXT(attr, attrlen); | 
|  | 1117 | } | 
|  | 1118 | extra[sizeof(extra) - 1] = '\0'; | 
|  | 1119 |  | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1120 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", | 
|  | 1121 | ifi->ifi_index, ifname, extra, ifi->ifi_family, | 
|  | 1122 | ifi->ifi_flags, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1123 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", | 
|  | 1124 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", | 
|  | 1125 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", | 
|  | 1126 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); | 
|  | 1127 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1128 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, &init_failed); | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1129 | if (!drv) | 
|  | 1130 | goto event_newlink; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1131 | if (init_failed) | 
|  | 1132 | return; /* do not update interface state */ | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1133 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1134 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1135 | namebuf[0] = '\0'; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1136 | if (if_indextoname(ifi->ifi_index, namebuf) && | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1137 | linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1138 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " | 
|  | 1139 | "event since interface %s is up", namebuf); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1140 | drv->ignore_if_down_event = 0; | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1141 | /* Re-read MAC address as it may have changed */ | 
|  | 1142 | nl80211_refresh_mac(drv, ifi->ifi_index, 1); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1143 | return; | 
|  | 1144 | } | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1145 | wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", | 
|  | 1146 | namebuf, ifname); | 
|  | 1147 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { | 
|  | 1148 | wpa_printf(MSG_DEBUG, | 
|  | 1149 | "nl80211: Not the main interface (%s) - do not indicate interface down", | 
|  | 1150 | drv->first_bss->ifname); | 
|  | 1151 | } else if (drv->ignore_if_down_event) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1152 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " | 
|  | 1153 | "event generated by mode change"); | 
|  | 1154 | drv->ignore_if_down_event = 0; | 
|  | 1155 | } else { | 
|  | 1156 | drv->if_disabled = 1; | 
|  | 1157 | wpa_supplicant_event(drv->ctx, | 
|  | 1158 | EVENT_INTERFACE_DISABLED, NULL); | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1159 |  | 
|  | 1160 | /* | 
|  | 1161 | * Try to get drv again, since it may be removed as | 
|  | 1162 | * part of the EVENT_INTERFACE_DISABLED handling for | 
|  | 1163 | * dynamic interfaces | 
|  | 1164 | */ | 
|  | 1165 | drv = nl80211_find_drv(global, ifi->ifi_index, | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1166 | buf, len, NULL); | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1167 | if (!drv) | 
|  | 1168 | return; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1169 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1170 | } | 
|  | 1171 |  | 
|  | 1172 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { | 
| Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 1173 | namebuf[0] = '\0'; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1174 | if (if_indextoname(ifi->ifi_index, namebuf) && | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1175 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1176 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " | 
|  | 1177 | "event since interface %s is down", | 
|  | 1178 | namebuf); | 
| Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 1179 | return; | 
|  | 1180 | } | 
|  | 1181 | wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)", | 
|  | 1182 | namebuf, ifname); | 
|  | 1183 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { | 
|  | 1184 | wpa_printf(MSG_DEBUG, | 
|  | 1185 | "nl80211: Not the main interface (%s) - do not indicate interface up", | 
|  | 1186 | drv->first_bss->ifname); | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1187 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1188 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " | 
|  | 1189 | "event since interface %s does not exist", | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1190 | drv->first_bss->ifname); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1191 | } else if (drv->if_removed) { | 
|  | 1192 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " | 
|  | 1193 | "event since interface %s is marked " | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1194 | "removed", drv->first_bss->ifname); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1195 | } else { | 
| Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1196 | /* Re-read MAC address as it may have changed */ | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1197 | nl80211_refresh_mac(drv, ifi->ifi_index, 0); | 
| Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1198 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1199 | drv->if_disabled = 0; | 
|  | 1200 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, | 
|  | 1201 | NULL); | 
|  | 1202 | } | 
| Sunil Ravi | 9077544 | 2020-09-24 11:53:19 -0700 | [diff] [blame] | 1203 | } else if (ifi->ifi_flags & IFF_UP) { | 
|  | 1204 | /* Re-read MAC address as it may have changed */ | 
|  | 1205 | nl80211_refresh_mac(drv, ifi->ifi_index, 1); | 
|  | 1206 | return; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1207 | } | 
|  | 1208 |  | 
|  | 1209 | /* | 
|  | 1210 | * Some drivers send the association event before the operup event--in | 
|  | 1211 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() | 
|  | 1212 | * fails. This will hit us when wpa_supplicant does not need to do | 
|  | 1213 | * IEEE 802.1X authentication | 
|  | 1214 | */ | 
|  | 1215 | if (drv->operstate == 1 && | 
|  | 1216 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1217 | !(ifi->ifi_flags & IFF_RUNNING)) { | 
|  | 1218 | 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] | 1219 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1220 | -1, IF_OPER_UP); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1221 | } | 
|  | 1222 |  | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1223 | event_newlink: | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1224 | if (ifname[0]) | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1225 | wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index, | 
|  | 1226 | ifname); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1227 |  | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1228 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1229 | struct i802_bss *bss; | 
|  | 1230 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1231 | /* device has been added to bridge */ | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1232 | if (!if_indextoname(brid, namebuf)) { | 
|  | 1233 | wpa_printf(MSG_DEBUG, | 
|  | 1234 | "nl80211: Could not find bridge ifname for ifindex %u", | 
|  | 1235 | brid); | 
|  | 1236 | return; | 
|  | 1237 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1238 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", | 
|  | 1239 | brid, namebuf); | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1240 | add_ifidx(drv, brid, ifi->ifi_index); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1241 |  | 
|  | 1242 | for (bss = drv->first_bss; bss; bss = bss->next) { | 
|  | 1243 | if (os_strcmp(ifname, bss->ifname) == 0) { | 
|  | 1244 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); | 
|  | 1245 | break; | 
|  | 1246 | } | 
|  | 1247 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1248 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1249 | } | 
|  | 1250 |  | 
|  | 1251 |  | 
|  | 1252 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, | 
|  | 1253 | struct ifinfomsg *ifi, | 
|  | 1254 | u8 *buf, size_t len) | 
|  | 1255 | { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1256 | struct nl80211_global *global = ctx; | 
|  | 1257 | struct wpa_driver_nl80211_data *drv; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1258 | int attrlen; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1259 | struct rtattr *attr; | 
|  | 1260 | u32 brid = 0; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1261 | char ifname[IFNAMSIZ + 1]; | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1262 | char extra[100], *pos, *end; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1263 |  | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1264 | extra[0] = '\0'; | 
|  | 1265 | pos = extra; | 
|  | 1266 | end = pos + sizeof(extra); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1267 | ifname[0] = '\0'; | 
|  | 1268 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1269 | attrlen = len; | 
|  | 1270 | attr = (struct rtattr *) buf; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1271 | while (RTA_OK(attr, attrlen)) { | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1272 | switch (attr->rta_type) { | 
|  | 1273 | case IFLA_IFNAME: | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1274 | if (RTA_PAYLOAD(attr) > IFNAMSIZ) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1275 | break; | 
|  | 1276 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); | 
|  | 1277 | ifname[RTA_PAYLOAD(attr)] = '\0'; | 
|  | 1278 | break; | 
|  | 1279 | case IFLA_MASTER: | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1280 | brid = nla_get_u32((struct nlattr *) attr); | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1281 | pos += os_snprintf(pos, end - pos, " master=%u", brid); | 
|  | 1282 | break; | 
|  | 1283 | case IFLA_OPERSTATE: | 
|  | 1284 | pos += os_snprintf(pos, end - pos, " operstate=%u", | 
|  | 1285 | nla_get_u32((struct nlattr *) attr)); | 
|  | 1286 | break; | 
|  | 1287 | case IFLA_LINKMODE: | 
|  | 1288 | pos += os_snprintf(pos, end - pos, " linkmode=%u", | 
|  | 1289 | nla_get_u32((struct nlattr *) attr)); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1290 | break; | 
|  | 1291 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1292 | attr = RTA_NEXT(attr, attrlen); | 
|  | 1293 | } | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1294 | extra[sizeof(extra) - 1] = '\0'; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1295 |  | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1296 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", | 
|  | 1297 | ifi->ifi_index, ifname, extra, ifi->ifi_family, | 
|  | 1298 | ifi->ifi_flags, | 
|  | 1299 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", | 
|  | 1300 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", | 
|  | 1301 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", | 
|  | 1302 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); | 
|  | 1303 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1304 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, NULL); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1305 |  | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1306 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1307 | /* device has been removed from bridge */ | 
|  | 1308 | char namebuf[IFNAMSIZ]; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1309 |  | 
|  | 1310 | if (!if_indextoname(brid, namebuf)) { | 
|  | 1311 | wpa_printf(MSG_DEBUG, | 
|  | 1312 | "nl80211: Could not find bridge ifname for ifindex %u", | 
|  | 1313 | brid); | 
|  | 1314 | } else { | 
|  | 1315 | wpa_printf(MSG_DEBUG, | 
|  | 1316 | "nl80211: Remove ifindex %u for bridge %s", | 
|  | 1317 | brid, namebuf); | 
|  | 1318 | } | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1319 | del_ifidx(drv, brid, ifi->ifi_index); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1320 | } | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1321 |  | 
|  | 1322 | if (ifi->ifi_family != AF_BRIDGE || !brid) | 
|  | 1323 | wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index, | 
|  | 1324 | ifname); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1325 | } | 
|  | 1326 |  | 
|  | 1327 |  | 
| Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1328 | struct nl80211_get_assoc_freq_arg { | 
|  | 1329 | struct wpa_driver_nl80211_data *drv; | 
|  | 1330 | unsigned int assoc_freq; | 
|  | 1331 | unsigned int ibss_freq; | 
|  | 1332 | u8 assoc_bssid[ETH_ALEN]; | 
|  | 1333 | u8 assoc_ssid[SSID_MAX_LEN]; | 
|  | 1334 | u8 assoc_ssid_len; | 
|  | 1335 | }; | 
|  | 1336 |  | 
|  | 1337 | static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg) | 
|  | 1338 | { | 
|  | 1339 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | 
|  | 1340 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | 
|  | 1341 | struct nlattr *bss[NL80211_BSS_MAX + 1]; | 
|  | 1342 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { | 
|  | 1343 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, | 
|  | 1344 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, | 
|  | 1345 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, | 
|  | 1346 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, | 
|  | 1347 | }; | 
|  | 1348 | struct nl80211_get_assoc_freq_arg *ctx = arg; | 
|  | 1349 | enum nl80211_bss_status status; | 
|  | 1350 |  | 
|  | 1351 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | 
|  | 1352 | genlmsg_attrlen(gnlh, 0), NULL); | 
|  | 1353 | if (!tb[NL80211_ATTR_BSS] || | 
|  | 1354 | nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], | 
|  | 1355 | bss_policy) || | 
|  | 1356 | !bss[NL80211_BSS_STATUS]) | 
|  | 1357 | return NL_SKIP; | 
|  | 1358 |  | 
|  | 1359 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); | 
|  | 1360 | if (status == NL80211_BSS_STATUS_ASSOCIATED && | 
|  | 1361 | bss[NL80211_BSS_FREQUENCY]) { | 
|  | 1362 | ctx->assoc_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); | 
|  | 1363 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", | 
|  | 1364 | ctx->assoc_freq); | 
|  | 1365 | } | 
|  | 1366 | if (status == NL80211_BSS_STATUS_IBSS_JOINED && | 
|  | 1367 | bss[NL80211_BSS_FREQUENCY]) { | 
|  | 1368 | ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); | 
|  | 1369 | wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz", | 
|  | 1370 | ctx->ibss_freq); | 
|  | 1371 | } | 
|  | 1372 | if (status == NL80211_BSS_STATUS_ASSOCIATED && | 
|  | 1373 | bss[NL80211_BSS_BSSID]) { | 
|  | 1374 | os_memcpy(ctx->assoc_bssid, | 
|  | 1375 | nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN); | 
|  | 1376 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " | 
|  | 1377 | MACSTR, MAC2STR(ctx->assoc_bssid)); | 
|  | 1378 | } | 
|  | 1379 |  | 
|  | 1380 | if (status == NL80211_BSS_STATUS_ASSOCIATED && | 
|  | 1381 | bss[NL80211_BSS_INFORMATION_ELEMENTS]) { | 
|  | 1382 | const u8 *ie, *ssid; | 
|  | 1383 | size_t ie_len; | 
|  | 1384 |  | 
|  | 1385 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | 
|  | 1386 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); | 
|  | 1387 | ssid = get_ie(ie, ie_len, WLAN_EID_SSID); | 
|  | 1388 | if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) { | 
|  | 1389 | ctx->assoc_ssid_len = ssid[1]; | 
|  | 1390 | os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]); | 
|  | 1391 | } | 
|  | 1392 | } | 
|  | 1393 |  | 
|  | 1394 | return NL_SKIP; | 
|  | 1395 | } | 
|  | 1396 |  | 
|  | 1397 |  | 
|  | 1398 | 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] | 1399 | { | 
|  | 1400 | struct nl_msg *msg; | 
|  | 1401 | int ret; | 
| Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1402 | struct nl80211_get_assoc_freq_arg arg; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1403 | int count = 0; | 
| Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1404 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1405 | try_again: | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1406 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); | 
| Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1407 | os_memset(&arg, 0, sizeof(arg)); | 
| Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1408 | arg.drv = drv; | 
| Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1409 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, | 
|  | 1410 | &arg); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1411 | if (ret == -EAGAIN) { | 
|  | 1412 | count++; | 
|  | 1413 | if (count >= 10) { | 
|  | 1414 | wpa_printf(MSG_INFO, | 
|  | 1415 | "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid"); | 
|  | 1416 | } else { | 
|  | 1417 | wpa_printf(MSG_DEBUG, | 
|  | 1418 | "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid - try again"); | 
|  | 1419 | goto try_again; | 
|  | 1420 | } | 
|  | 1421 | } | 
| Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1422 | if (ret == 0) { | 
|  | 1423 | os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len); | 
|  | 1424 | return arg.assoc_ssid_len; | 
|  | 1425 | } | 
|  | 1426 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)", | 
|  | 1427 | ret, strerror(-ret)); | 
|  | 1428 | return ret; | 
|  | 1429 | } | 
|  | 1430 |  | 
|  | 1431 |  | 
|  | 1432 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) | 
|  | 1433 | { | 
|  | 1434 | struct nl_msg *msg; | 
|  | 1435 | int ret; | 
|  | 1436 | struct nl80211_get_assoc_freq_arg arg; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1437 | int count = 0; | 
| Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1438 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1439 | try_again: | 
| Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1440 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); | 
|  | 1441 | os_memset(&arg, 0, sizeof(arg)); | 
|  | 1442 | arg.drv = drv; | 
|  | 1443 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, | 
|  | 1444 | &arg); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1445 | if (ret == -EAGAIN) { | 
|  | 1446 | count++; | 
|  | 1447 | if (count >= 10) { | 
|  | 1448 | wpa_printf(MSG_INFO, | 
|  | 1449 | "nl80211: Failed to receive consistent scan result dump for get_assoc_freq"); | 
|  | 1450 | } else { | 
|  | 1451 | wpa_printf(MSG_DEBUG, | 
|  | 1452 | "nl80211: Failed to receive consistent scan result dump for get_assoc_freq - try again"); | 
|  | 1453 | goto try_again; | 
|  | 1454 | } | 
|  | 1455 | } | 
| Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1456 | if (ret == 0) { | 
| Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1457 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? | 
|  | 1458 | arg.ibss_freq : arg.assoc_freq; | 
| Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1459 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " | 
| Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1460 | "associated BSS from scan results: %u MHz", freq); | 
|  | 1461 | if (freq) | 
|  | 1462 | drv->assoc_freq = freq; | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1463 | return drv->assoc_freq; | 
| Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1464 | } | 
|  | 1465 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " | 
|  | 1466 | "(%s)", ret, strerror(-ret)); | 
| Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1467 | return drv->assoc_freq; | 
|  | 1468 | } | 
|  | 1469 |  | 
|  | 1470 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1471 | static int get_link_signal(struct nl_msg *msg, void *arg) | 
|  | 1472 | { | 
|  | 1473 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | 
|  | 1474 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | 
|  | 1475 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; | 
|  | 1476 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { | 
|  | 1477 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1478 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, | 
| Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1479 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 }, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1480 | }; | 
|  | 1481 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; | 
|  | 1482 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { | 
|  | 1483 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, | 
|  | 1484 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, | 
|  | 1485 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, | 
|  | 1486 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, | 
|  | 1487 | }; | 
|  | 1488 | struct wpa_signal_info *sig_change = arg; | 
|  | 1489 |  | 
|  | 1490 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | 
|  | 1491 | genlmsg_attrlen(gnlh, 0), NULL); | 
|  | 1492 | if (!tb[NL80211_ATTR_STA_INFO] || | 
|  | 1493 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, | 
|  | 1494 | tb[NL80211_ATTR_STA_INFO], policy)) | 
|  | 1495 | return NL_SKIP; | 
|  | 1496 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) | 
|  | 1497 | return NL_SKIP; | 
|  | 1498 |  | 
|  | 1499 | sig_change->current_signal = | 
|  | 1500 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); | 
|  | 1501 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1502 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) | 
|  | 1503 | sig_change->avg_signal = | 
|  | 1504 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); | 
|  | 1505 | else | 
|  | 1506 | sig_change->avg_signal = 0; | 
|  | 1507 |  | 
| Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1508 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) | 
|  | 1509 | sig_change->avg_beacon_signal = | 
|  | 1510 | (s8) | 
|  | 1511 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); | 
|  | 1512 | else | 
|  | 1513 | sig_change->avg_beacon_signal = 0; | 
|  | 1514 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1515 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { | 
|  | 1516 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, | 
|  | 1517 | sinfo[NL80211_STA_INFO_TX_BITRATE], | 
|  | 1518 | rate_policy)) { | 
|  | 1519 | sig_change->current_txrate = 0; | 
|  | 1520 | } else { | 
|  | 1521 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { | 
|  | 1522 | sig_change->current_txrate = | 
|  | 1523 | nla_get_u16(rinfo[ | 
|  | 1524 | NL80211_RATE_INFO_BITRATE]) * 100; | 
|  | 1525 | } | 
|  | 1526 | } | 
|  | 1527 | } | 
|  | 1528 |  | 
|  | 1529 | return NL_SKIP; | 
|  | 1530 | } | 
|  | 1531 |  | 
|  | 1532 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1533 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, | 
|  | 1534 | struct wpa_signal_info *sig) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1535 | { | 
|  | 1536 | struct nl_msg *msg; | 
|  | 1537 |  | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1538 | sig->current_signal = -WPA_INVALID_NOISE; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1539 | sig->current_txrate = 0; | 
|  | 1540 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1541 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || | 
|  | 1542 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) { | 
|  | 1543 | nlmsg_free(msg); | 
|  | 1544 | return -ENOBUFS; | 
|  | 1545 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1546 |  | 
|  | 1547 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1548 | } | 
|  | 1549 |  | 
|  | 1550 |  | 
|  | 1551 | static int get_link_noise(struct nl_msg *msg, void *arg) | 
|  | 1552 | { | 
|  | 1553 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | 
|  | 1554 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | 
|  | 1555 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | 
|  | 1556 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | 
|  | 1557 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | 
|  | 1558 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | 
|  | 1559 | }; | 
|  | 1560 | struct wpa_signal_info *sig_change = arg; | 
|  | 1561 |  | 
|  | 1562 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | 
|  | 1563 | genlmsg_attrlen(gnlh, 0), NULL); | 
|  | 1564 |  | 
|  | 1565 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { | 
|  | 1566 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); | 
|  | 1567 | return NL_SKIP; | 
|  | 1568 | } | 
|  | 1569 |  | 
|  | 1570 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | 
|  | 1571 | tb[NL80211_ATTR_SURVEY_INFO], | 
|  | 1572 | survey_policy)) { | 
|  | 1573 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " | 
|  | 1574 | "attributes!"); | 
|  | 1575 | return NL_SKIP; | 
|  | 1576 | } | 
|  | 1577 |  | 
|  | 1578 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) | 
|  | 1579 | return NL_SKIP; | 
|  | 1580 |  | 
|  | 1581 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != | 
|  | 1582 | sig_change->frequency) | 
|  | 1583 | return NL_SKIP; | 
|  | 1584 |  | 
|  | 1585 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) | 
|  | 1586 | return NL_SKIP; | 
|  | 1587 |  | 
|  | 1588 | sig_change->current_noise = | 
|  | 1589 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | 
|  | 1590 |  | 
|  | 1591 | return NL_SKIP; | 
|  | 1592 | } | 
|  | 1593 |  | 
|  | 1594 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1595 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, | 
|  | 1596 | struct wpa_signal_info *sig_change) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1597 | { | 
|  | 1598 | struct nl_msg *msg; | 
|  | 1599 |  | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1600 | sig_change->current_noise = WPA_INVALID_NOISE; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1601 | sig_change->frequency = drv->assoc_freq; | 
|  | 1602 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1603 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1604 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1605 | } | 
|  | 1606 |  | 
|  | 1607 |  | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1608 | static int get_channel_info(struct nl_msg *msg, void *arg) | 
|  | 1609 | { | 
|  | 1610 | struct nlattr *tb[NL80211_ATTR_MAX + 1] = { 0 }; | 
|  | 1611 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | 
|  | 1612 | struct wpa_channel_info *chan_info = arg; | 
|  | 1613 |  | 
|  | 1614 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | 
|  | 1615 | genlmsg_attrlen(gnlh, 0), NULL); | 
|  | 1616 |  | 
|  | 1617 | os_memset(chan_info, 0, sizeof(struct wpa_channel_info)); | 
|  | 1618 | chan_info->chanwidth = CHAN_WIDTH_UNKNOWN; | 
|  | 1619 |  | 
|  | 1620 | if (tb[NL80211_ATTR_WIPHY_FREQ]) | 
|  | 1621 | chan_info->frequency = | 
|  | 1622 | nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]); | 
|  | 1623 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) | 
|  | 1624 | chan_info->chanwidth = convert2width( | 
|  | 1625 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); | 
|  | 1626 | if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { | 
|  | 1627 | enum nl80211_channel_type ct = | 
|  | 1628 | nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); | 
|  | 1629 |  | 
|  | 1630 | switch (ct) { | 
|  | 1631 | case NL80211_CHAN_HT40MINUS: | 
|  | 1632 | chan_info->sec_channel = -1; | 
|  | 1633 | break; | 
|  | 1634 | case NL80211_CHAN_HT40PLUS: | 
|  | 1635 | chan_info->sec_channel = 1; | 
|  | 1636 | break; | 
|  | 1637 | default: | 
|  | 1638 | chan_info->sec_channel = 0; | 
|  | 1639 | break; | 
|  | 1640 | } | 
|  | 1641 | } | 
|  | 1642 | if (tb[NL80211_ATTR_CENTER_FREQ1]) | 
|  | 1643 | chan_info->center_frq1 = | 
|  | 1644 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); | 
|  | 1645 | if (tb[NL80211_ATTR_CENTER_FREQ2]) | 
|  | 1646 | chan_info->center_frq2 = | 
|  | 1647 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); | 
|  | 1648 |  | 
|  | 1649 | if (chan_info->center_frq2) { | 
|  | 1650 | u8 seg1_idx = 0; | 
|  | 1651 |  | 
|  | 1652 | if (ieee80211_freq_to_chan(chan_info->center_frq2, &seg1_idx) != | 
|  | 1653 | NUM_HOSTAPD_MODES) | 
|  | 1654 | chan_info->seg1_idx = seg1_idx; | 
|  | 1655 | } | 
|  | 1656 |  | 
|  | 1657 | return NL_SKIP; | 
|  | 1658 | } | 
|  | 1659 |  | 
|  | 1660 |  | 
|  | 1661 | static int nl80211_channel_info(void *priv, struct wpa_channel_info *ci) | 
|  | 1662 | { | 
|  | 1663 | struct i802_bss *bss = priv; | 
|  | 1664 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 1665 | struct nl_msg *msg; | 
|  | 1666 |  | 
|  | 1667 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); | 
|  | 1668 | return send_and_recv_msgs(drv, msg, get_channel_info, ci); | 
|  | 1669 | } | 
|  | 1670 |  | 
|  | 1671 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1672 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, | 
|  | 1673 | void *handle) | 
|  | 1674 | { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1675 | struct nl_cb *cb = eloop_ctx; | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1676 | int res; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1677 |  | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1678 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1679 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1680 | res = nl_recvmsgs(handle, cb); | 
| Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 1681 | if (res < 0) { | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1682 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", | 
|  | 1683 | __func__, res); | 
|  | 1684 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1685 | } | 
|  | 1686 |  | 
|  | 1687 |  | 
|  | 1688 | /** | 
|  | 1689 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain | 
|  | 1690 | * @priv: driver_nl80211 private data | 
|  | 1691 | * @alpha2_arg: country to which to switch to | 
|  | 1692 | * Returns: 0 on success, -1 on failure | 
|  | 1693 | * | 
|  | 1694 | * This asks nl80211 to set the regulatory domain for given | 
|  | 1695 | * country ISO / IEC alpha2. | 
|  | 1696 | */ | 
|  | 1697 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) | 
|  | 1698 | { | 
|  | 1699 | struct i802_bss *bss = priv; | 
|  | 1700 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 1701 | char alpha2[3]; | 
|  | 1702 | struct nl_msg *msg; | 
|  | 1703 |  | 
|  | 1704 | msg = nlmsg_alloc(); | 
|  | 1705 | if (!msg) | 
|  | 1706 | return -ENOMEM; | 
|  | 1707 |  | 
|  | 1708 | alpha2[0] = alpha2_arg[0]; | 
|  | 1709 | alpha2[1] = alpha2_arg[1]; | 
|  | 1710 | alpha2[2] = '\0'; | 
|  | 1711 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1712 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || | 
|  | 1713 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { | 
|  | 1714 | nlmsg_free(msg); | 
|  | 1715 | return -EINVAL; | 
|  | 1716 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1717 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) | 
|  | 1718 | return -EINVAL; | 
|  | 1719 | return 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1720 | } | 
|  | 1721 |  | 
|  | 1722 |  | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1723 | static int nl80211_get_country(struct nl_msg *msg, void *arg) | 
|  | 1724 | { | 
|  | 1725 | char *alpha2 = arg; | 
|  | 1726 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | 
|  | 1727 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | 
|  | 1728 |  | 
|  | 1729 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | 
|  | 1730 | genlmsg_attrlen(gnlh, 0), NULL); | 
|  | 1731 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { | 
|  | 1732 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); | 
|  | 1733 | return NL_SKIP; | 
|  | 1734 | } | 
|  | 1735 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); | 
|  | 1736 | return NL_SKIP; | 
|  | 1737 | } | 
|  | 1738 |  | 
|  | 1739 |  | 
|  | 1740 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) | 
|  | 1741 | { | 
|  | 1742 | struct i802_bss *bss = priv; | 
|  | 1743 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 1744 | struct nl_msg *msg; | 
|  | 1745 | int ret; | 
|  | 1746 |  | 
|  | 1747 | msg = nlmsg_alloc(); | 
|  | 1748 | if (!msg) | 
|  | 1749 | return -ENOMEM; | 
|  | 1750 |  | 
|  | 1751 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); | 
|  | 1752 | alpha2[0] = '\0'; | 
|  | 1753 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2); | 
|  | 1754 | if (!alpha2[0]) | 
|  | 1755 | ret = -1; | 
|  | 1756 |  | 
|  | 1757 | return ret; | 
|  | 1758 | } | 
|  | 1759 |  | 
|  | 1760 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1761 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1762 | { | 
|  | 1763 | int ret; | 
|  | 1764 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1765 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | 
|  | 1766 | if (global->nl_cb == NULL) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1767 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " | 
|  | 1768 | "callbacks"); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1769 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1770 | } | 
|  | 1771 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1772 | global->nl = nl_create_handle(global->nl_cb, "nl"); | 
|  | 1773 | if (global->nl == NULL) | 
|  | 1774 | goto err; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1775 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1776 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); | 
|  | 1777 | if (global->nl80211_id < 0) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1778 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " | 
|  | 1779 | "found"); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1780 | goto err; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1781 | } | 
|  | 1782 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1783 | global->nl_event = nl_create_handle(global->nl_cb, "event"); | 
|  | 1784 | if (global->nl_event == NULL) | 
|  | 1785 | goto err; | 
|  | 1786 |  | 
|  | 1787 | ret = nl_get_multicast_id(global, "nl80211", "scan"); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1788 | if (ret >= 0) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1789 | ret = nl_socket_add_membership(global->nl_event, ret); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1790 | if (ret < 0) { | 
|  | 1791 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | 
|  | 1792 | "membership for scan events: %d (%s)", | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1793 | ret, nl_geterror(ret)); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1794 | goto err; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1795 | } | 
|  | 1796 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1797 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1798 | if (ret >= 0) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1799 | ret = nl_socket_add_membership(global->nl_event, ret); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1800 | if (ret < 0) { | 
|  | 1801 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " | 
|  | 1802 | "membership for mlme events: %d (%s)", | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1803 | ret, nl_geterror(ret)); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1804 | goto err; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1805 | } | 
|  | 1806 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1807 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1808 | if (ret >= 0) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1809 | ret = nl_socket_add_membership(global->nl_event, ret); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1810 | if (ret < 0) { | 
|  | 1811 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " | 
|  | 1812 | "membership for regulatory events: %d (%s)", | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1813 | ret, nl_geterror(ret)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1814 | /* Continue without regulatory events */ | 
|  | 1815 | } | 
|  | 1816 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1817 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); | 
|  | 1818 | if (ret >= 0) | 
|  | 1819 | ret = nl_socket_add_membership(global->nl_event, ret); | 
|  | 1820 | if (ret < 0) { | 
|  | 1821 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " | 
|  | 1822 | "membership for vendor events: %d (%s)", | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1823 | ret, nl_geterror(ret)); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1824 | /* Continue without vendor events */ | 
|  | 1825 | } | 
|  | 1826 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1827 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, | 
|  | 1828 | no_seq_check, NULL); | 
|  | 1829 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | 
|  | 1830 | process_global_event, global); | 
|  | 1831 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1832 | nl80211_register_eloop_read(&global->nl_event, | 
|  | 1833 | wpa_driver_nl80211_event_receive, | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1834 | global->nl_cb, 0); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1835 |  | 
|  | 1836 | return 0; | 
|  | 1837 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1838 | err: | 
|  | 1839 | nl_destroy_handles(&global->nl_event); | 
|  | 1840 | nl_destroy_handles(&global->nl); | 
|  | 1841 | nl_cb_put(global->nl_cb); | 
|  | 1842 | global->nl_cb = NULL; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1843 | return -1; | 
|  | 1844 | } | 
|  | 1845 |  | 
|  | 1846 |  | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1847 | static void nl80211_check_global(struct nl80211_global *global) | 
|  | 1848 | { | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1849 | struct nl_sock *handle; | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1850 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; | 
|  | 1851 | int ret; | 
|  | 1852 | unsigned int i; | 
|  | 1853 |  | 
|  | 1854 | /* | 
|  | 1855 | * Try to re-add memberships to handle case of cfg80211 getting reloaded | 
|  | 1856 | * and all registration having been cleared. | 
|  | 1857 | */ | 
|  | 1858 | handle = (void *) (((intptr_t) global->nl_event) ^ | 
|  | 1859 | ELOOP_SOCKET_INVALID); | 
|  | 1860 |  | 
|  | 1861 | for (i = 0; groups[i]; i++) { | 
|  | 1862 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); | 
|  | 1863 | if (ret >= 0) | 
|  | 1864 | ret = nl_socket_add_membership(handle, ret); | 
|  | 1865 | if (ret < 0) { | 
|  | 1866 | wpa_printf(MSG_INFO, | 
|  | 1867 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 1868 | groups[i], ret, nl_geterror(ret)); | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1869 | } | 
|  | 1870 | } | 
|  | 1871 | } | 
|  | 1872 |  | 
|  | 1873 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1874 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) | 
|  | 1875 | { | 
| Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1876 | struct wpa_driver_nl80211_data *drv = ctx; | 
|  | 1877 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1878 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); | 
| Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1879 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1880 | /* | 
| Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1881 | * rtnetlink ifdown handler will report interfaces other than the P2P | 
|  | 1882 | * Device interface as disabled. | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1883 | */ | 
| Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1884 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) | 
|  | 1885 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1886 | } | 
|  | 1887 |  | 
|  | 1888 |  | 
|  | 1889 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) | 
|  | 1890 | { | 
|  | 1891 | struct wpa_driver_nl80211_data *drv = ctx; | 
|  | 1892 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1893 | if (i802_set_iface_flags(drv->first_bss, 1)) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1894 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " | 
|  | 1895 | "after rfkill unblock"); | 
|  | 1896 | return; | 
|  | 1897 | } | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1898 |  | 
|  | 1899 | if (is_p2p_net_interface(drv->nlmode)) | 
|  | 1900 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); | 
|  | 1901 |  | 
| Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1902 | /* | 
|  | 1903 | * rtnetlink ifup handler will report interfaces other than the P2P | 
|  | 1904 | * Device interface as enabled. | 
|  | 1905 | */ | 
|  | 1906 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) | 
|  | 1907 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1908 | } | 
|  | 1909 |  | 
|  | 1910 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1911 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, | 
|  | 1912 | void *eloop_ctx, | 
|  | 1913 | void *handle) | 
|  | 1914 | { | 
|  | 1915 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | 
|  | 1916 | u8 data[2048]; | 
|  | 1917 | struct msghdr msg; | 
|  | 1918 | struct iovec entry; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1919 | u8 control[512]; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1920 | struct cmsghdr *cmsg; | 
|  | 1921 | int res, found_ee = 0, found_wifi = 0, acked = 0; | 
|  | 1922 | union wpa_event_data event; | 
|  | 1923 |  | 
|  | 1924 | memset(&msg, 0, sizeof(msg)); | 
|  | 1925 | msg.msg_iov = &entry; | 
|  | 1926 | msg.msg_iovlen = 1; | 
|  | 1927 | entry.iov_base = data; | 
|  | 1928 | entry.iov_len = sizeof(data); | 
|  | 1929 | msg.msg_control = &control; | 
|  | 1930 | msg.msg_controllen = sizeof(control); | 
|  | 1931 |  | 
|  | 1932 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); | 
|  | 1933 | /* if error or not fitting 802.3 header, return */ | 
|  | 1934 | if (res < 14) | 
|  | 1935 | return; | 
|  | 1936 |  | 
|  | 1937 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) | 
|  | 1938 | { | 
|  | 1939 | if (cmsg->cmsg_level == SOL_SOCKET && | 
|  | 1940 | cmsg->cmsg_type == SCM_WIFI_STATUS) { | 
|  | 1941 | int *ack; | 
|  | 1942 |  | 
|  | 1943 | found_wifi = 1; | 
|  | 1944 | ack = (void *)CMSG_DATA(cmsg); | 
|  | 1945 | acked = *ack; | 
|  | 1946 | } | 
|  | 1947 |  | 
|  | 1948 | if (cmsg->cmsg_level == SOL_PACKET && | 
|  | 1949 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { | 
|  | 1950 | struct sock_extended_err *err = | 
|  | 1951 | (struct sock_extended_err *)CMSG_DATA(cmsg); | 
|  | 1952 |  | 
|  | 1953 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) | 
|  | 1954 | found_ee = 1; | 
|  | 1955 | } | 
|  | 1956 | } | 
|  | 1957 |  | 
|  | 1958 | if (!found_ee || !found_wifi) | 
|  | 1959 | return; | 
|  | 1960 |  | 
|  | 1961 | memset(&event, 0, sizeof(event)); | 
|  | 1962 | event.eapol_tx_status.dst = data; | 
|  | 1963 | event.eapol_tx_status.data = data + 14; | 
|  | 1964 | event.eapol_tx_status.data_len = res - 14; | 
|  | 1965 | event.eapol_tx_status.ack = acked; | 
|  | 1966 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); | 
|  | 1967 | } | 
|  | 1968 |  | 
|  | 1969 |  | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 1970 | static int nl80211_init_connect_handle(struct i802_bss *bss) | 
|  | 1971 | { | 
|  | 1972 | if (bss->nl_connect) { | 
|  | 1973 | wpa_printf(MSG_DEBUG, | 
|  | 1974 | "nl80211: Connect handle already created (nl_connect=%p)", | 
|  | 1975 | bss->nl_connect); | 
|  | 1976 | return -1; | 
|  | 1977 | } | 
|  | 1978 |  | 
|  | 1979 | bss->nl_connect = nl_create_handle(bss->nl_cb, "connect"); | 
|  | 1980 | if (!bss->nl_connect) | 
|  | 1981 | return -1; | 
|  | 1982 | nl80211_register_eloop_read(&bss->nl_connect, | 
|  | 1983 | wpa_driver_nl80211_event_receive, | 
|  | 1984 | bss->nl_cb, 1); | 
|  | 1985 | return 0; | 
|  | 1986 | } | 
|  | 1987 |  | 
|  | 1988 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1989 | static int nl80211_init_bss(struct i802_bss *bss) | 
|  | 1990 | { | 
|  | 1991 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); | 
|  | 1992 | if (!bss->nl_cb) | 
|  | 1993 | return -1; | 
|  | 1994 |  | 
|  | 1995 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, | 
|  | 1996 | no_seq_check, NULL); | 
|  | 1997 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, | 
|  | 1998 | process_bss_event, bss); | 
|  | 1999 |  | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 2000 | nl80211_init_connect_handle(bss); | 
|  | 2001 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2002 | return 0; | 
|  | 2003 | } | 
|  | 2004 |  | 
|  | 2005 |  | 
|  | 2006 | static void nl80211_destroy_bss(struct i802_bss *bss) | 
|  | 2007 | { | 
|  | 2008 | nl_cb_put(bss->nl_cb); | 
|  | 2009 | bss->nl_cb = NULL; | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 2010 |  | 
|  | 2011 | if (bss->nl_connect) | 
|  | 2012 | nl80211_destroy_eloop_handle(&bss->nl_connect, 1); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2013 | } | 
|  | 2014 |  | 
|  | 2015 |  | 
| Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2016 | static void | 
|  | 2017 | wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv) | 
|  | 2018 | { | 
|  | 2019 | struct rfkill_config *rcfg; | 
|  | 2020 |  | 
|  | 2021 | if (drv->rfkill) | 
|  | 2022 | return; | 
|  | 2023 |  | 
|  | 2024 | rcfg = os_zalloc(sizeof(*rcfg)); | 
|  | 2025 | if (!rcfg) | 
|  | 2026 | return; | 
|  | 2027 |  | 
|  | 2028 | rcfg->ctx = drv; | 
|  | 2029 |  | 
|  | 2030 | /* rfkill uses netdev sysfs for initialization. However, P2P Device is | 
|  | 2031 | * not associated with a netdev, so use the name of some other interface | 
|  | 2032 | * sharing the same wiphy as the P2P Device interface. | 
|  | 2033 | * | 
|  | 2034 | * Note: This is valid, as a P2P Device interface is always dynamically | 
|  | 2035 | * created and is created only once another wpa_s interface was added. | 
|  | 2036 | */ | 
|  | 2037 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { | 
|  | 2038 | struct nl80211_global *global = drv->global; | 
|  | 2039 | struct wpa_driver_nl80211_data *tmp1; | 
|  | 2040 |  | 
|  | 2041 | dl_list_for_each(tmp1, &global->interfaces, | 
|  | 2042 | struct wpa_driver_nl80211_data, list) { | 
|  | 2043 | if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx || | 
|  | 2044 | !tmp1->rfkill) | 
|  | 2045 | continue; | 
|  | 2046 |  | 
|  | 2047 | wpa_printf(MSG_DEBUG, | 
|  | 2048 | "nl80211: Use (%s) to initialize P2P Device rfkill", | 
|  | 2049 | tmp1->first_bss->ifname); | 
|  | 2050 | os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname, | 
|  | 2051 | sizeof(rcfg->ifname)); | 
|  | 2052 | break; | 
|  | 2053 | } | 
|  | 2054 | } else { | 
|  | 2055 | os_strlcpy(rcfg->ifname, drv->first_bss->ifname, | 
|  | 2056 | sizeof(rcfg->ifname)); | 
|  | 2057 | } | 
|  | 2058 |  | 
|  | 2059 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; | 
|  | 2060 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; | 
|  | 2061 | drv->rfkill = rfkill_init(rcfg); | 
|  | 2062 | if (!drv->rfkill) { | 
|  | 2063 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); | 
|  | 2064 | os_free(rcfg); | 
|  | 2065 | } | 
|  | 2066 | } | 
|  | 2067 |  | 
|  | 2068 |  | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2069 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, | 
|  | 2070 | void *global_priv, int hostapd, | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2071 | const u8 *set_addr, | 
|  | 2072 | const char *driver_params) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2073 | { | 
|  | 2074 | struct wpa_driver_nl80211_data *drv; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2075 | struct i802_bss *bss; | 
|  | 2076 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2077 | if (global_priv == NULL) | 
|  | 2078 | return NULL; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2079 | drv = os_zalloc(sizeof(*drv)); | 
|  | 2080 | if (drv == NULL) | 
|  | 2081 | return NULL; | 
|  | 2082 | drv->global = global_priv; | 
|  | 2083 | drv->ctx = ctx; | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2084 | drv->hostapd = !!hostapd; | 
|  | 2085 | drv->eapol_sock = -1; | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 2086 |  | 
|  | 2087 | /* | 
|  | 2088 | * There is no driver capability flag for this, so assume it is | 
|  | 2089 | * supported and disable this on first attempt to use if the driver | 
|  | 2090 | * rejects the command due to missing support. | 
|  | 2091 | */ | 
|  | 2092 | drv->set_rekey_offload = 1; | 
|  | 2093 |  | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2094 | drv->num_if_indices = ARRAY_SIZE(drv->default_if_indices); | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2095 | drv->if_indices = drv->default_if_indices; | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2096 |  | 
|  | 2097 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); | 
|  | 2098 | if (!drv->first_bss) { | 
|  | 2099 | os_free(drv); | 
|  | 2100 | return NULL; | 
|  | 2101 | } | 
|  | 2102 | bss = drv->first_bss; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2103 | bss->drv = drv; | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2104 | bss->ctx = ctx; | 
|  | 2105 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2106 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); | 
|  | 2107 | drv->monitor_ifidx = -1; | 
|  | 2108 | drv->monitor_sock = -1; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2109 | drv->eapol_tx_sock = -1; | 
|  | 2110 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2111 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2112 | if (nl80211_init_bss(bss)) | 
|  | 2113 | goto failed; | 
|  | 2114 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2115 | 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] | 2116 | goto failed; | 
|  | 2117 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2118 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); | 
|  | 2119 | if (drv->eapol_tx_sock < 0) | 
|  | 2120 | goto failed; | 
|  | 2121 |  | 
|  | 2122 | if (drv->data_tx_status) { | 
|  | 2123 | int enabled = 1; | 
|  | 2124 |  | 
|  | 2125 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, | 
|  | 2126 | &enabled, sizeof(enabled)) < 0) { | 
|  | 2127 | wpa_printf(MSG_DEBUG, | 
|  | 2128 | "nl80211: wifi status sockopt failed\n"); | 
|  | 2129 | drv->data_tx_status = 0; | 
|  | 2130 | if (!drv->use_monitor) | 
|  | 2131 | drv->capa.flags &= | 
|  | 2132 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; | 
|  | 2133 | } else { | 
|  | 2134 | eloop_register_read_sock(drv->eapol_tx_sock, | 
|  | 2135 | wpa_driver_nl80211_handle_eapol_tx_status, | 
|  | 2136 | drv, NULL); | 
|  | 2137 | } | 
|  | 2138 | } | 
|  | 2139 |  | 
|  | 2140 | if (drv->global) { | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2141 | nl80211_check_global(drv->global); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2142 | dl_list_add(&drv->global->interfaces, &drv->list); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2143 | drv->in_interface_list = 1; | 
|  | 2144 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2145 |  | 
|  | 2146 | return bss; | 
|  | 2147 |  | 
|  | 2148 | failed: | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2149 | wpa_driver_nl80211_deinit(bss); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2150 | return NULL; | 
|  | 2151 | } | 
|  | 2152 |  | 
|  | 2153 |  | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2154 | /** | 
|  | 2155 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface | 
|  | 2156 | * @ctx: context to be used when calling wpa_supplicant functions, | 
|  | 2157 | * e.g., wpa_supplicant_event() | 
|  | 2158 | * @ifname: interface name, e.g., wlan0 | 
|  | 2159 | * @global_priv: private driver global data from global_init() | 
|  | 2160 | * Returns: Pointer to private data, %NULL on failure | 
|  | 2161 | */ | 
|  | 2162 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, | 
|  | 2163 | void *global_priv) | 
|  | 2164 | { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2165 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, | 
|  | 2166 | NULL); | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2167 | } | 
|  | 2168 |  | 
|  | 2169 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2170 | static int nl80211_register_frame(struct i802_bss *bss, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2171 | struct nl_sock *nl_handle, | 
| Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2172 | u16 type, const u8 *match, size_t match_len, | 
|  | 2173 | bool multicast) | 
| 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 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2176 | struct nl_msg *msg; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2177 | int ret; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2178 | char buf[30]; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2179 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2180 | buf[0] = '\0'; | 
|  | 2181 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); | 
| Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2182 | wpa_printf(MSG_DEBUG, | 
|  | 2183 | "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s multicast=%d", | 
|  | 2184 | type, fc2str(type), nl_handle, buf, multicast); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2185 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2186 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_FRAME)) || | 
| Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2187 | (multicast && nla_put_flag(msg, NL80211_ATTR_RECEIVE_MULTICAST)) || | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2188 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || | 
|  | 2189 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { | 
|  | 2190 | nlmsg_free(msg); | 
|  | 2191 | return -1; | 
|  | 2192 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2193 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2194 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2195 | if (ret) { | 
|  | 2196 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " | 
|  | 2197 | "failed (type=%u): ret=%d (%s)", | 
|  | 2198 | type, ret, strerror(-ret)); | 
|  | 2199 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", | 
|  | 2200 | match, match_len); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2201 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2202 | return ret; | 
|  | 2203 | } | 
|  | 2204 |  | 
|  | 2205 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2206 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) | 
|  | 2207 | { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2208 | if (bss->nl_mgmt) { | 
|  | 2209 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " | 
|  | 2210 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); | 
|  | 2211 | return -1; | 
|  | 2212 | } | 
|  | 2213 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2214 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2215 | if (bss->nl_mgmt == NULL) | 
|  | 2216 | return -1; | 
|  | 2217 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2218 | return 0; | 
|  | 2219 | } | 
|  | 2220 |  | 
|  | 2221 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2222 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) | 
|  | 2223 | { | 
|  | 2224 | nl80211_register_eloop_read(&bss->nl_mgmt, | 
|  | 2225 | wpa_driver_nl80211_event_receive, | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2226 | bss->nl_cb, 0); | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2227 | } | 
|  | 2228 |  | 
|  | 2229 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2230 | static int nl80211_register_action_frame(struct i802_bss *bss, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2231 | const u8 *match, size_t match_len) | 
|  | 2232 | { | 
|  | 2233 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2234 | return nl80211_register_frame(bss, bss->nl_mgmt, | 
| Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2235 | type, match, match_len, false); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2236 | } | 
|  | 2237 |  | 
|  | 2238 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2239 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2240 | { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2241 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2242 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2243 | int ret = 0; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2244 |  | 
|  | 2245 | if (nl80211_alloc_mgmt_handle(bss)) | 
|  | 2246 | return -1; | 
|  | 2247 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " | 
|  | 2248 | "handle %p", bss->nl_mgmt); | 
|  | 2249 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2250 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2251 | /* register for any AUTH message */ | 
| Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2252 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0, false); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2253 | } else if ((drv->capa.flags & WPA_DRIVER_FLAGS_SAE) && | 
|  | 2254 | !(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { | 
|  | 2255 | /* register for SAE Authentication frames */ | 
|  | 2256 | nl80211_register_frame(bss, bss->nl_mgmt, type, | 
| Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2257 | (u8 *) "\x03\x00", 2, false); | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2258 | } | 
|  | 2259 |  | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2260 | #ifdef CONFIG_INTERWORKING | 
|  | 2261 | /* QoS Map Configure */ | 
|  | 2262 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2263 | ret = -1; | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2264 | #endif /* CONFIG_INTERWORKING */ | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2265 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2266 | /* GAS Initial Request */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2267 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2268 | ret = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2269 | /* GAS Initial Response */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2270 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2271 | ret = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2272 | /* GAS Comeback Request */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2273 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2274 | ret = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2275 | /* GAS Comeback Response */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2276 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2277 | ret = -1; | 
| Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2278 | /* Protected GAS Initial Request */ | 
|  | 2279 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) | 
|  | 2280 | ret = -1; | 
|  | 2281 | /* Protected GAS Initial Response */ | 
|  | 2282 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) | 
|  | 2283 | ret = -1; | 
|  | 2284 | /* Protected GAS Comeback Request */ | 
|  | 2285 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) | 
|  | 2286 | ret = -1; | 
|  | 2287 | /* Protected GAS Comeback Response */ | 
|  | 2288 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) | 
|  | 2289 | ret = -1; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2290 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2291 | #ifdef CONFIG_P2P | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2292 | /* P2P Public Action */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2293 | if (nl80211_register_action_frame(bss, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2294 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", | 
|  | 2295 | 6) < 0) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2296 | ret = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2297 | /* P2P Action */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2298 | if (nl80211_register_action_frame(bss, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2299 | (u8 *) "\x7f\x50\x6f\x9a\x09", | 
|  | 2300 | 5) < 0) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2301 | ret = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2302 | #endif /* CONFIG_P2P */ | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2303 | #ifdef CONFIG_DPP | 
|  | 2304 | /* DPP Public Action */ | 
|  | 2305 | if (nl80211_register_action_frame(bss, | 
|  | 2306 | (u8 *) "\x04\x09\x50\x6f\x9a\x1a", | 
|  | 2307 | 6) < 0) | 
|  | 2308 | ret = -1; | 
|  | 2309 | #endif /* CONFIG_DPP */ | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2310 | #ifdef CONFIG_OCV | 
|  | 2311 | /* SA Query Request */ | 
|  | 2312 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x00", 2) < 0) | 
|  | 2313 | ret = -1; | 
|  | 2314 | #endif /* CONFIG_OCV */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2315 | /* SA Query Response */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2316 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2317 | ret = -1; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2318 | #ifdef CONFIG_TDLS | 
|  | 2319 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { | 
|  | 2320 | /* TDLS Discovery Response */ | 
|  | 2321 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < | 
|  | 2322 | 0) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2323 | ret = -1; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2324 | } | 
|  | 2325 | #endif /* CONFIG_TDLS */ | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2326 | #ifdef CONFIG_FST | 
|  | 2327 | /* FST Action frames */ | 
|  | 2328 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) | 
|  | 2329 | ret = -1; | 
|  | 2330 | #endif /* CONFIG_FST */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2331 |  | 
|  | 2332 | /* FT Action frames */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2333 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2334 | ret = -1; | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2335 | else if (!drv->has_driver_key_mgmt) { | 
|  | 2336 | int i; | 
|  | 2337 |  | 
|  | 2338 | /* Update supported AKMs only if the driver doesn't advertize | 
|  | 2339 | * any AKM capabilities. */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2340 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | | 
|  | 2341 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; | 
|  | 2342 |  | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2343 | /* Update per interface supported AKMs */ | 
|  | 2344 | for (i = 0; i < WPA_IF_MAX; i++) | 
|  | 2345 | drv->capa.key_mgmt_iftype[i] = drv->capa.key_mgmt; | 
|  | 2346 | } | 
|  | 2347 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2348 | /* WNM - BSS Transition Management Request */ | 
|  | 2349 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2350 | ret = -1; | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2351 | /* WNM-Sleep Mode Response */ | 
|  | 2352 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2353 | ret = -1; | 
| Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2354 | #ifdef CONFIG_WNM | 
|  | 2355 | /* WNM - Collocated Interference Request */ | 
|  | 2356 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x0b", 2) < 0) | 
|  | 2357 | ret = -1; | 
|  | 2358 | #endif /* CONFIG_WNM */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2359 |  | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2360 | #ifdef CONFIG_HS20 | 
|  | 2361 | /* WNM-Notification */ | 
|  | 2362 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2363 | ret = -1; | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2364 | #endif /* CONFIG_HS20 */ | 
|  | 2365 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2366 | /* WMM-AC ADDTS Response */ | 
|  | 2367 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) | 
|  | 2368 | ret = -1; | 
|  | 2369 |  | 
|  | 2370 | /* WMM-AC DELTS */ | 
|  | 2371 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) | 
|  | 2372 | ret = -1; | 
|  | 2373 |  | 
|  | 2374 | /* Radio Measurement - Neighbor Report Response */ | 
|  | 2375 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) | 
|  | 2376 | ret = -1; | 
|  | 2377 |  | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2378 | /* Radio Measurement - Radio Measurement Request */ | 
|  | 2379 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0) | 
|  | 2380 | ret = -1; | 
|  | 2381 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2382 | /* Radio Measurement - Link Measurement Request */ | 
|  | 2383 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && | 
|  | 2384 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) | 
|  | 2385 | ret = -1; | 
|  | 2386 |  | 
|  | 2387 | nl80211_mgmt_handle_register_eloop(bss); | 
|  | 2388 |  | 
|  | 2389 | return ret; | 
|  | 2390 | } | 
|  | 2391 |  | 
|  | 2392 |  | 
|  | 2393 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) | 
|  | 2394 | { | 
|  | 2395 | int ret = 0; | 
|  | 2396 |  | 
|  | 2397 | if (nl80211_alloc_mgmt_handle(bss)) | 
|  | 2398 | return -1; | 
|  | 2399 |  | 
|  | 2400 | wpa_printf(MSG_DEBUG, | 
|  | 2401 | "nl80211: Subscribe to mgmt frames with mesh handle %p", | 
|  | 2402 | bss->nl_mgmt); | 
|  | 2403 |  | 
|  | 2404 | /* Auth frames for mesh SAE */ | 
|  | 2405 | if (nl80211_register_frame(bss, bss->nl_mgmt, | 
|  | 2406 | (WLAN_FC_TYPE_MGMT << 2) | | 
|  | 2407 | (WLAN_FC_STYPE_AUTH << 4), | 
| Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2408 | NULL, 0, false) < 0) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2409 | ret = -1; | 
|  | 2410 |  | 
|  | 2411 | /* Mesh peering open */ | 
|  | 2412 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) | 
|  | 2413 | ret = -1; | 
|  | 2414 | /* Mesh peering confirm */ | 
|  | 2415 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) | 
|  | 2416 | ret = -1; | 
|  | 2417 | /* Mesh peering close */ | 
|  | 2418 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) | 
|  | 2419 | ret = -1; | 
|  | 2420 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2421 | nl80211_mgmt_handle_register_eloop(bss); | 
|  | 2422 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2423 | return ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2424 | } | 
|  | 2425 |  | 
|  | 2426 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2427 | static int nl80211_register_spurious_class3(struct i802_bss *bss) | 
|  | 2428 | { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2429 | struct nl_msg *msg; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2430 | int ret; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2431 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2432 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); | 
|  | 2433 | ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2434 | if (ret) { | 
|  | 2435 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " | 
|  | 2436 | "failed: ret=%d (%s)", | 
|  | 2437 | ret, strerror(-ret)); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2438 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2439 | return ret; | 
|  | 2440 | } | 
|  | 2441 |  | 
|  | 2442 |  | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2443 | static int nl80211_action_subscribe_ap(struct i802_bss *bss) | 
|  | 2444 | { | 
|  | 2445 | int ret = 0; | 
|  | 2446 |  | 
|  | 2447 | /* Public Action frames */ | 
|  | 2448 | if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0) | 
|  | 2449 | ret = -1; | 
|  | 2450 | /* RRM Measurement Report */ | 
|  | 2451 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0) | 
|  | 2452 | ret = -1; | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2453 | /* RRM Link Measurement Report */ | 
|  | 2454 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0) | 
|  | 2455 | ret = -1; | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2456 | /* RRM Neighbor Report Request */ | 
|  | 2457 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0) | 
|  | 2458 | ret = -1; | 
|  | 2459 | /* FT Action frames */ | 
|  | 2460 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) | 
|  | 2461 | ret = -1; | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2462 | /* SA Query */ | 
|  | 2463 | if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0) | 
|  | 2464 | ret = -1; | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2465 | /* Protected Dual of Public Action */ | 
|  | 2466 | if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0) | 
|  | 2467 | ret = -1; | 
|  | 2468 | /* WNM */ | 
|  | 2469 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0) | 
|  | 2470 | ret = -1; | 
|  | 2471 | /* WMM */ | 
|  | 2472 | if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0) | 
|  | 2473 | ret = -1; | 
|  | 2474 | #ifdef CONFIG_FST | 
|  | 2475 | /* FST Action frames */ | 
|  | 2476 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) | 
|  | 2477 | ret = -1; | 
|  | 2478 | #endif /* CONFIG_FST */ | 
|  | 2479 | /* Vendor-specific */ | 
|  | 2480 | if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0) | 
|  | 2481 | ret = -1; | 
|  | 2482 |  | 
|  | 2483 | return ret; | 
|  | 2484 | } | 
|  | 2485 |  | 
|  | 2486 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2487 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) | 
|  | 2488 | { | 
|  | 2489 | static const int stypes[] = { | 
|  | 2490 | WLAN_FC_STYPE_AUTH, | 
|  | 2491 | WLAN_FC_STYPE_ASSOC_REQ, | 
|  | 2492 | WLAN_FC_STYPE_REASSOC_REQ, | 
|  | 2493 | WLAN_FC_STYPE_DISASSOC, | 
|  | 2494 | WLAN_FC_STYPE_DEAUTH, | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2495 | WLAN_FC_STYPE_PROBE_REQ, | 
|  | 2496 | /* Beacon doesn't work as mac80211 doesn't currently allow | 
|  | 2497 | * it, but it wouldn't really be the right thing anyway as | 
|  | 2498 | * it isn't per interface ... maybe just dump the scan | 
|  | 2499 | * results periodically for OLBC? | 
|  | 2500 | */ | 
| Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2501 | /* WLAN_FC_STYPE_BEACON, */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2502 | }; | 
|  | 2503 | unsigned int i; | 
|  | 2504 |  | 
|  | 2505 | if (nl80211_alloc_mgmt_handle(bss)) | 
|  | 2506 | return -1; | 
|  | 2507 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " | 
|  | 2508 | "handle %p", bss->nl_mgmt); | 
|  | 2509 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2510 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2511 | if (nl80211_register_frame(bss, bss->nl_mgmt, | 
|  | 2512 | (WLAN_FC_TYPE_MGMT << 2) | | 
|  | 2513 | (stypes[i] << 4), | 
| Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2514 | NULL, 0, false) < 0) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2515 | goto out_err; | 
|  | 2516 | } | 
|  | 2517 | } | 
|  | 2518 |  | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2519 | if (nl80211_action_subscribe_ap(bss)) | 
|  | 2520 | goto out_err; | 
|  | 2521 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2522 | if (nl80211_register_spurious_class3(bss)) | 
|  | 2523 | goto out_err; | 
|  | 2524 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2525 | nl80211_mgmt_handle_register_eloop(bss); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2526 | return 0; | 
|  | 2527 |  | 
|  | 2528 | out_err: | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2529 | nl_destroy_handles(&bss->nl_mgmt); | 
|  | 2530 | return -1; | 
|  | 2531 | } | 
|  | 2532 |  | 
|  | 2533 |  | 
|  | 2534 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) | 
|  | 2535 | { | 
|  | 2536 | if (nl80211_alloc_mgmt_handle(bss)) | 
|  | 2537 | return -1; | 
|  | 2538 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " | 
|  | 2539 | "handle %p (device SME)", bss->nl_mgmt); | 
|  | 2540 |  | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2541 | if (nl80211_action_subscribe_ap(bss)) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2542 | goto out_err; | 
|  | 2543 |  | 
| Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 2544 | if (bss->drv->device_ap_sme) { | 
|  | 2545 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); | 
|  | 2546 |  | 
|  | 2547 | /* Register for all Authentication frames */ | 
| Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 2548 | if (nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0, | 
|  | 2549 | false) < 0) | 
| Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 2550 | wpa_printf(MSG_DEBUG, | 
|  | 2551 | "nl80211: Failed to subscribe to handle Authentication frames - SAE offload may not work"); | 
|  | 2552 | } | 
|  | 2553 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2554 | nl80211_mgmt_handle_register_eloop(bss); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2555 | return 0; | 
|  | 2556 |  | 
|  | 2557 | out_err: | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2558 | nl_destroy_handles(&bss->nl_mgmt); | 
|  | 2559 | return -1; | 
|  | 2560 | } | 
|  | 2561 |  | 
|  | 2562 |  | 
|  | 2563 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) | 
|  | 2564 | { | 
|  | 2565 | if (bss->nl_mgmt == NULL) | 
|  | 2566 | return; | 
|  | 2567 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " | 
|  | 2568 | "(%s)", bss->nl_mgmt, reason); | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2569 | nl80211_destroy_eloop_handle(&bss->nl_mgmt, 0); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2570 |  | 
|  | 2571 | nl80211_put_wiphy_data_ap(bss); | 
|  | 2572 | } | 
|  | 2573 |  | 
|  | 2574 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2575 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) | 
|  | 2576 | { | 
|  | 2577 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); | 
|  | 2578 | } | 
|  | 2579 |  | 
|  | 2580 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2581 | static void nl80211_del_p2pdev(struct i802_bss *bss) | 
|  | 2582 | { | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2583 | struct nl_msg *msg; | 
|  | 2584 | int ret; | 
|  | 2585 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2586 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); | 
|  | 2587 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2588 |  | 
|  | 2589 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", | 
|  | 2590 | bss->ifname, (long long unsigned int) bss->wdev_id, | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2591 | strerror(-ret)); | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2592 | } | 
|  | 2593 |  | 
|  | 2594 |  | 
|  | 2595 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) | 
|  | 2596 | { | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2597 | struct nl_msg *msg; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2598 | int ret; | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2599 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2600 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : | 
|  | 2601 | NL80211_CMD_STOP_P2P_DEVICE); | 
|  | 2602 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2603 |  | 
|  | 2604 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", | 
|  | 2605 | start ? "Start" : "Stop", | 
|  | 2606 | bss->ifname, (long long unsigned int) bss->wdev_id, | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2607 | strerror(-ret)); | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2608 | return ret; | 
|  | 2609 | } | 
|  | 2610 |  | 
|  | 2611 |  | 
|  | 2612 | static int i802_set_iface_flags(struct i802_bss *bss, int up) | 
|  | 2613 | { | 
|  | 2614 | enum nl80211_iftype nlmode; | 
|  | 2615 |  | 
|  | 2616 | nlmode = nl80211_get_ifmode(bss); | 
|  | 2617 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { | 
|  | 2618 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, | 
|  | 2619 | bss->ifname, up); | 
|  | 2620 | } | 
|  | 2621 |  | 
|  | 2622 | /* P2P Device has start/stop which is equivalent */ | 
|  | 2623 | return nl80211_set_p2pdev(bss, up); | 
|  | 2624 | } | 
|  | 2625 |  | 
|  | 2626 |  | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2627 | #ifdef CONFIG_TESTING_OPTIONS | 
|  | 2628 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) | 
|  | 2629 | { | 
|  | 2630 | /* struct wpa_driver_nl80211_data *drv = arg; */ | 
|  | 2631 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | 
|  | 2632 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | 
|  | 2633 |  | 
|  | 2634 |  | 
|  | 2635 | wpa_printf(MSG_DEBUG, | 
|  | 2636 | "nl80211: QCA vendor test command response received"); | 
|  | 2637 |  | 
|  | 2638 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | 
|  | 2639 | genlmsg_attrlen(gnlh, 0), NULL); | 
|  | 2640 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { | 
|  | 2641 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); | 
|  | 2642 | return NL_SKIP; | 
|  | 2643 | } | 
|  | 2644 |  | 
|  | 2645 | wpa_hexdump(MSG_DEBUG, | 
|  | 2646 | "nl80211: Received QCA vendor test command response", | 
|  | 2647 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), | 
|  | 2648 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); | 
|  | 2649 |  | 
|  | 2650 | return NL_SKIP; | 
|  | 2651 | } | 
|  | 2652 | #endif /* CONFIG_TESTING_OPTIONS */ | 
|  | 2653 |  | 
|  | 2654 |  | 
|  | 2655 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) | 
|  | 2656 | { | 
|  | 2657 | #ifdef CONFIG_TESTING_OPTIONS | 
|  | 2658 | struct nl_msg *msg; | 
|  | 2659 | struct nlattr *params; | 
|  | 2660 | int ret; | 
|  | 2661 |  | 
|  | 2662 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | 
|  | 2663 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 2664 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 2665 | QCA_NL80211_VENDOR_SUBCMD_TEST) || | 
|  | 2666 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | 
|  | 2667 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { | 
|  | 2668 | nlmsg_free(msg); | 
|  | 2669 | return; | 
|  | 2670 | } | 
|  | 2671 | nla_nest_end(msg, params); | 
|  | 2672 |  | 
|  | 2673 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv); | 
|  | 2674 | wpa_printf(MSG_DEBUG, | 
|  | 2675 | "nl80211: QCA vendor test command returned %d (%s)", | 
|  | 2676 | ret, strerror(-ret)); | 
|  | 2677 | #endif /* CONFIG_TESTING_OPTIONS */ | 
|  | 2678 | } | 
|  | 2679 |  | 
|  | 2680 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2681 | static int | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2682 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2683 | const u8 *set_addr, int first, | 
|  | 2684 | const char *driver_params) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2685 | { | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2686 | struct i802_bss *bss = drv->first_bss; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2687 | int send_rfkill_event = 0; | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2688 | enum nl80211_iftype nlmode; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2689 |  | 
|  | 2690 | drv->ifindex = if_nametoindex(bss->ifname); | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2691 | bss->ifindex = drv->ifindex; | 
|  | 2692 | bss->wdev_id = drv->global->if_add_wdevid; | 
|  | 2693 | bss->wdev_id_set = drv->global->if_add_wdevid_set; | 
|  | 2694 |  | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2695 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; | 
|  | 2696 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2697 | drv->global->if_add_wdevid_set = 0; | 
|  | 2698 |  | 
| Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2699 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) | 
|  | 2700 | bss->static_ap = 1; | 
|  | 2701 |  | 
| Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 2702 | if (first && | 
|  | 2703 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && | 
|  | 2704 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) | 
|  | 2705 | drv->start_iface_up = 1; | 
|  | 2706 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2707 | if (wpa_driver_nl80211_capa(drv)) | 
|  | 2708 | return -1; | 
|  | 2709 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2710 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) | 
|  | 2711 | return -1; | 
|  | 2712 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2713 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", | 
|  | 2714 | bss->ifname, drv->phyname); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2715 |  | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2716 | if (set_addr && | 
|  | 2717 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || | 
|  | 2718 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, | 
|  | 2719 | set_addr))) | 
|  | 2720 | return -1; | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2721 |  | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2722 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) | 
|  | 2723 | drv->start_mode_ap = 1; | 
|  | 2724 |  | 
| Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2725 | if (drv->hostapd || bss->static_ap) | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2726 | nlmode = NL80211_IFTYPE_AP; | 
| Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 2727 | else if (bss->if_dynamic || | 
|  | 2728 | nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT) | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2729 | nlmode = nl80211_get_ifmode(bss); | 
|  | 2730 | else | 
|  | 2731 | nlmode = NL80211_IFTYPE_STATION; | 
|  | 2732 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2733 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2734 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2735 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2736 | } | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2737 |  | 
| Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2738 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2739 | nl80211_get_macaddr(bss); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2740 |  | 
| Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2741 | wpa_driver_nl80211_drv_init_rfkill(drv); | 
|  | 2742 |  | 
| Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2743 | if (!rfkill_is_blocked(drv->rfkill)) { | 
|  | 2744 | int ret = i802_set_iface_flags(bss, 1); | 
|  | 2745 | if (ret) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2746 | wpa_printf(MSG_ERROR, "nl80211: Could not set " | 
|  | 2747 | "interface '%s' UP", bss->ifname); | 
| Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2748 | return ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2749 | } | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2750 |  | 
|  | 2751 | if (is_p2p_net_interface(nlmode)) | 
|  | 2752 | nl80211_disable_11b_rates(bss->drv, | 
|  | 2753 | bss->drv->ifindex, 1); | 
|  | 2754 |  | 
| Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2755 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) | 
|  | 2756 | return ret; | 
|  | 2757 | } else { | 
|  | 2758 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " | 
|  | 2759 | "interface '%s' due to rfkill", bss->ifname); | 
| Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2760 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) | 
|  | 2761 | drv->if_disabled = 1; | 
|  | 2762 |  | 
| Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2763 | send_rfkill_event = 1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2764 | } | 
|  | 2765 |  | 
| Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2766 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2767 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, | 
|  | 2768 | 1, IF_OPER_DORMANT); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2769 |  | 
| Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2770 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { | 
|  | 2771 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, | 
|  | 2772 | bss->addr)) | 
|  | 2773 | return -1; | 
|  | 2774 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); | 
|  | 2775 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2776 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2777 | if (send_rfkill_event) { | 
|  | 2778 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, | 
|  | 2779 | drv, drv->ctx); | 
|  | 2780 | } | 
|  | 2781 |  | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2782 | if (drv->vendor_cmd_test_avail) | 
|  | 2783 | qca_vendor_test(drv); | 
|  | 2784 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2785 | return 0; | 
|  | 2786 | } | 
|  | 2787 |  | 
|  | 2788 |  | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2789 | static int wpa_driver_nl80211_del_beacon(struct i802_bss *bss) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2790 | { | 
|  | 2791 | struct nl_msg *msg; | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2792 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2793 |  | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2794 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", | 
|  | 2795 | drv->ifindex); | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2796 | nl80211_put_wiphy_data_ap(bss); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2797 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2798 | return send_and_recv_msgs(drv, msg, NULL, NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2799 | } | 
|  | 2800 |  | 
|  | 2801 |  | 
|  | 2802 | /** | 
|  | 2803 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2804 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2805 | * | 
|  | 2806 | * Shut down driver interface and processing of driver events. Free | 
|  | 2807 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). | 
|  | 2808 | */ | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2809 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2810 | { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2811 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
| Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2812 | unsigned int i; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2813 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2814 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", | 
|  | 2815 | bss->ifname, drv->disabled_11b_rates); | 
|  | 2816 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2817 | bss->in_deinit = 1; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2818 | if (drv->data_tx_status) | 
|  | 2819 | eloop_unregister_read_sock(drv->eapol_tx_sock); | 
|  | 2820 | if (drv->eapol_tx_sock >= 0) | 
|  | 2821 | close(drv->eapol_tx_sock); | 
|  | 2822 |  | 
|  | 2823 | if (bss->nl_preq) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2824 | wpa_driver_nl80211_probe_req_report(bss, 0); | 
|  | 2825 | if (bss->added_if_into_bridge) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2826 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, | 
|  | 2827 | bss->ifname) < 0) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2828 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " | 
|  | 2829 | "interface %s from bridge %s: %s", | 
|  | 2830 | bss->ifname, bss->brname, strerror(errno)); | 
|  | 2831 | } | 
| Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 2832 |  | 
|  | 2833 | if (drv->rtnl_sk) | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 2834 | nl_socket_free(drv->rtnl_sk); | 
| Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 2835 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2836 | if (bss->added_bridge) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2837 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, | 
|  | 2838 | 0) < 0) | 
|  | 2839 | wpa_printf(MSG_INFO, | 
|  | 2840 | "nl80211: Could not set bridge %s down", | 
|  | 2841 | bss->brname); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2842 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2843 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " | 
|  | 2844 | "bridge %s: %s", | 
|  | 2845 | bss->brname, strerror(errno)); | 
|  | 2846 | } | 
|  | 2847 |  | 
|  | 2848 | nl80211_remove_monitor_interface(drv); | 
|  | 2849 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2850 | if (is_ap_interface(drv->nlmode)) | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2851 | wpa_driver_nl80211_del_beacon(bss); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2852 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2853 | if (drv->eapol_sock >= 0) { | 
|  | 2854 | eloop_unregister_read_sock(drv->eapol_sock); | 
|  | 2855 | close(drv->eapol_sock); | 
|  | 2856 | } | 
|  | 2857 |  | 
|  | 2858 | if (drv->if_indices != drv->default_if_indices) | 
|  | 2859 | os_free(drv->if_indices); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2860 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2861 | if (drv->disabled_11b_rates) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2862 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); | 
|  | 2863 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2864 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, | 
|  | 2865 | IF_OPER_UP); | 
| Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 2866 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2867 | rfkill_deinit(drv->rfkill); | 
|  | 2868 |  | 
|  | 2869 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); | 
|  | 2870 |  | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2871 | if (!drv->start_iface_up) | 
|  | 2872 | (void) i802_set_iface_flags(bss, 0); | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2873 |  | 
|  | 2874 | if (drv->addr_changed) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2875 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, | 
|  | 2876 | 0) < 0) { | 
|  | 2877 | wpa_printf(MSG_DEBUG, | 
|  | 2878 | "nl80211: Could not set interface down to restore permanent MAC address"); | 
|  | 2879 | } | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2880 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, | 
|  | 2881 | drv->perm_addr) < 0) { | 
|  | 2882 | wpa_printf(MSG_DEBUG, | 
|  | 2883 | "nl80211: Could not restore permanent MAC address"); | 
|  | 2884 | } | 
|  | 2885 | } | 
|  | 2886 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2887 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2888 | if (!drv->hostapd || !drv->start_mode_ap) | 
|  | 2889 | wpa_driver_nl80211_set_mode(bss, | 
|  | 2890 | NL80211_IFTYPE_STATION); | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2891 | nl80211_mgmt_unsubscribe(bss, "deinit"); | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2892 | } else { | 
|  | 2893 | nl80211_mgmt_unsubscribe(bss, "deinit"); | 
|  | 2894 | nl80211_del_p2pdev(bss); | 
|  | 2895 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2896 |  | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2897 | nl80211_destroy_bss(drv->first_bss); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2898 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2899 | os_free(drv->filter_ssids); | 
|  | 2900 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2901 | os_free(drv->auth_ie); | 
|  | 2902 |  | 
|  | 2903 | if (drv->in_interface_list) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2904 | dl_list_del(&drv->list); | 
|  | 2905 |  | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2906 | os_free(drv->extended_capa); | 
|  | 2907 | os_free(drv->extended_capa_mask); | 
| Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2908 | for (i = 0; i < drv->num_iface_ext_capa; i++) { | 
|  | 2909 | os_free(drv->iface_ext_capa[i].ext_capa); | 
|  | 2910 | os_free(drv->iface_ext_capa[i].ext_capa_mask); | 
|  | 2911 | } | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2912 | os_free(drv->first_bss); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2913 | os_free(drv); | 
|  | 2914 | } | 
|  | 2915 |  | 
|  | 2916 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2917 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) | 
|  | 2918 | { | 
|  | 2919 | switch (alg) { | 
|  | 2920 | case WPA_ALG_WEP: | 
|  | 2921 | if (key_len == 5) | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2922 | return RSN_CIPHER_SUITE_WEP40; | 
|  | 2923 | return RSN_CIPHER_SUITE_WEP104; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2924 | case WPA_ALG_TKIP: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2925 | return RSN_CIPHER_SUITE_TKIP; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2926 | case WPA_ALG_CCMP: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2927 | return RSN_CIPHER_SUITE_CCMP; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2928 | case WPA_ALG_GCMP: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2929 | return RSN_CIPHER_SUITE_GCMP; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2930 | case WPA_ALG_CCMP_256: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2931 | return RSN_CIPHER_SUITE_CCMP_256; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2932 | case WPA_ALG_GCMP_256: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2933 | return RSN_CIPHER_SUITE_GCMP_256; | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 2934 | case WPA_ALG_BIP_CMAC_128: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2935 | return RSN_CIPHER_SUITE_AES_128_CMAC; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2936 | case WPA_ALG_BIP_GMAC_128: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2937 | return RSN_CIPHER_SUITE_BIP_GMAC_128; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2938 | case WPA_ALG_BIP_GMAC_256: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2939 | return RSN_CIPHER_SUITE_BIP_GMAC_256; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2940 | case WPA_ALG_BIP_CMAC_256: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2941 | return RSN_CIPHER_SUITE_BIP_CMAC_256; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2942 | case WPA_ALG_SMS4: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2943 | return RSN_CIPHER_SUITE_SMS4; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2944 | case WPA_ALG_KRK: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2945 | return RSN_CIPHER_SUITE_KRK; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2946 | case WPA_ALG_NONE: | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2947 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", | 
|  | 2948 | alg); | 
|  | 2949 | return 0; | 
|  | 2950 | } | 
|  | 2951 |  | 
|  | 2952 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", | 
|  | 2953 | alg); | 
|  | 2954 | return 0; | 
|  | 2955 | } | 
|  | 2956 |  | 
|  | 2957 |  | 
|  | 2958 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) | 
|  | 2959 | { | 
|  | 2960 | switch (cipher) { | 
|  | 2961 | case WPA_CIPHER_CCMP_256: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2962 | return RSN_CIPHER_SUITE_CCMP_256; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2963 | case WPA_CIPHER_GCMP_256: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2964 | return RSN_CIPHER_SUITE_GCMP_256; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2965 | case WPA_CIPHER_CCMP: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2966 | return RSN_CIPHER_SUITE_CCMP; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2967 | case WPA_CIPHER_GCMP: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2968 | return RSN_CIPHER_SUITE_GCMP; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2969 | case WPA_CIPHER_TKIP: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2970 | return RSN_CIPHER_SUITE_TKIP; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2971 | case WPA_CIPHER_WEP104: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2972 | return RSN_CIPHER_SUITE_WEP104; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2973 | case WPA_CIPHER_WEP40: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2974 | return RSN_CIPHER_SUITE_WEP40; | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2975 | case WPA_CIPHER_GTK_NOT_USED: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2976 | return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2977 | } | 
|  | 2978 |  | 
|  | 2979 | return 0; | 
|  | 2980 | } | 
|  | 2981 |  | 
|  | 2982 |  | 
|  | 2983 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], | 
|  | 2984 | int max_suites) | 
|  | 2985 | { | 
|  | 2986 | int num_suites = 0; | 
|  | 2987 |  | 
|  | 2988 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2989 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP_256; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2990 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2991 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP_256; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2992 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2993 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2994 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2995 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2996 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2997 | suites[num_suites++] = RSN_CIPHER_SUITE_TKIP; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2998 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2999 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP104; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3000 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3001 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP40; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3002 |  | 
|  | 3003 | return num_suites; | 
|  | 3004 | } | 
|  | 3005 |  | 
|  | 3006 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3007 | static int wpa_key_mgmt_to_suites(unsigned int key_mgmt_suites, u32 suites[], | 
|  | 3008 | int max_suites) | 
|  | 3009 | { | 
|  | 3010 | int num_suites = 0; | 
|  | 3011 |  | 
|  | 3012 | #define __AKM(a, b) \ | 
|  | 3013 | if (num_suites < max_suites && \ | 
|  | 3014 | (key_mgmt_suites & (WPA_KEY_MGMT_ ## a))) \ | 
|  | 3015 | suites[num_suites++] = (RSN_AUTH_KEY_MGMT_ ## b) | 
|  | 3016 | __AKM(IEEE8021X, UNSPEC_802_1X); | 
|  | 3017 | __AKM(PSK, PSK_OVER_802_1X); | 
|  | 3018 | __AKM(FT_IEEE8021X, FT_802_1X); | 
|  | 3019 | __AKM(FT_PSK, FT_PSK); | 
|  | 3020 | __AKM(IEEE8021X_SHA256, 802_1X_SHA256); | 
|  | 3021 | __AKM(PSK_SHA256, PSK_SHA256); | 
|  | 3022 | __AKM(SAE, SAE); | 
|  | 3023 | __AKM(FT_SAE, FT_SAE); | 
|  | 3024 | __AKM(CCKM, CCKM); | 
|  | 3025 | __AKM(OSEN, OSEN); | 
|  | 3026 | __AKM(IEEE8021X_SUITE_B, 802_1X_SUITE_B); | 
|  | 3027 | __AKM(IEEE8021X_SUITE_B_192, 802_1X_SUITE_B_192); | 
|  | 3028 | __AKM(FILS_SHA256, FILS_SHA256); | 
|  | 3029 | __AKM(FILS_SHA384, FILS_SHA384); | 
|  | 3030 | __AKM(FT_FILS_SHA256, FT_FILS_SHA256); | 
|  | 3031 | __AKM(FT_FILS_SHA384, FT_FILS_SHA384); | 
|  | 3032 | __AKM(OWE, OWE); | 
|  | 3033 | __AKM(DPP, DPP); | 
|  | 3034 | __AKM(FT_IEEE8021X_SHA384, FT_802_1X_SHA384); | 
|  | 3035 | #undef __AKM | 
|  | 3036 |  | 
|  | 3037 | return num_suites; | 
|  | 3038 | } | 
|  | 3039 |  | 
|  | 3040 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3041 | #ifdef CONFIG_DRIVER_NL80211_QCA | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3042 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, | 
|  | 3043 | const u8 *key, size_t key_len) | 
|  | 3044 | { | 
|  | 3045 | struct nl_msg *msg; | 
|  | 3046 | int ret; | 
|  | 3047 |  | 
|  | 3048 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) | 
|  | 3049 | return 0; | 
|  | 3050 |  | 
|  | 3051 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | 
|  | 3052 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 3053 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 3054 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || | 
|  | 3055 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { | 
|  | 3056 | nl80211_nlmsg_clear(msg); | 
|  | 3057 | nlmsg_free(msg); | 
|  | 3058 | return -1; | 
|  | 3059 | } | 
|  | 3060 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); | 
|  | 3061 | if (ret) { | 
|  | 3062 | wpa_printf(MSG_DEBUG, | 
|  | 3063 | "nl80211: Key management set key failed: ret=%d (%s)", | 
|  | 3064 | ret, strerror(-ret)); | 
|  | 3065 | } | 
|  | 3066 |  | 
|  | 3067 | return ret; | 
|  | 3068 | } | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3069 | #endif /* CONFIG_DRIVER_NL80211_QCA */ | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3070 |  | 
|  | 3071 |  | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3072 | static int nl80211_set_pmk(struct wpa_driver_nl80211_data *drv, | 
|  | 3073 | const u8 *key, size_t key_len, | 
|  | 3074 | const u8 *addr) | 
|  | 3075 | { | 
|  | 3076 | struct nl_msg *msg = NULL; | 
|  | 3077 | int ret; | 
|  | 3078 |  | 
|  | 3079 | /* | 
|  | 3080 | * If the authenticator address is not set, assume it is | 
|  | 3081 | * the current BSSID. | 
|  | 3082 | */ | 
|  | 3083 | if (!addr && drv->associated) | 
|  | 3084 | addr = drv->bssid; | 
|  | 3085 | else if (!addr) | 
|  | 3086 | return -1; | 
|  | 3087 |  | 
|  | 3088 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK to the driver for " MACSTR, | 
|  | 3089 | MAC2STR(addr)); | 
|  | 3090 | wpa_hexdump_key(MSG_DEBUG, "nl80211: PMK", key, key_len); | 
|  | 3091 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_PMK); | 
|  | 3092 | if (!msg || | 
|  | 3093 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | 
|  | 3094 | nla_put(msg, NL80211_ATTR_PMK, key_len, key)) { | 
|  | 3095 | nl80211_nlmsg_clear(msg); | 
|  | 3096 | nlmsg_free(msg); | 
|  | 3097 | return -ENOBUFS; | 
|  | 3098 | } | 
|  | 3099 |  | 
|  | 3100 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); | 
|  | 3101 | if (ret) { | 
|  | 3102 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK failed: ret=%d (%s)", | 
|  | 3103 | ret, strerror(-ret)); | 
|  | 3104 | } | 
|  | 3105 |  | 
|  | 3106 | return ret; | 
|  | 3107 | } | 
|  | 3108 |  | 
|  | 3109 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3110 | static int wpa_driver_nl80211_set_key(struct i802_bss *bss, | 
|  | 3111 | struct wpa_driver_set_key_params *params) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3112 | { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3113 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3114 | int ifindex; | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3115 | struct nl_msg *msg; | 
|  | 3116 | struct nl_msg *key_msg; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3117 | int ret; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3118 | int skip_set_key = 1; | 
|  | 3119 | const char *ifname = params->ifname; | 
|  | 3120 | enum wpa_alg alg = params->alg; | 
|  | 3121 | const u8 *addr = params->addr; | 
|  | 3122 | int key_idx = params->key_idx; | 
|  | 3123 | int set_tx = params->set_tx; | 
|  | 3124 | const u8 *seq = params->seq; | 
|  | 3125 | size_t seq_len = params->seq_len; | 
|  | 3126 | const u8 *key = params->key; | 
|  | 3127 | size_t key_len = params->key_len; | 
|  | 3128 | int vlan_id = params->vlan_id; | 
|  | 3129 | enum key_flag key_flag = params->key_flag; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3130 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3131 | /* Ignore for P2P Device */ | 
|  | 3132 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) | 
|  | 3133 | return 0; | 
|  | 3134 |  | 
|  | 3135 | ifindex = if_nametoindex(ifname); | 
|  | 3136 | 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] | 3137 | "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] | 3138 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3139 | (unsigned long) seq_len, (unsigned long) key_len, key_flag); | 
|  | 3140 |  | 
|  | 3141 | if (check_key_flag(key_flag)) { | 
|  | 3142 | wpa_printf(MSG_DEBUG, "%s: invalid key_flag", __func__); | 
|  | 3143 | return -EINVAL; | 
| Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 3144 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3145 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3146 | #ifdef CONFIG_DRIVER_NL80211_QCA | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3147 | if ((key_flag & KEY_FLAG_PMK) && | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3148 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { | 
|  | 3149 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", | 
|  | 3150 | __func__); | 
|  | 3151 | ret = issue_key_mgmt_set_key(drv, key, key_len); | 
|  | 3152 | return ret; | 
|  | 3153 | } | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3154 | #endif /* CONFIG_DRIVER_NL80211_QCA */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3155 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3156 | if (key_flag & KEY_FLAG_PMK) { | 
|  | 3157 | if (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) | 
|  | 3158 | return nl80211_set_pmk(drv, key, key_len, addr); | 
|  | 3159 | /* The driver does not have any offload mechanism for PMK, so | 
|  | 3160 | * there is no need to configure this key. */ | 
|  | 3161 | return 0; | 
|  | 3162 | } | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3163 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3164 | ret = -ENOBUFS; | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3165 | key_msg = nlmsg_alloc(); | 
|  | 3166 | if (!key_msg) | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3167 | return ret; | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3168 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3169 | if ((key_flag & KEY_FLAG_PAIRWISE_MASK) == | 
|  | 3170 | KEY_FLAG_PAIRWISE_RX_TX_MODIFY) { | 
|  | 3171 | wpa_printf(MSG_DEBUG, | 
|  | 3172 | "nl80211: SET_KEY (pairwise RX/TX modify)"); | 
|  | 3173 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); | 
|  | 3174 | if (!msg) | 
|  | 3175 | goto fail2; | 
|  | 3176 | } else if (alg == WPA_ALG_NONE && (key_flag & KEY_FLAG_RX_TX)) { | 
|  | 3177 | wpa_printf(MSG_DEBUG, "%s: invalid key_flag to delete key", | 
|  | 3178 | __func__); | 
|  | 3179 | ret = -EINVAL; | 
|  | 3180 | goto fail2; | 
|  | 3181 | } else if (alg == WPA_ALG_NONE) { | 
|  | 3182 | wpa_printf(MSG_DEBUG, "nl80211: DEL_KEY"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3183 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); | 
|  | 3184 | if (!msg) | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3185 | goto fail2; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3186 | } else { | 
| Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3187 | u32 suite; | 
|  | 3188 |  | 
|  | 3189 | suite = wpa_alg_to_cipher_suite(alg, key_len); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3190 | if (!suite) { | 
|  | 3191 | ret = -EINVAL; | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3192 | goto fail2; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3193 | } | 
|  | 3194 | wpa_printf(MSG_DEBUG, "nl80211: NEW_KEY"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3195 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3196 | if (!msg) | 
|  | 3197 | goto fail2; | 
|  | 3198 | if (nla_put(key_msg, NL80211_KEY_DATA, key_len, key) || | 
|  | 3199 | nla_put_u32(key_msg, NL80211_KEY_CIPHER, suite)) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3200 | goto fail; | 
| Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3201 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3202 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3203 | if (seq && seq_len) { | 
|  | 3204 | if (nla_put(key_msg, NL80211_KEY_SEQ, seq_len, seq)) | 
|  | 3205 | goto fail; | 
|  | 3206 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", | 
|  | 3207 | seq, seq_len); | 
|  | 3208 | } | 
| Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3209 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3210 |  | 
|  | 3211 | if (addr && !is_broadcast_ether_addr(addr)) { | 
|  | 3212 | wpa_printf(MSG_DEBUG, "   addr=" MACSTR, MAC2STR(addr)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3213 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | 
|  | 3214 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3215 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3216 | if ((key_flag & KEY_FLAG_PAIRWISE_MASK) == | 
|  | 3217 | KEY_FLAG_PAIRWISE_RX || | 
|  | 3218 | (key_flag & KEY_FLAG_PAIRWISE_MASK) == | 
|  | 3219 | KEY_FLAG_PAIRWISE_RX_TX_MODIFY) { | 
|  | 3220 | if (nla_put_u8(key_msg, NL80211_KEY_MODE, | 
|  | 3221 | key_flag == KEY_FLAG_PAIRWISE_RX ? | 
|  | 3222 | NL80211_KEY_NO_TX : NL80211_KEY_SET_TX)) | 
|  | 3223 | goto fail; | 
|  | 3224 | } else if ((key_flag & KEY_FLAG_GROUP_MASK) == | 
|  | 3225 | KEY_FLAG_GROUP_RX) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3226 | wpa_printf(MSG_DEBUG, "   RSN IBSS RX GTK"); | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3227 | if (nla_put_u32(key_msg, NL80211_KEY_TYPE, | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3228 | NL80211_KEYTYPE_GROUP)) | 
|  | 3229 | goto fail; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3230 | } else if (!(key_flag & KEY_FLAG_PAIRWISE)) { | 
|  | 3231 | wpa_printf(MSG_DEBUG, | 
|  | 3232 | "   key_flag missing PAIRWISE when setting a pairwise key"); | 
|  | 3233 | ret = -EINVAL; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3234 | goto fail; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3235 | } else if (alg == WPA_ALG_WEP && | 
|  | 3236 | (key_flag & KEY_FLAG_RX_TX) == KEY_FLAG_RX_TX) { | 
|  | 3237 | wpa_printf(MSG_DEBUG, "   unicast WEP key"); | 
|  | 3238 | skip_set_key = 0; | 
|  | 3239 | } else { | 
|  | 3240 | wpa_printf(MSG_DEBUG, "   pairwise key"); | 
|  | 3241 | } | 
|  | 3242 | } else if ((key_flag & KEY_FLAG_PAIRWISE) || | 
|  | 3243 | !(key_flag & KEY_FLAG_GROUP)) { | 
|  | 3244 | wpa_printf(MSG_DEBUG, | 
|  | 3245 | "   invalid key_flag for a broadcast key"); | 
|  | 3246 | ret = -EINVAL; | 
|  | 3247 | goto fail; | 
|  | 3248 | } else { | 
|  | 3249 | wpa_printf(MSG_DEBUG, "   broadcast key"); | 
|  | 3250 | if (key_flag & KEY_FLAG_DEFAULT) | 
|  | 3251 | skip_set_key = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3252 | } | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3253 | if (nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) || | 
|  | 3254 | nla_put_nested(msg, NL80211_ATTR_KEY, key_msg)) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3255 | goto fail; | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3256 | nl80211_nlmsg_clear(key_msg); | 
|  | 3257 | nlmsg_free(key_msg); | 
|  | 3258 | key_msg = NULL; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3259 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3260 | if (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) { | 
|  | 3261 | wpa_printf(MSG_DEBUG, "nl80211: VLAN ID %d", vlan_id); | 
|  | 3262 | if (nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) | 
|  | 3263 | goto fail; | 
|  | 3264 | } | 
|  | 3265 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3266 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3267 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) | 
|  | 3268 | ret = 0; | 
|  | 3269 | if (ret) | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3270 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s", | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3271 | ret, strerror(-ret)); | 
|  | 3272 |  | 
|  | 3273 | /* | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3274 | * 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] | 3275 | * we're done here. | 
|  | 3276 | */ | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3277 | if (ret || skip_set_key) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3278 | return ret; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3279 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_SET_KEY - default key"); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3280 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3281 | ret = -ENOBUFS; | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3282 | key_msg = nlmsg_alloc(); | 
|  | 3283 | if (!key_msg) | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3284 | return ret; | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3285 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3286 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3287 | if (!msg) | 
|  | 3288 | goto fail2; | 
|  | 3289 | if (!key_msg || | 
|  | 3290 | nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) || | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3291 | nla_put_flag(key_msg, wpa_alg_bip(alg) ? | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3292 | (key_idx == 6 || key_idx == 7 ? | 
|  | 3293 | NL80211_KEY_DEFAULT_BEACON : | 
|  | 3294 | NL80211_KEY_DEFAULT_MGMT) : | 
|  | 3295 | NL80211_KEY_DEFAULT)) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3296 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3297 | if (addr && is_broadcast_ether_addr(addr)) { | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3298 | struct nlattr *types; | 
|  | 3299 |  | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3300 | types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3301 | if (!types || | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3302 | nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3303 | goto fail; | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3304 | nla_nest_end(key_msg, types); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3305 | } else if (addr) { | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3306 | struct nlattr *types; | 
|  | 3307 |  | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3308 | types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3309 | if (!types || | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3310 | nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3311 | goto fail; | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3312 | nla_nest_end(key_msg, types); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3313 | } | 
|  | 3314 |  | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3315 | if (nla_put_nested(msg, NL80211_ATTR_KEY, key_msg)) | 
|  | 3316 | goto fail; | 
|  | 3317 | nl80211_nlmsg_clear(key_msg); | 
|  | 3318 | nlmsg_free(key_msg); | 
|  | 3319 | key_msg = NULL; | 
|  | 3320 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3321 | if (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) { | 
|  | 3322 | wpa_printf(MSG_DEBUG, "nl80211: set_key default - VLAN ID %d", | 
|  | 3323 | vlan_id); | 
|  | 3324 | if (nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) | 
|  | 3325 | goto fail; | 
|  | 3326 | } | 
|  | 3327 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3328 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3329 | if (ret) | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3330 | wpa_printf(MSG_DEBUG, | 
|  | 3331 | "nl80211: set_key default failed; err=%d %s", | 
|  | 3332 | ret, strerror(-ret)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3333 | return ret; | 
|  | 3334 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3335 | fail: | 
|  | 3336 | nl80211_nlmsg_clear(msg); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3337 | nlmsg_free(msg); | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3338 | fail2: | 
|  | 3339 | nl80211_nlmsg_clear(key_msg); | 
|  | 3340 | nlmsg_free(key_msg); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3341 | return ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3342 | } | 
|  | 3343 |  | 
|  | 3344 |  | 
|  | 3345 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, | 
|  | 3346 | int key_idx, int defkey, | 
|  | 3347 | const u8 *seq, size_t seq_len, | 
|  | 3348 | const u8 *key, size_t key_len) | 
|  | 3349 | { | 
|  | 3350 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); | 
| Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3351 | u32 suite; | 
|  | 3352 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3353 | if (!key_attr) | 
|  | 3354 | return -1; | 
|  | 3355 |  | 
| Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3356 | suite = wpa_alg_to_cipher_suite(alg, key_len); | 
|  | 3357 | if (!suite) | 
|  | 3358 | return -1; | 
|  | 3359 |  | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 3360 | if (defkey && wpa_alg_bip(alg)) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3361 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) | 
|  | 3362 | return -1; | 
|  | 3363 | } else if (defkey) { | 
|  | 3364 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) | 
|  | 3365 | return -1; | 
|  | 3366 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3367 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3368 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || | 
| Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3369 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3370 | (seq && seq_len && | 
|  | 3371 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || | 
|  | 3372 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) | 
|  | 3373 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3374 |  | 
|  | 3375 | nla_nest_end(msg, key_attr); | 
|  | 3376 |  | 
|  | 3377 | return 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3378 | } | 
|  | 3379 |  | 
|  | 3380 |  | 
|  | 3381 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, | 
|  | 3382 | struct nl_msg *msg) | 
|  | 3383 | { | 
|  | 3384 | int i, privacy = 0; | 
|  | 3385 | struct nlattr *nl_keys, *nl_key; | 
|  | 3386 |  | 
|  | 3387 | for (i = 0; i < 4; i++) { | 
|  | 3388 | if (!params->wep_key[i]) | 
|  | 3389 | continue; | 
|  | 3390 | privacy = 1; | 
|  | 3391 | break; | 
|  | 3392 | } | 
|  | 3393 | if (params->wps == WPS_MODE_PRIVACY) | 
|  | 3394 | privacy = 1; | 
|  | 3395 | if (params->pairwise_suite && | 
|  | 3396 | params->pairwise_suite != WPA_CIPHER_NONE) | 
|  | 3397 | privacy = 1; | 
|  | 3398 |  | 
|  | 3399 | if (!privacy) | 
|  | 3400 | return 0; | 
|  | 3401 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3402 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) | 
|  | 3403 | return -ENOBUFS; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3404 |  | 
|  | 3405 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); | 
|  | 3406 | if (!nl_keys) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3407 | return -ENOBUFS; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3408 |  | 
|  | 3409 | for (i = 0; i < 4; i++) { | 
|  | 3410 | if (!params->wep_key[i]) | 
|  | 3411 | continue; | 
|  | 3412 |  | 
|  | 3413 | nl_key = nla_nest_start(msg, i); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3414 | if (!nl_key || | 
|  | 3415 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], | 
|  | 3416 | params->wep_key[i]) || | 
|  | 3417 | nla_put_u32(msg, NL80211_KEY_CIPHER, | 
|  | 3418 | params->wep_key_len[i] == 5 ? | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3419 | RSN_CIPHER_SUITE_WEP40 : | 
|  | 3420 | RSN_CIPHER_SUITE_WEP104) || | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3421 | nla_put_u8(msg, NL80211_KEY_IDX, i) || | 
|  | 3422 | (i == params->wep_tx_keyidx && | 
|  | 3423 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) | 
|  | 3424 | return -ENOBUFS; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3425 |  | 
|  | 3426 | nla_nest_end(msg, nl_key); | 
|  | 3427 | } | 
|  | 3428 | nla_nest_end(msg, nl_keys); | 
|  | 3429 |  | 
|  | 3430 | return 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3431 | } | 
|  | 3432 |  | 
|  | 3433 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3434 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, | 
|  | 3435 | const u8 *addr, int cmd, u16 reason_code, | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3436 | int local_state_change, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3437 | struct nl_sock *nl_connect) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3438 | { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3439 | int ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3440 | struct nl_msg *msg; | 
|  | 3441 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3442 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || | 
|  | 3443 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || | 
|  | 3444 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | 
|  | 3445 | (local_state_change && | 
|  | 3446 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { | 
|  | 3447 | nlmsg_free(msg); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3448 | return -1; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3449 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3450 |  | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3451 | if (nl_connect) | 
|  | 3452 | ret = send_and_recv(drv->global, nl_connect, msg, NULL, NULL); | 
|  | 3453 | else | 
|  | 3454 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3455 | if (ret) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3456 | wpa_dbg(drv->ctx, MSG_DEBUG, | 
|  | 3457 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", | 
|  | 3458 | reason_code, ret, strerror(-ret)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3459 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3460 | return ret; | 
|  | 3461 | } | 
|  | 3462 |  | 
|  | 3463 |  | 
|  | 3464 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3465 | u16 reason_code, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3466 | struct nl_sock *nl_connect) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3467 | { | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3468 | int ret; | 
| Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3469 | int drv_associated = drv->associated; | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3470 |  | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3471 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3472 | nl80211_mark_disconnected(drv); | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3473 | /* Disconnect command doesn't need BSSID - it uses cached value */ | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3474 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3475 | reason_code, 0, nl_connect); | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3476 | /* | 
|  | 3477 | * For locally generated disconnect, supplicant already generates a | 
|  | 3478 | * DEAUTH event, so ignore the event from NL80211. | 
|  | 3479 | */ | 
| Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3480 | drv->ignore_next_local_disconnect = drv_associated && (ret == 0); | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3481 |  | 
|  | 3482 | return ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3483 | } | 
|  | 3484 |  | 
|  | 3485 |  | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3486 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3487 | const u8 *addr, u16 reason_code) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3488 | { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3489 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
| Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3490 | int ret; | 
| Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3491 | int drv_associated = drv->associated; | 
| Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3492 |  | 
|  | 3493 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { | 
|  | 3494 | nl80211_mark_disconnected(drv); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3495 | return nl80211_leave_ibss(drv, 1); | 
| Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3496 | } | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3497 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3498 | return wpa_driver_nl80211_disconnect(drv, reason_code, | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 3499 | get_connect_handle(bss)); | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3500 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3501 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", | 
|  | 3502 | __func__, MAC2STR(addr), reason_code); | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3503 | nl80211_mark_disconnected(drv); | 
| Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3504 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 3505 | reason_code, 0, get_connect_handle(bss)); | 
| Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3506 | /* | 
|  | 3507 | * For locally generated deauthenticate, supplicant already generates a | 
|  | 3508 | * DEAUTH event, so ignore the event from NL80211. | 
|  | 3509 | */ | 
| Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3510 | drv->ignore_next_local_deauth = drv_associated && (ret == 0); | 
|  | 3511 |  | 
| Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3512 | return ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3513 | } | 
|  | 3514 |  | 
|  | 3515 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3516 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, | 
|  | 3517 | struct wpa_driver_auth_params *params) | 
|  | 3518 | { | 
|  | 3519 | int i; | 
|  | 3520 |  | 
|  | 3521 | drv->auth_freq = params->freq; | 
|  | 3522 | drv->auth_alg = params->auth_alg; | 
|  | 3523 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; | 
|  | 3524 | drv->auth_local_state_change = params->local_state_change; | 
|  | 3525 | drv->auth_p2p = params->p2p; | 
|  | 3526 |  | 
|  | 3527 | if (params->bssid) | 
|  | 3528 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); | 
|  | 3529 | else | 
|  | 3530 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); | 
|  | 3531 |  | 
|  | 3532 | if (params->ssid) { | 
|  | 3533 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); | 
|  | 3534 | drv->auth_ssid_len = params->ssid_len; | 
|  | 3535 | } else | 
|  | 3536 | drv->auth_ssid_len = 0; | 
|  | 3537 |  | 
|  | 3538 |  | 
|  | 3539 | os_free(drv->auth_ie); | 
|  | 3540 | drv->auth_ie = NULL; | 
|  | 3541 | drv->auth_ie_len = 0; | 
|  | 3542 | if (params->ie) { | 
|  | 3543 | drv->auth_ie = os_malloc(params->ie_len); | 
|  | 3544 | if (drv->auth_ie) { | 
|  | 3545 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); | 
|  | 3546 | drv->auth_ie_len = params->ie_len; | 
|  | 3547 | } | 
|  | 3548 | } | 
|  | 3549 |  | 
|  | 3550 | for (i = 0; i < 4; i++) { | 
|  | 3551 | if (params->wep_key[i] && params->wep_key_len[i] && | 
|  | 3552 | params->wep_key_len[i] <= 16) { | 
|  | 3553 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], | 
|  | 3554 | params->wep_key_len[i]); | 
|  | 3555 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; | 
|  | 3556 | } else | 
|  | 3557 | drv->auth_wep_key_len[i] = 0; | 
|  | 3558 | } | 
|  | 3559 | } | 
|  | 3560 |  | 
|  | 3561 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3562 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) | 
|  | 3563 | { | 
|  | 3564 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 3565 |  | 
|  | 3566 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) | 
|  | 3567 | return; | 
|  | 3568 |  | 
|  | 3569 | /* | 
|  | 3570 | * Looks like we failed to unmask 11b rates previously. This could | 
|  | 3571 | * happen, e.g., if the interface was down at the point in time when a | 
|  | 3572 | * P2P group was terminated. | 
|  | 3573 | */ | 
|  | 3574 | wpa_printf(MSG_DEBUG, | 
|  | 3575 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", | 
|  | 3576 | bss->ifname); | 
|  | 3577 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); | 
|  | 3578 | } | 
|  | 3579 |  | 
|  | 3580 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3581 | static enum nl80211_auth_type get_nl_auth_type(int wpa_auth_alg) | 
|  | 3582 | { | 
|  | 3583 | if (wpa_auth_alg & WPA_AUTH_ALG_OPEN) | 
|  | 3584 | return NL80211_AUTHTYPE_OPEN_SYSTEM; | 
|  | 3585 | if (wpa_auth_alg & WPA_AUTH_ALG_SHARED) | 
|  | 3586 | return NL80211_AUTHTYPE_SHARED_KEY; | 
|  | 3587 | if (wpa_auth_alg & WPA_AUTH_ALG_LEAP) | 
|  | 3588 | return NL80211_AUTHTYPE_NETWORK_EAP; | 
|  | 3589 | if (wpa_auth_alg & WPA_AUTH_ALG_FT) | 
|  | 3590 | return NL80211_AUTHTYPE_FT; | 
|  | 3591 | if (wpa_auth_alg & WPA_AUTH_ALG_SAE) | 
|  | 3592 | return NL80211_AUTHTYPE_SAE; | 
|  | 3593 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS) | 
|  | 3594 | return NL80211_AUTHTYPE_FILS_SK; | 
|  | 3595 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS_SK_PFS) | 
|  | 3596 | return NL80211_AUTHTYPE_FILS_SK_PFS; | 
|  | 3597 |  | 
|  | 3598 | return NL80211_AUTHTYPE_MAX; | 
|  | 3599 | } | 
|  | 3600 |  | 
|  | 3601 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3602 | static int wpa_driver_nl80211_authenticate( | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3603 | struct i802_bss *bss, struct wpa_driver_auth_params *params) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3604 | { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3605 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 3606 | int ret = -1, i; | 
|  | 3607 | struct nl_msg *msg; | 
|  | 3608 | enum nl80211_auth_type type; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3609 | enum nl80211_iftype nlmode; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3610 | int count = 0; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3611 | int is_retry; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3612 | struct wpa_driver_set_key_params p; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3613 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3614 | nl80211_unmask_11b_rates(bss); | 
|  | 3615 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3616 | is_retry = drv->retry_auth; | 
|  | 3617 | drv->retry_auth = 0; | 
| Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3618 | drv->ignore_deauth_event = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3619 |  | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3620 | nl80211_mark_disconnected(drv); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3621 | os_memset(drv->auth_bssid, 0, ETH_ALEN); | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3622 | if (params->bssid) | 
|  | 3623 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); | 
|  | 3624 | else | 
|  | 3625 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3626 | /* FIX: IBSS mode */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3627 | nlmode = params->p2p ? | 
|  | 3628 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | 
|  | 3629 | if (drv->nlmode != nlmode && | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3630 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3631 | return -1; | 
|  | 3632 |  | 
|  | 3633 | retry: | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3634 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", | 
|  | 3635 | drv->ifindex); | 
|  | 3636 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3637 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); | 
|  | 3638 | if (!msg) | 
|  | 3639 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3640 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3641 | os_memset(&p, 0, sizeof(p)); | 
|  | 3642 | p.ifname = bss->ifname; | 
|  | 3643 | p.alg = WPA_ALG_WEP; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3644 | for (i = 0; i < 4; i++) { | 
|  | 3645 | if (!params->wep_key[i]) | 
|  | 3646 | continue; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3647 | p.key_idx = i; | 
|  | 3648 | p.set_tx = i == params->wep_tx_keyidx; | 
|  | 3649 | p.key = params->wep_key[i]; | 
|  | 3650 | p.key_len = params->wep_key_len[i]; | 
|  | 3651 | p.key_flag = i == params->wep_tx_keyidx ? | 
|  | 3652 | KEY_FLAG_GROUP_RX_TX_DEFAULT : | 
|  | 3653 | KEY_FLAG_GROUP_RX_TX; | 
|  | 3654 | wpa_driver_nl80211_set_key(bss, &p); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3655 | if (params->wep_tx_keyidx != i) | 
|  | 3656 | continue; | 
|  | 3657 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3658 | params->wep_key[i], params->wep_key_len[i])) | 
|  | 3659 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3660 | } | 
|  | 3661 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3662 | if (params->bssid) { | 
|  | 3663 | wpa_printf(MSG_DEBUG, "  * bssid=" MACSTR, | 
|  | 3664 | MAC2STR(params->bssid)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3665 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) | 
|  | 3666 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3667 | } | 
|  | 3668 | if (params->freq) { | 
|  | 3669 | wpa_printf(MSG_DEBUG, "  * freq=%d", params->freq); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3670 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) | 
|  | 3671 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3672 | } | 
|  | 3673 | if (params->ssid) { | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3674 | wpa_printf(MSG_DEBUG, "  * SSID=%s", | 
|  | 3675 | wpa_ssid_txt(params->ssid, params->ssid_len)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3676 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, | 
|  | 3677 | params->ssid)) | 
|  | 3678 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3679 | } | 
|  | 3680 | wpa_hexdump(MSG_DEBUG, "  * IEs", params->ie, params->ie_len); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3681 | if (params->ie && | 
|  | 3682 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) | 
|  | 3683 | goto fail; | 
| Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3684 | if (params->auth_data) { | 
|  | 3685 | wpa_hexdump(MSG_DEBUG, "  * auth_data", params->auth_data, | 
|  | 3686 | params->auth_data_len); | 
|  | 3687 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len, | 
|  | 3688 | params->auth_data)) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3689 | goto fail; | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3690 | } | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3691 | type = get_nl_auth_type(params->auth_alg); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3692 | wpa_printf(MSG_DEBUG, "  * Auth Type %d", type); | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3693 | if (type == NL80211_AUTHTYPE_MAX || | 
|  | 3694 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3695 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3696 | if (params->local_state_change) { | 
|  | 3697 | wpa_printf(MSG_DEBUG, "  * Local state change only"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3698 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) | 
|  | 3699 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3700 | } | 
|  | 3701 |  | 
|  | 3702 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 3703 | msg = NULL; | 
|  | 3704 | if (ret) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3705 | wpa_dbg(drv->ctx, MSG_DEBUG, | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3706 | "nl80211: MLME command failed (auth): count=%d ret=%d (%s)", | 
|  | 3707 | count, ret, strerror(-ret)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3708 | count++; | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3709 | if ((ret == -EALREADY || ret == -EEXIST) && count == 1 && | 
|  | 3710 | params->bssid && !params->local_state_change) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3711 | /* | 
|  | 3712 | * mac80211 does not currently accept new | 
|  | 3713 | * authentication if we are already authenticated. As a | 
|  | 3714 | * workaround, force deauthentication and try again. | 
|  | 3715 | */ | 
|  | 3716 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " | 
|  | 3717 | "after forced deauthentication"); | 
| Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3718 | drv->ignore_deauth_event = 1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3719 | wpa_driver_nl80211_deauthenticate( | 
|  | 3720 | bss, params->bssid, | 
|  | 3721 | WLAN_REASON_PREV_AUTH_NOT_VALID); | 
|  | 3722 | nlmsg_free(msg); | 
|  | 3723 | goto retry; | 
|  | 3724 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3725 |  | 
|  | 3726 | if (ret == -ENOENT && params->freq && !is_retry) { | 
|  | 3727 | /* | 
|  | 3728 | * cfg80211 has likely expired the BSS entry even | 
|  | 3729 | * though it was previously available in our internal | 
|  | 3730 | * BSS table. To recover quickly, start a single | 
|  | 3731 | * channel scan on the specified channel. | 
|  | 3732 | */ | 
|  | 3733 | struct wpa_driver_scan_params scan; | 
|  | 3734 | int freqs[2]; | 
|  | 3735 |  | 
|  | 3736 | os_memset(&scan, 0, sizeof(scan)); | 
|  | 3737 | scan.num_ssids = 1; | 
|  | 3738 | if (params->ssid) { | 
|  | 3739 | scan.ssids[0].ssid = params->ssid; | 
|  | 3740 | scan.ssids[0].ssid_len = params->ssid_len; | 
|  | 3741 | } | 
|  | 3742 | freqs[0] = params->freq; | 
|  | 3743 | freqs[1] = 0; | 
|  | 3744 | scan.freqs = freqs; | 
|  | 3745 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " | 
|  | 3746 | "channel scan to refresh cfg80211 BSS " | 
|  | 3747 | "entry"); | 
|  | 3748 | ret = wpa_driver_nl80211_scan(bss, &scan); | 
|  | 3749 | if (ret == 0) { | 
|  | 3750 | nl80211_copy_auth_params(drv, params); | 
|  | 3751 | drv->scan_for_auth = 1; | 
|  | 3752 | } | 
|  | 3753 | } else if (is_retry) { | 
|  | 3754 | /* | 
|  | 3755 | * Need to indicate this with an event since the return | 
|  | 3756 | * value from the retry is not delivered to core code. | 
|  | 3757 | */ | 
|  | 3758 | union wpa_event_data event; | 
|  | 3759 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " | 
|  | 3760 | "failed"); | 
|  | 3761 | os_memset(&event, 0, sizeof(event)); | 
|  | 3762 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, | 
|  | 3763 | ETH_ALEN); | 
|  | 3764 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, | 
|  | 3765 | &event); | 
|  | 3766 | } | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3767 | } else { | 
|  | 3768 | wpa_printf(MSG_DEBUG, | 
|  | 3769 | "nl80211: Authentication request send successfully"); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3770 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3771 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3772 | fail: | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3773 | nlmsg_free(msg); | 
|  | 3774 | return ret; | 
|  | 3775 | } | 
|  | 3776 |  | 
|  | 3777 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3778 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3779 | { | 
|  | 3780 | struct wpa_driver_auth_params params; | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3781 | struct i802_bss *bss = drv->first_bss; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3782 | int i; | 
|  | 3783 |  | 
|  | 3784 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); | 
|  | 3785 |  | 
|  | 3786 | os_memset(¶ms, 0, sizeof(params)); | 
|  | 3787 | params.freq = drv->auth_freq; | 
|  | 3788 | params.auth_alg = drv->auth_alg; | 
|  | 3789 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; | 
|  | 3790 | params.local_state_change = drv->auth_local_state_change; | 
|  | 3791 | params.p2p = drv->auth_p2p; | 
|  | 3792 |  | 
|  | 3793 | if (!is_zero_ether_addr(drv->auth_bssid_)) | 
|  | 3794 | params.bssid = drv->auth_bssid_; | 
|  | 3795 |  | 
|  | 3796 | if (drv->auth_ssid_len) { | 
|  | 3797 | params.ssid = drv->auth_ssid; | 
|  | 3798 | params.ssid_len = drv->auth_ssid_len; | 
|  | 3799 | } | 
|  | 3800 |  | 
|  | 3801 | params.ie = drv->auth_ie; | 
|  | 3802 | params.ie_len = drv->auth_ie_len; | 
|  | 3803 |  | 
|  | 3804 | for (i = 0; i < 4; i++) { | 
|  | 3805 | if (drv->auth_wep_key_len[i]) { | 
|  | 3806 | params.wep_key[i] = drv->auth_wep_key[i]; | 
|  | 3807 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; | 
|  | 3808 | } | 
|  | 3809 | } | 
|  | 3810 |  | 
|  | 3811 | drv->retry_auth = 1; | 
|  | 3812 | return wpa_driver_nl80211_authenticate(bss, ¶ms); | 
|  | 3813 | } | 
|  | 3814 |  | 
|  | 3815 |  | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3816 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, | 
|  | 3817 | size_t data_len, int noack, | 
|  | 3818 | unsigned int freq, int no_cck, | 
|  | 3819 | int offchanok, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3820 | unsigned int wait_time, | 
|  | 3821 | const u16 *csa_offs, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3822 | size_t csa_offs_len, int no_encrypt) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3823 | { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3824 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 3825 | struct ieee80211_mgmt *mgmt; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3826 | int encrypt = !no_encrypt; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3827 | u16 fc; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3828 | int use_cookie = 1; | 
|  | 3829 | int res; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3830 |  | 
|  | 3831 | mgmt = (struct ieee80211_mgmt *) data; | 
|  | 3832 | fc = le_to_host16(mgmt->frame_control); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3833 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da=" MACSTR | 
|  | 3834 | " 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] | 3835 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3836 | no_encrypt, fc, fc2str(fc), drv->nlmode); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3837 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3838 | if ((is_sta_interface(drv->nlmode) || | 
|  | 3839 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3840 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | 
|  | 3841 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { | 
|  | 3842 | /* | 
|  | 3843 | * The use of last_mgmt_freq is a bit of a hack, | 
|  | 3844 | * but it works due to the single-threaded nature | 
|  | 3845 | * of wpa_supplicant. | 
|  | 3846 | */ | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3847 | if (freq == 0) { | 
|  | 3848 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", | 
|  | 3849 | drv->last_mgmt_freq); | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3850 | freq = drv->last_mgmt_freq; | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3851 | } | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3852 | wait_time = 0; | 
|  | 3853 | use_cookie = 0; | 
|  | 3854 | no_cck = 1; | 
|  | 3855 | offchanok = 1; | 
|  | 3856 | goto send_frame_cmd; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3857 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3858 |  | 
|  | 3859 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3860 | if (freq == 0) { | 
|  | 3861 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", | 
|  | 3862 | bss->freq); | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3863 | freq = bss->freq; | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3864 | } | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3865 | if ((int) freq == bss->freq) | 
|  | 3866 | wait_time = 0; | 
|  | 3867 | goto send_frame_cmd; | 
| Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 3868 | } | 
| Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 3869 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3870 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | 
|  | 3871 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { | 
|  | 3872 | /* | 
|  | 3873 | * Only one of the authentication frame types is encrypted. | 
|  | 3874 | * In order for static WEP encryption to work properly (i.e., | 
|  | 3875 | * to not encrypt the frame), we need to tell mac80211 about | 
|  | 3876 | * the frames that must not be encrypted. | 
|  | 3877 | */ | 
|  | 3878 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); | 
|  | 3879 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); | 
|  | 3880 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) | 
|  | 3881 | encrypt = 0; | 
|  | 3882 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3883 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 3884 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_STATION && | 
|  | 3885 | (drv->capa.flags & WPA_DRIVER_FLAGS_SAE) && | 
|  | 3886 | !(drv->capa.flags & WPA_DRIVER_FLAGS_SME) && | 
|  | 3887 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && | 
|  | 3888 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { | 
|  | 3889 | freq = nl80211_get_assoc_freq(drv); | 
|  | 3890 | wpa_printf(MSG_DEBUG, | 
|  | 3891 | "nl80211: send_mlme - Use assoc_freq=%u for external auth", | 
|  | 3892 | freq); | 
|  | 3893 | } | 
|  | 3894 |  | 
|  | 3895 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { | 
|  | 3896 | freq = nl80211_get_assoc_freq(drv); | 
|  | 3897 | wpa_printf(MSG_DEBUG, | 
|  | 3898 | "nl80211: send_mlme - Use assoc_freq=%u for IBSS", | 
|  | 3899 | freq); | 
|  | 3900 | } | 
|  | 3901 | if (freq == 0) { | 
|  | 3902 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - Use bss->freq=%u", | 
|  | 3903 | bss->freq); | 
|  | 3904 | freq = bss->freq; | 
|  | 3905 | } | 
|  | 3906 |  | 
|  | 3907 | if (drv->use_monitor) { | 
|  | 3908 | wpa_printf(MSG_DEBUG, | 
|  | 3909 | "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor", | 
|  | 3910 | freq, bss->freq); | 
|  | 3911 | return nl80211_send_monitor(drv, data, data_len, encrypt, | 
|  | 3912 | noack); | 
|  | 3913 | } | 
|  | 3914 |  | 
|  | 3915 | if (noack || WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT || | 
|  | 3916 | WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION) | 
|  | 3917 | use_cookie = 0; | 
|  | 3918 | send_frame_cmd: | 
|  | 3919 | #ifdef CONFIG_TESTING_OPTIONS | 
|  | 3920 | if (no_encrypt && !encrypt && !drv->use_monitor) { | 
|  | 3921 | wpa_printf(MSG_DEBUG, | 
|  | 3922 | "nl80211: Request to send an unencrypted frame - use a monitor interface for this"); | 
|  | 3923 | if (nl80211_create_monitor_interface(drv) < 0) | 
|  | 3924 | return -1; | 
|  | 3925 | res = nl80211_send_monitor(drv, data, data_len, encrypt, | 
|  | 3926 | noack); | 
|  | 3927 | nl80211_remove_monitor_interface(drv); | 
|  | 3928 | return res; | 
|  | 3929 | } | 
|  | 3930 | #endif /* CONFIG_TESTING_OPTIONS */ | 
|  | 3931 |  | 
|  | 3932 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame_cmd"); | 
|  | 3933 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, data_len, | 
|  | 3934 | use_cookie, no_cck, noack, offchanok, | 
|  | 3935 | csa_offs, csa_offs_len); | 
|  | 3936 |  | 
|  | 3937 | return res; | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3938 | } | 
|  | 3939 |  | 
|  | 3940 |  | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3941 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) | 
|  | 3942 | { | 
|  | 3943 | u8 rates[NL80211_MAX_SUPP_RATES]; | 
|  | 3944 | u8 rates_len = 0; | 
|  | 3945 | int i; | 
|  | 3946 |  | 
|  | 3947 | if (!basic_rates) | 
|  | 3948 | return 0; | 
|  | 3949 |  | 
|  | 3950 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) | 
|  | 3951 | rates[rates_len++] = basic_rates[i] / 5; | 
|  | 3952 |  | 
|  | 3953 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); | 
|  | 3954 | } | 
|  | 3955 |  | 
|  | 3956 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3957 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, | 
|  | 3958 | int slot, int ht_opmode, int ap_isolate, | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3959 | const int *basic_rates) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3960 | { | 
|  | 3961 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 3962 | struct nl_msg *msg; | 
|  | 3963 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3964 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || | 
|  | 3965 | (cts >= 0 && | 
|  | 3966 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || | 
|  | 3967 | (preamble >= 0 && | 
|  | 3968 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || | 
|  | 3969 | (slot >= 0 && | 
|  | 3970 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || | 
|  | 3971 | (ht_opmode >= 0 && | 
|  | 3972 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || | 
|  | 3973 | (ap_isolate >= 0 && | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3974 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || | 
|  | 3975 | nl80211_put_basic_rates(msg, basic_rates)) { | 
|  | 3976 | nlmsg_free(msg); | 
|  | 3977 | return -ENOBUFS; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3978 | } | 
|  | 3979 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3980 | return send_and_recv_msgs(drv, msg, NULL, NULL); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3981 | } | 
|  | 3982 |  | 
|  | 3983 |  | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3984 | static int wpa_driver_nl80211_set_acl(void *priv, | 
|  | 3985 | struct hostapd_acl_params *params) | 
|  | 3986 | { | 
|  | 3987 | struct i802_bss *bss = priv; | 
|  | 3988 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 3989 | struct nl_msg *msg; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3990 | struct nl_msg *acl; | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3991 | unsigned int i; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3992 | int ret; | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3993 |  | 
|  | 3994 | if (!(drv->capa.max_acl_mac_addrs)) | 
|  | 3995 | return -ENOTSUP; | 
|  | 3996 |  | 
|  | 3997 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) | 
|  | 3998 | return -ENOTSUP; | 
|  | 3999 |  | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4000 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", | 
|  | 4001 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); | 
|  | 4002 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4003 | acl = nlmsg_alloc(); | 
|  | 4004 | if (!acl) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4005 | return -ENOMEM; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4006 | for (i = 0; i < params->num_mac_acl; i++) { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4007 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { | 
|  | 4008 | nlmsg_free(acl); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4009 | return -ENOMEM; | 
|  | 4010 | } | 
|  | 4011 | } | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4012 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4013 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || | 
|  | 4014 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? | 
|  | 4015 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : | 
|  | 4016 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || | 
|  | 4017 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { | 
|  | 4018 | nlmsg_free(msg); | 
|  | 4019 | nlmsg_free(acl); | 
|  | 4020 | return -ENOMEM; | 
|  | 4021 | } | 
|  | 4022 | nlmsg_free(acl); | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4023 |  | 
|  | 4024 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4025 | if (ret) { | 
|  | 4026 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", | 
|  | 4027 | ret, strerror(-ret)); | 
|  | 4028 | } | 
|  | 4029 |  | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4030 | return ret; | 
|  | 4031 | } | 
|  | 4032 |  | 
|  | 4033 |  | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4034 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) | 
|  | 4035 | { | 
|  | 4036 | if (beacon_int > 0) { | 
|  | 4037 | wpa_printf(MSG_DEBUG, "  * beacon_int=%d", beacon_int); | 
|  | 4038 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, | 
|  | 4039 | beacon_int); | 
|  | 4040 | } | 
|  | 4041 |  | 
|  | 4042 | return 0; | 
|  | 4043 | } | 
|  | 4044 |  | 
|  | 4045 |  | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4046 | static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period) | 
|  | 4047 | { | 
|  | 4048 | if (dtim_period > 0) { | 
|  | 4049 | wpa_printf(MSG_DEBUG, "  * dtim_period=%d", dtim_period); | 
|  | 4050 | return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); | 
|  | 4051 | } | 
|  | 4052 |  | 
|  | 4053 | return 0; | 
|  | 4054 | } | 
|  | 4055 |  | 
|  | 4056 |  | 
| Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4057 | #ifdef CONFIG_MESH | 
|  | 4058 | static int nl80211_set_mesh_config(void *priv, | 
|  | 4059 | struct wpa_driver_mesh_bss_params *params) | 
|  | 4060 | { | 
|  | 4061 | struct i802_bss *bss = priv; | 
|  | 4062 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 4063 | struct nl_msg *msg; | 
|  | 4064 | int ret; | 
|  | 4065 |  | 
|  | 4066 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG); | 
|  | 4067 | if (!msg) | 
|  | 4068 | return -1; | 
|  | 4069 |  | 
|  | 4070 | ret = nl80211_put_mesh_config(msg, params); | 
|  | 4071 | if (ret < 0) { | 
|  | 4072 | nlmsg_free(msg); | 
|  | 4073 | return ret; | 
|  | 4074 | } | 
|  | 4075 |  | 
|  | 4076 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 4077 | if (ret) { | 
|  | 4078 | wpa_printf(MSG_ERROR, | 
|  | 4079 | "nl80211: Mesh config set failed: %d (%s)", | 
|  | 4080 | ret, strerror(-ret)); | 
|  | 4081 | return ret; | 
|  | 4082 | } | 
|  | 4083 | return 0; | 
|  | 4084 | } | 
|  | 4085 | #endif /* CONFIG_MESH */ | 
|  | 4086 |  | 
|  | 4087 |  | 
| Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4088 | static int nl80211_put_beacon_rate(struct nl_msg *msg, const u64 flags, | 
|  | 4089 | struct wpa_driver_ap_params *params) | 
|  | 4090 | { | 
|  | 4091 | struct nlattr *bands, *band; | 
|  | 4092 | struct nl80211_txrate_vht vht_rate; | 
|  | 4093 |  | 
|  | 4094 | if (!params->freq || | 
|  | 4095 | (params->beacon_rate == 0 && | 
|  | 4096 | params->rate_type == BEACON_RATE_LEGACY)) | 
|  | 4097 | return 0; | 
|  | 4098 |  | 
|  | 4099 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); | 
|  | 4100 | if (!bands) | 
|  | 4101 | return -1; | 
|  | 4102 |  | 
|  | 4103 | switch (params->freq->mode) { | 
|  | 4104 | case HOSTAPD_MODE_IEEE80211B: | 
|  | 4105 | case HOSTAPD_MODE_IEEE80211G: | 
|  | 4106 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); | 
|  | 4107 | break; | 
|  | 4108 | case HOSTAPD_MODE_IEEE80211A: | 
|  | 4109 | band = nla_nest_start(msg, NL80211_BAND_5GHZ); | 
|  | 4110 | break; | 
|  | 4111 | case HOSTAPD_MODE_IEEE80211AD: | 
|  | 4112 | band = nla_nest_start(msg, NL80211_BAND_60GHZ); | 
|  | 4113 | break; | 
|  | 4114 | default: | 
|  | 4115 | return 0; | 
|  | 4116 | } | 
|  | 4117 |  | 
|  | 4118 | if (!band) | 
|  | 4119 | return -1; | 
|  | 4120 |  | 
|  | 4121 | os_memset(&vht_rate, 0, sizeof(vht_rate)); | 
|  | 4122 |  | 
|  | 4123 | switch (params->rate_type) { | 
|  | 4124 | case BEACON_RATE_LEGACY: | 
|  | 4125 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) { | 
|  | 4126 | wpa_printf(MSG_INFO, | 
|  | 4127 | "nl80211: Driver does not support setting Beacon frame rate (legacy)"); | 
|  | 4128 | return -1; | 
|  | 4129 | } | 
|  | 4130 |  | 
|  | 4131 | if (nla_put_u8(msg, NL80211_TXRATE_LEGACY, | 
|  | 4132 | (u8) params->beacon_rate / 5) || | 
|  | 4133 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || | 
|  | 4134 | (params->freq->vht_enabled && | 
|  | 4135 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | 
|  | 4136 | &vht_rate))) | 
|  | 4137 | return -1; | 
|  | 4138 |  | 
|  | 4139 | wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)", | 
|  | 4140 | params->beacon_rate); | 
|  | 4141 | break; | 
|  | 4142 | case BEACON_RATE_HT: | 
|  | 4143 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) { | 
|  | 4144 | wpa_printf(MSG_INFO, | 
|  | 4145 | "nl80211: Driver does not support setting Beacon frame rate (HT)"); | 
|  | 4146 | return -1; | 
|  | 4147 | } | 
|  | 4148 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || | 
|  | 4149 | nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) || | 
|  | 4150 | (params->freq->vht_enabled && | 
|  | 4151 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | 
|  | 4152 | &vht_rate))) | 
|  | 4153 | return -1; | 
|  | 4154 | wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u", | 
|  | 4155 | params->beacon_rate); | 
|  | 4156 | break; | 
|  | 4157 | case BEACON_RATE_VHT: | 
|  | 4158 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) { | 
|  | 4159 | wpa_printf(MSG_INFO, | 
|  | 4160 | "nl80211: Driver does not support setting Beacon frame rate (VHT)"); | 
|  | 4161 | return -1; | 
|  | 4162 | } | 
|  | 4163 | vht_rate.mcs[0] = BIT(params->beacon_rate); | 
|  | 4164 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL)) | 
|  | 4165 | return -1; | 
|  | 4166 | if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL)) | 
|  | 4167 | return -1; | 
|  | 4168 | if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), | 
|  | 4169 | &vht_rate)) | 
|  | 4170 | return -1; | 
|  | 4171 | wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u", | 
|  | 4172 | params->beacon_rate); | 
|  | 4173 | break; | 
|  | 4174 | } | 
|  | 4175 |  | 
|  | 4176 | nla_nest_end(msg, band); | 
|  | 4177 | nla_nest_end(msg, bands); | 
|  | 4178 |  | 
|  | 4179 | return 0; | 
|  | 4180 | } | 
|  | 4181 |  | 
|  | 4182 |  | 
|  | 4183 | static int nl80211_set_multicast_to_unicast(struct i802_bss *bss, | 
|  | 4184 | int multicast_to_unicast) | 
|  | 4185 | { | 
|  | 4186 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 4187 | struct nl_msg *msg; | 
|  | 4188 | int ret; | 
|  | 4189 |  | 
|  | 4190 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST); | 
|  | 4191 | if (!msg || | 
|  | 4192 | (multicast_to_unicast && | 
|  | 4193 | nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) { | 
|  | 4194 | wpa_printf(MSG_ERROR, | 
|  | 4195 | "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s", | 
|  | 4196 | bss->ifname); | 
|  | 4197 | nlmsg_free(msg); | 
|  | 4198 | return -ENOBUFS; | 
|  | 4199 | } | 
|  | 4200 |  | 
|  | 4201 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 4202 |  | 
|  | 4203 | switch (ret) { | 
|  | 4204 | case 0: | 
|  | 4205 | wpa_printf(MSG_DEBUG, | 
|  | 4206 | "nl80211: multicast to unicast %s on interface %s", | 
|  | 4207 | multicast_to_unicast ? "enabled" : "disabled", | 
|  | 4208 | bss->ifname); | 
|  | 4209 | break; | 
|  | 4210 | case -EOPNOTSUPP: | 
|  | 4211 | if (!multicast_to_unicast) | 
|  | 4212 | break; | 
|  | 4213 | wpa_printf(MSG_INFO, | 
|  | 4214 | "nl80211: multicast to unicast not supported on interface %s", | 
|  | 4215 | bss->ifname); | 
|  | 4216 | break; | 
|  | 4217 | default: | 
|  | 4218 | wpa_printf(MSG_ERROR, | 
|  | 4219 | "nl80211: %s multicast to unicast failed with %d (%s) on interface %s", | 
|  | 4220 | multicast_to_unicast ? "enabling" : "disabling", | 
|  | 4221 | ret, strerror(-ret), bss->ifname); | 
|  | 4222 | break; | 
|  | 4223 | } | 
|  | 4224 |  | 
|  | 4225 | return ret; | 
|  | 4226 | } | 
|  | 4227 |  | 
|  | 4228 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4229 | static int wpa_driver_nl80211_set_ap(void *priv, | 
|  | 4230 | struct wpa_driver_ap_params *params) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4231 | { | 
|  | 4232 | struct i802_bss *bss = priv; | 
|  | 4233 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 4234 | struct nl_msg *msg; | 
|  | 4235 | u8 cmd = NL80211_CMD_NEW_BEACON; | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4236 | int ret = -ENOBUFS; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4237 | int beacon_set; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4238 | int num_suites; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4239 | u32 suites[20], suite; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4240 | u32 ver; | 
| Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4241 | #ifdef CONFIG_MESH | 
|  | 4242 | struct wpa_driver_mesh_bss_params mesh_params; | 
|  | 4243 | #endif /* CONFIG_MESH */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4244 |  | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4245 | beacon_set = params->reenable ? 0 : bss->beacon_set; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4246 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4247 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", | 
|  | 4248 | beacon_set); | 
|  | 4249 | if (beacon_set) | 
|  | 4250 | cmd = NL80211_CMD_SET_BEACON; | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4251 | else if (!drv->device_ap_sme && !drv->use_monitor && | 
|  | 4252 | !nl80211_get_wiphy_data_ap(bss)) | 
|  | 4253 | return -ENOBUFS; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4254 |  | 
| Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4255 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", | 
|  | 4256 | params->head, params->head_len); | 
| Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4257 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", | 
|  | 4258 | params->tail, params->tail_len); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4259 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); | 
| Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4260 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); | 
| Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4261 | wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate); | 
|  | 4262 | wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type); | 
| Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4263 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4264 | wpa_printf(MSG_DEBUG, "nl80211: ssid=%s", | 
|  | 4265 | wpa_ssid_txt(params->ssid, params->ssid_len)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4266 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || | 
|  | 4267 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, | 
|  | 4268 | params->head) || | 
|  | 4269 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, | 
|  | 4270 | params->tail) || | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4271 | nl80211_put_beacon_int(msg, params->beacon_int) || | 
| Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4272 | nl80211_put_beacon_rate(msg, drv->capa.flags, params) || | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4273 | nl80211_put_dtim_period(msg, params->dtim_period) || | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4274 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) | 
|  | 4275 | goto fail; | 
| Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4276 | if (params->proberesp && params->proberesp_len) { | 
|  | 4277 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", | 
|  | 4278 | params->proberesp, params->proberesp_len); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4279 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, | 
|  | 4280 | params->proberesp)) | 
|  | 4281 | goto fail; | 
| Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4282 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4283 | switch (params->hide_ssid) { | 
|  | 4284 | case NO_SSID_HIDING: | 
| Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4285 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4286 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, | 
|  | 4287 | NL80211_HIDDEN_SSID_NOT_IN_USE)) | 
|  | 4288 | goto fail; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4289 | break; | 
|  | 4290 | case HIDDEN_SSID_ZERO_LEN: | 
| Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4291 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4292 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, | 
|  | 4293 | NL80211_HIDDEN_SSID_ZERO_LEN)) | 
|  | 4294 | goto fail; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4295 | break; | 
|  | 4296 | case HIDDEN_SSID_ZERO_CONTENTS: | 
| Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4297 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4298 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, | 
|  | 4299 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) | 
|  | 4300 | goto fail; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4301 | break; | 
|  | 4302 | } | 
| Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4303 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4304 | if (params->privacy && | 
|  | 4305 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) | 
|  | 4306 | goto fail; | 
| Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4307 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4308 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == | 
|  | 4309 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { | 
|  | 4310 | /* Leave out the attribute */ | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4311 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { | 
|  | 4312 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, | 
|  | 4313 | NL80211_AUTHTYPE_SHARED_KEY)) | 
|  | 4314 | goto fail; | 
|  | 4315 | } else { | 
|  | 4316 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, | 
|  | 4317 | NL80211_AUTHTYPE_OPEN_SYSTEM)) | 
|  | 4318 | goto fail; | 
|  | 4319 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4320 |  | 
| Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4321 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4322 | ver = 0; | 
|  | 4323 | if (params->wpa_version & WPA_PROTO_WPA) | 
|  | 4324 | ver |= NL80211_WPA_VERSION_1; | 
|  | 4325 | if (params->wpa_version & WPA_PROTO_RSN) | 
|  | 4326 | ver |= NL80211_WPA_VERSION_2; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4327 | if (ver && | 
|  | 4328 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) | 
|  | 4329 | goto fail; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4330 |  | 
| Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4331 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", | 
|  | 4332 | params->key_mgmt_suites); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4333 | num_suites = wpa_key_mgmt_to_suites(params->key_mgmt_suites, | 
|  | 4334 | suites, ARRAY_SIZE(suites)); | 
|  | 4335 | if (num_suites > NL80211_MAX_NR_AKM_SUITES) | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 4336 | wpa_printf(MSG_DEBUG, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4337 | "nl80211: Not enough room for all AKM suites (num_suites=%d > NL80211_MAX_NR_AKM_SUITES)", | 
|  | 4338 | num_suites); | 
|  | 4339 | else if (num_suites && | 
|  | 4340 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), | 
|  | 4341 | suites)) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4342 | goto fail; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4343 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4344 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && | 
| Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4345 | (!params->pairwise_ciphers || | 
|  | 4346 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) && | 
|  | 4347 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || | 
|  | 4348 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4349 | goto fail; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4350 |  | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4351 | if (drv->device_ap_sme && | 
|  | 4352 | (params->key_mgmt_suites & WPA_KEY_MGMT_SAE) && | 
|  | 4353 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) | 
|  | 4354 | goto fail; | 
| Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 4355 |  | 
| Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4356 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", | 
|  | 4357 | params->pairwise_ciphers); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4358 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, | 
|  | 4359 | suites, ARRAY_SIZE(suites)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4360 | if (num_suites && | 
|  | 4361 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, | 
|  | 4362 | num_suites * sizeof(u32), suites)) | 
|  | 4363 | goto fail; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4364 |  | 
| Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4365 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", | 
|  | 4366 | params->group_cipher); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4367 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4368 | if (suite && | 
|  | 4369 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) | 
|  | 4370 | goto fail; | 
|  | 4371 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4372 | if (params->beacon_ies) { | 
| Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4373 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", | 
|  | 4374 | params->beacon_ies); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4375 | if (nla_put(msg, NL80211_ATTR_IE, | 
|  | 4376 | wpabuf_len(params->beacon_ies), | 
|  | 4377 | wpabuf_head(params->beacon_ies))) | 
|  | 4378 | goto fail; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4379 | } | 
|  | 4380 | if (params->proberesp_ies) { | 
| Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4381 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", | 
|  | 4382 | params->proberesp_ies); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4383 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, | 
|  | 4384 | wpabuf_len(params->proberesp_ies), | 
|  | 4385 | wpabuf_head(params->proberesp_ies))) | 
|  | 4386 | goto fail; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4387 | } | 
|  | 4388 | if (params->assocresp_ies) { | 
| Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4389 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", | 
|  | 4390 | params->assocresp_ies); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4391 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, | 
|  | 4392 | wpabuf_len(params->assocresp_ies), | 
|  | 4393 | wpabuf_head(params->assocresp_ies))) | 
|  | 4394 | goto fail; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4395 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4396 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4397 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER)  { | 
| Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4398 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", | 
|  | 4399 | params->ap_max_inactivity); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4400 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, | 
|  | 4401 | params->ap_max_inactivity)) | 
|  | 4402 | goto fail; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4403 | } | 
|  | 4404 |  | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4405 | #ifdef CONFIG_P2P | 
|  | 4406 | if (params->p2p_go_ctwindow > 0) { | 
|  | 4407 | if (drv->p2p_go_ctwindow_supported) { | 
|  | 4408 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", | 
|  | 4409 | params->p2p_go_ctwindow); | 
|  | 4410 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, | 
|  | 4411 | params->p2p_go_ctwindow)) | 
|  | 4412 | goto fail; | 
|  | 4413 | } else { | 
|  | 4414 | wpa_printf(MSG_INFO, | 
|  | 4415 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); | 
|  | 4416 | } | 
|  | 4417 | } | 
|  | 4418 | #endif /* CONFIG_P2P */ | 
|  | 4419 |  | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4420 | if (params->pbss) { | 
|  | 4421 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); | 
|  | 4422 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) | 
|  | 4423 | goto fail; | 
|  | 4424 | } | 
|  | 4425 |  | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4426 | if (params->ftm_responder) { | 
|  | 4427 | struct nlattr *ftm; | 
|  | 4428 |  | 
|  | 4429 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_FTM_RESPONDER)) { | 
|  | 4430 | ret = -ENOTSUP; | 
|  | 4431 | goto fail; | 
|  | 4432 | } | 
|  | 4433 |  | 
|  | 4434 | ftm = nla_nest_start(msg, NL80211_ATTR_FTM_RESPONDER); | 
|  | 4435 | if (!ftm || | 
|  | 4436 | nla_put_flag(msg, NL80211_FTM_RESP_ATTR_ENABLED) || | 
|  | 4437 | (params->lci && | 
|  | 4438 | nla_put(msg, NL80211_FTM_RESP_ATTR_LCI, | 
|  | 4439 | wpabuf_len(params->lci), | 
|  | 4440 | wpabuf_head(params->lci))) || | 
|  | 4441 | (params->civic && | 
|  | 4442 | nla_put(msg, NL80211_FTM_RESP_ATTR_CIVICLOC, | 
|  | 4443 | wpabuf_len(params->civic), | 
|  | 4444 | wpabuf_head(params->civic)))) | 
|  | 4445 | goto fail; | 
|  | 4446 | nla_nest_end(msg, ftm); | 
|  | 4447 | } | 
|  | 4448 |  | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4449 | #ifdef CONFIG_IEEE80211AX | 
|  | 4450 | if (params->he_spr) { | 
|  | 4451 | struct nlattr *spr; | 
|  | 4452 |  | 
|  | 4453 | spr = nla_nest_start(msg, NL80211_ATTR_HE_OBSS_PD); | 
|  | 4454 | wpa_printf(MSG_DEBUG, "nl80211: he_spr=%d", params->he_spr); | 
|  | 4455 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4456 | if (!spr || | 
|  | 4457 | nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET, | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4458 | params->he_spr_srg_obss_pd_min_offset) || | 
|  | 4459 | nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET, | 
|  | 4460 | params->he_spr_srg_obss_pd_max_offset)) | 
|  | 4461 | goto fail; | 
|  | 4462 |  | 
|  | 4463 | nla_nest_end(msg, spr); | 
|  | 4464 | } | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 4465 |  | 
|  | 4466 | if (params->freq && params->freq->he_enabled) { | 
|  | 4467 | struct nlattr *bss_color; | 
|  | 4468 |  | 
|  | 4469 | bss_color = nla_nest_start(msg, NL80211_ATTR_HE_BSS_COLOR); | 
|  | 4470 | if (!bss_color || | 
|  | 4471 | (params->he_bss_color_disabled && | 
|  | 4472 | nla_put_flag(msg, NL80211_HE_BSS_COLOR_ATTR_DISABLED)) || | 
|  | 4473 | (params->he_bss_color_partial && | 
|  | 4474 | nla_put_flag(msg, NL80211_HE_BSS_COLOR_ATTR_PARTIAL)) || | 
|  | 4475 | nla_put_u8(msg, NL80211_HE_BSS_COLOR_ATTR_COLOR, | 
|  | 4476 | params->he_bss_color)) | 
|  | 4477 | goto fail; | 
|  | 4478 | nla_nest_end(msg, bss_color); | 
|  | 4479 | } | 
|  | 4480 |  | 
|  | 4481 | if (params->twt_responder) { | 
|  | 4482 | wpa_printf(MSG_DEBUG, "nl80211: twt_responder=%d", | 
|  | 4483 | params->twt_responder); | 
|  | 4484 | if (nla_put_flag(msg, NL80211_ATTR_TWT_RESPONDER)) | 
|  | 4485 | goto fail; | 
|  | 4486 | } | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4487 | #endif /* CONFIG_IEEE80211AX */ | 
|  | 4488 |  | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 4489 | ret = send_and_recv_msgs_owner(drv, msg, get_connect_handle(bss), 1, | 
|  | 4490 | NULL, NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4491 | if (ret) { | 
|  | 4492 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", | 
|  | 4493 | ret, strerror(-ret)); | 
|  | 4494 | } else { | 
|  | 4495 | bss->beacon_set = 1; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4496 | nl80211_set_bss(bss, params->cts_protect, params->preamble, | 
|  | 4497 | params->short_slot_time, params->ht_opmode, | 
|  | 4498 | params->isolate, params->basic_rates); | 
| Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4499 | nl80211_set_multicast_to_unicast(bss, | 
|  | 4500 | params->multicast_to_unicast); | 
| Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4501 | if (beacon_set && params->freq && | 
|  | 4502 | params->freq->bandwidth != bss->bandwidth) { | 
|  | 4503 | wpa_printf(MSG_DEBUG, | 
|  | 4504 | "nl80211: Update BSS %s bandwidth: %d -> %d", | 
|  | 4505 | bss->ifname, bss->bandwidth, | 
|  | 4506 | params->freq->bandwidth); | 
|  | 4507 | ret = nl80211_set_channel(bss, params->freq, 1); | 
|  | 4508 | if (ret) { | 
|  | 4509 | wpa_printf(MSG_DEBUG, | 
|  | 4510 | "nl80211: Frequency set failed: %d (%s)", | 
|  | 4511 | ret, strerror(-ret)); | 
|  | 4512 | } else { | 
|  | 4513 | wpa_printf(MSG_DEBUG, | 
|  | 4514 | "nl80211: Frequency set succeeded for ht2040 coex"); | 
|  | 4515 | bss->bandwidth = params->freq->bandwidth; | 
|  | 4516 | } | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4517 | } else if (!beacon_set && params->freq) { | 
| Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4518 | /* | 
|  | 4519 | * cfg80211 updates the driver on frequence change in AP | 
|  | 4520 | * mode only at the point when beaconing is started, so | 
|  | 4521 | * set the initial value here. | 
|  | 4522 | */ | 
|  | 4523 | bss->bandwidth = params->freq->bandwidth; | 
|  | 4524 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4525 | } | 
| Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4526 |  | 
|  | 4527 | #ifdef CONFIG_MESH | 
|  | 4528 | if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) { | 
|  | 4529 | os_memset(&mesh_params, 0, sizeof(mesh_params)); | 
|  | 4530 | mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE; | 
|  | 4531 | mesh_params.ht_opmode = params->ht_opmode; | 
|  | 4532 | ret = nl80211_set_mesh_config(priv, &mesh_params); | 
|  | 4533 | if (ret < 0) | 
|  | 4534 | return ret; | 
|  | 4535 | } | 
|  | 4536 | #endif /* CONFIG_MESH */ | 
|  | 4537 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4538 | return ret; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4539 | fail: | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4540 | nlmsg_free(msg); | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4541 | return ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4542 | } | 
|  | 4543 |  | 
|  | 4544 |  | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4545 | static int nl80211_put_freq_params(struct nl_msg *msg, | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4546 | const struct hostapd_freq_params *freq) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4547 | { | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4548 | enum hostapd_hw_mode hw_mode; | 
|  | 4549 | int is_24ghz; | 
|  | 4550 | u8 channel; | 
|  | 4551 |  | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4552 | wpa_printf(MSG_DEBUG, "  * freq=%d", freq->freq); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4553 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) | 
|  | 4554 | return -ENOBUFS; | 
|  | 4555 |  | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4556 | wpa_printf(MSG_DEBUG, "  * he_enabled=%d", freq->he_enabled); | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4557 | wpa_printf(MSG_DEBUG, "  * vht_enabled=%d", freq->vht_enabled); | 
|  | 4558 | wpa_printf(MSG_DEBUG, "  * ht_enabled=%d", freq->ht_enabled); | 
|  | 4559 |  | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4560 | hw_mode = ieee80211_freq_to_chan(freq->freq, &channel); | 
|  | 4561 | is_24ghz = hw_mode == HOSTAPD_MODE_IEEE80211G || | 
|  | 4562 | hw_mode == HOSTAPD_MODE_IEEE80211B; | 
|  | 4563 |  | 
|  | 4564 | if (freq->vht_enabled || (freq->he_enabled && !is_24ghz)) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4565 | enum nl80211_chan_width cw; | 
|  | 4566 |  | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4567 | wpa_printf(MSG_DEBUG, "  * bandwidth=%d", freq->bandwidth); | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4568 | switch (freq->bandwidth) { | 
|  | 4569 | case 20: | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4570 | cw = NL80211_CHAN_WIDTH_20; | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4571 | break; | 
|  | 4572 | case 40: | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4573 | cw = NL80211_CHAN_WIDTH_40; | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4574 | break; | 
|  | 4575 | case 80: | 
|  | 4576 | if (freq->center_freq2) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4577 | cw = NL80211_CHAN_WIDTH_80P80; | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4578 | else | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4579 | cw = NL80211_CHAN_WIDTH_80; | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4580 | break; | 
|  | 4581 | case 160: | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4582 | cw = NL80211_CHAN_WIDTH_160; | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4583 | break; | 
|  | 4584 | default: | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4585 | return -EINVAL; | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4586 | } | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4587 |  | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4588 | wpa_printf(MSG_DEBUG, "  * channel_width=%d", cw); | 
|  | 4589 | wpa_printf(MSG_DEBUG, "  * center_freq1=%d", | 
|  | 4590 | freq->center_freq1); | 
|  | 4591 | wpa_printf(MSG_DEBUG, "  * center_freq2=%d", | 
|  | 4592 | freq->center_freq2); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4593 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || | 
|  | 4594 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, | 
|  | 4595 | freq->center_freq1) || | 
|  | 4596 | (freq->center_freq2 && | 
|  | 4597 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, | 
|  | 4598 | freq->center_freq2))) | 
|  | 4599 | return -ENOBUFS; | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4600 | } else if (freq->ht_enabled) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4601 | enum nl80211_channel_type ct; | 
|  | 4602 |  | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4603 | wpa_printf(MSG_DEBUG, "  * sec_channel_offset=%d", | 
|  | 4604 | freq->sec_channel_offset); | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4605 | switch (freq->sec_channel_offset) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4606 | case -1: | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4607 | ct = NL80211_CHAN_HT40MINUS; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4608 | break; | 
|  | 4609 | case 1: | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4610 | ct = NL80211_CHAN_HT40PLUS; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4611 | break; | 
|  | 4612 | default: | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4613 | ct = NL80211_CHAN_HT20; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4614 | break; | 
|  | 4615 | } | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4616 |  | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4617 | wpa_printf(MSG_DEBUG, "  * channel_type=%d", ct); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4618 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) | 
|  | 4619 | return -ENOBUFS; | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4620 | } else if (freq->edmg.channels && freq->edmg.bw_config) { | 
|  | 4621 | wpa_printf(MSG_DEBUG, | 
|  | 4622 | "  * EDMG configuration: channels=0x%x bw_config=%d", | 
|  | 4623 | freq->edmg.channels, freq->edmg.bw_config); | 
|  | 4624 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS, | 
|  | 4625 | freq->edmg.channels) || | 
|  | 4626 | nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG, | 
|  | 4627 | freq->edmg.bw_config)) | 
|  | 4628 | return -1; | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4629 | } else { | 
|  | 4630 | wpa_printf(MSG_DEBUG, "  * channel_type=%d", | 
|  | 4631 | NL80211_CHAN_NO_HT); | 
|  | 4632 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, | 
|  | 4633 | NL80211_CHAN_NO_HT)) | 
|  | 4634 | return -ENOBUFS; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4635 | } | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4636 | return 0; | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4637 | } | 
|  | 4638 |  | 
|  | 4639 |  | 
| Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4640 | static int nl80211_set_channel(struct i802_bss *bss, | 
|  | 4641 | struct hostapd_freq_params *freq, int set_chan) | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4642 | { | 
|  | 4643 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 4644 | struct nl_msg *msg; | 
|  | 4645 | int ret; | 
|  | 4646 |  | 
|  | 4647 | wpa_printf(MSG_DEBUG, | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4648 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, he_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", | 
|  | 4649 | freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled, | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4650 | freq->bandwidth, freq->center_freq1, freq->center_freq2); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4651 |  | 
|  | 4652 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : | 
|  | 4653 | NL80211_CMD_SET_WIPHY); | 
|  | 4654 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { | 
|  | 4655 | nlmsg_free(msg); | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4656 | return -1; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4657 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4658 |  | 
|  | 4659 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4660 | if (ret == 0) { | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4661 | bss->freq = freq->freq; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4662 | return 0; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4663 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4664 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4665 | "%d (%s)", freq->freq, ret, strerror(-ret)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4666 | return -1; | 
|  | 4667 | } | 
|  | 4668 |  | 
|  | 4669 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4670 | static u32 sta_flags_nl80211(int flags) | 
|  | 4671 | { | 
|  | 4672 | u32 f = 0; | 
|  | 4673 |  | 
|  | 4674 | if (flags & WPA_STA_AUTHORIZED) | 
|  | 4675 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); | 
|  | 4676 | if (flags & WPA_STA_WMM) | 
|  | 4677 | f |= BIT(NL80211_STA_FLAG_WME); | 
|  | 4678 | if (flags & WPA_STA_SHORT_PREAMBLE) | 
|  | 4679 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); | 
|  | 4680 | if (flags & WPA_STA_MFP) | 
|  | 4681 | f |= BIT(NL80211_STA_FLAG_MFP); | 
|  | 4682 | if (flags & WPA_STA_TDLS_PEER) | 
|  | 4683 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4684 | if (flags & WPA_STA_AUTHENTICATED) | 
|  | 4685 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4686 | if (flags & WPA_STA_ASSOCIATED) | 
|  | 4687 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4688 |  | 
|  | 4689 | return f; | 
|  | 4690 | } | 
|  | 4691 |  | 
|  | 4692 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4693 | #ifdef CONFIG_MESH | 
|  | 4694 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) | 
|  | 4695 | { | 
|  | 4696 | switch (state) { | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4697 | case PLINK_IDLE: | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4698 | return NL80211_PLINK_LISTEN; | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4699 | case PLINK_OPN_SNT: | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4700 | return NL80211_PLINK_OPN_SNT; | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4701 | case PLINK_OPN_RCVD: | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4702 | return NL80211_PLINK_OPN_RCVD; | 
|  | 4703 | case PLINK_CNF_RCVD: | 
|  | 4704 | return NL80211_PLINK_CNF_RCVD; | 
|  | 4705 | case PLINK_ESTAB: | 
|  | 4706 | return NL80211_PLINK_ESTAB; | 
|  | 4707 | case PLINK_HOLDING: | 
|  | 4708 | return NL80211_PLINK_HOLDING; | 
|  | 4709 | case PLINK_BLOCKED: | 
|  | 4710 | return NL80211_PLINK_BLOCKED; | 
|  | 4711 | default: | 
|  | 4712 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", | 
|  | 4713 | state); | 
|  | 4714 | } | 
|  | 4715 | return -1; | 
|  | 4716 | } | 
|  | 4717 | #endif /* CONFIG_MESH */ | 
|  | 4718 |  | 
|  | 4719 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4720 | static int wpa_driver_nl80211_sta_add(void *priv, | 
|  | 4721 | struct hostapd_sta_add_params *params) | 
|  | 4722 | { | 
|  | 4723 | struct i802_bss *bss = priv; | 
|  | 4724 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4725 | struct nl_msg *msg; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4726 | struct nl80211_sta_flag_update upd; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4727 | int ret = -ENOBUFS; | 
|  | 4728 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4729 | if ((params->flags & WPA_STA_TDLS_PEER) && | 
|  | 4730 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | 
|  | 4731 | return -EOPNOTSUPP; | 
|  | 4732 |  | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4733 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, | 
|  | 4734 | params->set ? "Set" : "Add", MAC2STR(params->addr)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4735 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : | 
|  | 4736 | NL80211_CMD_NEW_STATION); | 
|  | 4737 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) | 
|  | 4738 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4739 |  | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4740 | /* | 
|  | 4741 | * Set the below properties only in one of the following cases: | 
|  | 4742 | * 1. New station is added, already associated. | 
|  | 4743 | * 2. Set WPA_STA_TDLS_PEER station. | 
|  | 4744 | * 3. Set an already added unassociated station, if driver supports | 
|  | 4745 | * full AP client state. (Set these properties after station became | 
|  | 4746 | * associated will be rejected by the driver). | 
|  | 4747 | */ | 
|  | 4748 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || | 
|  | 4749 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && | 
|  | 4750 | (params->flags & WPA_STA_ASSOCIATED))) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4751 | wpa_hexdump(MSG_DEBUG, "  * supported rates", | 
|  | 4752 | params->supp_rates, params->supp_rates_len); | 
|  | 4753 | wpa_printf(MSG_DEBUG, "  * capability=0x%x", | 
|  | 4754 | params->capability); | 
|  | 4755 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, | 
|  | 4756 | params->supp_rates_len, params->supp_rates) || | 
|  | 4757 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, | 
|  | 4758 | params->capability)) | 
|  | 4759 | goto fail; | 
|  | 4760 |  | 
|  | 4761 | if (params->ht_capabilities) { | 
|  | 4762 | wpa_hexdump(MSG_DEBUG, "  * ht_capabilities", | 
|  | 4763 | (u8 *) params->ht_capabilities, | 
|  | 4764 | sizeof(*params->ht_capabilities)); | 
|  | 4765 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, | 
|  | 4766 | sizeof(*params->ht_capabilities), | 
|  | 4767 | params->ht_capabilities)) | 
|  | 4768 | goto fail; | 
|  | 4769 | } | 
|  | 4770 |  | 
|  | 4771 | if (params->vht_capabilities) { | 
|  | 4772 | wpa_hexdump(MSG_DEBUG, "  * vht_capabilities", | 
|  | 4773 | (u8 *) params->vht_capabilities, | 
|  | 4774 | sizeof(*params->vht_capabilities)); | 
|  | 4775 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, | 
|  | 4776 | sizeof(*params->vht_capabilities), | 
|  | 4777 | params->vht_capabilities)) | 
|  | 4778 | goto fail; | 
|  | 4779 | } | 
|  | 4780 |  | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4781 | if (params->he_capab) { | 
|  | 4782 | wpa_hexdump(MSG_DEBUG, "  * he_capab", | 
|  | 4783 | params->he_capab, params->he_capab_len); | 
|  | 4784 | if (nla_put(msg, NL80211_ATTR_HE_CAPABILITY, | 
|  | 4785 | params->he_capab_len, params->he_capab)) | 
|  | 4786 | goto fail; | 
|  | 4787 | } | 
|  | 4788 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4789 | if (params->ext_capab) { | 
|  | 4790 | wpa_hexdump(MSG_DEBUG, "  * ext_capab", | 
|  | 4791 | params->ext_capab, params->ext_capab_len); | 
|  | 4792 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, | 
|  | 4793 | params->ext_capab_len, params->ext_capab)) | 
|  | 4794 | goto fail; | 
|  | 4795 | } | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4796 |  | 
|  | 4797 | if (is_ap_interface(drv->nlmode) && | 
|  | 4798 | nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS, | 
|  | 4799 | params->support_p2p_ps ? | 
|  | 4800 | NL80211_P2P_PS_SUPPORTED : | 
|  | 4801 | NL80211_P2P_PS_UNSUPPORTED)) | 
|  | 4802 | goto fail; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4803 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4804 | if (!params->set) { | 
| Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4805 | if (params->aid) { | 
|  | 4806 | wpa_printf(MSG_DEBUG, "  * aid=%u", params->aid); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4807 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) | 
|  | 4808 | goto fail; | 
| Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4809 | } else { | 
|  | 4810 | /* | 
|  | 4811 | * cfg80211 validates that AID is non-zero, so we have | 
|  | 4812 | * to make this a non-zero value for the TDLS case where | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4813 | * a dummy STA entry is used for now and for a station | 
|  | 4814 | * that is still not associated. | 
| Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4815 | */ | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4816 | wpa_printf(MSG_DEBUG, "  * aid=1 (%s workaround)", | 
|  | 4817 | (params->flags & WPA_STA_TDLS_PEER) ? | 
|  | 4818 | "TDLS" : "UNASSOC_STA"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4819 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) | 
|  | 4820 | goto fail; | 
| Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4821 | } | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4822 | wpa_printf(MSG_DEBUG, "  * listen_interval=%u", | 
|  | 4823 | params->listen_interval); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4824 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, | 
|  | 4825 | params->listen_interval)) | 
|  | 4826 | goto fail; | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4827 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { | 
|  | 4828 | wpa_printf(MSG_DEBUG, "  * peer_aid=%u", params->aid); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4829 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) | 
|  | 4830 | goto fail; | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4831 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && | 
|  | 4832 | (params->flags & WPA_STA_ASSOCIATED)) { | 
|  | 4833 | wpa_printf(MSG_DEBUG, "  * aid=%u", params->aid); | 
|  | 4834 | wpa_printf(MSG_DEBUG, "  * listen_interval=%u", | 
|  | 4835 | params->listen_interval); | 
|  | 4836 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || | 
|  | 4837 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, | 
|  | 4838 | params->listen_interval)) | 
|  | 4839 | goto fail; | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4840 | } | 
|  | 4841 |  | 
| Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 4842 | if (params->vht_opmode_enabled) { | 
|  | 4843 | wpa_printf(MSG_DEBUG, "  * opmode=%u", params->vht_opmode); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4844 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, | 
|  | 4845 | params->vht_opmode)) | 
|  | 4846 | goto fail; | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4847 | } | 
|  | 4848 |  | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4849 | if (params->supp_channels) { | 
|  | 4850 | wpa_hexdump(MSG_DEBUG, "  * supported channels", | 
|  | 4851 | params->supp_channels, params->supp_channels_len); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4852 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, | 
|  | 4853 | params->supp_channels_len, params->supp_channels)) | 
|  | 4854 | goto fail; | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4855 | } | 
|  | 4856 |  | 
|  | 4857 | if (params->supp_oper_classes) { | 
|  | 4858 | wpa_hexdump(MSG_DEBUG, "  * supported operating classes", | 
|  | 4859 | params->supp_oper_classes, | 
|  | 4860 | params->supp_oper_classes_len); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4861 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, | 
|  | 4862 | params->supp_oper_classes_len, | 
|  | 4863 | params->supp_oper_classes)) | 
|  | 4864 | goto fail; | 
| Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4865 | } | 
|  | 4866 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4867 | os_memset(&upd, 0, sizeof(upd)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4868 | upd.set = sta_flags_nl80211(params->flags); | 
|  | 4869 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4870 |  | 
|  | 4871 | /* | 
|  | 4872 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH | 
|  | 4873 | * flags, as nl80211 driver moves a new station, by default, into | 
|  | 4874 | * associated state. | 
|  | 4875 | * | 
|  | 4876 | * On the other hand, if the driver supports that feature and the | 
|  | 4877 | * station is added in unauthenticated state, set the | 
|  | 4878 | * authenticated/associated bits in the mask to prevent moving this | 
|  | 4879 | * station to associated state before it is actually associated. | 
|  | 4880 | * | 
|  | 4881 | * This is irrelevant for mesh mode where the station is added to the | 
|  | 4882 | * driver as authenticated already, and ASSOCIATED isn't part of the | 
|  | 4883 | * nl80211 API. | 
|  | 4884 | */ | 
|  | 4885 | if (!is_mesh_interface(drv->nlmode)) { | 
|  | 4886 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { | 
|  | 4887 | wpa_printf(MSG_DEBUG, | 
|  | 4888 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); | 
|  | 4889 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | | 
|  | 4890 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); | 
|  | 4891 | } else if (!params->set && | 
|  | 4892 | !(params->flags & WPA_STA_TDLS_PEER)) { | 
|  | 4893 | if (!(params->flags & WPA_STA_AUTHENTICATED)) | 
|  | 4894 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); | 
|  | 4895 | if (!(params->flags & WPA_STA_ASSOCIATED)) | 
|  | 4896 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); | 
|  | 4897 | } | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4898 | #ifdef CONFIG_MESH | 
|  | 4899 | } else { | 
|  | 4900 | if (params->plink_state == PLINK_ESTAB && params->peer_aid) { | 
|  | 4901 | ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID, | 
|  | 4902 | params->peer_aid); | 
|  | 4903 | if (ret) | 
|  | 4904 | goto fail; | 
|  | 4905 | } | 
|  | 4906 | #endif /* CONFIG_MESH */ | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4907 | } | 
|  | 4908 |  | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4909 | wpa_printf(MSG_DEBUG, "  * flags set=0x%x mask=0x%x", | 
|  | 4910 | upd.set, upd.mask); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4911 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) | 
|  | 4912 | goto fail; | 
|  | 4913 |  | 
|  | 4914 | #ifdef CONFIG_MESH | 
|  | 4915 | if (params->plink_state && | 
|  | 4916 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, | 
|  | 4917 | sta_plink_state_nl80211(params->plink_state))) | 
|  | 4918 | goto fail; | 
|  | 4919 | #endif /* CONFIG_MESH */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4920 |  | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4921 | if ((!params->set || (params->flags & WPA_STA_TDLS_PEER) || | 
|  | 4922 | FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) && | 
|  | 4923 | (params->flags & WPA_STA_WMM)) { | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4924 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); | 
|  | 4925 |  | 
| Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4926 | wpa_printf(MSG_DEBUG, "  * qosinfo=0x%x", params->qosinfo); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4927 | if (!wme || | 
|  | 4928 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, | 
|  | 4929 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || | 
|  | 4930 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, | 
|  | 4931 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & | 
|  | 4932 | WMM_QOSINFO_STA_SP_MASK)) | 
|  | 4933 | goto fail; | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4934 | nla_nest_end(msg, wme); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4935 | } | 
|  | 4936 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4937 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4938 | msg = NULL; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4939 | if (ret) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4940 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " | 
|  | 4941 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, | 
|  | 4942 | strerror(-ret)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4943 | if (ret == -EEXIST) | 
|  | 4944 | ret = 0; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4945 | fail: | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4946 | nlmsg_free(msg); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4947 | return ret; | 
|  | 4948 | } | 
|  | 4949 |  | 
|  | 4950 |  | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4951 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) | 
|  | 4952 | { | 
|  | 4953 | #ifdef CONFIG_LIBNL3_ROUTE | 
|  | 4954 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 4955 | struct rtnl_neigh *rn; | 
|  | 4956 | struct nl_addr *nl_addr; | 
|  | 4957 | int err; | 
|  | 4958 |  | 
|  | 4959 | rn = rtnl_neigh_alloc(); | 
|  | 4960 | if (!rn) | 
|  | 4961 | return; | 
|  | 4962 |  | 
|  | 4963 | rtnl_neigh_set_family(rn, AF_BRIDGE); | 
|  | 4964 | rtnl_neigh_set_ifindex(rn, bss->ifindex); | 
|  | 4965 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); | 
|  | 4966 | if (!nl_addr) { | 
|  | 4967 | rtnl_neigh_put(rn); | 
|  | 4968 | return; | 
|  | 4969 | } | 
|  | 4970 | rtnl_neigh_set_lladdr(rn, nl_addr); | 
|  | 4971 |  | 
|  | 4972 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); | 
|  | 4973 | if (err < 0) { | 
|  | 4974 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " | 
|  | 4975 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), | 
|  | 4976 | bss->ifindex, nl_geterror(err)); | 
|  | 4977 | } else { | 
|  | 4978 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " | 
|  | 4979 | MACSTR, MAC2STR(addr)); | 
|  | 4980 | } | 
|  | 4981 |  | 
|  | 4982 | nl_addr_put(nl_addr); | 
|  | 4983 | rtnl_neigh_put(rn); | 
|  | 4984 | #endif /* CONFIG_LIBNL3_ROUTE */ | 
|  | 4985 | } | 
|  | 4986 |  | 
|  | 4987 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4988 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, | 
|  | 4989 | int deauth, u16 reason_code) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4990 | { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4991 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 4992 | struct nl_msg *msg; | 
|  | 4993 | int ret; | 
|  | 4994 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4995 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || | 
|  | 4996 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | 
|  | 4997 | (deauth == 0 && | 
|  | 4998 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, | 
|  | 4999 | WLAN_FC_STYPE_DISASSOC)) || | 
|  | 5000 | (deauth == 1 && | 
|  | 5001 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, | 
|  | 5002 | WLAN_FC_STYPE_DEAUTH)) || | 
|  | 5003 | (reason_code && | 
|  | 5004 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { | 
|  | 5005 | nlmsg_free(msg); | 
|  | 5006 | return -ENOBUFS; | 
|  | 5007 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5008 |  | 
|  | 5009 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5010 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR | 
|  | 5011 | " --> %d (%s)", | 
|  | 5012 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5013 |  | 
|  | 5014 | if (drv->rtnl_sk) | 
|  | 5015 | rtnl_neigh_delete_fdb_entry(bss, addr); | 
|  | 5016 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5017 | if (ret == -ENOENT) | 
|  | 5018 | return 0; | 
|  | 5019 | return ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5020 | } | 
|  | 5021 |  | 
|  | 5022 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5023 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5024 | { | 
|  | 5025 | struct nl_msg *msg; | 
| Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5026 | struct wpa_driver_nl80211_data *drv2; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5027 |  | 
|  | 5028 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); | 
|  | 5029 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5030 | /* stop listening for EAPOL on this interface */ | 
| Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5031 | dl_list_for_each(drv2, &drv->global->interfaces, | 
|  | 5032 | struct wpa_driver_nl80211_data, list) | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5033 | { | 
|  | 5034 | del_ifidx(drv2, ifidx, IFIDX_ANY); | 
|  | 5035 | /* Remove all bridges learned for this iface */ | 
|  | 5036 | del_ifidx(drv2, IFIDX_ANY, ifidx); | 
|  | 5037 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5038 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5039 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5040 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) | 
|  | 5041 | return; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5042 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); | 
|  | 5043 | } | 
|  | 5044 |  | 
|  | 5045 |  | 
| Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5046 | const char * nl80211_iftype_str(enum nl80211_iftype mode) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5047 | { | 
|  | 5048 | switch (mode) { | 
|  | 5049 | case NL80211_IFTYPE_ADHOC: | 
|  | 5050 | return "ADHOC"; | 
|  | 5051 | case NL80211_IFTYPE_STATION: | 
|  | 5052 | return "STATION"; | 
|  | 5053 | case NL80211_IFTYPE_AP: | 
|  | 5054 | return "AP"; | 
| Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 5055 | case NL80211_IFTYPE_AP_VLAN: | 
|  | 5056 | return "AP_VLAN"; | 
|  | 5057 | case NL80211_IFTYPE_WDS: | 
|  | 5058 | return "WDS"; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5059 | case NL80211_IFTYPE_MONITOR: | 
|  | 5060 | return "MONITOR"; | 
| Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 5061 | case NL80211_IFTYPE_MESH_POINT: | 
|  | 5062 | return "MESH_POINT"; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5063 | case NL80211_IFTYPE_P2P_CLIENT: | 
|  | 5064 | return "P2P_CLIENT"; | 
|  | 5065 | case NL80211_IFTYPE_P2P_GO: | 
|  | 5066 | return "P2P_GO"; | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5067 | case NL80211_IFTYPE_P2P_DEVICE: | 
|  | 5068 | return "P2P_DEVICE"; | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 5069 | case NL80211_IFTYPE_OCB: | 
|  | 5070 | return "OCB"; | 
|  | 5071 | case NL80211_IFTYPE_NAN: | 
|  | 5072 | return "NAN"; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5073 | default: | 
|  | 5074 | return "unknown"; | 
|  | 5075 | } | 
|  | 5076 | } | 
|  | 5077 |  | 
|  | 5078 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5079 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, | 
|  | 5080 | const char *ifname, | 
|  | 5081 | enum nl80211_iftype iftype, | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5082 | const u8 *addr, int wds, | 
|  | 5083 | int (*handler)(struct nl_msg *, void *), | 
|  | 5084 | void *arg) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5085 | { | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5086 | struct nl_msg *msg; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5087 | int ifidx; | 
|  | 5088 | int ret = -ENOBUFS; | 
|  | 5089 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5090 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", | 
|  | 5091 | iftype, nl80211_iftype_str(iftype)); | 
|  | 5092 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5093 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); | 
|  | 5094 | if (!msg || | 
|  | 5095 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || | 
|  | 5096 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) | 
|  | 5097 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5098 |  | 
|  | 5099 | if (iftype == NL80211_IFTYPE_MONITOR) { | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5100 | struct nlattr *flags; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5101 |  | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5102 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5103 | if (!flags || | 
|  | 5104 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) | 
|  | 5105 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5106 |  | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5107 | nla_nest_end(msg, flags); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5108 | } else if (wds) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5109 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) | 
|  | 5110 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5111 | } | 
|  | 5112 |  | 
| Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 5113 | /* | 
|  | 5114 | * Tell cfg80211 that the interface belongs to the socket that created | 
|  | 5115 | * it, and the interface should be deleted when the socket is closed. | 
|  | 5116 | */ | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5117 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) | 
|  | 5118 | goto fail; | 
| Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 5119 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5120 | ret = send_and_recv_msgs(drv, msg, handler, arg); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5121 | msg = NULL; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5122 | if (ret) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5123 | fail: | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5124 | nlmsg_free(msg); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5125 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", | 
|  | 5126 | ifname, ret, strerror(-ret)); | 
|  | 5127 | return ret; | 
|  | 5128 | } | 
|  | 5129 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5130 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) | 
|  | 5131 | return 0; | 
|  | 5132 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5133 | ifidx = if_nametoindex(ifname); | 
|  | 5134 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", | 
|  | 5135 | ifname, ifidx); | 
|  | 5136 |  | 
|  | 5137 | if (ifidx <= 0) | 
|  | 5138 | return -1; | 
|  | 5139 |  | 
| Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5140 | /* | 
|  | 5141 | * Some virtual interfaces need to process EAPOL packets and events on | 
|  | 5142 | * the parent interface. This is used mainly with hostapd. | 
|  | 5143 | */ | 
|  | 5144 | if (drv->hostapd || | 
|  | 5145 | iftype == NL80211_IFTYPE_AP_VLAN || | 
|  | 5146 | iftype == NL80211_IFTYPE_WDS || | 
|  | 5147 | iftype == NL80211_IFTYPE_MONITOR) { | 
|  | 5148 | /* start listening for EAPOL on this interface */ | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5149 | add_ifidx(drv, ifidx, IFIDX_ANY); | 
| Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5150 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5151 |  | 
|  | 5152 | if (addr && iftype != NL80211_IFTYPE_MONITOR && | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5153 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5154 | nl80211_remove_iface(drv, ifidx); | 
|  | 5155 | return -1; | 
|  | 5156 | } | 
|  | 5157 |  | 
|  | 5158 | return ifidx; | 
|  | 5159 | } | 
|  | 5160 |  | 
|  | 5161 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5162 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, | 
|  | 5163 | const char *ifname, enum nl80211_iftype iftype, | 
|  | 5164 | const u8 *addr, int wds, | 
|  | 5165 | int (*handler)(struct nl_msg *, void *), | 
|  | 5166 | void *arg, int use_existing) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5167 | { | 
|  | 5168 | int ret; | 
|  | 5169 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5170 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, | 
|  | 5171 | arg); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5172 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5173 | /* if error occurred and interface exists already */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5174 | if (ret == -ENFILE && if_nametoindex(ifname)) { | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5175 | if (use_existing) { | 
|  | 5176 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", | 
|  | 5177 | ifname); | 
| Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5178 | if (addr && iftype != NL80211_IFTYPE_MONITOR && | 
|  | 5179 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, | 
|  | 5180 | addr) < 0 && | 
|  | 5181 | (linux_set_iface_flags(drv->global->ioctl_sock, | 
|  | 5182 | ifname, 0) < 0 || | 
|  | 5183 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, | 
|  | 5184 | addr) < 0 || | 
|  | 5185 | linux_set_iface_flags(drv->global->ioctl_sock, | 
|  | 5186 | ifname, 1) < 0)) | 
|  | 5187 | return -1; | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5188 | return -ENFILE; | 
|  | 5189 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5190 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); | 
|  | 5191 |  | 
|  | 5192 | /* Try to remove the interface that was already there. */ | 
|  | 5193 | nl80211_remove_iface(drv, if_nametoindex(ifname)); | 
|  | 5194 |  | 
|  | 5195 | /* Try to create the interface again */ | 
|  | 5196 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5197 | wds, handler, arg); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5198 | } | 
|  | 5199 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5200 | if (ret >= 0 && is_p2p_net_interface(iftype)) { | 
|  | 5201 | wpa_printf(MSG_DEBUG, | 
|  | 5202 | "nl80211: Interface %s created for P2P - disable 11b rates", | 
|  | 5203 | ifname); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5204 | nl80211_disable_11b_rates(drv, ret, 1); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5205 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5206 |  | 
|  | 5207 | return ret; | 
|  | 5208 | } | 
|  | 5209 |  | 
|  | 5210 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5211 | static int nl80211_setup_ap(struct i802_bss *bss) | 
|  | 5212 | { | 
|  | 5213 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 5214 |  | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5215 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", | 
|  | 5216 | bss->ifname, drv->device_ap_sme, drv->use_monitor); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5217 |  | 
|  | 5218 | /* | 
|  | 5219 | * Disable Probe Request reporting unless we need it in this way for | 
|  | 5220 | * devices that include the AP SME, in the other case (unless using | 
|  | 5221 | * monitor iface) we'll get it through the nl_mgmt socket instead. | 
|  | 5222 | */ | 
|  | 5223 | if (!drv->device_ap_sme) | 
|  | 5224 | wpa_driver_nl80211_probe_req_report(bss, 0); | 
|  | 5225 |  | 
|  | 5226 | if (!drv->device_ap_sme && !drv->use_monitor) | 
|  | 5227 | if (nl80211_mgmt_subscribe_ap(bss)) | 
|  | 5228 | return -1; | 
|  | 5229 |  | 
|  | 5230 | if (drv->device_ap_sme && !drv->use_monitor) | 
|  | 5231 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5232 | wpa_printf(MSG_DEBUG, | 
|  | 5233 | "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] | 5234 |  | 
|  | 5235 | if (!drv->device_ap_sme && drv->use_monitor && | 
| Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 5236 | nl80211_create_monitor_interface(drv) && | 
|  | 5237 | !drv->device_ap_sme) | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5238 | return -1; | 
|  | 5239 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5240 | if (drv->device_ap_sme && | 
|  | 5241 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { | 
|  | 5242 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " | 
|  | 5243 | "Probe Request frame reporting in AP mode"); | 
|  | 5244 | /* Try to survive without this */ | 
|  | 5245 | } | 
|  | 5246 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5247 | return 0; | 
|  | 5248 | } | 
|  | 5249 |  | 
|  | 5250 |  | 
|  | 5251 | static void nl80211_teardown_ap(struct i802_bss *bss) | 
|  | 5252 | { | 
|  | 5253 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 5254 |  | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5255 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", | 
|  | 5256 | bss->ifname, drv->device_ap_sme, drv->use_monitor); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5257 | if (drv->device_ap_sme) { | 
|  | 5258 | wpa_driver_nl80211_probe_req_report(bss, 0); | 
|  | 5259 | if (!drv->use_monitor) | 
|  | 5260 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); | 
|  | 5261 | } else if (drv->use_monitor) | 
|  | 5262 | nl80211_remove_monitor_interface(drv); | 
|  | 5263 | else | 
|  | 5264 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); | 
|  | 5265 |  | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5266 | nl80211_put_wiphy_data_ap(bss); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5267 | bss->beacon_set = 0; | 
|  | 5268 | } | 
|  | 5269 |  | 
|  | 5270 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5271 | static int nl80211_tx_control_port(void *priv, const u8 *dest, | 
|  | 5272 | u16 proto, const u8 *buf, size_t len, | 
|  | 5273 | int no_encrypt) | 
|  | 5274 | { | 
|  | 5275 | struct i802_bss *bss = priv; | 
|  | 5276 | struct nl_msg *msg; | 
|  | 5277 | int ret; | 
|  | 5278 |  | 
|  | 5279 | wpa_printf(MSG_DEBUG, | 
|  | 5280 | "nl80211: Send over control port dest=" MACSTR | 
|  | 5281 | " proto=0x%04x len=%u no_encrypt=%d", | 
|  | 5282 | MAC2STR(dest), proto, (unsigned int) len, no_encrypt); | 
|  | 5283 |  | 
|  | 5284 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CONTROL_PORT_FRAME); | 
|  | 5285 | if (!msg || | 
|  | 5286 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || | 
|  | 5287 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dest) || | 
|  | 5288 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || | 
|  | 5289 | (no_encrypt && | 
|  | 5290 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) { | 
|  | 5291 | nlmsg_free(msg); | 
|  | 5292 | return -ENOBUFS; | 
|  | 5293 | } | 
|  | 5294 |  | 
|  | 5295 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | 
|  | 5296 | if (ret) | 
|  | 5297 | wpa_printf(MSG_DEBUG, | 
|  | 5298 | "nl80211: tx_control_port failed: ret=%d (%s)", | 
|  | 5299 | ret, strerror(-ret)); | 
|  | 5300 |  | 
|  | 5301 | return ret; | 
|  | 5302 | } | 
|  | 5303 |  | 
|  | 5304 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5305 | static int nl80211_send_eapol_data(struct i802_bss *bss, | 
|  | 5306 | const u8 *addr, const u8 *data, | 
|  | 5307 | size_t data_len) | 
|  | 5308 | { | 
|  | 5309 | struct sockaddr_ll ll; | 
|  | 5310 | int ret; | 
|  | 5311 |  | 
|  | 5312 | if (bss->drv->eapol_tx_sock < 0) { | 
|  | 5313 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); | 
|  | 5314 | return -1; | 
|  | 5315 | } | 
|  | 5316 |  | 
|  | 5317 | os_memset(&ll, 0, sizeof(ll)); | 
|  | 5318 | ll.sll_family = AF_PACKET; | 
|  | 5319 | ll.sll_ifindex = bss->ifindex; | 
|  | 5320 | ll.sll_protocol = htons(ETH_P_PAE); | 
|  | 5321 | ll.sll_halen = ETH_ALEN; | 
|  | 5322 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); | 
|  | 5323 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, | 
|  | 5324 | (struct sockaddr *) &ll, sizeof(ll)); | 
|  | 5325 | if (ret < 0) | 
|  | 5326 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", | 
|  | 5327 | strerror(errno)); | 
|  | 5328 |  | 
|  | 5329 | return ret; | 
|  | 5330 | } | 
|  | 5331 |  | 
|  | 5332 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5333 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; | 
|  | 5334 |  | 
|  | 5335 | static int wpa_driver_nl80211_hapd_send_eapol( | 
|  | 5336 | void *priv, const u8 *addr, const u8 *data, | 
|  | 5337 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) | 
|  | 5338 | { | 
|  | 5339 | struct i802_bss *bss = priv; | 
|  | 5340 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 5341 | struct ieee80211_hdr *hdr; | 
|  | 5342 | size_t len; | 
|  | 5343 | u8 *pos; | 
|  | 5344 | int res; | 
|  | 5345 | int qos = flags & WPA_STA_WMM; | 
| Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 5346 |  | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 5347 | /* For now, disable EAPOL TX over control port in AP mode by default | 
|  | 5348 | * since it does not provide TX status notifications. */ | 
|  | 5349 | if (drv->control_port_ap && | 
|  | 5350 | (drv->capa.flags & WPA_DRIVER_FLAGS_CONTROL_PORT)) | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5351 | return nl80211_tx_control_port(bss, addr, ETH_P_EAPOL, | 
|  | 5352 | data, data_len, !encrypt); | 
|  | 5353 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5354 | if (drv->device_ap_sme || !drv->use_monitor) | 
|  | 5355 | return nl80211_send_eapol_data(bss, addr, data, data_len); | 
|  | 5356 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5357 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + | 
|  | 5358 | data_len; | 
|  | 5359 | hdr = os_zalloc(len); | 
|  | 5360 | if (hdr == NULL) { | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5361 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", | 
|  | 5362 | (unsigned long) len); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5363 | return -1; | 
|  | 5364 | } | 
|  | 5365 |  | 
|  | 5366 | hdr->frame_control = | 
|  | 5367 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); | 
|  | 5368 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); | 
|  | 5369 | if (encrypt) | 
|  | 5370 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); | 
|  | 5371 | if (qos) { | 
|  | 5372 | hdr->frame_control |= | 
|  | 5373 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); | 
|  | 5374 | } | 
|  | 5375 |  | 
|  | 5376 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); | 
|  | 5377 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | 
|  | 5378 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | 
|  | 5379 | pos = (u8 *) (hdr + 1); | 
|  | 5380 |  | 
|  | 5381 | if (qos) { | 
| Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 5382 | /* Set highest priority in QoS header */ | 
|  | 5383 | pos[0] = 7; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5384 | pos[1] = 0; | 
|  | 5385 | pos += 2; | 
|  | 5386 | } | 
|  | 5387 |  | 
|  | 5388 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); | 
|  | 5389 | pos += sizeof(rfc1042_header); | 
|  | 5390 | WPA_PUT_BE16(pos, ETH_P_PAE); | 
|  | 5391 | pos += 2; | 
|  | 5392 | memcpy(pos, data, data_len); | 
|  | 5393 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5394 | res = nl80211_send_monitor(drv, hdr, len, encrypt, 0); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5395 | if (res < 0) { | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5396 | wpa_printf(MSG_ERROR, | 
|  | 5397 | "hapd_send_eapol - packet len: %lu - failed", | 
|  | 5398 | (unsigned long) len); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5399 | } | 
|  | 5400 | os_free(hdr); | 
|  | 5401 |  | 
|  | 5402 | return res; | 
|  | 5403 | } | 
|  | 5404 |  | 
|  | 5405 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5406 | 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] | 5407 | unsigned int total_flags, | 
|  | 5408 | unsigned int flags_or, | 
|  | 5409 | unsigned int flags_and) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5410 | { | 
|  | 5411 | struct i802_bss *bss = priv; | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5412 | struct nl_msg *msg; | 
|  | 5413 | struct nlattr *flags; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5414 | struct nl80211_sta_flag_update upd; | 
|  | 5415 |  | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5416 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR | 
|  | 5417 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", | 
|  | 5418 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, | 
|  | 5419 | !!(total_flags & WPA_STA_AUTHORIZED)); | 
|  | 5420 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5421 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || | 
|  | 5422 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) | 
|  | 5423 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5424 |  | 
|  | 5425 | /* | 
|  | 5426 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This | 
|  | 5427 | * can be removed eventually. | 
|  | 5428 | */ | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5429 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5430 | if (!flags || | 
|  | 5431 | ((total_flags & WPA_STA_AUTHORIZED) && | 
|  | 5432 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || | 
|  | 5433 | ((total_flags & WPA_STA_WMM) && | 
|  | 5434 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || | 
|  | 5435 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && | 
|  | 5436 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || | 
|  | 5437 | ((total_flags & WPA_STA_MFP) && | 
|  | 5438 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || | 
|  | 5439 | ((total_flags & WPA_STA_TDLS_PEER) && | 
|  | 5440 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) | 
|  | 5441 | goto fail; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5442 |  | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5443 | nla_nest_end(msg, flags); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5444 |  | 
|  | 5445 | os_memset(&upd, 0, sizeof(upd)); | 
|  | 5446 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); | 
|  | 5447 | upd.set = sta_flags_nl80211(flags_or); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5448 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) | 
|  | 5449 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5450 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5451 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); | 
|  | 5452 | fail: | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5453 | nlmsg_free(msg); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5454 | return -ENOBUFS; | 
|  | 5455 | } | 
|  | 5456 |  | 
|  | 5457 |  | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5458 | static int driver_nl80211_sta_set_airtime_weight(void *priv, const u8 *addr, | 
|  | 5459 | unsigned int weight) | 
|  | 5460 | { | 
|  | 5461 | struct i802_bss *bss = priv; | 
|  | 5462 | struct nl_msg *msg; | 
|  | 5463 |  | 
|  | 5464 | wpa_printf(MSG_DEBUG, | 
|  | 5465 | "nl80211: Set STA airtime weight - ifname=%s addr=" MACSTR | 
|  | 5466 | " weight=%u", bss->ifname, MAC2STR(addr), weight); | 
|  | 5467 |  | 
|  | 5468 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || | 
|  | 5469 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | 
|  | 5470 | nla_put_u16(msg, NL80211_ATTR_AIRTIME_WEIGHT, weight)) | 
|  | 5471 | goto fail; | 
|  | 5472 |  | 
|  | 5473 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); | 
|  | 5474 | fail: | 
|  | 5475 | nlmsg_free(msg); | 
|  | 5476 | return -ENOBUFS; | 
|  | 5477 | } | 
|  | 5478 |  | 
|  | 5479 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5480 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, | 
|  | 5481 | struct wpa_driver_associate_params *params) | 
|  | 5482 | { | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5483 | enum nl80211_iftype nlmode, old_mode; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5484 |  | 
|  | 5485 | if (params->p2p) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5486 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " | 
|  | 5487 | "group (GO)"); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5488 | nlmode = NL80211_IFTYPE_P2P_GO; | 
|  | 5489 | } else | 
|  | 5490 | nlmode = NL80211_IFTYPE_AP; | 
|  | 5491 |  | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5492 | old_mode = drv->nlmode; | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5493 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5494 | nl80211_remove_monitor_interface(drv); | 
|  | 5495 | return -1; | 
|  | 5496 | } | 
|  | 5497 |  | 
| Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5498 | if (params->freq.freq && | 
|  | 5499 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5500 | if (old_mode != nlmode) | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5501 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5502 | nl80211_remove_monitor_interface(drv); | 
|  | 5503 | return -1; | 
|  | 5504 | } | 
|  | 5505 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5506 | return 0; | 
|  | 5507 | } | 
|  | 5508 |  | 
|  | 5509 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5510 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, | 
|  | 5511 | int reset_mode) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5512 | { | 
|  | 5513 | struct nl_msg *msg; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5514 | int ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5515 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5516 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 5517 | ret = send_and_recv_msgs_owner(drv, msg, | 
|  | 5518 | get_connect_handle(drv->first_bss), 1, | 
|  | 5519 | NULL, NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5520 | if (ret) { | 
|  | 5521 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " | 
|  | 5522 | "(%s)", ret, strerror(-ret)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5523 | } else { | 
|  | 5524 | wpa_printf(MSG_DEBUG, | 
|  | 5525 | "nl80211: Leave IBSS request sent successfully"); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5526 | } | 
|  | 5527 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5528 | if (reset_mode && | 
|  | 5529 | wpa_driver_nl80211_set_mode(drv->first_bss, | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 5530 | NL80211_IFTYPE_STATION)) { | 
|  | 5531 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " | 
|  | 5532 | "station mode"); | 
|  | 5533 | } | 
|  | 5534 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5535 | return ret; | 
|  | 5536 | } | 
|  | 5537 |  | 
|  | 5538 |  | 
| Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5539 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, | 
|  | 5540 | struct wpa_driver_associate_params *params) | 
|  | 5541 | { | 
|  | 5542 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) | 
|  | 5543 | return -1; | 
|  | 5544 |  | 
|  | 5545 | if (params->htcaps && params->htcaps_mask) { | 
|  | 5546 | int sz = sizeof(struct ieee80211_ht_capabilities); | 
|  | 5547 | wpa_hexdump(MSG_DEBUG, "  * htcaps", params->htcaps, sz); | 
|  | 5548 | wpa_hexdump(MSG_DEBUG, "  * htcaps_mask", | 
|  | 5549 | params->htcaps_mask, sz); | 
|  | 5550 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, | 
|  | 5551 | params->htcaps) || | 
|  | 5552 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, | 
|  | 5553 | params->htcaps_mask)) | 
|  | 5554 | return -1; | 
|  | 5555 | } | 
|  | 5556 |  | 
|  | 5557 | #ifdef CONFIG_VHT_OVERRIDES | 
|  | 5558 | if (params->disable_vht) { | 
|  | 5559 | wpa_printf(MSG_DEBUG, "  * VHT disabled"); | 
|  | 5560 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) | 
|  | 5561 | return -1; | 
|  | 5562 | } | 
|  | 5563 |  | 
|  | 5564 | if (params->vhtcaps && params->vhtcaps_mask) { | 
|  | 5565 | int sz = sizeof(struct ieee80211_vht_capabilities); | 
|  | 5566 | wpa_hexdump(MSG_DEBUG, "  * vhtcaps", params->vhtcaps, sz); | 
|  | 5567 | wpa_hexdump(MSG_DEBUG, "  * vhtcaps_mask", | 
|  | 5568 | params->vhtcaps_mask, sz); | 
|  | 5569 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, | 
|  | 5570 | params->vhtcaps) || | 
|  | 5571 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, | 
|  | 5572 | params->vhtcaps_mask)) | 
|  | 5573 | return -1; | 
|  | 5574 | } | 
|  | 5575 | #endif /* CONFIG_VHT_OVERRIDES */ | 
|  | 5576 |  | 
|  | 5577 | return 0; | 
|  | 5578 | } | 
|  | 5579 |  | 
|  | 5580 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5581 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, | 
|  | 5582 | struct wpa_driver_associate_params *params) | 
|  | 5583 | { | 
|  | 5584 | struct nl_msg *msg; | 
|  | 5585 | int ret = -1; | 
|  | 5586 | int count = 0; | 
|  | 5587 |  | 
|  | 5588 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); | 
|  | 5589 |  | 
| Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5590 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5591 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " | 
|  | 5592 | "IBSS mode"); | 
|  | 5593 | return -1; | 
|  | 5594 | } | 
|  | 5595 |  | 
|  | 5596 | retry: | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5597 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || | 
|  | 5598 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) | 
|  | 5599 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5600 |  | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5601 | wpa_printf(MSG_DEBUG, "  * SSID=%s", | 
|  | 5602 | wpa_ssid_txt(params->ssid, params->ssid_len)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5603 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) | 
|  | 5604 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5605 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); | 
|  | 5606 | drv->ssid_len = params->ssid_len; | 
|  | 5607 |  | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5608 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || | 
|  | 5609 | nl80211_put_beacon_int(msg, params->beacon_int)) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5610 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5611 |  | 
|  | 5612 | ret = nl80211_set_conn_keys(params, msg); | 
|  | 5613 | if (ret) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5614 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5615 |  | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5616 | if (params->bssid && params->fixed_bssid) { | 
|  | 5617 | wpa_printf(MSG_DEBUG, "  * BSSID=" MACSTR, | 
|  | 5618 | MAC2STR(params->bssid)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5619 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) | 
|  | 5620 | goto fail; | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5621 | } | 
|  | 5622 |  | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5623 | if (params->fixed_freq) { | 
|  | 5624 | wpa_printf(MSG_DEBUG, "  * fixed_freq"); | 
|  | 5625 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) | 
|  | 5626 | goto fail; | 
|  | 5627 | } | 
|  | 5628 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5629 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || | 
|  | 5630 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | 
|  | 5631 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || | 
|  | 5632 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5633 | wpa_printf(MSG_DEBUG, "  * control port"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5634 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) | 
|  | 5635 | goto fail; | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5636 | } | 
|  | 5637 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5638 | if (params->wpa_ie) { | 
|  | 5639 | wpa_hexdump(MSG_DEBUG, | 
|  | 5640 | "  * Extra IEs for Beacon/Probe Response frames", | 
|  | 5641 | params->wpa_ie, params->wpa_ie_len); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5642 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, | 
|  | 5643 | params->wpa_ie)) | 
|  | 5644 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5645 | } | 
|  | 5646 |  | 
| Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 5647 | ret = nl80211_ht_vht_overrides(msg, params); | 
|  | 5648 | if (ret < 0) | 
|  | 5649 | goto fail; | 
| Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5650 |  | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 5651 | ret = send_and_recv_msgs_owner(drv, msg, | 
|  | 5652 | get_connect_handle(drv->first_bss), 1, | 
|  | 5653 | NULL, NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5654 | msg = NULL; | 
|  | 5655 | if (ret) { | 
|  | 5656 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", | 
|  | 5657 | ret, strerror(-ret)); | 
|  | 5658 | count++; | 
|  | 5659 | if (ret == -EALREADY && count == 1) { | 
|  | 5660 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " | 
|  | 5661 | "forced leave"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5662 | nl80211_leave_ibss(drv, 0); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5663 | nlmsg_free(msg); | 
|  | 5664 | goto retry; | 
|  | 5665 | } | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5666 | } else { | 
|  | 5667 | wpa_printf(MSG_DEBUG, | 
|  | 5668 | "nl80211: Join IBSS request sent successfully"); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5669 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5670 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5671 | fail: | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5672 | nlmsg_free(msg); | 
|  | 5673 | return ret; | 
|  | 5674 | } | 
|  | 5675 |  | 
|  | 5676 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5677 | static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data *drv, | 
|  | 5678 | struct wpa_driver_associate_params *params, | 
|  | 5679 | struct nl_msg *msg) | 
|  | 5680 | { | 
|  | 5681 | if (params->fils_erp_username_len) { | 
|  | 5682 | wpa_hexdump_ascii(MSG_DEBUG, "  * FILS ERP EMSKname/username", | 
|  | 5683 | params->fils_erp_username, | 
|  | 5684 | params->fils_erp_username_len); | 
|  | 5685 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_USERNAME, | 
|  | 5686 | params->fils_erp_username_len, | 
|  | 5687 | params->fils_erp_username)) | 
|  | 5688 | return -1; | 
|  | 5689 | } | 
|  | 5690 |  | 
|  | 5691 | if (params->fils_erp_realm_len) { | 
|  | 5692 | wpa_hexdump_ascii(MSG_DEBUG, "  * FILS ERP Realm", | 
|  | 5693 | params->fils_erp_realm, | 
|  | 5694 | params->fils_erp_realm_len); | 
|  | 5695 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_REALM, | 
|  | 5696 | params->fils_erp_realm_len, params->fils_erp_realm)) | 
|  | 5697 | return -1; | 
|  | 5698 | } | 
|  | 5699 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5700 | if (params->fils_erp_rrk_len) { | 
| Vinita S. Maloo | 3a5b441 | 2020-05-19 17:43:22 +0530 | [diff] [blame] | 5701 | wpa_printf(MSG_DEBUG, "  * FILS ERP next seq %u", | 
|  | 5702 | params->fils_erp_next_seq_num); | 
|  | 5703 | if (nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, | 
|  | 5704 | params->fils_erp_next_seq_num)) | 
|  | 5705 | return -1; | 
|  | 5706 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5707 | wpa_printf(MSG_DEBUG, "  * FILS ERP rRK (len=%lu)", | 
|  | 5708 | (unsigned long) params->fils_erp_rrk_len); | 
|  | 5709 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_RRK, | 
|  | 5710 | params->fils_erp_rrk_len, params->fils_erp_rrk)) | 
|  | 5711 | return -1; | 
|  | 5712 | } | 
|  | 5713 |  | 
|  | 5714 | return 0; | 
|  | 5715 | } | 
|  | 5716 |  | 
|  | 5717 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5718 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, | 
|  | 5719 | struct wpa_driver_associate_params *params, | 
|  | 5720 | struct nl_msg *msg) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5721 | { | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5722 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) | 
|  | 5723 | return -1; | 
|  | 5724 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5725 | if (params->bssid) { | 
|  | 5726 | wpa_printf(MSG_DEBUG, "  * bssid=" MACSTR, | 
|  | 5727 | MAC2STR(params->bssid)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5728 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) | 
|  | 5729 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5730 | } | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5731 |  | 
| Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5732 | if (params->bssid_hint) { | 
|  | 5733 | wpa_printf(MSG_DEBUG, "  * bssid_hint=" MACSTR, | 
|  | 5734 | MAC2STR(params->bssid_hint)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5735 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, | 
|  | 5736 | params->bssid_hint)) | 
|  | 5737 | return -1; | 
| Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5738 | } | 
|  | 5739 |  | 
| Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5740 | if (params->freq.freq) { | 
|  | 5741 | wpa_printf(MSG_DEBUG, "  * freq=%d", params->freq.freq); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5742 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, | 
|  | 5743 | params->freq.freq)) | 
|  | 5744 | return -1; | 
| Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5745 | drv->assoc_freq = params->freq.freq; | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5746 | } else | 
|  | 5747 | drv->assoc_freq = 0; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5748 |  | 
| Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5749 | if (params->freq_hint) { | 
|  | 5750 | wpa_printf(MSG_DEBUG, "  * freq_hint=%d", params->freq_hint); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5751 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, | 
|  | 5752 | params->freq_hint)) | 
|  | 5753 | return -1; | 
| Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5754 | } | 
|  | 5755 |  | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5756 | if (params->freq.edmg.channels && params->freq.edmg.bw_config) { | 
|  | 5757 | wpa_printf(MSG_DEBUG, | 
|  | 5758 | "  * EDMG configuration: channels=0x%x bw_config=%d", | 
|  | 5759 | params->freq.edmg.channels, | 
|  | 5760 | params->freq.edmg.bw_config); | 
|  | 5761 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS, | 
|  | 5762 | params->freq.edmg.channels) || | 
|  | 5763 | nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG, | 
|  | 5764 | params->freq.edmg.bw_config)) | 
|  | 5765 | return -1; | 
|  | 5766 | } | 
|  | 5767 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5768 | if (params->bg_scan_period >= 0) { | 
|  | 5769 | wpa_printf(MSG_DEBUG, "  * bg scan period=%d", | 
|  | 5770 | params->bg_scan_period); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5771 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, | 
|  | 5772 | params->bg_scan_period)) | 
|  | 5773 | return -1; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5774 | } | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5775 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5776 | if (params->ssid) { | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5777 | wpa_printf(MSG_DEBUG, "  * SSID=%s", | 
|  | 5778 | wpa_ssid_txt(params->ssid, params->ssid_len)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5779 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, | 
|  | 5780 | params->ssid)) | 
|  | 5781 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5782 | if (params->ssid_len > sizeof(drv->ssid)) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5783 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5784 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); | 
|  | 5785 | drv->ssid_len = params->ssid_len; | 
|  | 5786 | } | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5787 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5788 | wpa_hexdump(MSG_DEBUG, "  * IEs", params->wpa_ie, params->wpa_ie_len); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5789 | if (params->wpa_ie && | 
|  | 5790 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) | 
|  | 5791 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5792 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5793 | if (params->wpa_proto) { | 
|  | 5794 | enum nl80211_wpa_versions ver = 0; | 
|  | 5795 |  | 
|  | 5796 | if (params->wpa_proto & WPA_PROTO_WPA) | 
|  | 5797 | ver |= NL80211_WPA_VERSION_1; | 
|  | 5798 | if (params->wpa_proto & WPA_PROTO_RSN) | 
|  | 5799 | ver |= NL80211_WPA_VERSION_2; | 
|  | 5800 |  | 
|  | 5801 | wpa_printf(MSG_DEBUG, "  * WPA Versions 0x%x", ver); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5802 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) | 
|  | 5803 | return -1; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5804 | } | 
|  | 5805 |  | 
|  | 5806 | if (params->pairwise_suite != WPA_CIPHER_NONE) { | 
|  | 5807 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); | 
|  | 5808 | wpa_printf(MSG_DEBUG, "  * pairwise=0x%x", cipher); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5809 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, | 
|  | 5810 | cipher)) | 
|  | 5811 | return -1; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5812 | } | 
|  | 5813 |  | 
| Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 5814 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && | 
|  | 5815 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { | 
|  | 5816 | /* | 
|  | 5817 | * This is likely to work even though many drivers do not | 
|  | 5818 | * advertise support for operations without GTK. | 
|  | 5819 | */ | 
|  | 5820 | wpa_printf(MSG_DEBUG, "  * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); | 
|  | 5821 | } else if (params->group_suite != WPA_CIPHER_NONE) { | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5822 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); | 
|  | 5823 | wpa_printf(MSG_DEBUG, "  * group=0x%x", cipher); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5824 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) | 
|  | 5825 | return -1; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5826 | } | 
|  | 5827 |  | 
|  | 5828 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || | 
|  | 5829 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | 
|  | 5830 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || | 
|  | 5831 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || | 
| Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5832 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || | 
| Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5833 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || | 
|  | 5834 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5835 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 5836 | params->key_mgmt_suite == WPA_KEY_MGMT_SAE || | 
|  | 5837 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE || | 
| Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5838 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5839 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 || | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 5840 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X_SHA384 || | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5841 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA256 || | 
|  | 5842 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA384 || | 
|  | 5843 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA256 || | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5844 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA384 || | 
|  | 5845 | params->key_mgmt_suite == WPA_KEY_MGMT_OWE || | 
|  | 5846 | params->key_mgmt_suite == WPA_KEY_MGMT_DPP) { | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5847 | int mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5848 |  | 
|  | 5849 | switch (params->key_mgmt_suite) { | 
|  | 5850 | case WPA_KEY_MGMT_CCKM: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5851 | mgmt = RSN_AUTH_KEY_MGMT_CCKM; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5852 | break; | 
|  | 5853 | case WPA_KEY_MGMT_IEEE8021X: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5854 | mgmt = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5855 | break; | 
|  | 5856 | case WPA_KEY_MGMT_FT_IEEE8021X: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5857 | mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5858 | break; | 
|  | 5859 | case WPA_KEY_MGMT_FT_PSK: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5860 | mgmt = RSN_AUTH_KEY_MGMT_FT_PSK; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5861 | break; | 
| Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5862 | case WPA_KEY_MGMT_IEEE8021X_SHA256: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5863 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SHA256; | 
| Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5864 | break; | 
|  | 5865 | case WPA_KEY_MGMT_PSK_SHA256: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5866 | mgmt = RSN_AUTH_KEY_MGMT_PSK_SHA256; | 
| Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5867 | break; | 
| Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5868 | case WPA_KEY_MGMT_OSEN: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5869 | mgmt = RSN_AUTH_KEY_MGMT_OSEN; | 
| Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5870 | break; | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 5871 | case WPA_KEY_MGMT_SAE: | 
|  | 5872 | mgmt = RSN_AUTH_KEY_MGMT_SAE; | 
|  | 5873 | break; | 
|  | 5874 | case WPA_KEY_MGMT_FT_SAE: | 
|  | 5875 | mgmt = RSN_AUTH_KEY_MGMT_FT_SAE; | 
|  | 5876 | break; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5877 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5878 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5879 | break; | 
| Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5880 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5881 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192; | 
| Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5882 | break; | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 5883 | case WPA_KEY_MGMT_FT_IEEE8021X_SHA384: | 
|  | 5884 | mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384; | 
|  | 5885 | break; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5886 | case WPA_KEY_MGMT_FILS_SHA256: | 
|  | 5887 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA256; | 
|  | 5888 | break; | 
|  | 5889 | case WPA_KEY_MGMT_FILS_SHA384: | 
|  | 5890 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA384; | 
|  | 5891 | break; | 
|  | 5892 | case WPA_KEY_MGMT_FT_FILS_SHA256: | 
|  | 5893 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256; | 
|  | 5894 | break; | 
|  | 5895 | case WPA_KEY_MGMT_FT_FILS_SHA384: | 
|  | 5896 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384; | 
|  | 5897 | break; | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5898 | case WPA_KEY_MGMT_OWE: | 
|  | 5899 | mgmt = RSN_AUTH_KEY_MGMT_OWE; | 
|  | 5900 | break; | 
|  | 5901 | case WPA_KEY_MGMT_DPP: | 
|  | 5902 | mgmt = RSN_AUTH_KEY_MGMT_DPP; | 
|  | 5903 | break; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5904 | case WPA_KEY_MGMT_PSK: | 
|  | 5905 | default: | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5906 | mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5907 | break; | 
|  | 5908 | } | 
| Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5909 | wpa_printf(MSG_DEBUG, "  * akm=0x%x", mgmt); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5910 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) | 
|  | 5911 | return -1; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5912 | } | 
|  | 5913 |  | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5914 | if (params->req_handshake_offload && | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5915 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)) { | 
|  | 5916 | wpa_printf(MSG_DEBUG, "  * WANT_1X_4WAY_HS"); | 
|  | 5917 | if (nla_put_flag(msg, NL80211_ATTR_WANT_1X_4WAY_HS)) | 
|  | 5918 | return -1; | 
|  | 5919 | } | 
|  | 5920 |  | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5921 | /* Add PSK in case of 4-way handshake offload */ | 
|  | 5922 | if (params->psk && | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5923 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) { | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5924 | wpa_hexdump_key(MSG_DEBUG, "  * PSK", params->psk, 32); | 
|  | 5925 | if (nla_put(msg, NL80211_ATTR_PMK, 32, params->psk)) | 
|  | 5926 | return -1; | 
|  | 5927 | } | 
|  | 5928 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5929 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) | 
|  | 5930 | return -1; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5931 |  | 
| Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 5932 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA && | 
|  | 5933 | (params->pairwise_suite == WPA_CIPHER_NONE || | 
|  | 5934 | params->pairwise_suite == WPA_CIPHER_WEP104 || | 
|  | 5935 | params->pairwise_suite == WPA_CIPHER_WEP40) && | 
|  | 5936 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || | 
|  | 5937 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) | 
|  | 5938 | return -1; | 
|  | 5939 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5940 | if (params->rrm_used) { | 
|  | 5941 | u32 drv_rrm_flags = drv->capa.rrm_flags; | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5942 | if ((!((drv_rrm_flags & | 
|  | 5943 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && | 
|  | 5944 | (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && | 
|  | 5945 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) || | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5946 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) | 
|  | 5947 | return -1; | 
|  | 5948 | } | 
|  | 5949 |  | 
| Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5950 | if (nl80211_ht_vht_overrides(msg, params) < 0) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5951 | return -1; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5952 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5953 | if (params->p2p) | 
|  | 5954 | wpa_printf(MSG_DEBUG, "  * P2P group"); | 
|  | 5955 |  | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5956 | if (params->pbss) { | 
|  | 5957 | wpa_printf(MSG_DEBUG, "  * PBSS"); | 
|  | 5958 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) | 
|  | 5959 | return -1; | 
|  | 5960 | } | 
|  | 5961 |  | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 5962 | drv->connect_reassoc = 0; | 
|  | 5963 | if (params->prev_bssid) { | 
|  | 5964 | wpa_printf(MSG_DEBUG, "  * prev_bssid=" MACSTR, | 
|  | 5965 | MAC2STR(params->prev_bssid)); | 
|  | 5966 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, | 
|  | 5967 | params->prev_bssid)) | 
|  | 5968 | return -1; | 
|  | 5969 | drv->connect_reassoc = 1; | 
|  | 5970 | } | 
|  | 5971 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5972 | if ((params->auth_alg & WPA_AUTH_ALG_FILS) && | 
|  | 5973 | nl80211_put_fils_connect_params(drv, params, msg) != 0) | 
|  | 5974 | return -1; | 
|  | 5975 |  | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5976 | if ((params->key_mgmt_suite == WPA_KEY_MGMT_SAE || | 
|  | 5977 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE) && | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5978 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) && | 
|  | 5979 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) | 
|  | 5980 | return -1; | 
|  | 5981 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5982 | return 0; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5983 | } | 
|  | 5984 |  | 
|  | 5985 |  | 
|  | 5986 | static int wpa_driver_nl80211_try_connect( | 
|  | 5987 | struct wpa_driver_nl80211_data *drv, | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5988 | struct wpa_driver_associate_params *params, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 5989 | struct nl_sock *nl_connect) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5990 | { | 
|  | 5991 | struct nl_msg *msg; | 
|  | 5992 | enum nl80211_auth_type type; | 
|  | 5993 | int ret; | 
|  | 5994 | int algs; | 
|  | 5995 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5996 | #ifdef CONFIG_DRIVER_NL80211_QCA | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5997 | if (params->req_key_mgmt_offload && params->psk && | 
|  | 5998 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || | 
|  | 5999 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || | 
|  | 6000 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { | 
|  | 6001 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); | 
|  | 6002 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); | 
|  | 6003 | if (ret) | 
|  | 6004 | return ret; | 
|  | 6005 | } | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6006 | #endif /* CONFIG_DRIVER_NL80211_QCA */ | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6007 |  | 
|  | 6008 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); | 
|  | 6009 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6010 | if (!msg) | 
|  | 6011 | return -1; | 
|  | 6012 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6013 | ret = nl80211_connect_common(drv, params, msg); | 
|  | 6014 | if (ret) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6015 | goto fail; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6016 |  | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6017 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && | 
|  | 6018 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) | 
|  | 6019 | goto fail; | 
|  | 6020 |  | 
|  | 6021 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_OPTIONAL && | 
|  | 6022 | (drv->capa.flags & WPA_DRIVER_FLAGS_MFP_OPTIONAL) && | 
|  | 6023 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_OPTIONAL)) | 
|  | 6024 | goto fail; | 
|  | 6025 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6026 | algs = 0; | 
|  | 6027 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) | 
|  | 6028 | algs++; | 
|  | 6029 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) | 
|  | 6030 | algs++; | 
|  | 6031 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) | 
|  | 6032 | algs++; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6033 | if (params->auth_alg & WPA_AUTH_ALG_FILS) | 
|  | 6034 | algs++; | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6035 | if (params->auth_alg & WPA_AUTH_ALG_FT) | 
|  | 6036 | algs++; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6037 | if (algs > 1) { | 
|  | 6038 | wpa_printf(MSG_DEBUG, "  * Leave out Auth Type for automatic " | 
|  | 6039 | "selection"); | 
|  | 6040 | goto skip_auth_type; | 
|  | 6041 | } | 
|  | 6042 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6043 | type = get_nl_auth_type(params->auth_alg); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6044 | wpa_printf(MSG_DEBUG, "  * Auth Type %d", type); | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6045 | if (type == NL80211_AUTHTYPE_MAX || | 
|  | 6046 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6047 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6048 |  | 
|  | 6049 | skip_auth_type: | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6050 | ret = nl80211_set_conn_keys(params, msg); | 
|  | 6051 | if (ret) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6052 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6053 |  | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 6054 | ret = send_and_recv_msgs_owner(drv, msg, nl_connect, 1, NULL, | 
|  | 6055 | (void *) -1); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6056 | msg = NULL; | 
|  | 6057 | if (ret) { | 
|  | 6058 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " | 
|  | 6059 | "(%s)", ret, strerror(-ret)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6060 | } else { | 
|  | 6061 | wpa_printf(MSG_DEBUG, | 
|  | 6062 | "nl80211: Connect request send successfully"); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6063 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6064 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6065 | fail: | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6066 | nl80211_nlmsg_clear(msg); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6067 | nlmsg_free(msg); | 
|  | 6068 | return ret; | 
|  | 6069 |  | 
|  | 6070 | } | 
|  | 6071 |  | 
|  | 6072 |  | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6073 | static int wpa_driver_nl80211_connect( | 
|  | 6074 | struct wpa_driver_nl80211_data *drv, | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6075 | struct wpa_driver_associate_params *params, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6076 | struct nl_sock *nl_connect) | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6077 | { | 
| Jithu Jance | a7c60b4 | 2014-12-03 18:54:40 +0530 | [diff] [blame] | 6078 | int ret; | 
|  | 6079 |  | 
|  | 6080 | /* Store the connection attempted bssid for future use */ | 
|  | 6081 | if (params->bssid) | 
|  | 6082 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); | 
|  | 6083 | else | 
|  | 6084 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); | 
|  | 6085 |  | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6086 | ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect); | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6087 | if (ret == -EALREADY) { | 
|  | 6088 | /* | 
|  | 6089 | * cfg80211 does not currently accept new connections if | 
|  | 6090 | * we are already connected. As a workaround, force | 
|  | 6091 | * disconnection and try again. | 
|  | 6092 | */ | 
|  | 6093 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " | 
|  | 6094 | "disconnecting before reassociation " | 
|  | 6095 | "attempt"); | 
|  | 6096 | if (wpa_driver_nl80211_disconnect( | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6097 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID, nl_connect)) | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6098 | return -1; | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6099 | ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect); | 
| Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6100 | } | 
|  | 6101 | return ret; | 
|  | 6102 | } | 
|  | 6103 |  | 
|  | 6104 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6105 | static int wpa_driver_nl80211_associate( | 
|  | 6106 | void *priv, struct wpa_driver_associate_params *params) | 
|  | 6107 | { | 
|  | 6108 | struct i802_bss *bss = priv; | 
|  | 6109 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6110 | int ret = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6111 | struct nl_msg *msg; | 
|  | 6112 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6113 | nl80211_unmask_11b_rates(bss); | 
|  | 6114 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6115 | if (params->mode == IEEE80211_MODE_AP) | 
|  | 6116 | return wpa_driver_nl80211_ap(drv, params); | 
|  | 6117 |  | 
|  | 6118 | if (params->mode == IEEE80211_MODE_IBSS) | 
|  | 6119 | return wpa_driver_nl80211_ibss(drv, params); | 
|  | 6120 |  | 
|  | 6121 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6122 | enum nl80211_iftype nlmode = params->p2p ? | 
|  | 6123 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; | 
|  | 6124 |  | 
|  | 6125 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6126 | return -1; | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 6127 | if (params->key_mgmt_suite == WPA_KEY_MGMT_SAE || | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 6128 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE) | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6129 | bss->use_nl_connect = 1; | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 6130 | else | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6131 | bss->use_nl_connect = 0; | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6132 |  | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 6133 | return wpa_driver_nl80211_connect(drv, params, | 
|  | 6134 | get_connect_handle(bss)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6135 | } | 
|  | 6136 |  | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6137 | nl80211_mark_disconnected(drv); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6138 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6139 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", | 
|  | 6140 | drv->ifindex); | 
|  | 6141 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6142 | if (!msg) | 
|  | 6143 | return -1; | 
|  | 6144 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6145 | ret = nl80211_connect_common(drv, params, msg); | 
|  | 6146 | if (ret) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6147 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6148 |  | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6149 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && | 
|  | 6150 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) | 
|  | 6151 | goto fail; | 
|  | 6152 |  | 
| Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 6153 | if (params->fils_kek) { | 
|  | 6154 | wpa_printf(MSG_DEBUG, "  * FILS KEK (len=%u)", | 
|  | 6155 | (unsigned int) params->fils_kek_len); | 
|  | 6156 | if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len, | 
|  | 6157 | params->fils_kek)) | 
|  | 6158 | goto fail; | 
|  | 6159 | } | 
|  | 6160 | if (params->fils_nonces) { | 
|  | 6161 | wpa_hexdump(MSG_DEBUG, "  * FILS nonces (for AAD)", | 
|  | 6162 | params->fils_nonces, | 
|  | 6163 | params->fils_nonces_len); | 
|  | 6164 | if (nla_put(msg, NL80211_ATTR_FILS_NONCES, | 
|  | 6165 | params->fils_nonces_len, params->fils_nonces)) | 
|  | 6166 | goto fail; | 
|  | 6167 | } | 
|  | 6168 |  | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 6169 | ret = send_and_recv_msgs_owner(drv, msg, | 
|  | 6170 | get_connect_handle(drv->first_bss), 1, | 
|  | 6171 | NULL, NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6172 | msg = NULL; | 
|  | 6173 | if (ret) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6174 | wpa_dbg(drv->ctx, MSG_DEBUG, | 
|  | 6175 | "nl80211: MLME command failed (assoc): ret=%d (%s)", | 
|  | 6176 | ret, strerror(-ret)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6177 | nl80211_dump_scan(drv); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6178 | } else { | 
|  | 6179 | wpa_printf(MSG_DEBUG, | 
|  | 6180 | "nl80211: Association request send successfully"); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6181 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6182 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6183 | fail: | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6184 | nlmsg_free(msg); | 
|  | 6185 | return ret; | 
|  | 6186 | } | 
|  | 6187 |  | 
|  | 6188 |  | 
|  | 6189 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6190 | int ifindex, enum nl80211_iftype mode) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6191 | { | 
|  | 6192 | struct nl_msg *msg; | 
|  | 6193 | int ret = -ENOBUFS; | 
|  | 6194 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6195 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", | 
|  | 6196 | ifindex, mode, nl80211_iftype_str(mode)); | 
|  | 6197 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6198 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); | 
|  | 6199 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) | 
|  | 6200 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6201 |  | 
|  | 6202 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6203 | msg = NULL; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6204 | if (!ret) | 
|  | 6205 | return 0; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6206 | fail: | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6207 | nlmsg_free(msg); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6208 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" | 
|  | 6209 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); | 
|  | 6210 | return ret; | 
|  | 6211 | } | 
|  | 6212 |  | 
|  | 6213 |  | 
| Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6214 | static int wpa_driver_nl80211_set_mode_impl( | 
|  | 6215 | struct i802_bss *bss, | 
|  | 6216 | enum nl80211_iftype nlmode, | 
|  | 6217 | struct hostapd_freq_params *desired_freq_params) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6218 | { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6219 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 6220 | int ret = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6221 | int i; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6222 | int was_ap = is_ap_interface(drv->nlmode); | 
|  | 6223 | int res; | 
| Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6224 | int mode_switch_res; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6225 |  | 
| Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 6226 | if (TEST_FAIL()) | 
|  | 6227 | return -1; | 
|  | 6228 |  | 
| Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6229 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); | 
|  | 6230 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) | 
|  | 6231 | mode_switch_res = 0; | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6232 |  | 
| Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6233 | if (mode_switch_res == 0) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6234 | drv->nlmode = nlmode; | 
|  | 6235 | ret = 0; | 
|  | 6236 | goto done; | 
|  | 6237 | } | 
|  | 6238 |  | 
| Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6239 | if (mode_switch_res == -ENODEV) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6240 | return -1; | 
|  | 6241 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6242 | if (nlmode == drv->nlmode) { | 
|  | 6243 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " | 
|  | 6244 | "requested mode - ignore error"); | 
|  | 6245 | ret = 0; | 
|  | 6246 | goto done; /* Already in the requested mode */ | 
|  | 6247 | } | 
|  | 6248 |  | 
|  | 6249 | /* mac80211 doesn't allow mode changes while the device is up, so | 
|  | 6250 | * take the device down, try to set the mode again, and bring the | 
|  | 6251 | * device back up. | 
|  | 6252 | */ | 
|  | 6253 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " | 
|  | 6254 | "interface down"); | 
|  | 6255 | for (i = 0; i < 10; i++) { | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6256 | res = i802_set_iface_flags(bss, 0); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6257 | if (res == -EACCES || res == -ENODEV) | 
|  | 6258 | break; | 
| Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6259 | if (res != 0) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6260 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " | 
|  | 6261 | "interface down"); | 
| Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6262 | os_sleep(0, 100000); | 
|  | 6263 | continue; | 
|  | 6264 | } | 
|  | 6265 |  | 
|  | 6266 | /* | 
|  | 6267 | * Setting the mode will fail for some drivers if the phy is | 
|  | 6268 | * on a frequency that the mode is disallowed in. | 
|  | 6269 | */ | 
|  | 6270 | if (desired_freq_params) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6271 | res = nl80211_set_channel(bss, desired_freq_params, 0); | 
| Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6272 | if (res) { | 
|  | 6273 | wpa_printf(MSG_DEBUG, | 
|  | 6274 | "nl80211: Failed to set frequency on interface"); | 
|  | 6275 | } | 
|  | 6276 | } | 
|  | 6277 |  | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 6278 | if (i == 0 && was_ap && !is_ap_interface(nlmode) && | 
|  | 6279 | bss->brname[0] && | 
|  | 6280 | (bss->added_if_into_bridge || bss->already_in_bridge)) { | 
|  | 6281 | wpa_printf(MSG_DEBUG, | 
|  | 6282 | "nl80211: Remove AP interface %s temporarily from the bridge %s to allow its mode to be set to STATION", | 
|  | 6283 | bss->ifname, bss->brname); | 
|  | 6284 | if (linux_br_del_if(drv->global->ioctl_sock, | 
|  | 6285 | bss->brname, bss->ifname) < 0) | 
|  | 6286 | wpa_printf(MSG_INFO, | 
|  | 6287 | "nl80211: Failed to remove interface %s from bridge %s: %s", | 
|  | 6288 | bss->ifname, bss->brname, | 
|  | 6289 | strerror(errno)); | 
|  | 6290 | } | 
|  | 6291 |  | 
| Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6292 | /* Try to set the mode again while the interface is down */ | 
|  | 6293 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); | 
|  | 6294 | if (mode_switch_res == -EBUSY) { | 
|  | 6295 | wpa_printf(MSG_DEBUG, | 
|  | 6296 | "nl80211: Delaying mode set while interface going down"); | 
|  | 6297 | os_sleep(0, 100000); | 
|  | 6298 | continue; | 
|  | 6299 | } | 
|  | 6300 | ret = mode_switch_res; | 
|  | 6301 | break; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6302 | } | 
|  | 6303 |  | 
|  | 6304 | if (!ret) { | 
|  | 6305 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " | 
|  | 6306 | "interface is down"); | 
|  | 6307 | drv->nlmode = nlmode; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6308 | drv->ignore_if_down_event = 1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6309 | } | 
|  | 6310 |  | 
| Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6311 | /* Bring the interface back up */ | 
|  | 6312 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); | 
|  | 6313 | if (res != 0) { | 
|  | 6314 | wpa_printf(MSG_DEBUG, | 
|  | 6315 | "nl80211: Failed to set interface up after switching mode"); | 
|  | 6316 | ret = -1; | 
|  | 6317 | } | 
|  | 6318 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6319 | done: | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6320 | if (ret) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6321 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " | 
|  | 6322 | "from %d failed", nlmode, drv->nlmode); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6323 | return ret; | 
|  | 6324 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6325 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6326 | if (is_p2p_net_interface(nlmode)) { | 
|  | 6327 | wpa_printf(MSG_DEBUG, | 
|  | 6328 | "nl80211: Interface %s mode change to P2P - disable 11b rates", | 
|  | 6329 | bss->ifname); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6330 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6331 | } else if (drv->disabled_11b_rates) { | 
|  | 6332 | wpa_printf(MSG_DEBUG, | 
|  | 6333 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", | 
|  | 6334 | bss->ifname); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6335 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6336 | } | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6337 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6338 | if (is_ap_interface(nlmode)) { | 
|  | 6339 | nl80211_mgmt_unsubscribe(bss, "start AP"); | 
|  | 6340 | /* Setup additional AP mode functionality if needed */ | 
|  | 6341 | if (nl80211_setup_ap(bss)) | 
|  | 6342 | return -1; | 
|  | 6343 | } else if (was_ap) { | 
|  | 6344 | /* Remove additional AP mode functionality */ | 
|  | 6345 | nl80211_teardown_ap(bss); | 
|  | 6346 | } else { | 
|  | 6347 | nl80211_mgmt_unsubscribe(bss, "mode change"); | 
|  | 6348 | } | 
|  | 6349 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6350 | if (is_mesh_interface(nlmode) && | 
|  | 6351 | nl80211_mgmt_subscribe_mesh(bss)) | 
|  | 6352 | return -1; | 
|  | 6353 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6354 | if (!bss->in_deinit && !is_ap_interface(nlmode) && | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6355 | !is_mesh_interface(nlmode) && | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6356 | nl80211_mgmt_subscribe_non_ap(bss) < 0) | 
|  | 6357 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " | 
|  | 6358 | "frame processing - ignore for now"); | 
|  | 6359 |  | 
|  | 6360 | return 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6361 | } | 
|  | 6362 |  | 
|  | 6363 |  | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 6364 | void nl80211_restore_ap_mode(struct i802_bss *bss) | 
|  | 6365 | { | 
|  | 6366 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 6367 | int was_ap = is_ap_interface(drv->nlmode); | 
|  | 6368 |  | 
|  | 6369 | wpa_driver_nl80211_set_mode(bss, drv->ap_scan_as_station); | 
|  | 6370 | if (!was_ap && is_ap_interface(drv->ap_scan_as_station) && | 
|  | 6371 | bss->brname[0] && | 
|  | 6372 | (bss->added_if_into_bridge || bss->already_in_bridge)) { | 
|  | 6373 | wpa_printf(MSG_DEBUG, | 
|  | 6374 | "nl80211: Add AP interface %s back into the bridge %s", | 
|  | 6375 | bss->ifname, bss->brname); | 
|  | 6376 | if (linux_br_add_if(drv->global->ioctl_sock, bss->brname, | 
|  | 6377 | bss->ifname) < 0) { | 
|  | 6378 | wpa_printf(MSG_WARNING, | 
|  | 6379 | "nl80211: Failed to add interface %s into bridge %s: %s", | 
|  | 6380 | bss->ifname, bss->brname, strerror(errno)); | 
|  | 6381 | } | 
|  | 6382 | } | 
|  | 6383 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; | 
|  | 6384 | } | 
|  | 6385 |  | 
|  | 6386 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6387 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, | 
|  | 6388 | enum nl80211_iftype nlmode) | 
| Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6389 | { | 
|  | 6390 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); | 
|  | 6391 | } | 
|  | 6392 |  | 
|  | 6393 |  | 
| Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6394 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, | 
|  | 6395 | struct hostapd_freq_params *freq) | 
| Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6396 | { | 
| Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6397 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, | 
| Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6398 | freq); | 
| Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6399 | } | 
|  | 6400 |  | 
|  | 6401 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6402 | static int wpa_driver_nl80211_get_capa(void *priv, | 
|  | 6403 | struct wpa_driver_capa *capa) | 
|  | 6404 | { | 
|  | 6405 | struct i802_bss *bss = priv; | 
|  | 6406 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
| Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 6407 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6408 | if (!drv->has_capability) | 
|  | 6409 | return -1; | 
|  | 6410 | os_memcpy(capa, &drv->capa, sizeof(*capa)); | 
| Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 6411 | if (drv->extended_capa && drv->extended_capa_mask) { | 
|  | 6412 | capa->extended_capa = drv->extended_capa; | 
|  | 6413 | capa->extended_capa_mask = drv->extended_capa_mask; | 
|  | 6414 | capa->extended_capa_len = drv->extended_capa_len; | 
|  | 6415 | } | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6416 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6417 | return 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6418 | } | 
|  | 6419 |  | 
|  | 6420 |  | 
|  | 6421 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) | 
|  | 6422 | { | 
|  | 6423 | struct i802_bss *bss = priv; | 
|  | 6424 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 6425 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6426 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", | 
|  | 6427 | bss->ifname, drv->operstate, state, | 
|  | 6428 | state ? "UP" : "DORMANT"); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6429 | drv->operstate = state; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6430 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6431 | state ? IF_OPER_UP : IF_OPER_DORMANT); | 
|  | 6432 | } | 
|  | 6433 |  | 
|  | 6434 |  | 
|  | 6435 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) | 
|  | 6436 | { | 
|  | 6437 | struct i802_bss *bss = priv; | 
|  | 6438 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 6439 | struct nl_msg *msg; | 
|  | 6440 | struct nl80211_sta_flag_update upd; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6441 | int ret; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6442 |  | 
|  | 6443 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { | 
|  | 6444 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); | 
|  | 6445 | return 0; | 
|  | 6446 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6447 |  | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6448 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " | 
|  | 6449 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); | 
|  | 6450 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6451 | os_memset(&upd, 0, sizeof(upd)); | 
|  | 6452 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); | 
|  | 6453 | if (authorized) | 
|  | 6454 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6455 |  | 
|  | 6456 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || | 
|  | 6457 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || | 
|  | 6458 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { | 
|  | 6459 | nlmsg_free(msg); | 
|  | 6460 | return -ENOBUFS; | 
|  | 6461 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6462 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6463 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6464 | if (!ret) | 
|  | 6465 | return 0; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6466 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", | 
|  | 6467 | ret, strerror(-ret)); | 
|  | 6468 | return ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6469 | } | 
|  | 6470 |  | 
|  | 6471 |  | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6472 | /* Set kernel driver on given frequency (MHz) */ | 
|  | 6473 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6474 | { | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6475 | struct i802_bss *bss = priv; | 
| Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 6476 | return nl80211_set_channel(bss, freq, 0); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6477 | } | 
|  | 6478 |  | 
|  | 6479 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6480 | static inline int min_int(int a, int b) | 
|  | 6481 | { | 
|  | 6482 | if (a < b) | 
|  | 6483 | return a; | 
|  | 6484 | return b; | 
|  | 6485 | } | 
|  | 6486 |  | 
|  | 6487 |  | 
|  | 6488 | static int get_key_handler(struct nl_msg *msg, void *arg) | 
|  | 6489 | { | 
|  | 6490 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | 
|  | 6491 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | 
|  | 6492 |  | 
|  | 6493 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | 
|  | 6494 | genlmsg_attrlen(gnlh, 0), NULL); | 
|  | 6495 |  | 
|  | 6496 | /* | 
|  | 6497 | * TODO: validate the key index and mac address! | 
|  | 6498 | * Otherwise, there's a race condition as soon as | 
|  | 6499 | * the kernel starts sending key notifications. | 
|  | 6500 | */ | 
|  | 6501 |  | 
|  | 6502 | if (tb[NL80211_ATTR_KEY_SEQ]) | 
|  | 6503 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), | 
|  | 6504 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6505 | nl80211_nlmsg_clear(msg); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6506 | return NL_SKIP; | 
|  | 6507 | } | 
|  | 6508 |  | 
|  | 6509 |  | 
|  | 6510 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, | 
|  | 6511 | int idx, u8 *seq) | 
|  | 6512 | { | 
|  | 6513 | struct i802_bss *bss = priv; | 
|  | 6514 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 6515 | struct nl_msg *msg; | 
|  | 6516 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6517 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, | 
|  | 6518 | NL80211_CMD_GET_KEY); | 
|  | 6519 | if (!msg || | 
|  | 6520 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || | 
|  | 6521 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { | 
|  | 6522 | nlmsg_free(msg); | 
|  | 6523 | return -ENOBUFS; | 
|  | 6524 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6525 |  | 
|  | 6526 | memset(seq, 0, 6); | 
|  | 6527 |  | 
|  | 6528 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6529 | } | 
|  | 6530 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6531 |  | 
|  | 6532 | static int i802_set_rts(void *priv, int rts) | 
|  | 6533 | { | 
|  | 6534 | struct i802_bss *bss = priv; | 
|  | 6535 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 6536 | struct nl_msg *msg; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6537 | int ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6538 | u32 val; | 
|  | 6539 |  | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6540 | if (rts >= 2347 || rts == -1) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6541 | val = (u32) -1; | 
|  | 6542 | else | 
|  | 6543 | val = rts; | 
|  | 6544 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6545 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || | 
|  | 6546 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { | 
|  | 6547 | nlmsg_free(msg); | 
|  | 6548 | return -ENOBUFS; | 
|  | 6549 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6550 |  | 
|  | 6551 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 6552 | if (!ret) | 
|  | 6553 | return 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6554 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " | 
|  | 6555 | "%d (%s)", rts, ret, strerror(-ret)); | 
|  | 6556 | return ret; | 
|  | 6557 | } | 
|  | 6558 |  | 
|  | 6559 |  | 
|  | 6560 | static int i802_set_frag(void *priv, int frag) | 
|  | 6561 | { | 
|  | 6562 | struct i802_bss *bss = priv; | 
|  | 6563 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 6564 | struct nl_msg *msg; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6565 | int ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6566 | u32 val; | 
|  | 6567 |  | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6568 | if (frag >= 2346 || frag == -1) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6569 | val = (u32) -1; | 
|  | 6570 | else | 
|  | 6571 | val = frag; | 
|  | 6572 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6573 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || | 
|  | 6574 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { | 
|  | 6575 | nlmsg_free(msg); | 
|  | 6576 | return -ENOBUFS; | 
|  | 6577 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6578 |  | 
|  | 6579 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 6580 | if (!ret) | 
|  | 6581 | return 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6582 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " | 
|  | 6583 | "%d: %d (%s)", frag, ret, strerror(-ret)); | 
|  | 6584 | return ret; | 
|  | 6585 | } | 
|  | 6586 |  | 
|  | 6587 |  | 
|  | 6588 | static int i802_flush(void *priv) | 
|  | 6589 | { | 
|  | 6590 | struct i802_bss *bss = priv; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6591 | struct nl_msg *msg; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6592 | int res; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6593 |  | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6594 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", | 
|  | 6595 | bss->ifname); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6596 |  | 
|  | 6597 | /* | 
|  | 6598 | * XXX: FIX! this needs to flush all VLANs too | 
|  | 6599 | */ | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6600 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); | 
|  | 6601 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6602 | if (res) { | 
|  | 6603 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " | 
|  | 6604 | "(%s)", res, strerror(-res)); | 
|  | 6605 | } | 
|  | 6606 | return res; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6607 | } | 
|  | 6608 |  | 
|  | 6609 |  | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6610 | static void get_sta_tid_stats(struct hostap_sta_driver_data *data, | 
|  | 6611 | struct nlattr *attr) | 
|  | 6612 | { | 
|  | 6613 | struct nlattr *tid_stats[NL80211_TID_STATS_MAX + 1], *tidattr; | 
|  | 6614 | struct nlattr *txq_stats[NL80211_TXQ_STATS_MAX + 1]; | 
|  | 6615 | static struct nla_policy txq_stats_policy[NL80211_TXQ_STATS_MAX + 1] = { | 
|  | 6616 | [NL80211_TXQ_STATS_BACKLOG_BYTES] = { .type = NLA_U32 }, | 
|  | 6617 | [NL80211_TXQ_STATS_BACKLOG_PACKETS] = { .type = NLA_U32 }, | 
|  | 6618 | }; | 
|  | 6619 | int rem; | 
|  | 6620 |  | 
|  | 6621 | nla_for_each_nested(tidattr, attr, rem) { | 
|  | 6622 | if (nla_parse_nested(tid_stats, NL80211_TID_STATS_MAX, | 
|  | 6623 | tidattr, NULL) != 0 || | 
|  | 6624 | !tid_stats[NL80211_TID_STATS_TXQ_STATS] || | 
|  | 6625 | nla_parse_nested(txq_stats, NL80211_TXQ_STATS_MAX, | 
|  | 6626 | tid_stats[NL80211_TID_STATS_TXQ_STATS], | 
|  | 6627 | txq_stats_policy) != 0) | 
|  | 6628 | continue; | 
|  | 6629 | /* sum the backlogs over all TIDs for station */ | 
|  | 6630 | if (txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]) | 
|  | 6631 | data->backlog_bytes += nla_get_u32( | 
|  | 6632 | txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]); | 
|  | 6633 | if (txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]) | 
|  | 6634 | data->backlog_bytes += nla_get_u32( | 
|  | 6635 | txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]); | 
|  | 6636 | } | 
|  | 6637 | } | 
|  | 6638 |  | 
|  | 6639 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6640 | static int get_sta_handler(struct nl_msg *msg, void *arg) | 
|  | 6641 | { | 
|  | 6642 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | 
|  | 6643 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | 
|  | 6644 | struct hostap_sta_driver_data *data = arg; | 
|  | 6645 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; | 
|  | 6646 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { | 
|  | 6647 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, | 
|  | 6648 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, | 
|  | 6649 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, | 
|  | 6650 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, | 
|  | 6651 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, | 
| Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 6652 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6653 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, | 
|  | 6654 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6655 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6656 | [NL80211_STA_INFO_ACK_SIGNAL] = { .type = NLA_U8 }, | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6657 | [NL80211_STA_INFO_RX_DURATION] = { .type = NLA_U64 }, | 
|  | 6658 | [NL80211_STA_INFO_TX_DURATION] = { .type = NLA_U64 }, | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6659 | }; | 
|  | 6660 | struct nlattr *rate[NL80211_RATE_INFO_MAX + 1]; | 
|  | 6661 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { | 
|  | 6662 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, | 
|  | 6663 | [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 }, | 
|  | 6664 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, | 
|  | 6665 | [NL80211_RATE_INFO_VHT_MCS] = { .type = NLA_U8 }, | 
|  | 6666 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, | 
|  | 6667 | [NL80211_RATE_INFO_VHT_NSS] = { .type = NLA_U8 }, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6668 | }; | 
|  | 6669 |  | 
|  | 6670 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | 
|  | 6671 | genlmsg_attrlen(gnlh, 0), NULL); | 
|  | 6672 |  | 
|  | 6673 | /* | 
|  | 6674 | * TODO: validate the interface and mac address! | 
|  | 6675 | * Otherwise, there's a race condition as soon as | 
|  | 6676 | * the kernel starts sending station notifications. | 
|  | 6677 | */ | 
|  | 6678 |  | 
|  | 6679 | if (!tb[NL80211_ATTR_STA_INFO]) { | 
|  | 6680 | wpa_printf(MSG_DEBUG, "sta stats missing!"); | 
|  | 6681 | return NL_SKIP; | 
|  | 6682 | } | 
|  | 6683 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, | 
|  | 6684 | tb[NL80211_ATTR_STA_INFO], | 
|  | 6685 | stats_policy)) { | 
|  | 6686 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); | 
|  | 6687 | return NL_SKIP; | 
|  | 6688 | } | 
|  | 6689 |  | 
|  | 6690 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) | 
|  | 6691 | data->inactive_msec = | 
|  | 6692 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6693 | /* For backwards compatibility, fetch the 32-bit counters first. */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6694 | if (stats[NL80211_STA_INFO_RX_BYTES]) | 
|  | 6695 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); | 
|  | 6696 | if (stats[NL80211_STA_INFO_TX_BYTES]) | 
|  | 6697 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6698 | if (stats[NL80211_STA_INFO_RX_BYTES64] && | 
|  | 6699 | stats[NL80211_STA_INFO_TX_BYTES64]) { | 
|  | 6700 | /* | 
|  | 6701 | * The driver supports 64-bit counters, so use them to override | 
|  | 6702 | * the 32-bit values. | 
|  | 6703 | */ | 
|  | 6704 | data->rx_bytes = | 
|  | 6705 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); | 
|  | 6706 | data->tx_bytes = | 
|  | 6707 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); | 
|  | 6708 | data->bytes_64bit = 1; | 
|  | 6709 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6710 | if (stats[NL80211_STA_INFO_RX_PACKETS]) | 
|  | 6711 | data->rx_packets = | 
|  | 6712 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); | 
|  | 6713 | if (stats[NL80211_STA_INFO_TX_PACKETS]) | 
|  | 6714 | data->tx_packets = | 
|  | 6715 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6716 | if (stats[NL80211_STA_INFO_RX_DURATION]) | 
|  | 6717 | data->rx_airtime = | 
|  | 6718 | nla_get_u64(stats[NL80211_STA_INFO_RX_DURATION]); | 
|  | 6719 | if (stats[NL80211_STA_INFO_TX_DURATION]) | 
|  | 6720 | data->tx_airtime = | 
|  | 6721 | nla_get_u64(stats[NL80211_STA_INFO_TX_DURATION]); | 
| Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 6722 | if (stats[NL80211_STA_INFO_TX_FAILED]) | 
|  | 6723 | data->tx_retry_failed = | 
|  | 6724 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6725 | if (stats[NL80211_STA_INFO_SIGNAL]) | 
|  | 6726 | data->signal = nla_get_u8(stats[NL80211_STA_INFO_SIGNAL]); | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6727 | if (stats[NL80211_STA_INFO_ACK_SIGNAL]) { | 
|  | 6728 | data->last_ack_rssi = | 
|  | 6729 | nla_get_u8(stats[NL80211_STA_INFO_ACK_SIGNAL]); | 
|  | 6730 | data->flags |= STA_DRV_DATA_LAST_ACK_RSSI; | 
|  | 6731 | } | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6732 |  | 
|  | 6733 | if (stats[NL80211_STA_INFO_TX_BITRATE] && | 
|  | 6734 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, | 
|  | 6735 | stats[NL80211_STA_INFO_TX_BITRATE], | 
|  | 6736 | rate_policy) == 0) { | 
|  | 6737 | if (rate[NL80211_RATE_INFO_BITRATE32]) | 
|  | 6738 | data->current_tx_rate = | 
|  | 6739 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); | 
|  | 6740 | else if (rate[NL80211_RATE_INFO_BITRATE]) | 
|  | 6741 | data->current_tx_rate = | 
|  | 6742 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); | 
|  | 6743 |  | 
|  | 6744 | if (rate[NL80211_RATE_INFO_MCS]) { | 
|  | 6745 | data->tx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]); | 
|  | 6746 | data->flags |= STA_DRV_DATA_TX_MCS; | 
|  | 6747 | } | 
|  | 6748 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { | 
|  | 6749 | data->tx_vhtmcs = | 
|  | 6750 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); | 
|  | 6751 | data->flags |= STA_DRV_DATA_TX_VHT_MCS; | 
|  | 6752 | } | 
|  | 6753 | if (rate[NL80211_RATE_INFO_SHORT_GI]) | 
|  | 6754 | data->flags |= STA_DRV_DATA_TX_SHORT_GI; | 
|  | 6755 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { | 
|  | 6756 | data->tx_vht_nss = | 
|  | 6757 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); | 
|  | 6758 | data->flags |= STA_DRV_DATA_TX_VHT_NSS; | 
|  | 6759 | } | 
|  | 6760 | } | 
|  | 6761 |  | 
|  | 6762 | if (stats[NL80211_STA_INFO_RX_BITRATE] && | 
|  | 6763 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, | 
|  | 6764 | stats[NL80211_STA_INFO_RX_BITRATE], | 
|  | 6765 | rate_policy) == 0) { | 
|  | 6766 | if (rate[NL80211_RATE_INFO_BITRATE32]) | 
|  | 6767 | data->current_rx_rate = | 
|  | 6768 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); | 
|  | 6769 | else if (rate[NL80211_RATE_INFO_BITRATE]) | 
|  | 6770 | data->current_rx_rate = | 
|  | 6771 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); | 
|  | 6772 |  | 
|  | 6773 | if (rate[NL80211_RATE_INFO_MCS]) { | 
|  | 6774 | data->rx_mcs = | 
|  | 6775 | nla_get_u8(rate[NL80211_RATE_INFO_MCS]); | 
|  | 6776 | data->flags |= STA_DRV_DATA_RX_MCS; | 
|  | 6777 | } | 
|  | 6778 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { | 
|  | 6779 | data->rx_vhtmcs = | 
|  | 6780 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); | 
|  | 6781 | data->flags |= STA_DRV_DATA_RX_VHT_MCS; | 
|  | 6782 | } | 
|  | 6783 | if (rate[NL80211_RATE_INFO_SHORT_GI]) | 
|  | 6784 | data->flags |= STA_DRV_DATA_RX_SHORT_GI; | 
|  | 6785 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { | 
|  | 6786 | data->rx_vht_nss = | 
|  | 6787 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); | 
|  | 6788 | data->flags |= STA_DRV_DATA_RX_VHT_NSS; | 
|  | 6789 | } | 
|  | 6790 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6791 |  | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6792 | if (stats[NL80211_STA_INFO_TID_STATS]) | 
|  | 6793 | get_sta_tid_stats(data, stats[NL80211_STA_INFO_TID_STATS]); | 
|  | 6794 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6795 | return NL_SKIP; | 
|  | 6796 | } | 
|  | 6797 |  | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6798 | static int i802_read_sta_data(struct i802_bss *bss, | 
|  | 6799 | struct hostap_sta_driver_data *data, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6800 | const u8 *addr) | 
|  | 6801 | { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6802 | struct nl_msg *msg; | 
|  | 6803 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6804 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || | 
|  | 6805 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | 
|  | 6806 | nlmsg_free(msg); | 
|  | 6807 | return -ENOBUFS; | 
|  | 6808 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6809 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6810 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6811 | } | 
|  | 6812 |  | 
|  | 6813 |  | 
|  | 6814 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, | 
|  | 6815 | int cw_min, int cw_max, int burst_time) | 
|  | 6816 | { | 
|  | 6817 | struct i802_bss *bss = priv; | 
|  | 6818 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 6819 | struct nl_msg *msg; | 
|  | 6820 | struct nlattr *txq, *params; | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6821 | int res; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6822 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6823 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6824 | if (!msg) | 
|  | 6825 | return -1; | 
|  | 6826 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6827 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); | 
|  | 6828 | if (!txq) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6829 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6830 |  | 
|  | 6831 | /* We are only sending parameters for a single TXQ at a time */ | 
|  | 6832 | params = nla_nest_start(msg, 1); | 
|  | 6833 | if (!params) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6834 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6835 |  | 
|  | 6836 | switch (queue) { | 
|  | 6837 | case 0: | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6838 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) | 
|  | 6839 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6840 | break; | 
|  | 6841 | case 1: | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6842 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) | 
|  | 6843 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6844 | break; | 
|  | 6845 | case 2: | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6846 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) | 
|  | 6847 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6848 | break; | 
|  | 6849 | case 3: | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6850 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) | 
|  | 6851 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6852 | break; | 
|  | 6853 | } | 
|  | 6854 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in | 
|  | 6855 | * 32 usec, so need to convert the value here. */ | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6856 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, | 
|  | 6857 | (burst_time * 100 + 16) / 32) || | 
|  | 6858 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || | 
|  | 6859 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || | 
|  | 6860 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) | 
|  | 6861 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6862 |  | 
|  | 6863 | nla_nest_end(msg, params); | 
|  | 6864 |  | 
|  | 6865 | nla_nest_end(msg, txq); | 
|  | 6866 |  | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6867 | res = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 6868 | wpa_printf(MSG_DEBUG, | 
|  | 6869 | "nl80211: TX queue param set: queue=%d aifs=%d cw_min=%d cw_max=%d burst_time=%d --> res=%d", | 
|  | 6870 | queue, aifs, cw_min, cw_max, burst_time, res); | 
|  | 6871 | if (res == 0) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6872 | return 0; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6873 | msg = NULL; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6874 | fail: | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6875 | nlmsg_free(msg); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6876 | return -1; | 
|  | 6877 | } | 
|  | 6878 |  | 
|  | 6879 |  | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6880 | 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] | 6881 | const char *ifname, int vlan_id) | 
|  | 6882 | { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6883 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 6884 | struct nl_msg *msg; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6885 | int ret; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6886 |  | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6887 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR | 
|  | 6888 | ", ifname=%s[%d], vlan_id=%d)", | 
|  | 6889 | bss->ifname, if_nametoindex(bss->ifname), | 
|  | 6890 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6891 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || | 
|  | 6892 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6893 | ((drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD) && | 
|  | 6894 | nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) || | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6895 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { | 
|  | 6896 | nlmsg_free(msg); | 
|  | 6897 | return -ENOBUFS; | 
|  | 6898 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6899 |  | 
|  | 6900 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 6901 | if (ret < 0) { | 
|  | 6902 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" | 
|  | 6903 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", | 
|  | 6904 | MAC2STR(addr), ifname, vlan_id, ret, | 
|  | 6905 | strerror(-ret)); | 
|  | 6906 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6907 | return ret; | 
|  | 6908 | } | 
|  | 6909 |  | 
|  | 6910 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6911 | static int i802_get_inact_sec(void *priv, const u8 *addr) | 
|  | 6912 | { | 
|  | 6913 | struct hostap_sta_driver_data data; | 
|  | 6914 | int ret; | 
|  | 6915 |  | 
| Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 6916 | os_memset(&data, 0, sizeof(data)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6917 | data.inactive_msec = (unsigned long) -1; | 
|  | 6918 | ret = i802_read_sta_data(priv, &data, addr); | 
| Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6919 | if (ret == -ENOENT) | 
|  | 6920 | return -ENOENT; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6921 | if (ret || data.inactive_msec == (unsigned long) -1) | 
|  | 6922 | return -1; | 
|  | 6923 | return data.inactive_msec / 1000; | 
|  | 6924 | } | 
|  | 6925 |  | 
|  | 6926 |  | 
|  | 6927 | static int i802_sta_clear_stats(void *priv, const u8 *addr) | 
|  | 6928 | { | 
|  | 6929 | #if 0 | 
|  | 6930 | /* TODO */ | 
|  | 6931 | #endif | 
|  | 6932 | return 0; | 
|  | 6933 | } | 
|  | 6934 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6935 |  | 
|  | 6936 | 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] | 6937 | u16 reason) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6938 | { | 
|  | 6939 | struct i802_bss *bss = priv; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6940 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6941 | struct ieee80211_mgmt mgmt; | 
| Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 6942 | u8 channel; | 
|  | 6943 |  | 
|  | 6944 | if (ieee80211_freq_to_chan(bss->freq, &channel) == | 
|  | 6945 | HOSTAPD_MODE_IEEE80211AD) { | 
|  | 6946 | /* Deauthentication is not used in DMG/IEEE 802.11ad; | 
|  | 6947 | * disassociate the STA instead. */ | 
|  | 6948 | return i802_sta_disassoc(priv, own_addr, addr, reason); | 
|  | 6949 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6950 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6951 | if (is_mesh_interface(drv->nlmode)) | 
|  | 6952 | return -1; | 
|  | 6953 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6954 | if (drv->device_ap_sme) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6955 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6956 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6957 | memset(&mgmt, 0, sizeof(mgmt)); | 
|  | 6958 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | 
|  | 6959 | WLAN_FC_STYPE_DEAUTH); | 
|  | 6960 | memcpy(mgmt.da, addr, ETH_ALEN); | 
|  | 6961 | memcpy(mgmt.sa, own_addr, ETH_ALEN); | 
|  | 6962 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | 
|  | 6963 | mgmt.u.deauth.reason_code = host_to_le16(reason); | 
|  | 6964 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, | 
|  | 6965 | IEEE80211_HDRLEN + | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6966 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6967 | 0, NULL, 0, 0); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6968 | } | 
|  | 6969 |  | 
|  | 6970 |  | 
|  | 6971 | 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] | 6972 | u16 reason) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6973 | { | 
|  | 6974 | struct i802_bss *bss = priv; | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6975 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6976 | struct ieee80211_mgmt mgmt; | 
|  | 6977 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6978 | if (is_mesh_interface(drv->nlmode)) | 
|  | 6979 | return -1; | 
|  | 6980 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6981 | if (drv->device_ap_sme) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6982 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6983 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6984 | memset(&mgmt, 0, sizeof(mgmt)); | 
|  | 6985 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, | 
|  | 6986 | WLAN_FC_STYPE_DISASSOC); | 
|  | 6987 | memcpy(mgmt.da, addr, ETH_ALEN); | 
|  | 6988 | memcpy(mgmt.sa, own_addr, ETH_ALEN); | 
|  | 6989 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); | 
|  | 6990 | mgmt.u.disassoc.reason_code = host_to_le16(reason); | 
|  | 6991 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, | 
|  | 6992 | IEEE80211_HDRLEN + | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6993 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 6994 | 0, NULL, 0, 0); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6995 | } | 
|  | 6996 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6997 |  | 
| Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6998 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) | 
|  | 6999 | { | 
|  | 7000 | char buf[200], *pos, *end; | 
|  | 7001 | int i, res; | 
|  | 7002 |  | 
|  | 7003 | pos = buf; | 
|  | 7004 | end = pos + sizeof(buf); | 
|  | 7005 |  | 
|  | 7006 | for (i = 0; i < drv->num_if_indices; i++) { | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7007 | if (!drv->if_indices[i].ifindex) | 
| Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7008 | continue; | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7009 | res = os_snprintf(pos, end - pos, " %d(%d)", | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7010 | drv->if_indices[i].ifindex, | 
|  | 7011 | drv->if_indices[i].reason); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7012 | if (os_snprintf_error(end - pos, res)) | 
| Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7013 | break; | 
|  | 7014 | pos += res; | 
|  | 7015 | } | 
|  | 7016 | *pos = '\0'; | 
|  | 7017 |  | 
|  | 7018 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", | 
|  | 7019 | drv->num_if_indices, buf); | 
|  | 7020 | } | 
|  | 7021 |  | 
|  | 7022 |  | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7023 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, | 
|  | 7024 | int ifidx_reason) | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7025 | { | 
|  | 7026 | int i; | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7027 | struct drv_nl80211_if_info *old; | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7028 |  | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7029 | wpa_printf(MSG_DEBUG, | 
|  | 7030 | "nl80211: Add own interface ifindex %d (ifidx_reason %d)", | 
|  | 7031 | ifidx, ifidx_reason); | 
|  | 7032 | if (have_ifidx(drv, ifidx, ifidx_reason)) { | 
| Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7033 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", | 
|  | 7034 | ifidx); | 
|  | 7035 | return; | 
|  | 7036 | } | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7037 | for (i = 0; i < drv->num_if_indices; i++) { | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7038 | if (drv->if_indices[i].ifindex == 0) { | 
|  | 7039 | drv->if_indices[i].ifindex = ifidx; | 
|  | 7040 | drv->if_indices[i].reason = ifidx_reason; | 
| Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7041 | dump_ifidx(drv); | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7042 | return; | 
|  | 7043 | } | 
|  | 7044 | } | 
|  | 7045 |  | 
|  | 7046 | if (drv->if_indices != drv->default_if_indices) | 
|  | 7047 | old = drv->if_indices; | 
|  | 7048 | else | 
|  | 7049 | old = NULL; | 
|  | 7050 |  | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7051 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7052 | sizeof(*old)); | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7053 | if (!drv->if_indices) { | 
|  | 7054 | if (!old) | 
|  | 7055 | drv->if_indices = drv->default_if_indices; | 
|  | 7056 | else | 
|  | 7057 | drv->if_indices = old; | 
|  | 7058 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " | 
|  | 7059 | "interfaces"); | 
|  | 7060 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); | 
|  | 7061 | return; | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7062 | } | 
|  | 7063 | if (!old) | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7064 | os_memcpy(drv->if_indices, drv->default_if_indices, | 
|  | 7065 | sizeof(drv->default_if_indices)); | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7066 | drv->if_indices[drv->num_if_indices].ifindex = ifidx; | 
|  | 7067 | drv->if_indices[drv->num_if_indices].reason = ifidx_reason; | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7068 | drv->num_if_indices++; | 
| Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7069 | dump_ifidx(drv); | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7070 | } | 
|  | 7071 |  | 
|  | 7072 |  | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7073 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, | 
|  | 7074 | int ifidx_reason) | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7075 | { | 
|  | 7076 | int i; | 
|  | 7077 |  | 
|  | 7078 | for (i = 0; i < drv->num_if_indices; i++) { | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7079 | if ((drv->if_indices[i].ifindex == ifidx || | 
|  | 7080 | ifidx == IFIDX_ANY) && | 
|  | 7081 | (drv->if_indices[i].reason == ifidx_reason || | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7082 | ifidx_reason == IFIDX_ANY)) { | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7083 | drv->if_indices[i].ifindex = 0; | 
|  | 7084 | drv->if_indices[i].reason = 0; | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7085 | break; | 
|  | 7086 | } | 
|  | 7087 | } | 
| Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7088 | dump_ifidx(drv); | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7089 | } | 
|  | 7090 |  | 
|  | 7091 |  | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7092 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, | 
|  | 7093 | int ifidx_reason) | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7094 | { | 
|  | 7095 | int i; | 
|  | 7096 |  | 
|  | 7097 | for (i = 0; i < drv->num_if_indices; i++) | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 7098 | if (drv->if_indices[i].ifindex == ifidx && | 
|  | 7099 | (drv->if_indices[i].reason == ifidx_reason || | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7100 | ifidx_reason == IFIDX_ANY)) | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7101 | return 1; | 
|  | 7102 |  | 
|  | 7103 | return 0; | 
|  | 7104 | } | 
|  | 7105 |  | 
|  | 7106 |  | 
|  | 7107 | 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] | 7108 | const char *bridge_ifname, char *ifname_wds) | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7109 | { | 
|  | 7110 | struct i802_bss *bss = priv; | 
|  | 7111 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 7112 | char name[IFNAMSIZ + 1]; | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7113 | union wpa_event_data event; | 
| Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 7114 | int ret; | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7115 |  | 
| Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 7116 | ret = os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); | 
|  | 7117 | if (ret >= (int) sizeof(name)) | 
|  | 7118 | wpa_printf(MSG_WARNING, | 
|  | 7119 | "nl80211: WDS interface name was truncated"); | 
|  | 7120 | else if (ret < 0) | 
|  | 7121 | return ret; | 
|  | 7122 |  | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7123 | if (ifname_wds) | 
|  | 7124 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); | 
|  | 7125 |  | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7126 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR | 
|  | 7127 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); | 
|  | 7128 | if (val) { | 
|  | 7129 | if (!if_nametoindex(name)) { | 
|  | 7130 | if (nl80211_create_iface(drv, name, | 
|  | 7131 | NL80211_IFTYPE_AP_VLAN, | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7132 | bss->addr, 1, NULL, NULL, 0) < | 
|  | 7133 | 0) | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7134 | return -1; | 
|  | 7135 | if (bridge_ifname && | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7136 | linux_br_add_if(drv->global->ioctl_sock, | 
|  | 7137 | bridge_ifname, name) < 0) | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7138 | return -1; | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7139 |  | 
|  | 7140 | os_memset(&event, 0, sizeof(event)); | 
|  | 7141 | event.wds_sta_interface.sta_addr = addr; | 
|  | 7142 | event.wds_sta_interface.ifname = name; | 
|  | 7143 | event.wds_sta_interface.istatus = INTERFACE_ADDED; | 
| Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 7144 | wpa_supplicant_event(bss->ctx, | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7145 | EVENT_WDS_STA_INTERFACE_STATUS, | 
|  | 7146 | &event); | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7147 | } | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7148 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { | 
|  | 7149 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " | 
|  | 7150 | "interface %s up", name); | 
|  | 7151 | } | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7152 | return i802_set_sta_vlan(priv, addr, name, 0); | 
|  | 7153 | } else { | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7154 | if (bridge_ifname && | 
|  | 7155 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, | 
|  | 7156 | name) < 0) | 
|  | 7157 | wpa_printf(MSG_INFO, | 
|  | 7158 | "nl80211: Failed to remove interface %s from bridge %s: %s", | 
|  | 7159 | name, bridge_ifname, strerror(errno)); | 
| Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7160 |  | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7161 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7162 | nl80211_remove_iface(drv, if_nametoindex(name)); | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7163 | os_memset(&event, 0, sizeof(event)); | 
|  | 7164 | event.wds_sta_interface.sta_addr = addr; | 
|  | 7165 | event.wds_sta_interface.ifname = name; | 
|  | 7166 | event.wds_sta_interface.istatus = INTERFACE_REMOVED; | 
| Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 7167 | wpa_supplicant_event(bss->ctx, EVENT_WDS_STA_INTERFACE_STATUS, | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7168 | &event); | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7169 | return 0; | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7170 | } | 
|  | 7171 | } | 
|  | 7172 |  | 
|  | 7173 |  | 
|  | 7174 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) | 
|  | 7175 | { | 
|  | 7176 | struct wpa_driver_nl80211_data *drv = eloop_ctx; | 
|  | 7177 | struct sockaddr_ll lladdr; | 
|  | 7178 | unsigned char buf[3000]; | 
|  | 7179 | int len; | 
|  | 7180 | socklen_t fromlen = sizeof(lladdr); | 
|  | 7181 |  | 
|  | 7182 | len = recvfrom(sock, buf, sizeof(buf), 0, | 
|  | 7183 | (struct sockaddr *)&lladdr, &fromlen); | 
|  | 7184 | if (len < 0) { | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7185 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", | 
|  | 7186 | strerror(errno)); | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7187 | return; | 
|  | 7188 | } | 
|  | 7189 |  | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7190 | if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY)) | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7191 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); | 
|  | 7192 | } | 
|  | 7193 |  | 
|  | 7194 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7195 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, | 
|  | 7196 | struct i802_bss *bss, | 
|  | 7197 | const char *brname, const char *ifname) | 
|  | 7198 | { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7199 | int br_ifindex; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7200 | char in_br[IFNAMSIZ]; | 
|  | 7201 |  | 
|  | 7202 | os_strlcpy(bss->brname, brname, IFNAMSIZ); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7203 | br_ifindex = if_nametoindex(brname); | 
|  | 7204 | if (br_ifindex == 0) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7205 | /* | 
|  | 7206 | * Bridge was configured, but the bridge device does | 
|  | 7207 | * not exist. Try to add it now. | 
|  | 7208 | */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7209 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7210 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " | 
|  | 7211 | "bridge interface %s: %s", | 
|  | 7212 | brname, strerror(errno)); | 
|  | 7213 | return -1; | 
|  | 7214 | } | 
|  | 7215 | bss->added_bridge = 1; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7216 | br_ifindex = if_nametoindex(brname); | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7217 | add_ifidx(drv, br_ifindex, drv->ifindex); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7218 | } | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7219 | bss->br_ifindex = br_ifindex; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7220 |  | 
|  | 7221 | if (linux_br_get(in_br, ifname) == 0) { | 
| Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 7222 | if (os_strcmp(in_br, brname) == 0) { | 
|  | 7223 | bss->already_in_bridge = 1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7224 | return 0; /* already in the bridge */ | 
| Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 7225 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7226 |  | 
|  | 7227 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " | 
|  | 7228 | "bridge %s", ifname, in_br); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7229 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < | 
|  | 7230 | 0) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7231 | wpa_printf(MSG_ERROR, "nl80211: Failed to " | 
|  | 7232 | "remove interface %s from bridge " | 
|  | 7233 | "%s: %s", | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7234 | ifname, in_br, strerror(errno)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7235 | return -1; | 
|  | 7236 | } | 
|  | 7237 | } | 
|  | 7238 |  | 
|  | 7239 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", | 
|  | 7240 | ifname, brname); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7241 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7242 | wpa_printf(MSG_WARNING, | 
|  | 7243 | "nl80211: Failed to add interface %s into bridge %s: %s", | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7244 | ifname, brname, strerror(errno)); | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7245 | /* Try to continue without the interface being in a bridge. This | 
|  | 7246 | * may be needed for some cases, e.g., with Open vSwitch, where | 
|  | 7247 | * an external component will need to handle bridge | 
|  | 7248 | * configuration. */ | 
|  | 7249 | return 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7250 | } | 
|  | 7251 | bss->added_if_into_bridge = 1; | 
|  | 7252 |  | 
|  | 7253 | return 0; | 
|  | 7254 | } | 
|  | 7255 |  | 
|  | 7256 |  | 
|  | 7257 | static void *i802_init(struct hostapd_data *hapd, | 
|  | 7258 | struct wpa_init_params *params) | 
|  | 7259 | { | 
|  | 7260 | struct wpa_driver_nl80211_data *drv; | 
|  | 7261 | struct i802_bss *bss; | 
|  | 7262 | size_t i; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7263 | char master_ifname[IFNAMSIZ]; | 
|  | 7264 | int ifindex, br_ifindex = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7265 | int br_added = 0; | 
|  | 7266 |  | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7267 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, | 
|  | 7268 | params->global_priv, 1, | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7269 | params->bssid, params->driver_params); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7270 | if (bss == NULL) | 
|  | 7271 | return NULL; | 
|  | 7272 |  | 
|  | 7273 | drv = bss->drv; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7274 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7275 | if (linux_br_get(master_ifname, params->ifname) == 0) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7276 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7277 | params->ifname, master_ifname); | 
|  | 7278 | br_ifindex = if_nametoindex(master_ifname); | 
|  | 7279 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); | 
|  | 7280 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && | 
|  | 7281 | linux_master_get(master_ifname, params->ifname) == 0) { | 
|  | 7282 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", | 
|  | 7283 | params->ifname, master_ifname); | 
|  | 7284 | /* start listening for EAPOL on the master interface */ | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7285 | add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex); | 
| Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 7286 |  | 
|  | 7287 | /* check if master itself is under bridge */ | 
|  | 7288 | if (linux_br_get(master_ifname, master_ifname) == 0) { | 
|  | 7289 | wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s", | 
|  | 7290 | master_ifname); | 
|  | 7291 | br_ifindex = if_nametoindex(master_ifname); | 
|  | 7292 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); | 
|  | 7293 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7294 | } else { | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7295 | master_ifname[0] = '\0'; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7296 | } | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7297 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7298 | bss->br_ifindex = br_ifindex; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7299 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7300 | for (i = 0; i < params->num_bridge; i++) { | 
|  | 7301 | if (params->bridge[i]) { | 
|  | 7302 | ifindex = if_nametoindex(params->bridge[i]); | 
|  | 7303 | if (ifindex) | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7304 | add_ifidx(drv, ifindex, drv->ifindex); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7305 | if (ifindex == br_ifindex) | 
|  | 7306 | br_added = 1; | 
|  | 7307 | } | 
|  | 7308 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7309 |  | 
|  | 7310 | /* start listening for EAPOL on the default AP interface */ | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7311 | add_ifidx(drv, drv->ifindex, IFIDX_ANY); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7312 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7313 | if (params->num_bridge && params->bridge[0]) { | 
|  | 7314 | if (i802_check_bridge(drv, bss, params->bridge[0], | 
|  | 7315 | params->ifname) < 0) | 
|  | 7316 | goto failed; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7317 | if (os_strcmp(params->bridge[0], master_ifname) != 0) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7318 | br_added = 1; | 
|  | 7319 | } | 
|  | 7320 |  | 
|  | 7321 | if (!br_added && br_ifindex && | 
|  | 7322 | (params->num_bridge == 0 || !params->bridge[0])) | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7323 | add_ifidx(drv, br_ifindex, drv->ifindex); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7324 |  | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7325 | #ifdef CONFIG_LIBNL3_ROUTE | 
| Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 7326 | if (bss->added_if_into_bridge || bss->already_in_bridge) { | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7327 | int err; | 
|  | 7328 |  | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7329 | drv->rtnl_sk = nl_socket_alloc(); | 
|  | 7330 | if (drv->rtnl_sk == NULL) { | 
|  | 7331 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); | 
|  | 7332 | goto failed; | 
|  | 7333 | } | 
|  | 7334 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7335 | err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE); | 
|  | 7336 | if (err) { | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7337 | 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] | 7338 | nl_geterror(err)); | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7339 | goto failed; | 
|  | 7340 | } | 
|  | 7341 | } | 
|  | 7342 | #endif /* CONFIG_LIBNL3_ROUTE */ | 
|  | 7343 |  | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 7344 | if (drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) { | 
|  | 7345 | wpa_printf(MSG_DEBUG, | 
|  | 7346 | "nl80211: Do not open EAPOL RX socket - using control port for RX"); | 
|  | 7347 | goto skip_eapol_sock; | 
|  | 7348 | } | 
|  | 7349 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7350 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); | 
|  | 7351 | if (drv->eapol_sock < 0) { | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7352 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", | 
|  | 7353 | strerror(errno)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7354 | goto failed; | 
|  | 7355 | } | 
|  | 7356 |  | 
|  | 7357 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) | 
|  | 7358 | { | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7359 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7360 | goto failed; | 
|  | 7361 | } | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 7362 | skip_eapol_sock: | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7363 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7364 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, | 
|  | 7365 | params->own_addr)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7366 | goto failed; | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7367 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7368 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7369 | memcpy(bss->addr, params->own_addr, ETH_ALEN); | 
|  | 7370 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7371 | return bss; | 
|  | 7372 |  | 
|  | 7373 | failed: | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7374 | wpa_driver_nl80211_deinit(bss); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7375 | return NULL; | 
|  | 7376 | } | 
|  | 7377 |  | 
|  | 7378 |  | 
|  | 7379 | static void i802_deinit(void *priv) | 
|  | 7380 | { | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7381 | struct i802_bss *bss = priv; | 
|  | 7382 | wpa_driver_nl80211_deinit(bss); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7383 | } | 
|  | 7384 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7385 |  | 
|  | 7386 | static enum nl80211_iftype wpa_driver_nl80211_if_type( | 
|  | 7387 | enum wpa_driver_if_type type) | 
|  | 7388 | { | 
|  | 7389 | switch (type) { | 
|  | 7390 | case WPA_IF_STATION: | 
|  | 7391 | return NL80211_IFTYPE_STATION; | 
|  | 7392 | case WPA_IF_P2P_CLIENT: | 
|  | 7393 | case WPA_IF_P2P_GROUP: | 
|  | 7394 | return NL80211_IFTYPE_P2P_CLIENT; | 
|  | 7395 | case WPA_IF_AP_VLAN: | 
|  | 7396 | return NL80211_IFTYPE_AP_VLAN; | 
|  | 7397 | case WPA_IF_AP_BSS: | 
|  | 7398 | return NL80211_IFTYPE_AP; | 
|  | 7399 | case WPA_IF_P2P_GO: | 
|  | 7400 | return NL80211_IFTYPE_P2P_GO; | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7401 | case WPA_IF_P2P_DEVICE: | 
|  | 7402 | return NL80211_IFTYPE_P2P_DEVICE; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7403 | case WPA_IF_MESH: | 
|  | 7404 | return NL80211_IFTYPE_MESH_POINT; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7405 | default: | 
|  | 7406 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7407 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7408 | } | 
|  | 7409 |  | 
|  | 7410 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7411 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) | 
|  | 7412 | { | 
|  | 7413 | struct wpa_driver_nl80211_data *drv; | 
|  | 7414 | dl_list_for_each(drv, &global->interfaces, | 
|  | 7415 | struct wpa_driver_nl80211_data, list) { | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7416 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7417 | return 1; | 
|  | 7418 | } | 
|  | 7419 | return 0; | 
|  | 7420 | } | 
|  | 7421 |  | 
|  | 7422 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7423 | 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] | 7424 | { | 
|  | 7425 | unsigned int idx; | 
|  | 7426 |  | 
|  | 7427 | if (!drv->global) | 
|  | 7428 | return -1; | 
|  | 7429 |  | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7430 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7431 | for (idx = 0; idx < 64; idx++) { | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7432 | new_addr[0] = drv->first_bss->addr[0] | 0x02; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7433 | new_addr[0] ^= idx << 2; | 
|  | 7434 | if (!nl80211_addr_in_use(drv->global, new_addr)) | 
|  | 7435 | break; | 
|  | 7436 | } | 
|  | 7437 | if (idx == 64) | 
|  | 7438 | return -1; | 
|  | 7439 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7440 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7441 | MACSTR, MAC2STR(new_addr)); | 
|  | 7442 |  | 
|  | 7443 | return 0; | 
|  | 7444 | } | 
|  | 7445 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7446 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7447 | struct wdev_info { | 
|  | 7448 | u64 wdev_id; | 
|  | 7449 | int wdev_id_set; | 
|  | 7450 | u8 macaddr[ETH_ALEN]; | 
|  | 7451 | }; | 
|  | 7452 |  | 
|  | 7453 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) | 
|  | 7454 | { | 
|  | 7455 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | 
|  | 7456 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | 
|  | 7457 | struct wdev_info *wi = arg; | 
|  | 7458 |  | 
|  | 7459 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | 
|  | 7460 | genlmsg_attrlen(gnlh, 0), NULL); | 
|  | 7461 | if (tb[NL80211_ATTR_WDEV]) { | 
|  | 7462 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); | 
|  | 7463 | wi->wdev_id_set = 1; | 
|  | 7464 | } | 
|  | 7465 |  | 
|  | 7466 | if (tb[NL80211_ATTR_MAC]) | 
|  | 7467 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), | 
|  | 7468 | ETH_ALEN); | 
|  | 7469 |  | 
|  | 7470 | return NL_SKIP; | 
|  | 7471 | } | 
|  | 7472 |  | 
|  | 7473 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7474 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, | 
|  | 7475 | const char *ifname, const u8 *addr, | 
|  | 7476 | void *bss_ctx, void **drv_priv, | 
|  | 7477 | char *force_ifname, u8 *if_addr, | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7478 | const char *bridge, int use_existing, | 
|  | 7479 | int setup_ap) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7480 | { | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7481 | enum nl80211_iftype nlmode; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7482 | struct i802_bss *bss = priv; | 
|  | 7483 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 7484 | int ifidx; | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7485 | int added = 1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7486 |  | 
|  | 7487 | if (addr) | 
|  | 7488 | os_memcpy(if_addr, addr, ETH_ALEN); | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7489 | nlmode = wpa_driver_nl80211_if_type(type); | 
|  | 7490 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { | 
|  | 7491 | struct wdev_info p2pdev_info; | 
|  | 7492 |  | 
|  | 7493 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); | 
|  | 7494 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, | 
|  | 7495 | 0, nl80211_wdev_handler, | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7496 | &p2pdev_info, use_existing); | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7497 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { | 
|  | 7498 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", | 
|  | 7499 | ifname); | 
|  | 7500 | return -1; | 
|  | 7501 | } | 
|  | 7502 |  | 
|  | 7503 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; | 
|  | 7504 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; | 
|  | 7505 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) | 
|  | 7506 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); | 
|  | 7507 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", | 
|  | 7508 | ifname, | 
|  | 7509 | (long long unsigned int) p2pdev_info.wdev_id); | 
|  | 7510 | } else { | 
|  | 7511 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7512 | 0, NULL, NULL, use_existing); | 
|  | 7513 | if (use_existing && ifidx == -ENFILE) { | 
|  | 7514 | added = 0; | 
|  | 7515 | ifidx = if_nametoindex(ifname); | 
|  | 7516 | } else if (ifidx < 0) { | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7517 | return -1; | 
|  | 7518 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7519 | } | 
|  | 7520 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7521 | if (!addr) { | 
| Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 7522 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7523 | os_memcpy(if_addr, bss->addr, ETH_ALEN); | 
|  | 7524 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, | 
| Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 7525 | ifname, if_addr) < 0) { | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7526 | if (added) | 
|  | 7527 | nl80211_remove_iface(drv, ifidx); | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7528 | return -1; | 
|  | 7529 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7530 | } | 
|  | 7531 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7532 | if (!addr && | 
|  | 7533 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || | 
| Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 7534 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || | 
|  | 7535 | type == WPA_IF_STATION)) { | 
|  | 7536 | /* Enforce unique address */ | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7537 | u8 new_addr[ETH_ALEN]; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7538 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7539 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7540 | new_addr) < 0) { | 
| Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 7541 | if (added) | 
|  | 7542 | nl80211_remove_iface(drv, ifidx); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7543 | return -1; | 
|  | 7544 | } | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7545 | if (nl80211_addr_in_use(drv->global, new_addr)) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7546 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " | 
| Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 7547 | "for interface %s type %d", ifname, type); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7548 | if (nl80211_vif_addr(drv, new_addr) < 0) { | 
| Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 7549 | if (added) | 
|  | 7550 | nl80211_remove_iface(drv, ifidx); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7551 | return -1; | 
|  | 7552 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7553 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7554 | new_addr) < 0) { | 
| Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 7555 | if (added) | 
|  | 7556 | nl80211_remove_iface(drv, ifidx); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7557 | return -1; | 
|  | 7558 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7559 | } | 
| Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 7560 | os_memcpy(if_addr, new_addr, ETH_ALEN); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7561 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7562 |  | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7563 | if (type == WPA_IF_AP_BSS && setup_ap) { | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7564 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); | 
|  | 7565 | if (new_bss == NULL) { | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7566 | if (added) | 
|  | 7567 | nl80211_remove_iface(drv, ifidx); | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7568 | return -1; | 
|  | 7569 | } | 
|  | 7570 |  | 
|  | 7571 | if (bridge && | 
|  | 7572 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { | 
|  | 7573 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " | 
|  | 7574 | "interface %s to a bridge %s", | 
|  | 7575 | ifname, bridge); | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7576 | if (added) | 
|  | 7577 | nl80211_remove_iface(drv, ifidx); | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7578 | os_free(new_bss); | 
|  | 7579 | return -1; | 
|  | 7580 | } | 
|  | 7581 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7582 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) | 
|  | 7583 | { | 
| Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 7584 | if (added) | 
|  | 7585 | nl80211_remove_iface(drv, ifidx); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7586 | os_free(new_bss); | 
|  | 7587 | return -1; | 
|  | 7588 | } | 
|  | 7589 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7590 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7591 | new_bss->ifindex = ifidx; | 
|  | 7592 | new_bss->drv = drv; | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7593 | new_bss->next = drv->first_bss->next; | 
|  | 7594 | new_bss->freq = drv->first_bss->freq; | 
| Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7595 | new_bss->ctx = bss_ctx; | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7596 | new_bss->added_if = added; | 
|  | 7597 | drv->first_bss->next = new_bss; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7598 | if (drv_priv) | 
|  | 7599 | *drv_priv = new_bss; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7600 | nl80211_init_bss(new_bss); | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7601 |  | 
|  | 7602 | /* Subscribe management frames for this WPA_IF_AP_BSS */ | 
|  | 7603 | if (nl80211_setup_ap(new_bss)) | 
|  | 7604 | return -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7605 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7606 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7607 | if (drv->global) | 
|  | 7608 | drv->global->if_add_ifindex = ifidx; | 
|  | 7609 |  | 
| Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7610 | /* | 
|  | 7611 | * Some virtual interfaces need to process EAPOL packets and events on | 
|  | 7612 | * the parent interface. This is used mainly with hostapd. | 
|  | 7613 | */ | 
|  | 7614 | if (ifidx > 0 && | 
|  | 7615 | (drv->hostapd || | 
|  | 7616 | nlmode == NL80211_IFTYPE_AP_VLAN || | 
|  | 7617 | nlmode == NL80211_IFTYPE_WDS || | 
|  | 7618 | nlmode == NL80211_IFTYPE_MONITOR)) | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7619 | add_ifidx(drv, ifidx, IFIDX_ANY); | 
| Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7620 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7621 | return 0; | 
|  | 7622 | } | 
|  | 7623 |  | 
|  | 7624 |  | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7625 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7626 | enum wpa_driver_if_type type, | 
|  | 7627 | const char *ifname) | 
|  | 7628 | { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7629 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 7630 | int ifindex = if_nametoindex(ifname); | 
|  | 7631 |  | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7632 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", | 
|  | 7633 | __func__, type, ifname, ifindex, bss->added_if); | 
| Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 7634 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7635 | nl80211_remove_iface(drv, ifindex); | 
| Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 7636 | else if (ifindex > 0 && !bss->added_if) { | 
|  | 7637 | struct wpa_driver_nl80211_data *drv2; | 
|  | 7638 | dl_list_for_each(drv2, &drv->global->interfaces, | 
| Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7639 | struct wpa_driver_nl80211_data, list) { | 
|  | 7640 | del_ifidx(drv2, ifindex, IFIDX_ANY); | 
|  | 7641 | del_ifidx(drv2, IFIDX_ANY, ifindex); | 
|  | 7642 | } | 
| Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 7643 | } | 
| Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7644 |  | 
| Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7645 | if (type != WPA_IF_AP_BSS) | 
|  | 7646 | return 0; | 
|  | 7647 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7648 | if (bss->added_if_into_bridge) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7649 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, | 
|  | 7650 | bss->ifname) < 0) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7651 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " | 
|  | 7652 | "interface %s from bridge %s: %s", | 
|  | 7653 | bss->ifname, bss->brname, strerror(errno)); | 
|  | 7654 | } | 
|  | 7655 | if (bss->added_bridge) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7656 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7657 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " | 
|  | 7658 | "bridge %s: %s", | 
|  | 7659 | bss->brname, strerror(errno)); | 
|  | 7660 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7661 |  | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7662 | if (bss != drv->first_bss) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7663 | struct i802_bss *tbss; | 
|  | 7664 |  | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7665 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); | 
|  | 7666 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7667 | if (tbss->next == bss) { | 
|  | 7668 | tbss->next = bss->next; | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7669 | /* Unsubscribe management frames */ | 
|  | 7670 | nl80211_teardown_ap(bss); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7671 | nl80211_destroy_bss(bss); | 
| Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7672 | if (!bss->added_if) | 
|  | 7673 | i802_set_iface_flags(bss, 0); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7674 | os_free(bss); | 
|  | 7675 | bss = NULL; | 
|  | 7676 | break; | 
|  | 7677 | } | 
|  | 7678 | } | 
|  | 7679 | if (bss) | 
|  | 7680 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " | 
|  | 7681 | "BSS %p in the list", __func__, bss); | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7682 | } else { | 
|  | 7683 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); | 
|  | 7684 | nl80211_teardown_ap(bss); | 
|  | 7685 | if (!bss->added_if && !drv->first_bss->next) | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 7686 | wpa_driver_nl80211_del_beacon(bss); | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7687 | nl80211_destroy_bss(bss); | 
|  | 7688 | if (!bss->added_if) | 
|  | 7689 | i802_set_iface_flags(bss, 0); | 
|  | 7690 | if (drv->first_bss->next) { | 
|  | 7691 | drv->first_bss = drv->first_bss->next; | 
|  | 7692 | drv->ctx = drv->first_bss->ctx; | 
|  | 7693 | os_free(bss); | 
|  | 7694 | } else { | 
|  | 7695 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); | 
|  | 7696 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7697 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7698 |  | 
|  | 7699 | return 0; | 
|  | 7700 | } | 
|  | 7701 |  | 
|  | 7702 |  | 
|  | 7703 | static int cookie_handler(struct nl_msg *msg, void *arg) | 
|  | 7704 | { | 
|  | 7705 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | 
|  | 7706 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | 
|  | 7707 | u64 *cookie = arg; | 
|  | 7708 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | 
|  | 7709 | genlmsg_attrlen(gnlh, 0), NULL); | 
|  | 7710 | if (tb[NL80211_ATTR_COOKIE]) | 
|  | 7711 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); | 
|  | 7712 | return NL_SKIP; | 
|  | 7713 | } | 
|  | 7714 |  | 
|  | 7715 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7716 | static int nl80211_send_frame_cmd(struct i802_bss *bss, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7717 | unsigned int freq, unsigned int wait, | 
|  | 7718 | const u8 *buf, size_t buf_len, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7719 | int save_cookie, int no_cck, int no_ack, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7720 | int offchanok, const u16 *csa_offs, | 
|  | 7721 | size_t csa_offs_len) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7722 | { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7723 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7724 | struct nl_msg *msg; | 
|  | 7725 | u64 cookie; | 
|  | 7726 | int ret = -1; | 
|  | 7727 |  | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7728 | 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] | 7729 | "no_ack=%d offchanok=%d", | 
|  | 7730 | freq, wait, no_cck, no_ack, offchanok); | 
| Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7731 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7732 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7733 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || | 
|  | 7734 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || | 
|  | 7735 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || | 
|  | 7736 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || | 
|  | 7737 | drv->test_use_roc_tx) && | 
|  | 7738 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || | 
|  | 7739 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || | 
|  | 7740 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7741 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, | 
|  | 7742 | csa_offs_len * sizeof(u16), csa_offs)) || | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7743 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) | 
|  | 7744 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7745 |  | 
|  | 7746 | cookie = 0; | 
|  | 7747 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | 
|  | 7748 | msg = NULL; | 
|  | 7749 | if (ret) { | 
|  | 7750 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " | 
| Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 7751 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), | 
|  | 7752 | freq, wait); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7753 | } else { | 
|  | 7754 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " | 
|  | 7755 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", | 
|  | 7756 | (long long unsigned int) cookie); | 
|  | 7757 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7758 | if (save_cookie) | 
|  | 7759 | drv->send_frame_cookie = no_ack ? (u64) -1 : cookie; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7760 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7761 | if (drv->num_send_frame_cookies == MAX_SEND_FRAME_COOKIES) { | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7762 | wpa_printf(MSG_DEBUG, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7763 | "nl80211: Drop oldest pending send frame cookie 0x%llx", | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7764 | (long long unsigned int) | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7765 | drv->send_frame_cookies[0]); | 
|  | 7766 | os_memmove(&drv->send_frame_cookies[0], | 
|  | 7767 | &drv->send_frame_cookies[1], | 
|  | 7768 | (MAX_SEND_FRAME_COOKIES - 1) * | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7769 | sizeof(u64)); | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7770 | drv->num_send_frame_cookies--; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7771 | } | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7772 | drv->send_frame_cookies[drv->num_send_frame_cookies] = cookie; | 
|  | 7773 | drv->num_send_frame_cookies++; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7774 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7775 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7776 | fail: | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7777 | nlmsg_free(msg); | 
|  | 7778 | return ret; | 
|  | 7779 | } | 
|  | 7780 |  | 
|  | 7781 |  | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7782 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, | 
|  | 7783 | unsigned int freq, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7784 | unsigned int wait_time, | 
|  | 7785 | const u8 *dst, const u8 *src, | 
|  | 7786 | const u8 *bssid, | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7787 | const u8 *data, size_t data_len, | 
|  | 7788 | int no_cck) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7789 | { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7790 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 7791 | int ret = -1; | 
|  | 7792 | u8 *buf; | 
|  | 7793 | struct ieee80211_hdr *hdr; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7794 | int offchanok = 1; | 
|  | 7795 |  | 
| Hai Shalom | 4fbc08f | 2020-05-18 12:37:00 -0700 | [diff] [blame] | 7796 | if (is_ap_interface(drv->nlmode) && (int) freq == bss->freq && | 
|  | 7797 | bss->beacon_set) | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7798 | offchanok = 0; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7799 |  | 
|  | 7800 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7801 | "freq=%u MHz wait=%d ms no_cck=%d offchanok=%d)", | 
|  | 7802 | drv->ifindex, freq, wait_time, no_cck, offchanok); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7803 |  | 
|  | 7804 | buf = os_zalloc(24 + data_len); | 
|  | 7805 | if (buf == NULL) | 
|  | 7806 | return ret; | 
|  | 7807 | os_memcpy(buf + 24, data, data_len); | 
|  | 7808 | hdr = (struct ieee80211_hdr *) buf; | 
|  | 7809 | hdr->frame_control = | 
|  | 7810 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); | 
|  | 7811 | os_memcpy(hdr->addr1, dst, ETH_ALEN); | 
|  | 7812 | os_memcpy(hdr->addr2, src, ETH_ALEN); | 
|  | 7813 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); | 
|  | 7814 |  | 
| Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 7815 | if (os_memcmp(bss->addr, src, ETH_ALEN) != 0) { | 
|  | 7816 | wpa_printf(MSG_DEBUG, "nl80211: Use random TA " MACSTR, | 
|  | 7817 | MAC2STR(src)); | 
|  | 7818 | os_memcpy(bss->rand_addr, src, ETH_ALEN); | 
|  | 7819 | } else { | 
|  | 7820 | os_memset(bss->rand_addr, 0, ETH_ALEN); | 
|  | 7821 | } | 
|  | 7822 |  | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7823 | if (is_ap_interface(drv->nlmode) && | 
|  | 7824 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || | 
|  | 7825 | (int) freq == bss->freq || drv->device_ap_sme || | 
|  | 7826 | !drv->use_monitor)) | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7827 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7828 | 0, freq, no_cck, offchanok, | 
|  | 7829 | wait_time, NULL, 0, 0); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7830 | else | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7831 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7832 | 24 + data_len, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7833 | 1, no_cck, 0, offchanok, NULL, 0); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7834 |  | 
|  | 7835 | os_free(buf); | 
|  | 7836 | return ret; | 
|  | 7837 | } | 
|  | 7838 |  | 
|  | 7839 |  | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7840 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7841 | { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7842 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 7843 | struct nl_msg *msg; | 
|  | 7844 | int ret; | 
|  | 7845 |  | 
| Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 7846 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7847 | (long long unsigned int) cookie); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7848 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7849 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7850 | nlmsg_free(msg); | 
|  | 7851 | return; | 
|  | 7852 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7853 |  | 
|  | 7854 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7855 | if (ret) | 
|  | 7856 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " | 
|  | 7857 | "(%s)", ret, strerror(-ret)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7858 | } | 
|  | 7859 |  | 
|  | 7860 |  | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7861 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) | 
|  | 7862 | { | 
|  | 7863 | struct i802_bss *bss = priv; | 
|  | 7864 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 7865 | unsigned int i; | 
|  | 7866 | u64 cookie; | 
|  | 7867 |  | 
|  | 7868 | /* Cancel the last pending TX cookie */ | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7869 | nl80211_frame_wait_cancel(bss, drv->send_frame_cookie); | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7870 |  | 
|  | 7871 | /* | 
|  | 7872 | * Cancel the other pending TX cookies, if any. This is needed since | 
|  | 7873 | * the driver may keep a list of all pending offchannel TX operations | 
|  | 7874 | * and free up the radio only once they have expired or cancelled. | 
|  | 7875 | */ | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7876 | for (i = drv->num_send_frame_cookies; i > 0; i--) { | 
|  | 7877 | cookie = drv->send_frame_cookies[i - 1]; | 
|  | 7878 | if (cookie != drv->send_frame_cookie) | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7879 | nl80211_frame_wait_cancel(bss, cookie); | 
|  | 7880 | } | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 7881 | drv->num_send_frame_cookies = 0; | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7882 | } | 
|  | 7883 |  | 
|  | 7884 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7885 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, | 
|  | 7886 | unsigned int duration) | 
|  | 7887 | { | 
|  | 7888 | struct i802_bss *bss = priv; | 
|  | 7889 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 7890 | struct nl_msg *msg; | 
|  | 7891 | int ret; | 
|  | 7892 | u64 cookie; | 
|  | 7893 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7894 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || | 
|  | 7895 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || | 
|  | 7896 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { | 
|  | 7897 | nlmsg_free(msg); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7898 | return -1; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7899 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7900 |  | 
|  | 7901 | cookie = 0; | 
|  | 7902 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | 
|  | 7903 | if (ret == 0) { | 
|  | 7904 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " | 
|  | 7905 | "0x%llx for freq=%u MHz duration=%u", | 
|  | 7906 | (long long unsigned int) cookie, freq, duration); | 
|  | 7907 | drv->remain_on_chan_cookie = cookie; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7908 | drv->pending_remain_on_chan = 1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7909 | return 0; | 
|  | 7910 | } | 
|  | 7911 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " | 
|  | 7912 | "(freq=%d duration=%u): %d (%s)", | 
|  | 7913 | freq, duration, ret, strerror(-ret)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7914 | return -1; | 
|  | 7915 | } | 
|  | 7916 |  | 
|  | 7917 |  | 
|  | 7918 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) | 
|  | 7919 | { | 
|  | 7920 | struct i802_bss *bss = priv; | 
|  | 7921 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 7922 | struct nl_msg *msg; | 
|  | 7923 | int ret; | 
|  | 7924 |  | 
|  | 7925 | if (!drv->pending_remain_on_chan) { | 
|  | 7926 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " | 
|  | 7927 | "to cancel"); | 
|  | 7928 | return -1; | 
|  | 7929 | } | 
|  | 7930 |  | 
|  | 7931 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " | 
|  | 7932 | "0x%llx", | 
|  | 7933 | (long long unsigned int) drv->remain_on_chan_cookie); | 
|  | 7934 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7935 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); | 
|  | 7936 | if (!msg || | 
|  | 7937 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { | 
|  | 7938 | nlmsg_free(msg); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7939 | return -1; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7940 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7941 |  | 
|  | 7942 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 7943 | if (ret == 0) | 
|  | 7944 | return 0; | 
|  | 7945 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " | 
|  | 7946 | "%d (%s)", ret, strerror(-ret)); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7947 | return -1; | 
|  | 7948 | } | 
|  | 7949 |  | 
|  | 7950 |  | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7951 | 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] | 7952 | { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7953 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
| Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 7954 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7955 | if (!report) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7956 | if (bss->nl_preq && drv->device_ap_sme && | 
| Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 7957 | is_ap_interface(drv->nlmode) && !bss->in_deinit && | 
|  | 7958 | !bss->static_ap) { | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7959 | /* | 
|  | 7960 | * Do not disable Probe Request reporting that was | 
|  | 7961 | * enabled in nl80211_setup_ap(). | 
|  | 7962 | */ | 
|  | 7963 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " | 
|  | 7964 | "Probe Request reporting nl_preq=%p while " | 
|  | 7965 | "in AP mode", bss->nl_preq); | 
|  | 7966 | } else if (bss->nl_preq) { | 
|  | 7967 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " | 
|  | 7968 | "reporting nl_preq=%p", bss->nl_preq); | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7969 | nl80211_destroy_eloop_handle(&bss->nl_preq, 0); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7970 | } | 
|  | 7971 | return 0; | 
|  | 7972 | } | 
|  | 7973 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7974 | if (bss->nl_preq) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7975 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7976 | "already on! nl_preq=%p", bss->nl_preq); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7977 | return 0; | 
|  | 7978 | } | 
|  | 7979 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7980 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); | 
|  | 7981 | if (bss->nl_preq == NULL) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7982 | return -1; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7983 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " | 
|  | 7984 | "reporting nl_preq=%p", bss->nl_preq); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7985 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7986 | if (nl80211_register_frame(bss, bss->nl_preq, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7987 | (WLAN_FC_TYPE_MGMT << 2) | | 
|  | 7988 | (WLAN_FC_STYPE_PROBE_REQ << 4), | 
| Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 7989 | NULL, 0, false) < 0) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7990 | goto out_err; | 
| Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 7991 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7992 | nl80211_register_eloop_read(&bss->nl_preq, | 
|  | 7993 | wpa_driver_nl80211_event_receive, | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7994 | bss->nl_cb, 0); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7995 |  | 
|  | 7996 | return 0; | 
|  | 7997 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7998 | out_err: | 
|  | 7999 | nl_destroy_handles(&bss->nl_preq); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8000 | return -1; | 
|  | 8001 | } | 
|  | 8002 |  | 
|  | 8003 |  | 
|  | 8004 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, | 
|  | 8005 | int ifindex, int disabled) | 
|  | 8006 | { | 
|  | 8007 | struct nl_msg *msg; | 
|  | 8008 | struct nlattr *bands, *band; | 
|  | 8009 | int ret; | 
|  | 8010 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8011 | wpa_printf(MSG_DEBUG, | 
|  | 8012 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", | 
|  | 8013 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : | 
|  | 8014 | "no NL80211_TXRATE_LEGACY constraint"); | 
|  | 8015 |  | 
|  | 8016 | msg = nl80211_ifindex_msg(drv, ifindex, 0, | 
|  | 8017 | NL80211_CMD_SET_TX_BITRATE_MASK); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8018 | if (!msg) | 
|  | 8019 | return -1; | 
|  | 8020 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8021 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); | 
|  | 8022 | if (!bands) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8023 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8024 |  | 
|  | 8025 | /* | 
|  | 8026 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything | 
|  | 8027 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS | 
|  | 8028 | * rates. All 5 GHz rates are left enabled. | 
|  | 8029 | */ | 
|  | 8030 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8031 | if (!band || | 
|  | 8032 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, | 
|  | 8033 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) | 
|  | 8034 | goto fail; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8035 | nla_nest_end(msg, band); | 
|  | 8036 |  | 
|  | 8037 | nla_nest_end(msg, bands); | 
|  | 8038 |  | 
|  | 8039 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8040 | if (ret) { | 
|  | 8041 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " | 
|  | 8042 | "(%s)", ret, strerror(-ret)); | 
| Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 8043 | } else | 
|  | 8044 | drv->disabled_11b_rates = disabled; | 
|  | 8045 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8046 | return ret; | 
|  | 8047 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8048 | fail: | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8049 | nlmsg_free(msg); | 
|  | 8050 | return -1; | 
|  | 8051 | } | 
|  | 8052 |  | 
|  | 8053 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8054 | static int wpa_driver_nl80211_deinit_ap(void *priv) | 
|  | 8055 | { | 
|  | 8056 | struct i802_bss *bss = priv; | 
|  | 8057 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8058 | if (!is_ap_interface(drv->nlmode)) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8059 | return -1; | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8060 | wpa_driver_nl80211_del_beacon(bss); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8061 | bss->beacon_set = 0; | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8062 |  | 
|  | 8063 | /* | 
|  | 8064 | * If the P2P GO interface was dynamically added, then it is | 
|  | 8065 | * possible that the interface change to station is not possible. | 
|  | 8066 | */ | 
|  | 8067 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) | 
|  | 8068 | return 0; | 
|  | 8069 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8070 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8071 | } | 
|  | 8072 |  | 
|  | 8073 |  | 
| Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8074 | static int wpa_driver_nl80211_stop_ap(void *priv) | 
|  | 8075 | { | 
|  | 8076 | struct i802_bss *bss = priv; | 
|  | 8077 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 8078 | if (!is_ap_interface(drv->nlmode)) | 
|  | 8079 | return -1; | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8080 | wpa_driver_nl80211_del_beacon(bss); | 
| Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8081 | bss->beacon_set = 0; | 
|  | 8082 | return 0; | 
|  | 8083 | } | 
|  | 8084 |  | 
|  | 8085 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8086 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) | 
|  | 8087 | { | 
|  | 8088 | struct i802_bss *bss = priv; | 
|  | 8089 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 8090 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) | 
|  | 8091 | return -1; | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8092 |  | 
|  | 8093 | /* | 
|  | 8094 | * If the P2P Client interface was dynamically added, then it is | 
|  | 8095 | * possible that the interface change to station is not possible. | 
|  | 8096 | */ | 
|  | 8097 | if (bss->if_dynamic) | 
|  | 8098 | return 0; | 
|  | 8099 |  | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 8100 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); | 
|  | 8101 | } | 
|  | 8102 |  | 
|  | 8103 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8104 | static void wpa_driver_nl80211_resume(void *priv) | 
|  | 8105 | { | 
|  | 8106 | struct i802_bss *bss = priv; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8107 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8108 |  | 
|  | 8109 | if (i802_set_iface_flags(bss, 1)) | 
|  | 8110 | 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] | 8111 |  | 
|  | 8112 | if (is_p2p_net_interface(nlmode)) | 
|  | 8113 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8114 | } | 
|  | 8115 |  | 
|  | 8116 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8117 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) | 
|  | 8118 | { | 
|  | 8119 | struct i802_bss *bss = priv; | 
|  | 8120 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8121 | struct nl_msg *msg; | 
|  | 8122 | struct nlattr *cqm; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8123 |  | 
|  | 8124 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " | 
|  | 8125 | "hysteresis=%d", threshold, hysteresis); | 
|  | 8126 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8127 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || | 
|  | 8128 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || | 
|  | 8129 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || | 
|  | 8130 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { | 
|  | 8131 | nlmsg_free(msg); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8132 | return -1; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8133 | } | 
| Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8134 | nla_nest_end(msg, cqm); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8135 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8136 | return send_and_recv_msgs(drv, msg, NULL, NULL); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8137 | } | 
|  | 8138 |  | 
|  | 8139 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8140 | static int get_channel_width(struct nl_msg *msg, void *arg) | 
|  | 8141 | { | 
|  | 8142 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | 
|  | 8143 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | 
|  | 8144 | struct wpa_signal_info *sig_change = arg; | 
|  | 8145 |  | 
|  | 8146 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | 
|  | 8147 | genlmsg_attrlen(gnlh, 0), NULL); | 
|  | 8148 |  | 
|  | 8149 | sig_change->center_frq1 = -1; | 
|  | 8150 | sig_change->center_frq2 = -1; | 
|  | 8151 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; | 
|  | 8152 |  | 
|  | 8153 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { | 
|  | 8154 | sig_change->chanwidth = convert2width( | 
|  | 8155 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); | 
|  | 8156 | if (tb[NL80211_ATTR_CENTER_FREQ1]) | 
|  | 8157 | sig_change->center_frq1 = | 
|  | 8158 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); | 
|  | 8159 | if (tb[NL80211_ATTR_CENTER_FREQ2]) | 
|  | 8160 | sig_change->center_frq2 = | 
|  | 8161 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); | 
|  | 8162 | } | 
|  | 8163 |  | 
|  | 8164 | return NL_SKIP; | 
|  | 8165 | } | 
|  | 8166 |  | 
|  | 8167 |  | 
|  | 8168 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, | 
|  | 8169 | struct wpa_signal_info *sig) | 
|  | 8170 | { | 
|  | 8171 | struct nl_msg *msg; | 
|  | 8172 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8173 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8174 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8175 | } | 
|  | 8176 |  | 
|  | 8177 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8178 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) | 
|  | 8179 | { | 
|  | 8180 | struct i802_bss *bss = priv; | 
|  | 8181 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 8182 | int res; | 
|  | 8183 |  | 
|  | 8184 | os_memset(si, 0, sizeof(*si)); | 
|  | 8185 | res = nl80211_get_link_signal(drv, si); | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8186 | if (res) { | 
|  | 8187 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && | 
|  | 8188 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) | 
|  | 8189 | return res; | 
|  | 8190 | si->current_signal = 0; | 
|  | 8191 | } | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8192 |  | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8193 | res = nl80211_get_channel_width(drv, si); | 
|  | 8194 | if (res != 0) | 
|  | 8195 | return res; | 
|  | 8196 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8197 | return nl80211_get_link_noise(drv, si); | 
|  | 8198 | } | 
|  | 8199 |  | 
|  | 8200 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8201 | static int nl80211_set_param(void *priv, const char *param) | 
|  | 8202 | { | 
| Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 8203 | struct i802_bss *bss = priv; | 
|  | 8204 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 8205 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8206 | if (param == NULL) | 
|  | 8207 | return 0; | 
| Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 8208 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8209 |  | 
|  | 8210 | #ifdef CONFIG_P2P | 
|  | 8211 | if (os_strstr(param, "use_p2p_group_interface=1")) { | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8212 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " | 
|  | 8213 | "interface"); | 
|  | 8214 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; | 
|  | 8215 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; | 
|  | 8216 | } | 
|  | 8217 | #endif /* CONFIG_P2P */ | 
|  | 8218 |  | 
| Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 8219 | if (os_strstr(param, "use_monitor=1")) | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8220 | drv->use_monitor = 1; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8221 |  | 
|  | 8222 | if (os_strstr(param, "force_connect_cmd=1")) { | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8223 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8224 | drv->force_connect_cmd = 1; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8225 | } | 
|  | 8226 |  | 
| Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 8227 | if (os_strstr(param, "force_bss_selection=1")) | 
|  | 8228 | drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; | 
|  | 8229 |  | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 8230 | if (os_strstr(param, "no_offchannel_tx=1")) { | 
| Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 8231 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; | 
|  | 8232 | drv->test_use_roc_tx = 1; | 
|  | 8233 | } | 
|  | 8234 |  | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 8235 | if (os_strstr(param, "control_port=0")) { | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8236 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_CONTROL_PORT; | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 8237 | drv->capa.flags2 &= ~WPA_DRIVER_FLAGS2_CONTROL_PORT_RX; | 
|  | 8238 | } | 
|  | 8239 |  | 
|  | 8240 | if (os_strstr(param, "control_port_ap=1")) | 
|  | 8241 | drv->control_port_ap = 1; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8242 |  | 
|  | 8243 | if (os_strstr(param, "full_ap_client_state=0")) | 
|  | 8244 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE; | 
|  | 8245 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8246 | return 0; | 
|  | 8247 | } | 
|  | 8248 |  | 
|  | 8249 |  | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 8250 | static void * nl80211_global_init(void *ctx) | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8251 | { | 
|  | 8252 | struct nl80211_global *global; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8253 | struct netlink_config *cfg; | 
|  | 8254 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8255 | global = os_zalloc(sizeof(*global)); | 
|  | 8256 | if (global == NULL) | 
|  | 8257 | return NULL; | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 8258 | global->ctx = ctx; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8259 | global->ioctl_sock = -1; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8260 | dl_list_init(&global->interfaces); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8261 | global->if_add_ifindex = -1; | 
|  | 8262 |  | 
|  | 8263 | cfg = os_zalloc(sizeof(*cfg)); | 
|  | 8264 | if (cfg == NULL) | 
|  | 8265 | goto err; | 
|  | 8266 |  | 
|  | 8267 | cfg->ctx = global; | 
|  | 8268 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; | 
|  | 8269 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; | 
|  | 8270 | global->netlink = netlink_init(cfg); | 
|  | 8271 | if (global->netlink == NULL) { | 
|  | 8272 | os_free(cfg); | 
|  | 8273 | goto err; | 
|  | 8274 | } | 
|  | 8275 |  | 
|  | 8276 | if (wpa_driver_nl80211_init_nl_global(global) < 0) | 
|  | 8277 | goto err; | 
|  | 8278 |  | 
|  | 8279 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); | 
|  | 8280 | if (global->ioctl_sock < 0) { | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8281 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", | 
|  | 8282 | strerror(errno)); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8283 | goto err; | 
|  | 8284 | } | 
|  | 8285 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8286 | return global; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8287 |  | 
|  | 8288 | err: | 
|  | 8289 | nl80211_global_deinit(global); | 
|  | 8290 | return NULL; | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8291 | } | 
|  | 8292 |  | 
|  | 8293 |  | 
|  | 8294 | static void nl80211_global_deinit(void *priv) | 
|  | 8295 | { | 
|  | 8296 | struct nl80211_global *global = priv; | 
|  | 8297 | if (global == NULL) | 
|  | 8298 | return; | 
|  | 8299 | if (!dl_list_empty(&global->interfaces)) { | 
|  | 8300 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " | 
|  | 8301 | "nl80211_global_deinit", | 
|  | 8302 | dl_list_len(&global->interfaces)); | 
|  | 8303 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8304 |  | 
|  | 8305 | if (global->netlink) | 
|  | 8306 | netlink_deinit(global->netlink); | 
|  | 8307 |  | 
|  | 8308 | nl_destroy_handles(&global->nl); | 
|  | 8309 |  | 
| Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8310 | if (global->nl_event) | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8311 | nl80211_destroy_eloop_handle(&global->nl_event, 0); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8312 |  | 
|  | 8313 | nl_cb_put(global->nl_cb); | 
|  | 8314 |  | 
|  | 8315 | if (global->ioctl_sock >= 0) | 
|  | 8316 | close(global->ioctl_sock); | 
|  | 8317 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8318 | os_free(global); | 
|  | 8319 | } | 
|  | 8320 |  | 
|  | 8321 |  | 
|  | 8322 | static const char * nl80211_get_radio_name(void *priv) | 
|  | 8323 | { | 
|  | 8324 | struct i802_bss *bss = priv; | 
|  | 8325 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 8326 | return drv->phyname; | 
|  | 8327 | } | 
|  | 8328 |  | 
|  | 8329 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8330 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, | 
|  | 8331 | struct wpa_pmkid_params *params) | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8332 | { | 
|  | 8333 | struct nl_msg *msg; | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8334 | const size_t PMK_MAX_LEN = 48; /* current cfg80211 limit */ | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8335 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8336 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8337 | (params->pmkid && | 
|  | 8338 | nla_put(msg, NL80211_ATTR_PMKID, 16, params->pmkid)) || | 
|  | 8339 | (params->bssid && | 
|  | 8340 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) || | 
|  | 8341 | (params->ssid_len && | 
|  | 8342 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || | 
|  | 8343 | (params->fils_cache_id && | 
|  | 8344 | nla_put(msg, NL80211_ATTR_FILS_CACHE_ID, 2, | 
|  | 8345 | params->fils_cache_id)) || | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8346 | (params->pmk_lifetime && | 
|  | 8347 | nla_put_u32(msg, NL80211_ATTR_PMK_LIFETIME, | 
|  | 8348 | params->pmk_lifetime)) || | 
|  | 8349 | (params->pmk_reauth_threshold && | 
|  | 8350 | nla_put_u8(msg, NL80211_ATTR_PMK_REAUTH_THRESHOLD, | 
|  | 8351 | params->pmk_reauth_threshold)) || | 
| Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 8352 | (cmd != NL80211_CMD_DEL_PMKSA && | 
|  | 8353 | params->pmk_len && params->pmk_len <= PMK_MAX_LEN && | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8354 | nla_put(msg, NL80211_ATTR_PMK, params->pmk_len, params->pmk))) { | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8355 | nl80211_nlmsg_clear(msg); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8356 | nlmsg_free(msg); | 
|  | 8357 | return -ENOBUFS; | 
|  | 8358 | } | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8359 |  | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8360 | return send_and_recv_msgs(bss->drv, msg, NULL, (void *) -1); | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8361 | } | 
|  | 8362 |  | 
|  | 8363 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8364 | static int nl80211_add_pmkid(void *priv, struct wpa_pmkid_params *params) | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8365 | { | 
|  | 8366 | struct i802_bss *bss = priv; | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8367 | int ret; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8368 |  | 
|  | 8369 | if (params->bssid) | 
|  | 8370 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, | 
|  | 8371 | MAC2STR(params->bssid)); | 
|  | 8372 | else if (params->fils_cache_id && params->ssid_len) { | 
|  | 8373 | wpa_printf(MSG_DEBUG, | 
|  | 8374 | "nl80211: Add PMKSA for cache id %02x%02x SSID %s", | 
|  | 8375 | params->fils_cache_id[0], params->fils_cache_id[1], | 
|  | 8376 | wpa_ssid_txt(params->ssid, params->ssid_len)); | 
|  | 8377 | } | 
|  | 8378 |  | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8379 | ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params); | 
|  | 8380 | if (ret < 0) { | 
|  | 8381 | wpa_printf(MSG_DEBUG, | 
|  | 8382 | "nl80211: NL80211_CMD_SET_PMKSA failed: %d (%s)", | 
|  | 8383 | ret, strerror(-ret)); | 
|  | 8384 | } | 
|  | 8385 |  | 
|  | 8386 | return ret; | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8387 | } | 
|  | 8388 |  | 
|  | 8389 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8390 | static int nl80211_remove_pmkid(void *priv, struct wpa_pmkid_params *params) | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8391 | { | 
|  | 8392 | struct i802_bss *bss = priv; | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8393 | int ret; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8394 |  | 
|  | 8395 | if (params->bssid) | 
|  | 8396 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, | 
|  | 8397 | MAC2STR(params->bssid)); | 
|  | 8398 | else if (params->fils_cache_id && params->ssid_len) { | 
|  | 8399 | wpa_printf(MSG_DEBUG, | 
|  | 8400 | "nl80211: Delete PMKSA for cache id %02x%02x SSID %s", | 
|  | 8401 | params->fils_cache_id[0], params->fils_cache_id[1], | 
|  | 8402 | wpa_ssid_txt(params->ssid, params->ssid_len)); | 
|  | 8403 | } | 
|  | 8404 |  | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8405 | ret = nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, params); | 
|  | 8406 | if (ret < 0) { | 
|  | 8407 | wpa_printf(MSG_DEBUG, | 
|  | 8408 | "nl80211: NL80211_CMD_DEL_PMKSA failed: %d (%s)", | 
|  | 8409 | ret, strerror(-ret)); | 
|  | 8410 | } | 
|  | 8411 |  | 
|  | 8412 | return ret; | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8413 | } | 
|  | 8414 |  | 
|  | 8415 |  | 
|  | 8416 | static int nl80211_flush_pmkid(void *priv) | 
|  | 8417 | { | 
|  | 8418 | struct i802_bss *bss = priv; | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8419 | struct nl_msg *msg; | 
|  | 8420 |  | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8421 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8422 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_FLUSH_PMKSA); | 
|  | 8423 | if (!msg) | 
|  | 8424 | return -ENOBUFS; | 
|  | 8425 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8426 | } | 
|  | 8427 |  | 
|  | 8428 |  | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8429 | static void clean_survey_results(struct survey_results *survey_results) | 
|  | 8430 | { | 
|  | 8431 | struct freq_survey *survey, *tmp; | 
|  | 8432 |  | 
|  | 8433 | if (dl_list_empty(&survey_results->survey_list)) | 
|  | 8434 | return; | 
|  | 8435 |  | 
|  | 8436 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, | 
|  | 8437 | struct freq_survey, list) { | 
|  | 8438 | dl_list_del(&survey->list); | 
|  | 8439 | os_free(survey); | 
|  | 8440 | } | 
|  | 8441 | } | 
|  | 8442 |  | 
|  | 8443 |  | 
|  | 8444 | static void add_survey(struct nlattr **sinfo, u32 ifidx, | 
|  | 8445 | struct dl_list *survey_list) | 
|  | 8446 | { | 
|  | 8447 | struct freq_survey *survey; | 
|  | 8448 |  | 
|  | 8449 | survey = os_zalloc(sizeof(struct freq_survey)); | 
|  | 8450 | if  (!survey) | 
|  | 8451 | return; | 
|  | 8452 |  | 
|  | 8453 | survey->ifidx = ifidx; | 
|  | 8454 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | 
|  | 8455 | survey->filled = 0; | 
|  | 8456 |  | 
|  | 8457 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { | 
|  | 8458 | survey->nf = (int8_t) | 
|  | 8459 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); | 
|  | 8460 | survey->filled |= SURVEY_HAS_NF; | 
|  | 8461 | } | 
|  | 8462 |  | 
|  | 8463 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { | 
|  | 8464 | survey->channel_time = | 
|  | 8465 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); | 
|  | 8466 | survey->filled |= SURVEY_HAS_CHAN_TIME; | 
|  | 8467 | } | 
|  | 8468 |  | 
|  | 8469 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { | 
|  | 8470 | survey->channel_time_busy = | 
|  | 8471 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); | 
|  | 8472 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; | 
|  | 8473 | } | 
|  | 8474 |  | 
|  | 8475 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { | 
|  | 8476 | survey->channel_time_rx = | 
|  | 8477 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); | 
|  | 8478 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; | 
|  | 8479 | } | 
|  | 8480 |  | 
|  | 8481 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { | 
|  | 8482 | survey->channel_time_tx = | 
|  | 8483 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); | 
|  | 8484 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; | 
|  | 8485 | } | 
|  | 8486 |  | 
|  | 8487 | 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)", | 
|  | 8488 | survey->freq, | 
|  | 8489 | survey->nf, | 
|  | 8490 | (unsigned long int) survey->channel_time, | 
|  | 8491 | (unsigned long int) survey->channel_time_busy, | 
|  | 8492 | (unsigned long int) survey->channel_time_tx, | 
|  | 8493 | (unsigned long int) survey->channel_time_rx, | 
|  | 8494 | survey->filled); | 
|  | 8495 |  | 
|  | 8496 | dl_list_add_tail(survey_list, &survey->list); | 
|  | 8497 | } | 
|  | 8498 |  | 
|  | 8499 |  | 
|  | 8500 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, | 
|  | 8501 | unsigned int freq_filter) | 
|  | 8502 | { | 
|  | 8503 | if (!freq_filter) | 
|  | 8504 | return 1; | 
|  | 8505 |  | 
|  | 8506 | return freq_filter == surveyed_freq; | 
|  | 8507 | } | 
|  | 8508 |  | 
|  | 8509 |  | 
|  | 8510 | static int survey_handler(struct nl_msg *msg, void *arg) | 
|  | 8511 | { | 
|  | 8512 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | 
|  | 8513 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | 
|  | 8514 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; | 
|  | 8515 | struct survey_results *survey_results; | 
|  | 8516 | u32 surveyed_freq = 0; | 
|  | 8517 | u32 ifidx; | 
|  | 8518 |  | 
|  | 8519 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { | 
|  | 8520 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, | 
|  | 8521 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, | 
|  | 8522 | }; | 
|  | 8523 |  | 
|  | 8524 | survey_results = (struct survey_results *) arg; | 
|  | 8525 |  | 
|  | 8526 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | 
|  | 8527 | genlmsg_attrlen(gnlh, 0), NULL); | 
|  | 8528 |  | 
| Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 8529 | if (!tb[NL80211_ATTR_IFINDEX]) | 
|  | 8530 | return NL_SKIP; | 
|  | 8531 |  | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8532 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); | 
|  | 8533 |  | 
|  | 8534 | if (!tb[NL80211_ATTR_SURVEY_INFO]) | 
|  | 8535 | return NL_SKIP; | 
|  | 8536 |  | 
|  | 8537 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, | 
|  | 8538 | tb[NL80211_ATTR_SURVEY_INFO], | 
|  | 8539 | survey_policy)) | 
|  | 8540 | return NL_SKIP; | 
|  | 8541 |  | 
|  | 8542 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { | 
|  | 8543 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); | 
|  | 8544 | return NL_SKIP; | 
|  | 8545 | } | 
|  | 8546 |  | 
|  | 8547 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); | 
|  | 8548 |  | 
|  | 8549 | if (!check_survey_ok(sinfo, surveyed_freq, | 
|  | 8550 | survey_results->freq_filter)) | 
|  | 8551 | return NL_SKIP; | 
|  | 8552 |  | 
|  | 8553 | if (survey_results->freq_filter && | 
|  | 8554 | survey_results->freq_filter != surveyed_freq) { | 
|  | 8555 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", | 
|  | 8556 | surveyed_freq); | 
|  | 8557 | return NL_SKIP; | 
|  | 8558 | } | 
|  | 8559 |  | 
|  | 8560 | add_survey(sinfo, ifidx, &survey_results->survey_list); | 
|  | 8561 |  | 
|  | 8562 | return NL_SKIP; | 
|  | 8563 | } | 
|  | 8564 |  | 
|  | 8565 |  | 
|  | 8566 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) | 
|  | 8567 | { | 
|  | 8568 | struct i802_bss *bss = priv; | 
|  | 8569 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 8570 | struct nl_msg *msg; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8571 | int err; | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8572 | union wpa_event_data data; | 
|  | 8573 | struct survey_results *survey_results; | 
|  | 8574 |  | 
|  | 8575 | os_memset(&data, 0, sizeof(data)); | 
|  | 8576 | survey_results = &data.survey_results; | 
|  | 8577 |  | 
|  | 8578 | dl_list_init(&survey_results->survey_list); | 
|  | 8579 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8580 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8581 | if (!msg) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8582 | return -ENOBUFS; | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8583 |  | 
|  | 8584 | if (freq) | 
|  | 8585 | data.survey_results.freq_filter = freq; | 
|  | 8586 |  | 
|  | 8587 | do { | 
|  | 8588 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); | 
|  | 8589 | err = send_and_recv_msgs(drv, msg, survey_handler, | 
|  | 8590 | survey_results); | 
|  | 8591 | } while (err > 0); | 
|  | 8592 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8593 | if (err) | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8594 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8595 | else | 
|  | 8596 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8597 |  | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8598 | clean_survey_results(survey_results); | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8599 | return err; | 
|  | 8600 | } | 
|  | 8601 |  | 
|  | 8602 |  | 
| Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 8603 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, | 
|  | 8604 | const u8 *kck, size_t kck_len, | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8605 | const u8 *replay_ctr) | 
|  | 8606 | { | 
|  | 8607 | struct i802_bss *bss = priv; | 
|  | 8608 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 8609 | struct nlattr *replay_nested; | 
|  | 8610 | struct nl_msg *msg; | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8611 | int ret; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8612 |  | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8613 | if (!drv->set_rekey_offload) | 
|  | 8614 | return; | 
|  | 8615 |  | 
|  | 8616 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8617 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || | 
|  | 8618 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || | 
| Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 8619 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8620 | (kck_len && nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck)) || | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8621 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, | 
|  | 8622 | replay_ctr)) { | 
|  | 8623 | nl80211_nlmsg_clear(msg); | 
|  | 8624 | nlmsg_free(msg); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8625 | return; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8626 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8627 |  | 
|  | 8628 | nla_nest_end(msg, replay_nested); | 
|  | 8629 |  | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8630 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); | 
|  | 8631 | if (ret == -EOPNOTSUPP) { | 
|  | 8632 | wpa_printf(MSG_DEBUG, | 
|  | 8633 | "nl80211: Driver does not support rekey offload"); | 
|  | 8634 | drv->set_rekey_offload = 0; | 
|  | 8635 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8636 | } | 
|  | 8637 |  | 
|  | 8638 |  | 
|  | 8639 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, | 
|  | 8640 | const u8 *addr, int qos) | 
|  | 8641 | { | 
|  | 8642 | /* send data frame to poll STA and check whether | 
|  | 8643 | * this frame is ACKed */ | 
|  | 8644 | struct { | 
|  | 8645 | struct ieee80211_hdr hdr; | 
|  | 8646 | u16 qos_ctl; | 
|  | 8647 | } STRUCT_PACKED nulldata; | 
|  | 8648 | size_t size; | 
|  | 8649 |  | 
|  | 8650 | /* Send data frame to poll STA and check whether this frame is ACKed */ | 
|  | 8651 |  | 
|  | 8652 | os_memset(&nulldata, 0, sizeof(nulldata)); | 
|  | 8653 |  | 
|  | 8654 | if (qos) { | 
|  | 8655 | nulldata.hdr.frame_control = | 
|  | 8656 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | 
|  | 8657 | WLAN_FC_STYPE_QOS_NULL); | 
|  | 8658 | size = sizeof(nulldata); | 
|  | 8659 | } else { | 
|  | 8660 | nulldata.hdr.frame_control = | 
|  | 8661 | IEEE80211_FC(WLAN_FC_TYPE_DATA, | 
|  | 8662 | WLAN_FC_STYPE_NULLFUNC); | 
|  | 8663 | size = sizeof(struct ieee80211_hdr); | 
|  | 8664 | } | 
|  | 8665 |  | 
|  | 8666 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); | 
|  | 8667 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); | 
|  | 8668 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); | 
|  | 8669 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); | 
|  | 8670 |  | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8671 | 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] | 8672 | 0, 0, NULL, 0, 0) < 0) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8673 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " | 
|  | 8674 | "send poll frame"); | 
|  | 8675 | } | 
|  | 8676 |  | 
|  | 8677 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, | 
|  | 8678 | int qos) | 
|  | 8679 | { | 
|  | 8680 | struct i802_bss *bss = priv; | 
|  | 8681 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 8682 | struct nl_msg *msg; | 
| Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 8683 | u64 cookie; | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8684 | int ret; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8685 |  | 
|  | 8686 | if (!drv->poll_command_supported) { | 
|  | 8687 | nl80211_send_null_frame(bss, own_addr, addr, qos); | 
|  | 8688 | return; | 
|  | 8689 | } | 
|  | 8690 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8691 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || | 
|  | 8692 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | 
|  | 8693 | nlmsg_free(msg); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8694 | return; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8695 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8696 |  | 
| Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 8697 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8698 | if (ret < 0) { | 
|  | 8699 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " | 
|  | 8700 | MACSTR " failed: ret=%d (%s)", | 
|  | 8701 | MAC2STR(addr), ret, strerror(-ret)); | 
| Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 8702 | } else { | 
|  | 8703 | wpa_printf(MSG_DEBUG, | 
|  | 8704 | "nl80211: Client probe request addr=" MACSTR | 
|  | 8705 | " cookie=%llu", MAC2STR(addr), | 
|  | 8706 | (long long unsigned int) cookie); | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8707 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8708 | } | 
|  | 8709 |  | 
|  | 8710 |  | 
|  | 8711 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) | 
|  | 8712 | { | 
|  | 8713 | struct nl_msg *msg; | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8714 | int ret; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8715 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8716 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || | 
|  | 8717 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, | 
|  | 8718 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { | 
|  | 8719 | nlmsg_free(msg); | 
|  | 8720 | return -ENOBUFS; | 
|  | 8721 | } | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8722 |  | 
|  | 8723 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); | 
|  | 8724 | if (ret < 0) { | 
|  | 8725 | wpa_printf(MSG_DEBUG, | 
|  | 8726 | "nl80211: Setting PS state %s failed: %d (%s)", | 
|  | 8727 | enabled ? "enabled" : "disabled", | 
|  | 8728 | ret, strerror(-ret)); | 
|  | 8729 | } | 
|  | 8730 | return ret; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8731 | } | 
|  | 8732 |  | 
|  | 8733 |  | 
|  | 8734 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, | 
|  | 8735 | int ctwindow) | 
|  | 8736 | { | 
|  | 8737 | struct i802_bss *bss = priv; | 
|  | 8738 |  | 
|  | 8739 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " | 
|  | 8740 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); | 
|  | 8741 |  | 
| Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8742 | if (opp_ps != -1 || ctwindow != -1) { | 
| Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8743 | #ifdef ANDROID_P2P | 
|  | 8744 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); | 
| Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8745 | #else /* ANDROID_P2P */ | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8746 | return -1; /* Not yet supported */ | 
| Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8747 | #endif /* ANDROID_P2P */ | 
|  | 8748 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8749 |  | 
|  | 8750 | if (legacy_ps == -1) | 
|  | 8751 | return 0; | 
|  | 8752 | if (legacy_ps != 0 && legacy_ps != 1) | 
|  | 8753 | return -1; /* Not yet supported */ | 
|  | 8754 |  | 
|  | 8755 | return nl80211_set_power_save(bss, legacy_ps); | 
|  | 8756 | } | 
|  | 8757 |  | 
|  | 8758 |  | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8759 | static int nl80211_start_radar_detection(void *priv, | 
|  | 8760 | struct hostapd_freq_params *freq) | 
| Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8761 | { | 
|  | 8762 | struct i802_bss *bss = priv; | 
|  | 8763 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 8764 | struct nl_msg *msg; | 
|  | 8765 | int ret; | 
|  | 8766 |  | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 8767 | 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)", | 
|  | 8768 | freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled, | 
| Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8769 | freq->bandwidth, freq->center_freq1, freq->center_freq2); | 
|  | 8770 |  | 
| Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8771 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { | 
|  | 8772 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " | 
|  | 8773 | "detection"); | 
|  | 8774 | return -1; | 
|  | 8775 | } | 
|  | 8776 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8777 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || | 
|  | 8778 | nl80211_put_freq_params(msg, freq) < 0) { | 
|  | 8779 | nlmsg_free(msg); | 
| Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8780 | return -1; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8781 | } | 
| Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8782 |  | 
|  | 8783 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 8784 | if (ret == 0) | 
|  | 8785 | return 0; | 
|  | 8786 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " | 
|  | 8787 | "%d (%s)", ret, strerror(-ret)); | 
| Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8788 | return -1; | 
|  | 8789 | } | 
|  | 8790 |  | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8791 | #ifdef CONFIG_TDLS | 
|  | 8792 |  | 
|  | 8793 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, | 
|  | 8794 | u8 dialog_token, u16 status_code, | 
| Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 8795 | u32 peer_capab, int initiator, const u8 *buf, | 
|  | 8796 | size_t len) | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8797 | { | 
|  | 8798 | struct i802_bss *bss = priv; | 
|  | 8799 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 8800 | struct nl_msg *msg; | 
|  | 8801 |  | 
|  | 8802 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | 
|  | 8803 | return -EOPNOTSUPP; | 
|  | 8804 |  | 
|  | 8805 | if (!dst) | 
|  | 8806 | return -EINVAL; | 
|  | 8807 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8808 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || | 
|  | 8809 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || | 
|  | 8810 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || | 
|  | 8811 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || | 
|  | 8812 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) | 
|  | 8813 | goto fail; | 
| Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8814 | if (peer_capab) { | 
|  | 8815 | /* | 
|  | 8816 | * The internal enum tdls_peer_capability definition is | 
|  | 8817 | * currently identical with the nl80211 enum | 
|  | 8818 | * nl80211_tdls_peer_capability, so no conversion is needed | 
|  | 8819 | * here. | 
|  | 8820 | */ | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8821 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, | 
|  | 8822 | peer_capab)) | 
|  | 8823 | goto fail; | 
| Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8824 | } | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8825 | if ((initiator && | 
|  | 8826 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || | 
|  | 8827 | nla_put(msg, NL80211_ATTR_IE, len, buf)) | 
|  | 8828 | goto fail; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8829 |  | 
|  | 8830 | return send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 8831 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8832 | fail: | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8833 | nlmsg_free(msg); | 
|  | 8834 | return -ENOBUFS; | 
|  | 8835 | } | 
|  | 8836 |  | 
|  | 8837 |  | 
|  | 8838 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) | 
|  | 8839 | { | 
|  | 8840 | struct i802_bss *bss = priv; | 
|  | 8841 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 8842 | struct nl_msg *msg; | 
|  | 8843 | enum nl80211_tdls_operation nl80211_oper; | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8844 | int res; | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8845 |  | 
|  | 8846 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) | 
|  | 8847 | return -EOPNOTSUPP; | 
|  | 8848 |  | 
|  | 8849 | switch (oper) { | 
|  | 8850 | case TDLS_DISCOVERY_REQ: | 
|  | 8851 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; | 
|  | 8852 | break; | 
|  | 8853 | case TDLS_SETUP: | 
|  | 8854 | nl80211_oper = NL80211_TDLS_SETUP; | 
|  | 8855 | break; | 
|  | 8856 | case TDLS_TEARDOWN: | 
|  | 8857 | nl80211_oper = NL80211_TDLS_TEARDOWN; | 
|  | 8858 | break; | 
|  | 8859 | case TDLS_ENABLE_LINK: | 
|  | 8860 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; | 
|  | 8861 | break; | 
|  | 8862 | case TDLS_DISABLE_LINK: | 
|  | 8863 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; | 
|  | 8864 | break; | 
|  | 8865 | case TDLS_ENABLE: | 
|  | 8866 | return 0; | 
|  | 8867 | case TDLS_DISABLE: | 
|  | 8868 | return 0; | 
|  | 8869 | default: | 
|  | 8870 | return -EINVAL; | 
|  | 8871 | } | 
|  | 8872 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8873 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || | 
|  | 8874 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || | 
|  | 8875 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { | 
|  | 8876 | nlmsg_free(msg); | 
|  | 8877 | return -ENOBUFS; | 
|  | 8878 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8879 |  | 
| Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8880 | res = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 8881 | wpa_printf(MSG_DEBUG, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR | 
|  | 8882 | " --> res=%d (%s)", nl80211_oper, MAC2STR(peer), res, | 
|  | 8883 | strerror(-res)); | 
|  | 8884 | return res; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8885 | } | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8886 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8887 |  | 
|  | 8888 | static int | 
|  | 8889 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, | 
|  | 8890 | const struct hostapd_freq_params *params) | 
|  | 8891 | { | 
|  | 8892 | struct i802_bss *bss = priv; | 
|  | 8893 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 8894 | struct nl_msg *msg; | 
|  | 8895 | int ret = -ENOBUFS; | 
|  | 8896 |  | 
|  | 8897 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || | 
|  | 8898 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) | 
|  | 8899 | return -EOPNOTSUPP; | 
|  | 8900 |  | 
|  | 8901 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR | 
|  | 8902 | " oper_class=%u freq=%u", | 
|  | 8903 | MAC2STR(addr), oper_class, params->freq); | 
|  | 8904 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); | 
|  | 8905 | if (!msg || | 
|  | 8906 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | 
|  | 8907 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || | 
|  | 8908 | (ret = nl80211_put_freq_params(msg, params))) { | 
|  | 8909 | nlmsg_free(msg); | 
|  | 8910 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); | 
|  | 8911 | return ret; | 
|  | 8912 | } | 
|  | 8913 |  | 
|  | 8914 | return send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 8915 | } | 
|  | 8916 |  | 
|  | 8917 |  | 
|  | 8918 | static int | 
|  | 8919 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) | 
|  | 8920 | { | 
|  | 8921 | struct i802_bss *bss = priv; | 
|  | 8922 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 8923 | struct nl_msg *msg; | 
|  | 8924 |  | 
|  | 8925 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || | 
|  | 8926 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) | 
|  | 8927 | return -EOPNOTSUPP; | 
|  | 8928 |  | 
|  | 8929 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, | 
|  | 8930 | MAC2STR(addr)); | 
|  | 8931 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); | 
|  | 8932 | if (!msg || | 
|  | 8933 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | 
|  | 8934 | nlmsg_free(msg); | 
|  | 8935 | wpa_printf(MSG_DEBUG, | 
|  | 8936 | "nl80211: Could not build TDLS cancel chan switch"); | 
|  | 8937 | return -ENOBUFS; | 
|  | 8938 | } | 
|  | 8939 |  | 
|  | 8940 | return send_and_recv_msgs(drv, msg, NULL, NULL); | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8941 | } | 
|  | 8942 |  | 
|  | 8943 | #endif /* CONFIG TDLS */ | 
|  | 8944 |  | 
|  | 8945 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8946 | static int driver_nl80211_set_key(void *priv, | 
|  | 8947 | struct wpa_driver_set_key_params *params) | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8948 | { | 
|  | 8949 | struct i802_bss *bss = priv; | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 8950 |  | 
|  | 8951 | return wpa_driver_nl80211_set_key(bss, params); | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8952 | } | 
|  | 8953 |  | 
|  | 8954 |  | 
|  | 8955 | static int driver_nl80211_scan2(void *priv, | 
|  | 8956 | struct wpa_driver_scan_params *params) | 
|  | 8957 | { | 
|  | 8958 | struct i802_bss *bss = priv; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8959 | #ifdef CONFIG_DRIVER_NL80211_QCA | 
|  | 8960 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 8961 |  | 
|  | 8962 | /* | 
|  | 8963 | * Do a vendor specific scan if possible. If only_new_results is | 
|  | 8964 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush | 
|  | 8965 | * cannot be achieved through a vendor scan. The below condition may | 
|  | 8966 | * need to be modified if new scan flags are added in the future whose | 
|  | 8967 | * functionality can only be achieved through a normal scan. | 
|  | 8968 | */ | 
|  | 8969 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) | 
|  | 8970 | return wpa_driver_nl80211_vendor_scan(bss, params); | 
|  | 8971 | #endif /* CONFIG_DRIVER_NL80211_QCA */ | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8972 | return wpa_driver_nl80211_scan(bss, params); | 
|  | 8973 | } | 
|  | 8974 |  | 
|  | 8975 |  | 
|  | 8976 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 8977 | u16 reason_code) | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8978 | { | 
|  | 8979 | struct i802_bss *bss = priv; | 
|  | 8980 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); | 
|  | 8981 | } | 
|  | 8982 |  | 
|  | 8983 |  | 
|  | 8984 | static int driver_nl80211_authenticate(void *priv, | 
|  | 8985 | struct wpa_driver_auth_params *params) | 
|  | 8986 | { | 
|  | 8987 | struct i802_bss *bss = priv; | 
|  | 8988 | return wpa_driver_nl80211_authenticate(bss, params); | 
|  | 8989 | } | 
|  | 8990 |  | 
|  | 8991 |  | 
|  | 8992 | static void driver_nl80211_deinit(void *priv) | 
|  | 8993 | { | 
|  | 8994 | struct i802_bss *bss = priv; | 
|  | 8995 | wpa_driver_nl80211_deinit(bss); | 
|  | 8996 | } | 
|  | 8997 |  | 
|  | 8998 |  | 
|  | 8999 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, | 
|  | 9000 | const char *ifname) | 
|  | 9001 | { | 
|  | 9002 | struct i802_bss *bss = priv; | 
|  | 9003 | return wpa_driver_nl80211_if_remove(bss, type, ifname); | 
|  | 9004 | } | 
|  | 9005 |  | 
|  | 9006 |  | 
|  | 9007 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 9008 | size_t data_len, int noack, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9009 | unsigned int freq, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9010 | const u16 *csa_offs, size_t csa_offs_len, | 
|  | 9011 | int no_encrypt, unsigned int wait) | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9012 | { | 
|  | 9013 | struct i802_bss *bss = priv; | 
|  | 9014 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9015 | freq, 0, 0, wait, csa_offs, | 
|  | 9016 | csa_offs_len, no_encrypt); | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9017 | } | 
|  | 9018 |  | 
|  | 9019 |  | 
|  | 9020 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) | 
|  | 9021 | { | 
|  | 9022 | struct i802_bss *bss = priv; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9023 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9024 | } | 
|  | 9025 |  | 
|  | 9026 |  | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9027 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, | 
|  | 9028 | const char *ifname, int vlan_id) | 
|  | 9029 | { | 
|  | 9030 | struct i802_bss *bss = priv; | 
|  | 9031 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); | 
|  | 9032 | } | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9033 |  | 
|  | 9034 |  | 
|  | 9035 | static int driver_nl80211_read_sta_data(void *priv, | 
|  | 9036 | struct hostap_sta_driver_data *data, | 
|  | 9037 | const u8 *addr) | 
|  | 9038 | { | 
|  | 9039 | struct i802_bss *bss = priv; | 
| Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 9040 |  | 
|  | 9041 | os_memset(data, 0, sizeof(*data)); | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9042 | return i802_read_sta_data(bss, data, addr); | 
|  | 9043 | } | 
|  | 9044 |  | 
|  | 9045 |  | 
|  | 9046 | static int driver_nl80211_send_action(void *priv, unsigned int freq, | 
|  | 9047 | unsigned int wait_time, | 
|  | 9048 | const u8 *dst, const u8 *src, | 
|  | 9049 | const u8 *bssid, | 
|  | 9050 | const u8 *data, size_t data_len, | 
|  | 9051 | int no_cck) | 
|  | 9052 | { | 
|  | 9053 | struct i802_bss *bss = priv; | 
|  | 9054 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, | 
|  | 9055 | bssid, data, data_len, no_cck); | 
|  | 9056 | } | 
|  | 9057 |  | 
|  | 9058 |  | 
|  | 9059 | static int driver_nl80211_probe_req_report(void *priv, int report) | 
|  | 9060 | { | 
|  | 9061 | struct i802_bss *bss = priv; | 
|  | 9062 | return wpa_driver_nl80211_probe_req_report(bss, report); | 
|  | 9063 | } | 
|  | 9064 |  | 
|  | 9065 |  | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 9066 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, | 
|  | 9067 | const u8 *ies, size_t ies_len) | 
|  | 9068 | { | 
|  | 9069 | int ret; | 
|  | 9070 | struct nl_msg *msg; | 
|  | 9071 | struct i802_bss *bss = priv; | 
|  | 9072 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 9073 | u16 mdid = WPA_GET_LE16(md); | 
|  | 9074 |  | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 9075 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9076 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || | 
|  | 9077 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || | 
|  | 9078 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { | 
|  | 9079 | nlmsg_free(msg); | 
|  | 9080 | return -ENOBUFS; | 
|  | 9081 | } | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 9082 |  | 
|  | 9083 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 9084 | if (ret) { | 
|  | 9085 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " | 
|  | 9086 | "err=%d (%s)", ret, strerror(-ret)); | 
|  | 9087 | } | 
|  | 9088 |  | 
|  | 9089 | return ret; | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 9090 | } | 
|  | 9091 |  | 
|  | 9092 |  | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 9093 | static int nl80211_update_dh_ie(void *priv, const u8 *peer_mac, | 
|  | 9094 | u16 reason_code, const u8 *ie, size_t ie_len) | 
|  | 9095 | { | 
|  | 9096 | int ret; | 
|  | 9097 | struct nl_msg *msg; | 
|  | 9098 | struct i802_bss *bss = priv; | 
|  | 9099 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 9100 |  | 
|  | 9101 | wpa_printf(MSG_DEBUG, "nl80211: Updating DH IE peer: " MACSTR | 
|  | 9102 | " reason %u", MAC2STR(peer_mac), reason_code); | 
|  | 9103 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UPDATE_OWE_INFO)) || | 
|  | 9104 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer_mac) || | 
|  | 9105 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, reason_code) || | 
|  | 9106 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) { | 
|  | 9107 | nlmsg_free(msg); | 
|  | 9108 | return -ENOBUFS; | 
|  | 9109 | } | 
|  | 9110 |  | 
|  | 9111 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 9112 | if (ret) { | 
|  | 9113 | wpa_printf(MSG_DEBUG, | 
|  | 9114 | "nl80211: update_dh_ie failed err=%d (%s)", | 
|  | 9115 | ret, strerror(-ret)); | 
|  | 9116 | } | 
|  | 9117 |  | 
|  | 9118 | return ret; | 
|  | 9119 | } | 
|  | 9120 |  | 
|  | 9121 |  | 
| Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 9122 | static const u8 * wpa_driver_nl80211_get_macaddr(void *priv) | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9123 | { | 
|  | 9124 | struct i802_bss *bss = priv; | 
|  | 9125 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 9126 |  | 
|  | 9127 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) | 
|  | 9128 | return NULL; | 
|  | 9129 |  | 
|  | 9130 | return bss->addr; | 
|  | 9131 | } | 
|  | 9132 |  | 
|  | 9133 |  | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9134 | static const char * scan_state_str(enum scan_states scan_state) | 
|  | 9135 | { | 
|  | 9136 | switch (scan_state) { | 
|  | 9137 | case NO_SCAN: | 
|  | 9138 | return "NO_SCAN"; | 
|  | 9139 | case SCAN_REQUESTED: | 
|  | 9140 | return "SCAN_REQUESTED"; | 
|  | 9141 | case SCAN_STARTED: | 
|  | 9142 | return "SCAN_STARTED"; | 
|  | 9143 | case SCAN_COMPLETED: | 
|  | 9144 | return "SCAN_COMPLETED"; | 
|  | 9145 | case SCAN_ABORTED: | 
|  | 9146 | return "SCAN_ABORTED"; | 
|  | 9147 | case SCHED_SCAN_STARTED: | 
|  | 9148 | return "SCHED_SCAN_STARTED"; | 
|  | 9149 | case SCHED_SCAN_STOPPED: | 
|  | 9150 | return "SCHED_SCAN_STOPPED"; | 
|  | 9151 | case SCHED_SCAN_RESULTS: | 
|  | 9152 | return "SCHED_SCAN_RESULTS"; | 
|  | 9153 | } | 
|  | 9154 |  | 
|  | 9155 | return "??"; | 
|  | 9156 | } | 
|  | 9157 |  | 
|  | 9158 |  | 
|  | 9159 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) | 
|  | 9160 | { | 
|  | 9161 | struct i802_bss *bss = priv; | 
|  | 9162 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 9163 | int res; | 
|  | 9164 | char *pos, *end; | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9165 | struct nl_msg *msg; | 
|  | 9166 | char alpha2[3] = { 0, 0, 0 }; | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9167 |  | 
|  | 9168 | pos = buf; | 
|  | 9169 | end = buf + buflen; | 
|  | 9170 |  | 
|  | 9171 | res = os_snprintf(pos, end - pos, | 
|  | 9172 | "ifindex=%d\n" | 
|  | 9173 | "ifname=%s\n" | 
|  | 9174 | "brname=%s\n" | 
|  | 9175 | "addr=" MACSTR "\n" | 
|  | 9176 | "freq=%d\n" | 
| Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 9177 | "%s%s%s%s%s%s", | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9178 | bss->ifindex, | 
|  | 9179 | bss->ifname, | 
|  | 9180 | bss->brname, | 
|  | 9181 | MAC2STR(bss->addr), | 
|  | 9182 | bss->freq, | 
|  | 9183 | bss->beacon_set ? "beacon_set=1\n" : "", | 
|  | 9184 | bss->added_if_into_bridge ? | 
|  | 9185 | "added_if_into_bridge=1\n" : "", | 
| Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 9186 | bss->already_in_bridge ? "already_in_bridge=1\n" : "", | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9187 | bss->added_bridge ? "added_bridge=1\n" : "", | 
|  | 9188 | bss->in_deinit ? "in_deinit=1\n" : "", | 
|  | 9189 | bss->if_dynamic ? "if_dynamic=1\n" : ""); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9190 | if (os_snprintf_error(end - pos, res)) | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9191 | return pos - buf; | 
|  | 9192 | pos += res; | 
|  | 9193 |  | 
|  | 9194 | if (bss->wdev_id_set) { | 
|  | 9195 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", | 
|  | 9196 | (unsigned long long) bss->wdev_id); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9197 | if (os_snprintf_error(end - pos, res)) | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9198 | return pos - buf; | 
|  | 9199 | pos += res; | 
|  | 9200 | } | 
|  | 9201 |  | 
|  | 9202 | res = os_snprintf(pos, end - pos, | 
|  | 9203 | "phyname=%s\n" | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9204 | "perm_addr=" MACSTR "\n" | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9205 | "drv_ifindex=%d\n" | 
|  | 9206 | "operstate=%d\n" | 
|  | 9207 | "scan_state=%s\n" | 
|  | 9208 | "auth_bssid=" MACSTR "\n" | 
|  | 9209 | "auth_attempt_bssid=" MACSTR "\n" | 
|  | 9210 | "bssid=" MACSTR "\n" | 
|  | 9211 | "prev_bssid=" MACSTR "\n" | 
|  | 9212 | "associated=%d\n" | 
|  | 9213 | "assoc_freq=%u\n" | 
|  | 9214 | "monitor_sock=%d\n" | 
|  | 9215 | "monitor_ifidx=%d\n" | 
|  | 9216 | "monitor_refcount=%d\n" | 
|  | 9217 | "last_mgmt_freq=%u\n" | 
|  | 9218 | "eapol_tx_sock=%d\n" | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9219 | "%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] | 9220 | drv->phyname, | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9221 | MAC2STR(drv->perm_addr), | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9222 | drv->ifindex, | 
|  | 9223 | drv->operstate, | 
|  | 9224 | scan_state_str(drv->scan_state), | 
|  | 9225 | MAC2STR(drv->auth_bssid), | 
|  | 9226 | MAC2STR(drv->auth_attempt_bssid), | 
|  | 9227 | MAC2STR(drv->bssid), | 
|  | 9228 | MAC2STR(drv->prev_bssid), | 
|  | 9229 | drv->associated, | 
|  | 9230 | drv->assoc_freq, | 
|  | 9231 | drv->monitor_sock, | 
|  | 9232 | drv->monitor_ifidx, | 
|  | 9233 | drv->monitor_refcount, | 
|  | 9234 | drv->last_mgmt_freq, | 
|  | 9235 | drv->eapol_tx_sock, | 
|  | 9236 | drv->ignore_if_down_event ? | 
|  | 9237 | "ignore_if_down_event=1\n" : "", | 
|  | 9238 | drv->scan_complete_events ? | 
|  | 9239 | "scan_complete_events=1\n" : "", | 
|  | 9240 | drv->disabled_11b_rates ? | 
|  | 9241 | "disabled_11b_rates=1\n" : "", | 
|  | 9242 | drv->pending_remain_on_chan ? | 
|  | 9243 | "pending_remain_on_chan=1\n" : "", | 
|  | 9244 | drv->in_interface_list ? "in_interface_list=1\n" : "", | 
|  | 9245 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", | 
|  | 9246 | drv->poll_command_supported ? | 
|  | 9247 | "poll_command_supported=1\n" : "", | 
|  | 9248 | drv->data_tx_status ? "data_tx_status=1\n" : "", | 
|  | 9249 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", | 
|  | 9250 | drv->retry_auth ? "retry_auth=1\n" : "", | 
|  | 9251 | drv->use_monitor ? "use_monitor=1\n" : "", | 
|  | 9252 | drv->ignore_next_local_disconnect ? | 
|  | 9253 | "ignore_next_local_disconnect=1\n" : "", | 
| Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 9254 | drv->ignore_next_local_deauth ? | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9255 | "ignore_next_local_deauth=1\n" : ""); | 
|  | 9256 | if (os_snprintf_error(end - pos, res)) | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9257 | return pos - buf; | 
|  | 9258 | pos += res; | 
|  | 9259 |  | 
|  | 9260 | if (drv->has_capability) { | 
|  | 9261 | res = os_snprintf(pos, end - pos, | 
|  | 9262 | "capa.key_mgmt=0x%x\n" | 
|  | 9263 | "capa.enc=0x%x\n" | 
|  | 9264 | "capa.auth=0x%x\n" | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9265 | "capa.flags=0x%llx\n" | 
|  | 9266 | "capa.rrm_flags=0x%x\n" | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9267 | "capa.max_scan_ssids=%d\n" | 
|  | 9268 | "capa.max_sched_scan_ssids=%d\n" | 
|  | 9269 | "capa.sched_scan_supported=%d\n" | 
|  | 9270 | "capa.max_match_sets=%d\n" | 
|  | 9271 | "capa.max_remain_on_chan=%u\n" | 
|  | 9272 | "capa.max_stations=%u\n" | 
|  | 9273 | "capa.probe_resp_offloads=0x%x\n" | 
|  | 9274 | "capa.max_acl_mac_addrs=%u\n" | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9275 | "capa.num_multichan_concurrent=%u\n" | 
|  | 9276 | "capa.mac_addr_rand_sched_scan_supported=%d\n" | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9277 | "capa.mac_addr_rand_scan_supported=%d\n" | 
|  | 9278 | "capa.conc_capab=%u\n" | 
|  | 9279 | "capa.max_conc_chan_2_4=%u\n" | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9280 | "capa.max_conc_chan_5_0=%u\n" | 
|  | 9281 | "capa.max_sched_scan_plans=%u\n" | 
|  | 9282 | "capa.max_sched_scan_plan_interval=%u\n" | 
|  | 9283 | "capa.max_sched_scan_plan_iterations=%u\n", | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9284 | drv->capa.key_mgmt, | 
|  | 9285 | drv->capa.enc, | 
|  | 9286 | drv->capa.auth, | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9287 | (unsigned long long) drv->capa.flags, | 
|  | 9288 | drv->capa.rrm_flags, | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9289 | drv->capa.max_scan_ssids, | 
|  | 9290 | drv->capa.max_sched_scan_ssids, | 
|  | 9291 | drv->capa.sched_scan_supported, | 
|  | 9292 | drv->capa.max_match_sets, | 
|  | 9293 | drv->capa.max_remain_on_chan, | 
|  | 9294 | drv->capa.max_stations, | 
|  | 9295 | drv->capa.probe_resp_offloads, | 
|  | 9296 | drv->capa.max_acl_mac_addrs, | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9297 | drv->capa.num_multichan_concurrent, | 
|  | 9298 | drv->capa.mac_addr_rand_sched_scan_supported, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9299 | drv->capa.mac_addr_rand_scan_supported, | 
|  | 9300 | drv->capa.conc_capab, | 
|  | 9301 | drv->capa.max_conc_chan_2_4, | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9302 | drv->capa.max_conc_chan_5_0, | 
|  | 9303 | drv->capa.max_sched_scan_plans, | 
|  | 9304 | drv->capa.max_sched_scan_plan_interval, | 
|  | 9305 | drv->capa.max_sched_scan_plan_iterations); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9306 | if (os_snprintf_error(end - pos, res)) | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9307 | return pos - buf; | 
|  | 9308 | pos += res; | 
|  | 9309 | } | 
|  | 9310 |  | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9311 | msg = nlmsg_alloc(); | 
|  | 9312 | if (msg && | 
|  | 9313 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG) && | 
|  | 9314 | nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx) == 0) { | 
|  | 9315 | if (send_and_recv_msgs(drv, msg, nl80211_get_country, | 
|  | 9316 | alpha2) == 0 && | 
|  | 9317 | alpha2[0]) { | 
|  | 9318 | res = os_snprintf(pos, end - pos, "country=%s\n", | 
|  | 9319 | alpha2); | 
|  | 9320 | if (os_snprintf_error(end - pos, res)) | 
|  | 9321 | return pos - buf; | 
|  | 9322 | pos += res; | 
|  | 9323 | } | 
|  | 9324 | } else { | 
|  | 9325 | nlmsg_free(msg); | 
|  | 9326 | } | 
|  | 9327 |  | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9328 | return pos - buf; | 
|  | 9329 | } | 
|  | 9330 |  | 
|  | 9331 |  | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9332 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) | 
|  | 9333 | { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9334 | if ((settings->head && | 
|  | 9335 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, | 
|  | 9336 | settings->head_len, settings->head)) || | 
|  | 9337 | (settings->tail && | 
|  | 9338 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, | 
|  | 9339 | settings->tail_len, settings->tail)) || | 
|  | 9340 | (settings->beacon_ies && | 
|  | 9341 | nla_put(msg, NL80211_ATTR_IE, | 
|  | 9342 | settings->beacon_ies_len, settings->beacon_ies)) || | 
|  | 9343 | (settings->proberesp_ies && | 
|  | 9344 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, | 
|  | 9345 | settings->proberesp_ies_len, settings->proberesp_ies)) || | 
|  | 9346 | (settings->assocresp_ies && | 
|  | 9347 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, | 
|  | 9348 | settings->assocresp_ies_len, settings->assocresp_ies)) || | 
|  | 9349 | (settings->probe_resp && | 
|  | 9350 | nla_put(msg, NL80211_ATTR_PROBE_RESP, | 
|  | 9351 | settings->probe_resp_len, settings->probe_resp))) | 
|  | 9352 | return -ENOBUFS; | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9353 |  | 
|  | 9354 | return 0; | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9355 | } | 
|  | 9356 |  | 
|  | 9357 |  | 
|  | 9358 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) | 
|  | 9359 | { | 
|  | 9360 | struct nl_msg *msg; | 
|  | 9361 | struct i802_bss *bss = priv; | 
|  | 9362 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 9363 | struct nlattr *beacon_csa; | 
|  | 9364 | int ret = -ENOBUFS; | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9365 | int csa_off_len = 0; | 
|  | 9366 | int i; | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9367 |  | 
| Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 9368 | 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] | 9369 | settings->cs_count, settings->block_tx, | 
| Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 9370 | settings->freq_params.freq, settings->freq_params.bandwidth, | 
|  | 9371 | settings->freq_params.center_freq1, | 
|  | 9372 | settings->freq_params.center_freq2); | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9373 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9374 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9375 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); | 
|  | 9376 | return -EOPNOTSUPP; | 
|  | 9377 | } | 
|  | 9378 |  | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9379 | if (drv->nlmode != NL80211_IFTYPE_AP && | 
|  | 9380 | drv->nlmode != NL80211_IFTYPE_P2P_GO && | 
|  | 9381 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9382 | return -EOPNOTSUPP; | 
|  | 9383 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9384 | /* | 
|  | 9385 | * Remove empty counters, assuming Probe Response and Beacon frame | 
|  | 9386 | * counters match. This implementation assumes that there are only two | 
|  | 9387 | * counters. | 
|  | 9388 | */ | 
|  | 9389 | if (settings->counter_offset_beacon[0] && | 
|  | 9390 | !settings->counter_offset_beacon[1]) { | 
|  | 9391 | csa_off_len = 1; | 
|  | 9392 | } else if (settings->counter_offset_beacon[1] && | 
|  | 9393 | !settings->counter_offset_beacon[0]) { | 
|  | 9394 | csa_off_len = 1; | 
|  | 9395 | settings->counter_offset_beacon[0] = | 
|  | 9396 | settings->counter_offset_beacon[1]; | 
|  | 9397 | settings->counter_offset_presp[0] = | 
|  | 9398 | settings->counter_offset_presp[1]; | 
|  | 9399 | } else if (settings->counter_offset_beacon[1] && | 
|  | 9400 | settings->counter_offset_beacon[0]) { | 
|  | 9401 | csa_off_len = 2; | 
|  | 9402 | } else { | 
|  | 9403 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); | 
|  | 9404 | return -EINVAL; | 
|  | 9405 | } | 
|  | 9406 |  | 
|  | 9407 | /* Check CSA counters validity */ | 
|  | 9408 | if (drv->capa.max_csa_counters && | 
|  | 9409 | csa_off_len > drv->capa.max_csa_counters) { | 
|  | 9410 | wpa_printf(MSG_ERROR, | 
|  | 9411 | "nl80211: Too many CSA counters provided"); | 
|  | 9412 | return -EINVAL; | 
|  | 9413 | } | 
|  | 9414 |  | 
|  | 9415 | if (!settings->beacon_csa.tail) | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9416 | return -EINVAL; | 
|  | 9417 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9418 | for (i = 0; i < csa_off_len; i++) { | 
|  | 9419 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; | 
|  | 9420 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; | 
|  | 9421 |  | 
|  | 9422 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || | 
|  | 9423 | (settings->beacon_csa.tail[csa_c_off_bcn] != | 
|  | 9424 | settings->cs_count)) | 
|  | 9425 | return -EINVAL; | 
|  | 9426 |  | 
|  | 9427 | if (settings->beacon_csa.probe_resp && | 
|  | 9428 | ((settings->beacon_csa.probe_resp_len <= | 
|  | 9429 | csa_c_off_presp) || | 
|  | 9430 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != | 
|  | 9431 | settings->cs_count))) | 
|  | 9432 | return -EINVAL; | 
|  | 9433 | } | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9434 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9435 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || | 
|  | 9436 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, | 
|  | 9437 | settings->cs_count) || | 
|  | 9438 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || | 
|  | 9439 | (settings->block_tx && | 
|  | 9440 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9441 | goto error; | 
|  | 9442 |  | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9443 | /* beacon_after params */ | 
|  | 9444 | ret = set_beacon_data(msg, &settings->beacon_after); | 
|  | 9445 | if (ret) | 
|  | 9446 | goto error; | 
|  | 9447 |  | 
|  | 9448 | /* beacon_csa params */ | 
|  | 9449 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); | 
|  | 9450 | if (!beacon_csa) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9451 | goto fail; | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9452 |  | 
|  | 9453 | ret = set_beacon_data(msg, &settings->beacon_csa); | 
|  | 9454 | if (ret) | 
|  | 9455 | goto error; | 
|  | 9456 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9457 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, | 
|  | 9458 | csa_off_len * sizeof(u16), | 
|  | 9459 | settings->counter_offset_beacon) || | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9460 | (settings->beacon_csa.probe_resp && | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9461 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, | 
|  | 9462 | csa_off_len * sizeof(u16), | 
|  | 9463 | settings->counter_offset_presp))) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9464 | goto fail; | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9465 |  | 
|  | 9466 | nla_nest_end(msg, beacon_csa); | 
|  | 9467 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 9468 | if (ret) { | 
|  | 9469 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", | 
|  | 9470 | ret, strerror(-ret)); | 
|  | 9471 | } | 
|  | 9472 | return ret; | 
|  | 9473 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9474 | fail: | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9475 | ret = -ENOBUFS; | 
|  | 9476 | error: | 
|  | 9477 | nlmsg_free(msg); | 
|  | 9478 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); | 
|  | 9479 | return ret; | 
|  | 9480 | } | 
|  | 9481 |  | 
|  | 9482 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9483 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, | 
|  | 9484 | u8 user_priority, u16 admitted_time) | 
|  | 9485 | { | 
|  | 9486 | struct i802_bss *bss = priv; | 
|  | 9487 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 9488 | struct nl_msg *msg; | 
|  | 9489 | int ret; | 
|  | 9490 |  | 
|  | 9491 | wpa_printf(MSG_DEBUG, | 
|  | 9492 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", | 
|  | 9493 | tsid, admitted_time, user_priority); | 
|  | 9494 |  | 
|  | 9495 | if (!is_sta_interface(drv->nlmode)) | 
|  | 9496 | return -ENOTSUP; | 
|  | 9497 |  | 
|  | 9498 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); | 
|  | 9499 | if (!msg || | 
|  | 9500 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || | 
|  | 9501 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | 
|  | 9502 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || | 
|  | 9503 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { | 
|  | 9504 | nlmsg_free(msg); | 
|  | 9505 | return -ENOBUFS; | 
|  | 9506 | } | 
|  | 9507 |  | 
|  | 9508 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 9509 | if (ret) | 
|  | 9510 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", | 
|  | 9511 | ret, strerror(-ret)); | 
|  | 9512 | return ret; | 
|  | 9513 | } | 
|  | 9514 |  | 
|  | 9515 |  | 
|  | 9516 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) | 
|  | 9517 | { | 
|  | 9518 | struct i802_bss *bss = priv; | 
|  | 9519 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 9520 | struct nl_msg *msg; | 
|  | 9521 | int ret; | 
|  | 9522 |  | 
|  | 9523 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); | 
|  | 9524 |  | 
|  | 9525 | if (!is_sta_interface(drv->nlmode)) | 
|  | 9526 | return -ENOTSUP; | 
|  | 9527 |  | 
|  | 9528 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || | 
|  | 9529 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || | 
|  | 9530 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { | 
|  | 9531 | nlmsg_free(msg); | 
|  | 9532 | return -ENOBUFS; | 
|  | 9533 | } | 
|  | 9534 |  | 
|  | 9535 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 9536 | if (ret) | 
|  | 9537 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", | 
|  | 9538 | ret, strerror(-ret)); | 
|  | 9539 | return ret; | 
|  | 9540 | } | 
|  | 9541 |  | 
|  | 9542 |  | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9543 | #ifdef CONFIG_TESTING_OPTIONS | 
|  | 9544 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) | 
|  | 9545 | { | 
|  | 9546 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | 
|  | 9547 | struct wpabuf *buf = arg; | 
|  | 9548 |  | 
|  | 9549 | if (!buf) | 
|  | 9550 | return NL_SKIP; | 
|  | 9551 |  | 
|  | 9552 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { | 
|  | 9553 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); | 
|  | 9554 | return NL_SKIP; | 
|  | 9555 | } | 
|  | 9556 |  | 
|  | 9557 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), | 
|  | 9558 | genlmsg_attrlen(gnlh, 0)); | 
|  | 9559 |  | 
|  | 9560 | return NL_SKIP; | 
|  | 9561 | } | 
|  | 9562 | #endif /* CONFIG_TESTING_OPTIONS */ | 
|  | 9563 |  | 
|  | 9564 |  | 
|  | 9565 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) | 
|  | 9566 | { | 
|  | 9567 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | 
|  | 9568 | struct nlattr *nl_vendor_reply, *nl; | 
|  | 9569 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | 
|  | 9570 | struct wpabuf *buf = arg; | 
|  | 9571 | int rem; | 
|  | 9572 |  | 
|  | 9573 | if (!buf) | 
|  | 9574 | return NL_SKIP; | 
|  | 9575 |  | 
|  | 9576 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | 
|  | 9577 | genlmsg_attrlen(gnlh, 0), NULL); | 
|  | 9578 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; | 
|  | 9579 |  | 
|  | 9580 | if (!nl_vendor_reply) | 
|  | 9581 | return NL_SKIP; | 
|  | 9582 |  | 
|  | 9583 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { | 
|  | 9584 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); | 
|  | 9585 | return NL_SKIP; | 
|  | 9586 | } | 
|  | 9587 |  | 
|  | 9588 | nla_for_each_nested(nl, nl_vendor_reply, rem) { | 
|  | 9589 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); | 
|  | 9590 | } | 
|  | 9591 |  | 
|  | 9592 | return NL_SKIP; | 
|  | 9593 | } | 
|  | 9594 |  | 
|  | 9595 |  | 
|  | 9596 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, | 
|  | 9597 | unsigned int subcmd, const u8 *data, | 
|  | 9598 | size_t data_len, struct wpabuf *buf) | 
|  | 9599 | { | 
|  | 9600 | struct i802_bss *bss = priv; | 
|  | 9601 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 9602 | struct nl_msg *msg; | 
|  | 9603 | int ret; | 
|  | 9604 |  | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9605 | #ifdef CONFIG_TESTING_OPTIONS | 
|  | 9606 | if (vendor_id == 0xffffffff) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9607 | msg = nlmsg_alloc(); | 
|  | 9608 | if (!msg) | 
|  | 9609 | return -ENOMEM; | 
|  | 9610 |  | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9611 | nl80211_cmd(drv, msg, 0, subcmd); | 
|  | 9612 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < | 
|  | 9613 | 0) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9614 | goto fail; | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 9615 | /* This test vendor_cmd can be used with nl80211 commands that | 
|  | 9616 | * need the connect nl_sock, so use the owner-setting variant | 
|  | 9617 | * of send_and_recv_msgs(). */ | 
|  | 9618 | ret = send_and_recv_msgs_owner(drv, msg, | 
|  | 9619 | get_connect_handle(bss), 0, | 
|  | 9620 | cmd_reply_handler, buf); | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9621 | if (ret) | 
|  | 9622 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", | 
|  | 9623 | ret); | 
|  | 9624 | return ret; | 
|  | 9625 | } | 
|  | 9626 | #endif /* CONFIG_TESTING_OPTIONS */ | 
|  | 9627 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9628 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || | 
|  | 9629 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || | 
|  | 9630 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || | 
|  | 9631 | (data && | 
|  | 9632 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) | 
|  | 9633 | goto fail; | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9634 |  | 
|  | 9635 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); | 
|  | 9636 | if (ret) | 
|  | 9637 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", | 
|  | 9638 | ret); | 
|  | 9639 | return ret; | 
|  | 9640 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9641 | fail: | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9642 | nlmsg_free(msg); | 
|  | 9643 | return -ENOBUFS; | 
|  | 9644 | } | 
|  | 9645 |  | 
|  | 9646 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9647 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, | 
|  | 9648 | u8 qos_map_set_len) | 
|  | 9649 | { | 
|  | 9650 | struct i802_bss *bss = priv; | 
|  | 9651 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 9652 | struct nl_msg *msg; | 
|  | 9653 | int ret; | 
|  | 9654 |  | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9655 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", | 
|  | 9656 | qos_map_set, qos_map_set_len); | 
|  | 9657 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9658 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || | 
|  | 9659 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { | 
|  | 9660 | nlmsg_free(msg); | 
|  | 9661 | return -ENOBUFS; | 
|  | 9662 | } | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9663 |  | 
|  | 9664 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 9665 | if (ret) | 
|  | 9666 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); | 
|  | 9667 |  | 
|  | 9668 | return ret; | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9669 | } | 
|  | 9670 |  | 
|  | 9671 |  | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 9672 | static int get_wowlan_handler(struct nl_msg *msg, void *arg) | 
|  | 9673 | { | 
|  | 9674 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | 
|  | 9675 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | 
|  | 9676 | int *wowlan_enabled = arg; | 
|  | 9677 |  | 
|  | 9678 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | 
|  | 9679 | genlmsg_attrlen(gnlh, 0), NULL); | 
|  | 9680 |  | 
|  | 9681 | *wowlan_enabled = !!tb[NL80211_ATTR_WOWLAN_TRIGGERS]; | 
|  | 9682 |  | 
|  | 9683 | return NL_SKIP; | 
|  | 9684 | } | 
|  | 9685 |  | 
|  | 9686 |  | 
|  | 9687 | static int nl80211_get_wowlan(void *priv) | 
|  | 9688 | { | 
|  | 9689 | struct i802_bss *bss = priv; | 
|  | 9690 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 9691 | struct nl_msg *msg; | 
|  | 9692 | int wowlan_enabled; | 
|  | 9693 | int ret; | 
|  | 9694 |  | 
|  | 9695 | wpa_printf(MSG_DEBUG, "nl80211: Getting wowlan status"); | 
|  | 9696 |  | 
|  | 9697 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_WOWLAN); | 
|  | 9698 |  | 
|  | 9699 | ret = send_and_recv_msgs(drv, msg, get_wowlan_handler, &wowlan_enabled); | 
|  | 9700 | if (ret) { | 
|  | 9701 | wpa_printf(MSG_DEBUG, "nl80211: Getting wowlan status failed"); | 
|  | 9702 | return 0; | 
|  | 9703 | } | 
|  | 9704 |  | 
|  | 9705 | wpa_printf(MSG_DEBUG, "nl80211: wowlan is %s", | 
|  | 9706 | wowlan_enabled ? "enabled" : "disabled"); | 
|  | 9707 |  | 
|  | 9708 | return wowlan_enabled; | 
|  | 9709 | } | 
|  | 9710 |  | 
|  | 9711 |  | 
| Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9712 | static int nl80211_set_wowlan(void *priv, | 
|  | 9713 | const struct wowlan_triggers *triggers) | 
|  | 9714 | { | 
|  | 9715 | struct i802_bss *bss = priv; | 
|  | 9716 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 9717 | struct nl_msg *msg; | 
|  | 9718 | struct nlattr *wowlan_triggers; | 
|  | 9719 | int ret; | 
|  | 9720 |  | 
| Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9721 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); | 
|  | 9722 |  | 
| Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 9723 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9724 | !(wowlan_triggers = nla_nest_start(msg, | 
|  | 9725 | NL80211_ATTR_WOWLAN_TRIGGERS)) || | 
|  | 9726 | (triggers->any && | 
|  | 9727 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || | 
|  | 9728 | (triggers->disconnect && | 
|  | 9729 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || | 
|  | 9730 | (triggers->magic_pkt && | 
|  | 9731 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || | 
|  | 9732 | (triggers->gtk_rekey_failure && | 
|  | 9733 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || | 
|  | 9734 | (triggers->eap_identity_req && | 
|  | 9735 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || | 
|  | 9736 | (triggers->four_way_handshake && | 
|  | 9737 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || | 
|  | 9738 | (triggers->rfkill_release && | 
|  | 9739 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { | 
|  | 9740 | nlmsg_free(msg); | 
|  | 9741 | return -ENOBUFS; | 
|  | 9742 | } | 
| Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9743 |  | 
|  | 9744 | nla_nest_end(msg, wowlan_triggers); | 
|  | 9745 |  | 
|  | 9746 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 9747 | if (ret) | 
|  | 9748 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); | 
|  | 9749 |  | 
|  | 9750 | return ret; | 
| Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9751 | } | 
|  | 9752 |  | 
|  | 9753 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9754 | #ifdef CONFIG_DRIVER_NL80211_QCA | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9755 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) | 
|  | 9756 | { | 
|  | 9757 | struct i802_bss *bss = priv; | 
|  | 9758 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 9759 | struct nl_msg *msg; | 
|  | 9760 | struct nlattr *params; | 
|  | 9761 |  | 
|  | 9762 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); | 
|  | 9763 |  | 
|  | 9764 | if (!drv->roaming_vendor_cmd_avail) { | 
|  | 9765 | wpa_printf(MSG_DEBUG, | 
|  | 9766 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); | 
|  | 9767 | return -1; | 
|  | 9768 | } | 
|  | 9769 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9770 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | 
|  | 9771 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 9772 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 9773 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || | 
|  | 9774 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | 
|  | 9775 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, | 
|  | 9776 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : | 
|  | 9777 | QCA_ROAMING_NOT_ALLOWED) || | 
|  | 9778 | (bssid && | 
|  | 9779 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { | 
|  | 9780 | nlmsg_free(msg); | 
|  | 9781 | return -1; | 
|  | 9782 | } | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9783 | nla_nest_end(msg, params); | 
|  | 9784 |  | 
|  | 9785 | return send_and_recv_msgs(drv, msg, NULL, NULL); | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9786 | } | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9787 |  | 
|  | 9788 |  | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9789 | static int nl80211_disable_fils(void *priv, int disable) | 
|  | 9790 | { | 
|  | 9791 | struct i802_bss *bss = priv; | 
|  | 9792 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 9793 | struct nl_msg *msg; | 
|  | 9794 | struct nlattr *params; | 
|  | 9795 |  | 
|  | 9796 | wpa_printf(MSG_DEBUG, "nl80211: Disable FILS=%d", disable); | 
|  | 9797 |  | 
|  | 9798 | if (!drv->set_wifi_conf_vendor_cmd_avail) | 
|  | 9799 | return -1; | 
|  | 9800 |  | 
|  | 9801 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | 
|  | 9802 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 9803 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 9804 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) || | 
|  | 9805 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | 
|  | 9806 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS, | 
|  | 9807 | disable)) { | 
|  | 9808 | nlmsg_free(msg); | 
|  | 9809 | return -1; | 
|  | 9810 | } | 
|  | 9811 | nla_nest_end(msg, params); | 
|  | 9812 |  | 
|  | 9813 | return send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 9814 | } | 
|  | 9815 |  | 
|  | 9816 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9817 | /* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */ | 
|  | 9818 | #define WPA_SUPPLICANT_CLIENT_ID 1 | 
|  | 9819 |  | 
|  | 9820 | static int nl80211_set_bssid_blacklist(void *priv, unsigned int num_bssid, | 
|  | 9821 | const u8 *bssid) | 
|  | 9822 | { | 
|  | 9823 | struct i802_bss *bss = priv; | 
|  | 9824 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 9825 | struct nl_msg *msg; | 
|  | 9826 | struct nlattr *params, *nlbssids, *attr; | 
|  | 9827 | unsigned int i; | 
|  | 9828 |  | 
|  | 9829 | wpa_printf(MSG_DEBUG, "nl80211: Set blacklist BSSID (num=%u)", | 
|  | 9830 | num_bssid); | 
|  | 9831 |  | 
|  | 9832 | if (!drv->roam_vendor_cmd_avail) | 
|  | 9833 | return -1; | 
|  | 9834 |  | 
|  | 9835 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | 
|  | 9836 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 9837 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 9838 | QCA_NL80211_VENDOR_SUBCMD_ROAM) || | 
|  | 9839 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | 
|  | 9840 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD, | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 9841 | QCA_WLAN_VENDOR_ROAMING_SUBCMD_SET_BLACKLIST_BSSID) || | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9842 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID, | 
|  | 9843 | WPA_SUPPLICANT_CLIENT_ID) || | 
|  | 9844 | nla_put_u32(msg, | 
|  | 9845 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID, | 
|  | 9846 | num_bssid)) | 
|  | 9847 | goto fail; | 
|  | 9848 |  | 
|  | 9849 | nlbssids = nla_nest_start( | 
|  | 9850 | msg, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS); | 
|  | 9851 | if (!nlbssids) | 
|  | 9852 | goto fail; | 
|  | 9853 |  | 
|  | 9854 | for (i = 0; i < num_bssid; i++) { | 
|  | 9855 | attr = nla_nest_start(msg, i); | 
|  | 9856 | if (!attr) | 
|  | 9857 | goto fail; | 
|  | 9858 | if (nla_put(msg, | 
|  | 9859 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID, | 
|  | 9860 | ETH_ALEN, &bssid[i * ETH_ALEN])) | 
|  | 9861 | goto fail; | 
|  | 9862 | wpa_printf(MSG_DEBUG, "nl80211:   BSSID[%u]: " MACSTR, i, | 
|  | 9863 | MAC2STR(&bssid[i * ETH_ALEN])); | 
|  | 9864 | nla_nest_end(msg, attr); | 
|  | 9865 | } | 
|  | 9866 | nla_nest_end(msg, nlbssids); | 
|  | 9867 | nla_nest_end(msg, params); | 
|  | 9868 |  | 
|  | 9869 | return send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 9870 |  | 
|  | 9871 | fail: | 
|  | 9872 | nlmsg_free(msg); | 
|  | 9873 | return -1; | 
|  | 9874 | } | 
|  | 9875 |  | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 9876 |  | 
|  | 9877 | static int nl80211_add_sta_node(void *priv, const u8 *addr, u16 auth_alg) | 
|  | 9878 | { | 
|  | 9879 | struct i802_bss *bss = priv; | 
|  | 9880 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 9881 | struct nl_msg *msg; | 
|  | 9882 | struct nlattr *params; | 
|  | 9883 |  | 
|  | 9884 | if (!drv->add_sta_node_vendor_cmd_avail) | 
|  | 9885 | return -EOPNOTSUPP; | 
|  | 9886 |  | 
|  | 9887 | wpa_printf(MSG_DEBUG, "nl80211: Add STA node"); | 
|  | 9888 |  | 
|  | 9889 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | 
|  | 9890 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 9891 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 9892 | QCA_NL80211_VENDOR_SUBCMD_ADD_STA_NODE) || | 
|  | 9893 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | 
|  | 9894 | (addr && | 
|  | 9895 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_MAC_ADDR, ETH_ALEN, | 
|  | 9896 | addr)) || | 
|  | 9897 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_AUTH_ALGO, | 
|  | 9898 | auth_alg)) { | 
|  | 9899 | nlmsg_free(msg); | 
|  | 9900 | wpa_printf(MSG_ERROR, | 
|  | 9901 | "%s: err in adding vendor_cmd and vendor_data", | 
|  | 9902 | __func__); | 
|  | 9903 | return -1; | 
|  | 9904 | } | 
|  | 9905 | nla_nest_end(msg, params); | 
|  | 9906 |  | 
|  | 9907 | return send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 9908 | } | 
|  | 9909 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9910 | #endif /* CONFIG_DRIVER_NL80211_QCA */ | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9911 |  | 
|  | 9912 |  | 
|  | 9913 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) | 
|  | 9914 | { | 
|  | 9915 | struct i802_bss *bss = priv; | 
|  | 9916 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 9917 | int new_addr = addr != NULL; | 
|  | 9918 |  | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9919 | if (TEST_FAIL()) | 
|  | 9920 | return -1; | 
|  | 9921 |  | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9922 | if (!addr) | 
|  | 9923 | addr = drv->perm_addr; | 
|  | 9924 |  | 
|  | 9925 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) | 
|  | 9926 | return -1; | 
|  | 9927 |  | 
|  | 9928 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) | 
|  | 9929 | { | 
|  | 9930 | wpa_printf(MSG_DEBUG, | 
|  | 9931 | "nl80211: failed to set_mac_addr for %s to " MACSTR, | 
|  | 9932 | bss->ifname, MAC2STR(addr)); | 
|  | 9933 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, | 
|  | 9934 | 1) < 0) { | 
|  | 9935 | wpa_printf(MSG_DEBUG, | 
|  | 9936 | "nl80211: Could not restore interface UP after failed set_mac_addr"); | 
|  | 9937 | } | 
|  | 9938 | return -1; | 
|  | 9939 | } | 
|  | 9940 |  | 
|  | 9941 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, | 
|  | 9942 | bss->ifname, MAC2STR(addr)); | 
|  | 9943 | drv->addr_changed = new_addr; | 
|  | 9944 | os_memcpy(bss->addr, addr, ETH_ALEN); | 
|  | 9945 |  | 
|  | 9946 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) | 
|  | 9947 | { | 
|  | 9948 | wpa_printf(MSG_DEBUG, | 
|  | 9949 | "nl80211: Could not restore interface UP after set_mac_addr"); | 
|  | 9950 | } | 
|  | 9951 |  | 
|  | 9952 | return 0; | 
|  | 9953 | } | 
|  | 9954 |  | 
|  | 9955 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9956 | #ifdef CONFIG_MESH | 
|  | 9957 |  | 
|  | 9958 | static int wpa_driver_nl80211_init_mesh(void *priv) | 
|  | 9959 | { | 
|  | 9960 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { | 
|  | 9961 | wpa_printf(MSG_INFO, | 
|  | 9962 | "nl80211: Failed to set interface into mesh mode"); | 
|  | 9963 | return -1; | 
|  | 9964 | } | 
|  | 9965 | return 0; | 
|  | 9966 | } | 
|  | 9967 |  | 
|  | 9968 |  | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9969 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, | 
|  | 9970 | size_t mesh_id_len) | 
|  | 9971 | { | 
|  | 9972 | if (mesh_id) { | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9973 | wpa_printf(MSG_DEBUG, "  * Mesh ID (SSID)=%s", | 
|  | 9974 | wpa_ssid_txt(mesh_id, mesh_id_len)); | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9975 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); | 
|  | 9976 | } | 
|  | 9977 |  | 
|  | 9978 | return 0; | 
|  | 9979 | } | 
|  | 9980 |  | 
|  | 9981 |  | 
| Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9982 | static int nl80211_put_mesh_config(struct nl_msg *msg, | 
|  | 9983 | struct wpa_driver_mesh_bss_params *params) | 
|  | 9984 | { | 
|  | 9985 | struct nlattr *container; | 
|  | 9986 |  | 
|  | 9987 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); | 
|  | 9988 | if (!container) | 
|  | 9989 | return -1; | 
|  | 9990 |  | 
|  | 9991 | if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9992 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, | 
|  | 9993 | params->auto_plinks)) || | 
| Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9994 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) && | 
|  | 9995 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9996 | params->max_peer_links)) || | 
|  | 9997 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD) && | 
|  | 9998 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, | 
|  | 9999 | params->rssi_threshold))) | 
| Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 10000 | return -1; | 
|  | 10001 |  | 
|  | 10002 | /* | 
|  | 10003 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because | 
|  | 10004 | * the timer could disconnect stations even in that case. | 
|  | 10005 | */ | 
|  | 10006 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) && | 
|  | 10007 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, | 
|  | 10008 | params->peer_link_timeout)) { | 
|  | 10009 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); | 
|  | 10010 | return -1; | 
|  | 10011 | } | 
|  | 10012 |  | 
|  | 10013 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) && | 
|  | 10014 | nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) { | 
|  | 10015 | wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE"); | 
|  | 10016 | return -1; | 
|  | 10017 | } | 
|  | 10018 |  | 
|  | 10019 | nla_nest_end(msg, container); | 
|  | 10020 |  | 
|  | 10021 | return 0; | 
|  | 10022 | } | 
|  | 10023 |  | 
|  | 10024 |  | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 10025 | static int nl80211_join_mesh(struct i802_bss *bss, | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10026 | struct wpa_driver_mesh_join_params *params) | 
|  | 10027 | { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10028 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 10029 | struct nl_msg *msg; | 
|  | 10030 | struct nlattr *container; | 
| Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 10031 | int ret = -1; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10032 |  | 
|  | 10033 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); | 
|  | 10034 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); | 
| Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 10035 | if (!msg || | 
|  | 10036 | nl80211_put_freq_params(msg, ¶ms->freq) || | 
|  | 10037 | nl80211_put_basic_rates(msg, params->basic_rates) || | 
|  | 10038 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 10039 | nl80211_put_beacon_int(msg, params->beacon_int) || | 
|  | 10040 | nl80211_put_dtim_period(msg, params->dtim_period)) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10041 | goto fail; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10042 |  | 
|  | 10043 | wpa_printf(MSG_DEBUG, "  * flags=%08X", params->flags); | 
|  | 10044 |  | 
|  | 10045 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); | 
|  | 10046 | if (!container) | 
|  | 10047 | goto fail; | 
|  | 10048 |  | 
|  | 10049 | if (params->ies) { | 
|  | 10050 | wpa_hexdump(MSG_DEBUG, "  * IEs", params->ies, params->ie_len); | 
|  | 10051 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, | 
|  | 10052 | params->ies)) | 
|  | 10053 | goto fail; | 
|  | 10054 | } | 
|  | 10055 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ | 
|  | 10056 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { | 
|  | 10057 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || | 
|  | 10058 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) | 
|  | 10059 | goto fail; | 
|  | 10060 | } | 
|  | 10061 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && | 
|  | 10062 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) | 
|  | 10063 | goto fail; | 
|  | 10064 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && | 
|  | 10065 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) | 
|  | 10066 | goto fail; | 
|  | 10067 | nla_nest_end(msg, container); | 
|  | 10068 |  | 
| Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 10069 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS; | 
|  | 10070 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT; | 
|  | 10071 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS; | 
|  | 10072 | if (nl80211_put_mesh_config(msg, ¶ms->conf) < 0) | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10073 | goto fail; | 
|  | 10074 |  | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 10075 | ret = send_and_recv_msgs_owner(drv, msg, get_connect_handle(bss), 1, | 
|  | 10076 | NULL, NULL); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10077 | msg = NULL; | 
|  | 10078 | if (ret) { | 
|  | 10079 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", | 
|  | 10080 | ret, strerror(-ret)); | 
|  | 10081 | goto fail; | 
|  | 10082 | } | 
|  | 10083 | ret = 0; | 
| Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 10084 | drv->assoc_freq = bss->freq = params->freq.freq; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10085 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); | 
|  | 10086 |  | 
|  | 10087 | fail: | 
|  | 10088 | nlmsg_free(msg); | 
|  | 10089 | return ret; | 
|  | 10090 | } | 
|  | 10091 |  | 
|  | 10092 |  | 
| Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 10093 | static int | 
|  | 10094 | wpa_driver_nl80211_join_mesh(void *priv, | 
|  | 10095 | struct wpa_driver_mesh_join_params *params) | 
|  | 10096 | { | 
|  | 10097 | struct i802_bss *bss = priv; | 
|  | 10098 | int ret, timeout; | 
|  | 10099 |  | 
|  | 10100 | timeout = params->conf.peer_link_timeout; | 
|  | 10101 |  | 
|  | 10102 | /* Disable kernel inactivity timer */ | 
|  | 10103 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) | 
|  | 10104 | params->conf.peer_link_timeout = 0; | 
|  | 10105 |  | 
|  | 10106 | ret = nl80211_join_mesh(bss, params); | 
|  | 10107 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { | 
|  | 10108 | wpa_printf(MSG_DEBUG, | 
|  | 10109 | "nl80211: Mesh join retry for peer_link_timeout"); | 
|  | 10110 | /* | 
|  | 10111 | * Old kernel does not support setting | 
|  | 10112 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds | 
|  | 10113 | * into future from peer_link_timeout. | 
|  | 10114 | */ | 
|  | 10115 | params->conf.peer_link_timeout = timeout + 60; | 
|  | 10116 | ret = nl80211_join_mesh(priv, params); | 
|  | 10117 | } | 
|  | 10118 |  | 
|  | 10119 | params->conf.peer_link_timeout = timeout; | 
|  | 10120 | return ret; | 
|  | 10121 | } | 
|  | 10122 |  | 
|  | 10123 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10124 | static int wpa_driver_nl80211_leave_mesh(void *priv) | 
|  | 10125 | { | 
|  | 10126 | struct i802_bss *bss = priv; | 
|  | 10127 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 10128 | struct nl_msg *msg; | 
|  | 10129 | int ret; | 
|  | 10130 |  | 
|  | 10131 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); | 
|  | 10132 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); | 
| Hai Shalom | b755a2a | 2020-04-23 21:49:02 -0700 | [diff] [blame] | 10133 | ret = send_and_recv_msgs_owner(drv, msg, get_connect_handle(bss), 0, | 
|  | 10134 | NULL, NULL); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10135 | if (ret) { | 
|  | 10136 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", | 
|  | 10137 | ret, strerror(-ret)); | 
|  | 10138 | } else { | 
|  | 10139 | wpa_printf(MSG_DEBUG, | 
|  | 10140 | "nl80211: mesh leave request send successfully"); | 
|  | 10141 | } | 
|  | 10142 |  | 
|  | 10143 | if (wpa_driver_nl80211_set_mode(drv->first_bss, | 
|  | 10144 | NL80211_IFTYPE_STATION)) { | 
|  | 10145 | wpa_printf(MSG_INFO, | 
|  | 10146 | "nl80211: Failed to set interface into station mode"); | 
|  | 10147 | } | 
|  | 10148 | return ret; | 
|  | 10149 | } | 
|  | 10150 |  | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 10151 |  | 
|  | 10152 | static int nl80211_probe_mesh_link(void *priv, const u8 *addr, const u8 *eth, | 
|  | 10153 | size_t len) | 
|  | 10154 | { | 
|  | 10155 | struct i802_bss *bss = priv; | 
|  | 10156 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 10157 | struct nl_msg *msg; | 
|  | 10158 | int ret; | 
|  | 10159 |  | 
|  | 10160 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_PROBE_MESH_LINK); | 
|  | 10161 | if (!msg || | 
|  | 10162 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || | 
|  | 10163 | nla_put(msg, NL80211_ATTR_FRAME, len, eth)) { | 
|  | 10164 | nlmsg_free(msg); | 
|  | 10165 | return -ENOBUFS; | 
|  | 10166 | } | 
|  | 10167 |  | 
|  | 10168 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 10169 | if (ret) { | 
|  | 10170 | wpa_printf(MSG_DEBUG, "nl80211: mesh link probe to " MACSTR | 
|  | 10171 | " failed: ret=%d (%s)", | 
|  | 10172 | MAC2STR(addr), ret, strerror(-ret)); | 
|  | 10173 | } else { | 
|  | 10174 | wpa_printf(MSG_DEBUG, "nl80211: Mesh link to " MACSTR | 
|  | 10175 | " probed successfully", MAC2STR(addr)); | 
|  | 10176 | } | 
|  | 10177 |  | 
|  | 10178 | return ret; | 
|  | 10179 | } | 
|  | 10180 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10181 | #endif /* CONFIG_MESH */ | 
|  | 10182 |  | 
|  | 10183 |  | 
|  | 10184 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, | 
|  | 10185 | const u8 *ipaddr, int prefixlen, | 
|  | 10186 | const u8 *addr) | 
|  | 10187 | { | 
|  | 10188 | #ifdef CONFIG_LIBNL3_ROUTE | 
|  | 10189 | struct i802_bss *bss = priv; | 
|  | 10190 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 10191 | struct rtnl_neigh *rn; | 
|  | 10192 | struct nl_addr *nl_ipaddr = NULL; | 
|  | 10193 | struct nl_addr *nl_lladdr = NULL; | 
|  | 10194 | int family, addrsize; | 
|  | 10195 | int res; | 
|  | 10196 |  | 
|  | 10197 | if (!ipaddr || prefixlen == 0 || !addr) | 
|  | 10198 | return -EINVAL; | 
|  | 10199 |  | 
|  | 10200 | if (bss->br_ifindex == 0) { | 
|  | 10201 | wpa_printf(MSG_DEBUG, | 
|  | 10202 | "nl80211: bridge must be set before adding an ip neigh to it"); | 
|  | 10203 | return -1; | 
|  | 10204 | } | 
|  | 10205 |  | 
|  | 10206 | if (!drv->rtnl_sk) { | 
|  | 10207 | wpa_printf(MSG_DEBUG, | 
|  | 10208 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); | 
|  | 10209 | return -1; | 
|  | 10210 | } | 
|  | 10211 |  | 
|  | 10212 | if (version == 4) { | 
|  | 10213 | family = AF_INET; | 
|  | 10214 | addrsize = 4; | 
|  | 10215 | } else if (version == 6) { | 
|  | 10216 | family = AF_INET6; | 
|  | 10217 | addrsize = 16; | 
|  | 10218 | } else { | 
|  | 10219 | return -EINVAL; | 
|  | 10220 | } | 
|  | 10221 |  | 
|  | 10222 | rn = rtnl_neigh_alloc(); | 
|  | 10223 | if (rn == NULL) | 
|  | 10224 | return -ENOMEM; | 
|  | 10225 |  | 
|  | 10226 | /* set the destination ip address for neigh */ | 
|  | 10227 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); | 
|  | 10228 | if (nl_ipaddr == NULL) { | 
|  | 10229 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); | 
|  | 10230 | res = -ENOMEM; | 
|  | 10231 | goto errout; | 
|  | 10232 | } | 
|  | 10233 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); | 
|  | 10234 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); | 
|  | 10235 | if (res) { | 
|  | 10236 | wpa_printf(MSG_DEBUG, | 
|  | 10237 | "nl80211: neigh set destination addr failed"); | 
|  | 10238 | goto errout; | 
|  | 10239 | } | 
|  | 10240 |  | 
|  | 10241 | /* set the corresponding lladdr for neigh */ | 
|  | 10242 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); | 
|  | 10243 | if (nl_lladdr == NULL) { | 
|  | 10244 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); | 
|  | 10245 | res = -ENOMEM; | 
|  | 10246 | goto errout; | 
|  | 10247 | } | 
|  | 10248 | rtnl_neigh_set_lladdr(rn, nl_lladdr); | 
|  | 10249 |  | 
|  | 10250 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); | 
|  | 10251 | rtnl_neigh_set_state(rn, NUD_PERMANENT); | 
|  | 10252 |  | 
|  | 10253 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); | 
|  | 10254 | if (res) { | 
|  | 10255 | wpa_printf(MSG_DEBUG, | 
|  | 10256 | "nl80211: Adding bridge ip neigh failed: %s", | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10257 | nl_geterror(res)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10258 | } | 
|  | 10259 | errout: | 
|  | 10260 | if (nl_lladdr) | 
|  | 10261 | nl_addr_put(nl_lladdr); | 
|  | 10262 | if (nl_ipaddr) | 
|  | 10263 | nl_addr_put(nl_ipaddr); | 
|  | 10264 | if (rn) | 
|  | 10265 | rtnl_neigh_put(rn); | 
|  | 10266 | return res; | 
|  | 10267 | #else /* CONFIG_LIBNL3_ROUTE */ | 
|  | 10268 | return -1; | 
|  | 10269 | #endif /* CONFIG_LIBNL3_ROUTE */ | 
|  | 10270 | } | 
|  | 10271 |  | 
|  | 10272 |  | 
|  | 10273 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, | 
|  | 10274 | const u8 *ipaddr) | 
|  | 10275 | { | 
|  | 10276 | #ifdef CONFIG_LIBNL3_ROUTE | 
|  | 10277 | struct i802_bss *bss = priv; | 
|  | 10278 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 10279 | struct rtnl_neigh *rn; | 
|  | 10280 | struct nl_addr *nl_ipaddr; | 
|  | 10281 | int family, addrsize; | 
|  | 10282 | int res; | 
|  | 10283 |  | 
|  | 10284 | if (!ipaddr) | 
|  | 10285 | return -EINVAL; | 
|  | 10286 |  | 
|  | 10287 | if (version == 4) { | 
|  | 10288 | family = AF_INET; | 
|  | 10289 | addrsize = 4; | 
|  | 10290 | } else if (version == 6) { | 
|  | 10291 | family = AF_INET6; | 
|  | 10292 | addrsize = 16; | 
|  | 10293 | } else { | 
|  | 10294 | return -EINVAL; | 
|  | 10295 | } | 
|  | 10296 |  | 
|  | 10297 | if (bss->br_ifindex == 0) { | 
|  | 10298 | wpa_printf(MSG_DEBUG, | 
|  | 10299 | "nl80211: bridge must be set to delete an ip neigh"); | 
|  | 10300 | return -1; | 
|  | 10301 | } | 
|  | 10302 |  | 
|  | 10303 | if (!drv->rtnl_sk) { | 
|  | 10304 | wpa_printf(MSG_DEBUG, | 
|  | 10305 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); | 
|  | 10306 | return -1; | 
|  | 10307 | } | 
|  | 10308 |  | 
|  | 10309 | rn = rtnl_neigh_alloc(); | 
|  | 10310 | if (rn == NULL) | 
|  | 10311 | return -ENOMEM; | 
|  | 10312 |  | 
|  | 10313 | /* set the destination ip address for neigh */ | 
|  | 10314 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); | 
|  | 10315 | if (nl_ipaddr == NULL) { | 
|  | 10316 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); | 
|  | 10317 | res = -ENOMEM; | 
|  | 10318 | goto errout; | 
|  | 10319 | } | 
|  | 10320 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); | 
|  | 10321 | if (res) { | 
|  | 10322 | wpa_printf(MSG_DEBUG, | 
|  | 10323 | "nl80211: neigh set destination addr failed"); | 
|  | 10324 | goto errout; | 
|  | 10325 | } | 
|  | 10326 |  | 
|  | 10327 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); | 
|  | 10328 |  | 
|  | 10329 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); | 
|  | 10330 | if (res) { | 
|  | 10331 | wpa_printf(MSG_DEBUG, | 
|  | 10332 | "nl80211: Deleting bridge ip neigh failed: %s", | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10333 | nl_geterror(res)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10334 | } | 
|  | 10335 | errout: | 
|  | 10336 | if (nl_ipaddr) | 
|  | 10337 | nl_addr_put(nl_ipaddr); | 
|  | 10338 | if (rn) | 
|  | 10339 | rtnl_neigh_put(rn); | 
|  | 10340 | return res; | 
|  | 10341 | #else /* CONFIG_LIBNL3_ROUTE */ | 
|  | 10342 | return -1; | 
|  | 10343 | #endif /* CONFIG_LIBNL3_ROUTE */ | 
|  | 10344 | } | 
|  | 10345 |  | 
|  | 10346 |  | 
|  | 10347 | static int linux_write_system_file(const char *path, unsigned int val) | 
|  | 10348 | { | 
|  | 10349 | char buf[50]; | 
|  | 10350 | int fd, len; | 
|  | 10351 |  | 
|  | 10352 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); | 
|  | 10353 | if (os_snprintf_error(sizeof(buf), len)) | 
|  | 10354 | return -1; | 
|  | 10355 |  | 
|  | 10356 | fd = open(path, O_WRONLY); | 
|  | 10357 | if (fd < 0) | 
|  | 10358 | return -1; | 
|  | 10359 |  | 
|  | 10360 | if (write(fd, buf, len) < 0) { | 
|  | 10361 | wpa_printf(MSG_DEBUG, | 
|  | 10362 | "nl80211: Failed to write Linux system file: %s with the value of %d", | 
|  | 10363 | path, val); | 
|  | 10364 | close(fd); | 
|  | 10365 | return -1; | 
|  | 10366 | } | 
|  | 10367 | close(fd); | 
|  | 10368 |  | 
|  | 10369 | return 0; | 
|  | 10370 | } | 
|  | 10371 |  | 
|  | 10372 |  | 
|  | 10373 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) | 
|  | 10374 | { | 
|  | 10375 | switch (attr) { | 
|  | 10376 | case DRV_BR_PORT_ATTR_PROXYARP: | 
| Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 10377 | return "proxyarp_wifi"; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10378 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: | 
|  | 10379 | return "hairpin_mode"; | 
|  | 10380 | } | 
|  | 10381 |  | 
|  | 10382 | return NULL; | 
|  | 10383 | } | 
|  | 10384 |  | 
|  | 10385 |  | 
|  | 10386 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, | 
|  | 10387 | unsigned int val) | 
|  | 10388 | { | 
|  | 10389 | struct i802_bss *bss = priv; | 
|  | 10390 | char path[128]; | 
|  | 10391 | const char *attr_txt; | 
|  | 10392 |  | 
|  | 10393 | attr_txt = drv_br_port_attr_str(attr); | 
|  | 10394 | if (attr_txt == NULL) | 
|  | 10395 | return -EINVAL; | 
|  | 10396 |  | 
|  | 10397 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", | 
|  | 10398 | bss->ifname, attr_txt); | 
|  | 10399 |  | 
|  | 10400 | if (linux_write_system_file(path, val)) | 
|  | 10401 | return -1; | 
|  | 10402 |  | 
|  | 10403 | return 0; | 
|  | 10404 | } | 
|  | 10405 |  | 
|  | 10406 |  | 
|  | 10407 | static const char * drv_br_net_param_str(enum drv_br_net_param param) | 
|  | 10408 | { | 
|  | 10409 | switch (param) { | 
|  | 10410 | case DRV_BR_NET_PARAM_GARP_ACCEPT: | 
|  | 10411 | return "arp_accept"; | 
| Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 10412 | default: | 
|  | 10413 | return NULL; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10414 | } | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10415 | } | 
|  | 10416 |  | 
|  | 10417 |  | 
|  | 10418 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, | 
|  | 10419 | unsigned int val) | 
|  | 10420 | { | 
|  | 10421 | struct i802_bss *bss = priv; | 
|  | 10422 | char path[128]; | 
|  | 10423 | const char *param_txt; | 
|  | 10424 | int ip_version = 4; | 
|  | 10425 |  | 
| Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 10426 | if (param == DRV_BR_MULTICAST_SNOOPING) { | 
|  | 10427 | os_snprintf(path, sizeof(path), | 
|  | 10428 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", | 
|  | 10429 | bss->brname); | 
|  | 10430 | goto set_val; | 
|  | 10431 | } | 
|  | 10432 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10433 | param_txt = drv_br_net_param_str(param); | 
|  | 10434 | if (param_txt == NULL) | 
|  | 10435 | return -EINVAL; | 
|  | 10436 |  | 
|  | 10437 | switch (param) { | 
|  | 10438 | case DRV_BR_NET_PARAM_GARP_ACCEPT: | 
|  | 10439 | ip_version = 4; | 
|  | 10440 | break; | 
|  | 10441 | default: | 
|  | 10442 | return -EINVAL; | 
|  | 10443 | } | 
|  | 10444 |  | 
|  | 10445 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", | 
|  | 10446 | ip_version, bss->brname, param_txt); | 
|  | 10447 |  | 
| Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 10448 | set_val: | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10449 | if (linux_write_system_file(path, val)) | 
|  | 10450 | return -1; | 
|  | 10451 |  | 
|  | 10452 | return 0; | 
|  | 10453 | } | 
|  | 10454 |  | 
|  | 10455 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10456 | #ifdef CONFIG_DRIVER_NL80211_QCA | 
|  | 10457 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10458 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) | 
|  | 10459 | { | 
|  | 10460 | switch (hw_mode) { | 
|  | 10461 | case HOSTAPD_MODE_IEEE80211B: | 
|  | 10462 | return QCA_ACS_MODE_IEEE80211B; | 
|  | 10463 | case HOSTAPD_MODE_IEEE80211G: | 
|  | 10464 | return QCA_ACS_MODE_IEEE80211G; | 
|  | 10465 | case HOSTAPD_MODE_IEEE80211A: | 
|  | 10466 | return QCA_ACS_MODE_IEEE80211A; | 
|  | 10467 | case HOSTAPD_MODE_IEEE80211AD: | 
|  | 10468 | return QCA_ACS_MODE_IEEE80211AD; | 
| Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 10469 | case HOSTAPD_MODE_IEEE80211ANY: | 
|  | 10470 | return QCA_ACS_MODE_IEEE80211ANY; | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10471 | default: | 
|  | 10472 | return -1; | 
|  | 10473 | } | 
|  | 10474 | } | 
|  | 10475 |  | 
|  | 10476 |  | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 10477 | static int add_acs_ch_list(struct nl_msg *msg, const int *freq_list) | 
|  | 10478 | { | 
|  | 10479 | int num_channels = 0, num_freqs; | 
|  | 10480 | u8 *ch_list; | 
|  | 10481 | enum hostapd_hw_mode hw_mode; | 
|  | 10482 | int ret = 0; | 
|  | 10483 | int i; | 
|  | 10484 |  | 
|  | 10485 | if (!freq_list) | 
|  | 10486 | return 0; | 
|  | 10487 |  | 
|  | 10488 | num_freqs = int_array_len(freq_list); | 
|  | 10489 | ch_list = os_malloc(sizeof(u8) * num_freqs); | 
|  | 10490 | if (!ch_list) | 
|  | 10491 | return -1; | 
|  | 10492 |  | 
|  | 10493 | for (i = 0; i < num_freqs; i++) { | 
|  | 10494 | const int freq = freq_list[i]; | 
|  | 10495 |  | 
|  | 10496 | if (freq == 0) | 
|  | 10497 | break; | 
|  | 10498 | /* Send 2.4 GHz and 5 GHz channels with | 
|  | 10499 | * QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST to maintain backwards | 
|  | 10500 | * compatibility. | 
|  | 10501 | */ | 
|  | 10502 | if (!(freq >= 2412 && freq <= 2484) && | 
|  | 10503 | !(freq >= 5180 && freq <= 5900)) | 
|  | 10504 | continue; | 
|  | 10505 | hw_mode = ieee80211_freq_to_chan(freq, &ch_list[num_channels]); | 
|  | 10506 | if (hw_mode != NUM_HOSTAPD_MODES) | 
|  | 10507 | num_channels++; | 
|  | 10508 | } | 
|  | 10509 |  | 
|  | 10510 | if (num_channels) | 
|  | 10511 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, | 
|  | 10512 | num_channels, ch_list); | 
|  | 10513 |  | 
|  | 10514 | os_free(ch_list); | 
|  | 10515 | return ret; | 
|  | 10516 | } | 
|  | 10517 |  | 
|  | 10518 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10519 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) | 
|  | 10520 | { | 
|  | 10521 | int i, len, ret; | 
|  | 10522 | u32 *freqs; | 
|  | 10523 |  | 
|  | 10524 | if (!freq_list) | 
|  | 10525 | return 0; | 
|  | 10526 | len = int_array_len(freq_list); | 
|  | 10527 | freqs = os_malloc(sizeof(u32) * len); | 
|  | 10528 | if (!freqs) | 
|  | 10529 | return -1; | 
|  | 10530 | for (i = 0; i < len; i++) | 
|  | 10531 | freqs[i] = freq_list[i]; | 
|  | 10532 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, | 
|  | 10533 | sizeof(u32) * len, freqs); | 
|  | 10534 | os_free(freqs); | 
|  | 10535 | return ret; | 
|  | 10536 | } | 
|  | 10537 |  | 
|  | 10538 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10539 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) | 
|  | 10540 | { | 
|  | 10541 | struct i802_bss *bss = priv; | 
|  | 10542 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 10543 | struct nl_msg *msg; | 
|  | 10544 | struct nlattr *data; | 
|  | 10545 | int ret; | 
|  | 10546 | int mode; | 
|  | 10547 |  | 
|  | 10548 | mode = hw_mode_to_qca_acs(params->hw_mode); | 
|  | 10549 | if (mode < 0) | 
|  | 10550 | return -1; | 
|  | 10551 |  | 
|  | 10552 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | 
|  | 10553 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 10554 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 10555 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || | 
|  | 10556 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | 
|  | 10557 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || | 
|  | 10558 | (params->ht_enabled && | 
|  | 10559 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || | 
|  | 10560 | (params->ht40_enabled && | 
| Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 10561 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || | 
|  | 10562 | (params->vht_enabled && | 
|  | 10563 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || | 
|  | 10564 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, | 
|  | 10565 | params->ch_width) || | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 10566 | add_acs_ch_list(msg, params->freq_list) || | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10567 | add_acs_freq_list(msg, params->freq_list) || | 
|  | 10568 | (params->edmg_enabled && | 
|  | 10569 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_EDMG_ENABLED))) { | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10570 | nlmsg_free(msg); | 
|  | 10571 | return -ENOBUFS; | 
|  | 10572 | } | 
|  | 10573 | nla_nest_end(msg, data); | 
|  | 10574 |  | 
| Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 10575 | wpa_printf(MSG_DEBUG, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10576 | "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] | 10577 | params->hw_mode, params->ht_enabled, params->ht40_enabled, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10578 | params->vht_enabled, params->ch_width, params->edmg_enabled); | 
| Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 10579 |  | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10580 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 10581 | if (ret) { | 
|  | 10582 | wpa_printf(MSG_DEBUG, | 
|  | 10583 | "nl80211: Failed to invoke driver ACS function: %s", | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10584 | strerror(-ret)); | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10585 | } | 
|  | 10586 | return ret; | 
|  | 10587 | } | 
|  | 10588 |  | 
|  | 10589 |  | 
| Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 10590 | static int nl80211_set_band(void *priv, enum set_band band) | 
|  | 10591 | { | 
|  | 10592 | struct i802_bss *bss = priv; | 
|  | 10593 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 10594 | struct nl_msg *msg; | 
|  | 10595 | struct nlattr *data; | 
|  | 10596 | int ret; | 
|  | 10597 | enum qca_set_band qca_band; | 
|  | 10598 |  | 
|  | 10599 | if (!drv->setband_vendor_cmd_avail) | 
|  | 10600 | return -1; | 
|  | 10601 |  | 
|  | 10602 | switch (band) { | 
|  | 10603 | case WPA_SETBAND_AUTO: | 
|  | 10604 | qca_band = QCA_SETBAND_AUTO; | 
|  | 10605 | break; | 
|  | 10606 | case WPA_SETBAND_5G: | 
|  | 10607 | qca_band = QCA_SETBAND_5G; | 
|  | 10608 | break; | 
|  | 10609 | case WPA_SETBAND_2G: | 
|  | 10610 | qca_band = QCA_SETBAND_2G; | 
|  | 10611 | break; | 
|  | 10612 | default: | 
|  | 10613 | return -1; | 
|  | 10614 | } | 
|  | 10615 |  | 
|  | 10616 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | 
|  | 10617 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 10618 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 10619 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || | 
|  | 10620 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | 
|  | 10621 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) { | 
|  | 10622 | nlmsg_free(msg); | 
|  | 10623 | return -ENOBUFS; | 
|  | 10624 | } | 
|  | 10625 | nla_nest_end(msg, data); | 
|  | 10626 |  | 
|  | 10627 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 10628 | if (ret) { | 
|  | 10629 | wpa_printf(MSG_DEBUG, | 
|  | 10630 | "nl80211: Driver setband function failed: %s", | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 10631 | strerror(-ret)); | 
| Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 10632 | } | 
|  | 10633 | return ret; | 
|  | 10634 | } | 
|  | 10635 |  | 
|  | 10636 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10637 | struct nl80211_pcl { | 
|  | 10638 | unsigned int num; | 
|  | 10639 | unsigned int *freq_list; | 
|  | 10640 | }; | 
|  | 10641 |  | 
|  | 10642 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) | 
|  | 10643 | { | 
|  | 10644 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; | 
|  | 10645 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | 
|  | 10646 | struct nl80211_pcl *param = arg; | 
|  | 10647 | struct nlattr *nl_vend, *attr; | 
|  | 10648 | enum qca_iface_type iface_type; | 
|  | 10649 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; | 
|  | 10650 | unsigned int num, max_num; | 
|  | 10651 | u32 *freqs; | 
|  | 10652 |  | 
|  | 10653 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | 
|  | 10654 | genlmsg_attrlen(gnlh, 0), NULL); | 
|  | 10655 |  | 
|  | 10656 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; | 
|  | 10657 | if (!nl_vend) | 
|  | 10658 | return NL_SKIP; | 
|  | 10659 |  | 
|  | 10660 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, | 
|  | 10661 | nla_data(nl_vend), nla_len(nl_vend), NULL); | 
|  | 10662 |  | 
|  | 10663 | attr = tb_vendor[ | 
|  | 10664 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; | 
|  | 10665 | if (!attr) { | 
|  | 10666 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); | 
|  | 10667 | param->num = 0; | 
|  | 10668 | return NL_SKIP; | 
|  | 10669 | } | 
|  | 10670 |  | 
|  | 10671 | iface_type = (enum qca_iface_type) nla_get_u32(attr); | 
|  | 10672 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", | 
|  | 10673 | iface_type); | 
|  | 10674 |  | 
|  | 10675 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; | 
|  | 10676 | if (!attr) { | 
|  | 10677 | wpa_printf(MSG_ERROR, | 
|  | 10678 | "nl80211: preferred_freq_list couldn't be found"); | 
|  | 10679 | param->num = 0; | 
|  | 10680 | return NL_SKIP; | 
|  | 10681 | } | 
|  | 10682 |  | 
|  | 10683 | /* | 
|  | 10684 | * param->num has the maximum number of entries for which there | 
|  | 10685 | * is room in the freq_list provided by the caller. | 
|  | 10686 | */ | 
|  | 10687 | freqs = nla_data(attr); | 
|  | 10688 | max_num = nla_len(attr) / sizeof(u32); | 
|  | 10689 | if (max_num > param->num) | 
|  | 10690 | max_num = param->num; | 
|  | 10691 | for (num = 0; num < max_num; num++) | 
|  | 10692 | param->freq_list[num] = freqs[num]; | 
|  | 10693 | param->num = num; | 
|  | 10694 |  | 
|  | 10695 | return NL_SKIP; | 
|  | 10696 | } | 
|  | 10697 |  | 
|  | 10698 |  | 
|  | 10699 | static int nl80211_get_pref_freq_list(void *priv, | 
|  | 10700 | enum wpa_driver_if_type if_type, | 
|  | 10701 | unsigned int *num, | 
|  | 10702 | unsigned int *freq_list) | 
|  | 10703 | { | 
|  | 10704 | struct i802_bss *bss = priv; | 
|  | 10705 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 10706 | struct nl_msg *msg; | 
|  | 10707 | int ret; | 
|  | 10708 | unsigned int i; | 
|  | 10709 | struct nlattr *params; | 
|  | 10710 | struct nl80211_pcl param; | 
|  | 10711 | enum qca_iface_type iface_type; | 
|  | 10712 |  | 
|  | 10713 | if (!drv->get_pref_freq_list) | 
|  | 10714 | return -1; | 
|  | 10715 |  | 
|  | 10716 | switch (if_type) { | 
|  | 10717 | case WPA_IF_STATION: | 
|  | 10718 | iface_type = QCA_IFACE_TYPE_STA; | 
|  | 10719 | break; | 
|  | 10720 | case WPA_IF_AP_BSS: | 
|  | 10721 | iface_type = QCA_IFACE_TYPE_AP; | 
|  | 10722 | break; | 
|  | 10723 | case WPA_IF_P2P_GO: | 
|  | 10724 | iface_type = QCA_IFACE_TYPE_P2P_GO; | 
|  | 10725 | break; | 
|  | 10726 | case WPA_IF_P2P_CLIENT: | 
|  | 10727 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; | 
|  | 10728 | break; | 
|  | 10729 | case WPA_IF_IBSS: | 
|  | 10730 | iface_type = QCA_IFACE_TYPE_IBSS; | 
|  | 10731 | break; | 
|  | 10732 | case WPA_IF_TDLS: | 
|  | 10733 | iface_type = QCA_IFACE_TYPE_TDLS; | 
|  | 10734 | break; | 
|  | 10735 | default: | 
|  | 10736 | return -1; | 
|  | 10737 | } | 
|  | 10738 |  | 
|  | 10739 | param.num = *num; | 
|  | 10740 | param.freq_list = freq_list; | 
|  | 10741 |  | 
|  | 10742 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | 
|  | 10743 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || | 
|  | 10744 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 10745 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 10746 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || | 
|  | 10747 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | 
|  | 10748 | nla_put_u32(msg, | 
|  | 10749 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, | 
|  | 10750 | iface_type)) { | 
|  | 10751 | wpa_printf(MSG_ERROR, | 
|  | 10752 | "%s: err in adding vendor_cmd and vendor_data", | 
|  | 10753 | __func__); | 
|  | 10754 | nlmsg_free(msg); | 
|  | 10755 | return -1; | 
|  | 10756 | } | 
|  | 10757 | nla_nest_end(msg, params); | 
|  | 10758 |  | 
|  | 10759 | os_memset(freq_list, 0, *num * sizeof(freq_list[0])); | 
|  | 10760 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m); | 
|  | 10761 | if (ret) { | 
|  | 10762 | wpa_printf(MSG_ERROR, | 
|  | 10763 | "%s: err in send_and_recv_msgs", __func__); | 
|  | 10764 | return ret; | 
|  | 10765 | } | 
|  | 10766 |  | 
|  | 10767 | *num = param.num; | 
|  | 10768 |  | 
|  | 10769 | for (i = 0; i < *num; i++) { | 
|  | 10770 | wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d", | 
|  | 10771 | i, freq_list[i]); | 
|  | 10772 | } | 
|  | 10773 |  | 
|  | 10774 | return 0; | 
|  | 10775 | } | 
|  | 10776 |  | 
|  | 10777 |  | 
|  | 10778 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) | 
|  | 10779 | { | 
|  | 10780 | struct i802_bss *bss = priv; | 
|  | 10781 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 10782 | struct nl_msg *msg; | 
|  | 10783 | int ret; | 
|  | 10784 | struct nlattr *params; | 
|  | 10785 |  | 
|  | 10786 | if (!drv->set_prob_oper_freq) | 
|  | 10787 | return -1; | 
|  | 10788 |  | 
|  | 10789 | wpa_printf(MSG_DEBUG, | 
|  | 10790 | "nl80211: Set P2P probable operating freq %u for ifindex %d", | 
|  | 10791 | freq, bss->ifindex); | 
|  | 10792 |  | 
|  | 10793 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | 
|  | 10794 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 10795 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 10796 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || | 
|  | 10797 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || | 
|  | 10798 | nla_put_u32(msg, | 
|  | 10799 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, | 
|  | 10800 | QCA_IFACE_TYPE_P2P_CLIENT) || | 
|  | 10801 | nla_put_u32(msg, | 
|  | 10802 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, | 
|  | 10803 | freq)) { | 
|  | 10804 | wpa_printf(MSG_ERROR, | 
|  | 10805 | "%s: err in adding vendor_cmd and vendor_data", | 
|  | 10806 | __func__); | 
|  | 10807 | nlmsg_free(msg); | 
|  | 10808 | return -1; | 
|  | 10809 | } | 
|  | 10810 | nla_nest_end(msg, params); | 
|  | 10811 |  | 
|  | 10812 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 10813 | msg = NULL; | 
|  | 10814 | if (ret) { | 
|  | 10815 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", | 
|  | 10816 | __func__); | 
|  | 10817 | return ret; | 
|  | 10818 | } | 
|  | 10819 | nlmsg_free(msg); | 
|  | 10820 | return 0; | 
|  | 10821 | } | 
|  | 10822 |  | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 10823 |  | 
|  | 10824 | static int nl80211_p2p_lo_start(void *priv, unsigned int freq, | 
|  | 10825 | unsigned int period, unsigned int interval, | 
|  | 10826 | unsigned int count, const u8 *device_types, | 
|  | 10827 | size_t dev_types_len, | 
|  | 10828 | const u8 *ies, size_t ies_len) | 
|  | 10829 | { | 
|  | 10830 | struct i802_bss *bss = priv; | 
|  | 10831 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 10832 | struct nl_msg *msg; | 
|  | 10833 | struct nlattr *container; | 
|  | 10834 | int ret; | 
|  | 10835 |  | 
|  | 10836 | wpa_printf(MSG_DEBUG, | 
|  | 10837 | "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u", | 
|  | 10838 | freq, period, interval, count); | 
|  | 10839 |  | 
|  | 10840 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) | 
|  | 10841 | return -1; | 
|  | 10842 |  | 
|  | 10843 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | 
|  | 10844 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 10845 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 10846 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START)) | 
|  | 10847 | goto fail; | 
|  | 10848 |  | 
|  | 10849 | container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | 
|  | 10850 | if (!container) | 
|  | 10851 | goto fail; | 
|  | 10852 |  | 
|  | 10853 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL, | 
|  | 10854 | freq) || | 
|  | 10855 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD, | 
|  | 10856 | period) || | 
|  | 10857 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL, | 
|  | 10858 | interval) || | 
|  | 10859 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT, | 
|  | 10860 | count) || | 
|  | 10861 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES, | 
|  | 10862 | dev_types_len, device_types) || | 
|  | 10863 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE, | 
|  | 10864 | ies_len, ies)) | 
|  | 10865 | goto fail; | 
|  | 10866 |  | 
|  | 10867 | nla_nest_end(msg, container); | 
|  | 10868 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 10869 | msg = NULL; | 
|  | 10870 | if (ret) { | 
|  | 10871 | wpa_printf(MSG_DEBUG, | 
|  | 10872 | "nl80211: Failed to send P2P Listen offload vendor command"); | 
|  | 10873 | goto fail; | 
|  | 10874 | } | 
|  | 10875 |  | 
|  | 10876 | return 0; | 
|  | 10877 |  | 
|  | 10878 | fail: | 
|  | 10879 | nlmsg_free(msg); | 
|  | 10880 | return -1; | 
|  | 10881 | } | 
|  | 10882 |  | 
|  | 10883 |  | 
|  | 10884 | static int nl80211_p2p_lo_stop(void *priv) | 
|  | 10885 | { | 
|  | 10886 | struct i802_bss *bss = priv; | 
|  | 10887 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 10888 | struct nl_msg *msg; | 
|  | 10889 |  | 
|  | 10890 | wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload"); | 
|  | 10891 |  | 
|  | 10892 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) | 
|  | 10893 | return -1; | 
|  | 10894 |  | 
|  | 10895 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | 
|  | 10896 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 10897 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 10898 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) { | 
|  | 10899 | nlmsg_free(msg); | 
|  | 10900 | return -1; | 
|  | 10901 | } | 
|  | 10902 |  | 
|  | 10903 | return send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 10904 | } | 
|  | 10905 |  | 
| Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 10906 |  | 
|  | 10907 | static int nl80211_set_tdls_mode(void *priv, int tdls_external_control) | 
|  | 10908 | { | 
|  | 10909 | struct i802_bss *bss = priv; | 
|  | 10910 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 10911 | struct nl_msg *msg; | 
|  | 10912 | struct nlattr *params; | 
|  | 10913 | int ret; | 
|  | 10914 | u32 tdls_mode; | 
|  | 10915 |  | 
|  | 10916 | wpa_printf(MSG_DEBUG, | 
|  | 10917 | "nl80211: Set TDKS mode: tdls_external_control=%d", | 
|  | 10918 | tdls_external_control); | 
|  | 10919 |  | 
|  | 10920 | if (tdls_external_control == 1) | 
|  | 10921 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT | | 
|  | 10922 | QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL; | 
|  | 10923 | else | 
|  | 10924 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT; | 
|  | 10925 |  | 
|  | 10926 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | 
|  | 10927 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 10928 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 10929 | QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS)) | 
|  | 10930 | goto fail; | 
|  | 10931 |  | 
|  | 10932 | params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | 
|  | 10933 | if (!params) | 
|  | 10934 | goto fail; | 
|  | 10935 |  | 
|  | 10936 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE, | 
|  | 10937 | tdls_mode)) | 
|  | 10938 | goto fail; | 
|  | 10939 |  | 
|  | 10940 | nla_nest_end(msg, params); | 
|  | 10941 |  | 
|  | 10942 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 10943 | msg = NULL; | 
|  | 10944 | if (ret) { | 
|  | 10945 | wpa_printf(MSG_ERROR, | 
|  | 10946 | "nl80211: Set TDLS mode failed: ret=%d (%s)", | 
|  | 10947 | ret, strerror(-ret)); | 
|  | 10948 | goto fail; | 
|  | 10949 | } | 
|  | 10950 | return 0; | 
|  | 10951 | fail: | 
|  | 10952 | nlmsg_free(msg); | 
|  | 10953 | return -1; | 
|  | 10954 | } | 
|  | 10955 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10956 |  | 
|  | 10957 | #ifdef CONFIG_MBO | 
|  | 10958 |  | 
|  | 10959 | static enum mbo_transition_reject_reason | 
|  | 10960 | nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status) | 
|  | 10961 | { | 
|  | 10962 | switch (status) { | 
|  | 10963 | case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED: | 
|  | 10964 | return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS; | 
|  | 10965 | case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED: | 
|  | 10966 | return MBO_TRANSITION_REJECT_REASON_DELAY; | 
|  | 10967 | case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY: | 
|  | 10968 | return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY; | 
|  | 10969 | case QCA_STATUS_REJECT_LOW_RSSI: | 
|  | 10970 | return MBO_TRANSITION_REJECT_REASON_RSSI; | 
|  | 10971 | case QCA_STATUS_REJECT_HIGH_INTERFERENCE: | 
|  | 10972 | return MBO_TRANSITION_REJECT_REASON_INTERFERENCE; | 
|  | 10973 | case QCA_STATUS_REJECT_UNKNOWN: | 
|  | 10974 | default: | 
|  | 10975 | return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED; | 
|  | 10976 | } | 
|  | 10977 | } | 
|  | 10978 |  | 
|  | 10979 |  | 
|  | 10980 | static void nl80211_parse_btm_candidate_info(struct candidate_list *candidate, | 
|  | 10981 | struct nlattr *tb[], int num) | 
|  | 10982 | { | 
|  | 10983 | enum qca_wlan_btm_candidate_status status; | 
|  | 10984 | char buf[50]; | 
|  | 10985 |  | 
|  | 10986 | os_memcpy(candidate->bssid, | 
|  | 10987 | nla_data(tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID]), | 
|  | 10988 | ETH_ALEN); | 
|  | 10989 |  | 
|  | 10990 | status = nla_get_u32( | 
|  | 10991 | tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]); | 
|  | 10992 | candidate->is_accept = status == QCA_STATUS_ACCEPT; | 
|  | 10993 | candidate->reject_reason = nl80211_mbo_reject_reason_mapping(status); | 
|  | 10994 |  | 
|  | 10995 | if (candidate->is_accept) | 
|  | 10996 | os_snprintf(buf, sizeof(buf), "Accepted"); | 
|  | 10997 | else | 
|  | 10998 | os_snprintf(buf, sizeof(buf), | 
|  | 10999 | "Rejected, Reject_reason: %d", | 
|  | 11000 | candidate->reject_reason); | 
|  | 11001 | wpa_printf(MSG_DEBUG, "nl80211:   BSSID[%d]: " MACSTR " %s", | 
|  | 11002 | num, MAC2STR(candidate->bssid), buf); | 
|  | 11003 | } | 
|  | 11004 |  | 
|  | 11005 |  | 
|  | 11006 | static int | 
|  | 11007 | nl80211_get_bss_transition_status_handler(struct nl_msg *msg, void *arg) | 
|  | 11008 | { | 
|  | 11009 | struct wpa_bss_candidate_info *info = arg; | 
|  | 11010 | struct candidate_list *candidate = info->candidates; | 
|  | 11011 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; | 
|  | 11012 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; | 
|  | 11013 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1]; | 
|  | 11014 | static struct nla_policy policy[ | 
|  | 11015 | QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1] = { | 
|  | 11016 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] = { | 
|  | 11017 | .minlen = ETH_ALEN | 
|  | 11018 | }, | 
|  | 11019 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS] = { | 
|  | 11020 | .type = NLA_U32, | 
|  | 11021 | }, | 
|  | 11022 | }; | 
|  | 11023 | struct nlattr *attr; | 
|  | 11024 | int rem; | 
|  | 11025 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); | 
|  | 11026 | u8 num; | 
|  | 11027 |  | 
|  | 11028 | num = info->num; /* number of candidates sent to driver */ | 
|  | 11029 | info->num = 0; | 
|  | 11030 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), | 
|  | 11031 | genlmsg_attrlen(gnlh, 0), NULL); | 
|  | 11032 |  | 
|  | 11033 | if (!tb_msg[NL80211_ATTR_VENDOR_DATA] || | 
|  | 11034 | nla_parse_nested(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, | 
|  | 11035 | tb_msg[NL80211_ATTR_VENDOR_DATA], NULL) || | 
|  | 11036 | !tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO]) | 
|  | 11037 | return NL_SKIP; | 
|  | 11038 |  | 
|  | 11039 | wpa_printf(MSG_DEBUG, | 
|  | 11040 | "nl80211: WNM Candidate list received from driver"); | 
|  | 11041 | nla_for_each_nested(attr, | 
|  | 11042 | tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO], | 
|  | 11043 | rem) { | 
|  | 11044 | if (info->num >= num || | 
|  | 11045 | nla_parse_nested( | 
|  | 11046 | tb, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX, | 
|  | 11047 | attr, policy) || | 
|  | 11048 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] || | 
|  | 11049 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]) | 
|  | 11050 | break; | 
|  | 11051 |  | 
|  | 11052 | nl80211_parse_btm_candidate_info(candidate, tb, info->num); | 
|  | 11053 |  | 
|  | 11054 | candidate++; | 
|  | 11055 | info->num++; | 
|  | 11056 | } | 
|  | 11057 |  | 
|  | 11058 | return NL_SKIP; | 
|  | 11059 | } | 
|  | 11060 |  | 
|  | 11061 |  | 
|  | 11062 | static struct wpa_bss_candidate_info * | 
|  | 11063 | nl80211_get_bss_transition_status(void *priv, struct wpa_bss_trans_info *params) | 
|  | 11064 | { | 
|  | 11065 | struct i802_bss *bss = priv; | 
|  | 11066 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 11067 | struct nl_msg *msg; | 
|  | 11068 | struct nlattr *attr, *attr1, *attr2; | 
|  | 11069 | struct wpa_bss_candidate_info *info; | 
|  | 11070 | u8 i; | 
|  | 11071 | int ret; | 
|  | 11072 | u8 *pos; | 
|  | 11073 |  | 
|  | 11074 | if (!drv->fetch_bss_trans_status) | 
|  | 11075 | return NULL; | 
|  | 11076 |  | 
|  | 11077 | info = os_zalloc(sizeof(*info)); | 
|  | 11078 | if (!info) | 
|  | 11079 | return NULL; | 
|  | 11080 | /* Allocate memory for number of candidates sent to driver */ | 
|  | 11081 | info->candidates = os_calloc(params->n_candidates, | 
|  | 11082 | sizeof(*info->candidates)); | 
|  | 11083 | if (!info->candidates) { | 
|  | 11084 | os_free(info); | 
|  | 11085 | return NULL; | 
|  | 11086 | } | 
|  | 11087 |  | 
|  | 11088 | /* Copy the number of candidates being sent to driver. This is used in | 
|  | 11089 | * nl80211_get_bss_transition_status_handler() to limit the number of | 
|  | 11090 | * candidates that can be populated in info->candidates and will be | 
|  | 11091 | * later overwritten with the actual number of candidates received from | 
|  | 11092 | * the driver. | 
|  | 11093 | */ | 
|  | 11094 | info->num = params->n_candidates; | 
|  | 11095 |  | 
|  | 11096 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | 
|  | 11097 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 11098 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 11099 | QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS)) | 
|  | 11100 | goto fail; | 
|  | 11101 |  | 
|  | 11102 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | 
|  | 11103 | if (!attr) | 
|  | 11104 | goto fail; | 
|  | 11105 |  | 
|  | 11106 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON, | 
|  | 11107 | params->mbo_transition_reason)) | 
|  | 11108 | goto fail; | 
|  | 11109 |  | 
|  | 11110 | attr1 = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO); | 
|  | 11111 | if (!attr1) | 
|  | 11112 | goto fail; | 
|  | 11113 |  | 
|  | 11114 | wpa_printf(MSG_DEBUG, | 
|  | 11115 | "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d", | 
|  | 11116 | params->mbo_transition_reason, params->n_candidates); | 
|  | 11117 | pos = params->bssid; | 
|  | 11118 | for (i = 0; i < params->n_candidates; i++) { | 
|  | 11119 | wpa_printf(MSG_DEBUG, "nl80211:   BSSID[%d]: " MACSTR, i, | 
|  | 11120 | MAC2STR(pos)); | 
|  | 11121 | attr2 = nla_nest_start(msg, i); | 
|  | 11122 | if (!attr2 || | 
|  | 11123 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID, | 
|  | 11124 | ETH_ALEN, pos)) | 
|  | 11125 | goto fail; | 
|  | 11126 | pos += ETH_ALEN; | 
|  | 11127 | nla_nest_end(msg, attr2); | 
|  | 11128 | } | 
|  | 11129 |  | 
|  | 11130 | nla_nest_end(msg, attr1); | 
|  | 11131 | nla_nest_end(msg, attr); | 
|  | 11132 |  | 
|  | 11133 | ret = send_and_recv_msgs(drv, msg, | 
|  | 11134 | nl80211_get_bss_transition_status_handler, | 
|  | 11135 | info); | 
|  | 11136 | msg = NULL; | 
|  | 11137 | if (ret) { | 
|  | 11138 | wpa_printf(MSG_ERROR, | 
|  | 11139 | "nl80211: WNM Get BSS transition status failed: ret=%d (%s)", | 
|  | 11140 | ret, strerror(-ret)); | 
|  | 11141 | goto fail; | 
|  | 11142 | } | 
|  | 11143 | return info; | 
|  | 11144 |  | 
|  | 11145 | fail: | 
|  | 11146 | nlmsg_free(msg); | 
|  | 11147 | os_free(info->candidates); | 
|  | 11148 | os_free(info); | 
|  | 11149 | return NULL; | 
|  | 11150 | } | 
|  | 11151 |  | 
|  | 11152 |  | 
|  | 11153 | /** | 
|  | 11154 | * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow | 
|  | 11155 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() | 
|  | 11156 | * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore | 
|  | 11157 | * Returns: 0 on success, -1 on failure | 
|  | 11158 | */ | 
|  | 11159 | static int nl80211_ignore_assoc_disallow(void *priv, int ignore_disallow) | 
|  | 11160 | { | 
|  | 11161 | struct i802_bss *bss = priv; | 
|  | 11162 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 11163 | struct nl_msg *msg; | 
|  | 11164 | struct nlattr *attr; | 
|  | 11165 | int ret = -1; | 
|  | 11166 |  | 
|  | 11167 | if (!drv->set_wifi_conf_vendor_cmd_avail) | 
|  | 11168 | return -1; | 
|  | 11169 |  | 
|  | 11170 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || | 
|  | 11171 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || | 
|  | 11172 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, | 
|  | 11173 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) | 
|  | 11174 | goto fail; | 
|  | 11175 |  | 
|  | 11176 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); | 
|  | 11177 | if (!attr) | 
|  | 11178 | goto fail; | 
|  | 11179 |  | 
|  | 11180 | wpa_printf(MSG_DEBUG, "nl80211: Set ignore_assoc_disallow %d", | 
|  | 11181 | ignore_disallow); | 
|  | 11182 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED, | 
|  | 11183 | ignore_disallow)) | 
|  | 11184 | goto fail; | 
|  | 11185 |  | 
|  | 11186 | nla_nest_end(msg, attr); | 
|  | 11187 |  | 
|  | 11188 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 11189 | msg = NULL; | 
|  | 11190 | if (ret) { | 
|  | 11191 | wpa_printf(MSG_ERROR, | 
|  | 11192 | "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)", | 
|  | 11193 | ret, strerror(-ret)); | 
|  | 11194 | goto fail; | 
|  | 11195 | } | 
|  | 11196 |  | 
|  | 11197 | fail: | 
|  | 11198 | nlmsg_free(msg); | 
|  | 11199 | return ret; | 
|  | 11200 | } | 
|  | 11201 |  | 
|  | 11202 | #endif /* CONFIG_MBO */ | 
|  | 11203 |  | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11204 | #endif /* CONFIG_DRIVER_NL80211_QCA */ | 
|  | 11205 |  | 
|  | 11206 |  | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11207 | static int nl80211_write_to_file(const char *name, unsigned int val) | 
|  | 11208 | { | 
|  | 11209 | int fd, len; | 
|  | 11210 | char tmp[128]; | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11211 | int ret = 0; | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11212 |  | 
|  | 11213 | fd = open(name, O_RDWR); | 
|  | 11214 | if (fd < 0) { | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11215 | int level; | 
|  | 11216 | /* | 
|  | 11217 | * Flags may not exist on older kernels, or while we're tearing | 
|  | 11218 | * down a disappearing device. | 
|  | 11219 | */ | 
|  | 11220 | if (errno == ENOENT) { | 
|  | 11221 | ret = 0; | 
|  | 11222 | level = MSG_DEBUG; | 
|  | 11223 | } else { | 
|  | 11224 | ret = -1; | 
|  | 11225 | level = MSG_ERROR; | 
|  | 11226 | } | 
|  | 11227 | wpa_printf(level, "nl80211: Failed to open %s: %s", | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11228 | name, strerror(errno)); | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11229 | return ret; | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11230 | } | 
|  | 11231 |  | 
|  | 11232 | len = os_snprintf(tmp, sizeof(tmp), "%u\n", val); | 
|  | 11233 | len = write(fd, tmp, len); | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11234 | if (len < 0) { | 
|  | 11235 | ret = -1; | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11236 | wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s", | 
|  | 11237 | name, strerror(errno)); | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11238 | } | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11239 | close(fd); | 
|  | 11240 |  | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11241 | return ret; | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11242 | } | 
|  | 11243 |  | 
|  | 11244 |  | 
|  | 11245 | static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags) | 
|  | 11246 | { | 
|  | 11247 | struct i802_bss *bss = priv; | 
|  | 11248 | char path[128]; | 
|  | 11249 | int ret; | 
|  | 11250 |  | 
|  | 11251 | wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x", | 
|  | 11252 | filter_flags); | 
|  | 11253 |  | 
|  | 11254 | /* Configure filtering of unicast frame encrypted using GTK */ | 
|  | 11255 | ret = os_snprintf(path, sizeof(path), | 
|  | 11256 | "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast", | 
|  | 11257 | bss->ifname); | 
|  | 11258 | if (os_snprintf_error(sizeof(path), ret)) | 
|  | 11259 | return -1; | 
|  | 11260 |  | 
|  | 11261 | ret = nl80211_write_to_file(path, | 
|  | 11262 | !!(filter_flags & | 
|  | 11263 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); | 
|  | 11264 | if (ret) { | 
|  | 11265 | wpa_printf(MSG_ERROR, | 
|  | 11266 | "nl80211: Failed to set IPv4 unicast in multicast filter"); | 
|  | 11267 | return ret; | 
|  | 11268 | } | 
|  | 11269 |  | 
|  | 11270 | os_snprintf(path, sizeof(path), | 
|  | 11271 | "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast", | 
|  | 11272 | bss->ifname); | 
|  | 11273 | ret = nl80211_write_to_file(path, | 
|  | 11274 | !!(filter_flags & | 
|  | 11275 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); | 
|  | 11276 |  | 
|  | 11277 | if (ret) { | 
|  | 11278 | wpa_printf(MSG_ERROR, | 
|  | 11279 | "nl80211: Failed to set IPv6 unicast in multicast filter"); | 
|  | 11280 | return ret; | 
|  | 11281 | } | 
|  | 11282 |  | 
|  | 11283 | /* Configure filtering of unicast frame encrypted using GTK */ | 
|  | 11284 | os_snprintf(path, sizeof(path), | 
|  | 11285 | "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp", | 
|  | 11286 | bss->ifname); | 
|  | 11287 | ret = nl80211_write_to_file(path, | 
|  | 11288 | !!(filter_flags & | 
|  | 11289 | WPA_DATA_FRAME_FILTER_FLAG_ARP)); | 
|  | 11290 | if (ret) { | 
|  | 11291 | wpa_printf(MSG_ERROR, | 
|  | 11292 | "nl80211: Failed set gratuitous ARP filter"); | 
|  | 11293 | return ret; | 
|  | 11294 | } | 
|  | 11295 |  | 
|  | 11296 | /* Configure filtering of IPv6 NA frames */ | 
|  | 11297 | os_snprintf(path, sizeof(path), | 
|  | 11298 | "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na", | 
|  | 11299 | bss->ifname); | 
|  | 11300 | ret = nl80211_write_to_file(path, | 
|  | 11301 | !!(filter_flags & | 
|  | 11302 | WPA_DATA_FRAME_FILTER_FLAG_NA)); | 
|  | 11303 | if (ret) { | 
|  | 11304 | wpa_printf(MSG_ERROR, | 
|  | 11305 | "nl80211: Failed to set unsolicited NA filter"); | 
|  | 11306 | return ret; | 
|  | 11307 | } | 
|  | 11308 |  | 
|  | 11309 | return 0; | 
|  | 11310 | } | 
|  | 11311 |  | 
|  | 11312 |  | 
| Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 11313 | static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type, | 
|  | 11314 | const u8 **ext_capa, const u8 **ext_capa_mask, | 
|  | 11315 | unsigned int *ext_capa_len) | 
|  | 11316 | { | 
|  | 11317 | struct i802_bss *bss = priv; | 
|  | 11318 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 11319 | enum nl80211_iftype nlmode; | 
|  | 11320 | unsigned int i; | 
|  | 11321 |  | 
|  | 11322 | if (!ext_capa || !ext_capa_mask || !ext_capa_len) | 
|  | 11323 | return -1; | 
|  | 11324 |  | 
|  | 11325 | nlmode = wpa_driver_nl80211_if_type(type); | 
|  | 11326 |  | 
|  | 11327 | /* By default, use the per-radio values */ | 
|  | 11328 | *ext_capa = drv->extended_capa; | 
|  | 11329 | *ext_capa_mask = drv->extended_capa_mask; | 
|  | 11330 | *ext_capa_len = drv->extended_capa_len; | 
|  | 11331 |  | 
|  | 11332 | /* Replace the default value if a per-interface type value exists */ | 
|  | 11333 | for (i = 0; i < drv->num_iface_ext_capa; i++) { | 
|  | 11334 | if (nlmode == drv->iface_ext_capa[i].iftype) { | 
|  | 11335 | *ext_capa = drv->iface_ext_capa[i].ext_capa; | 
|  | 11336 | *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask; | 
|  | 11337 | *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len; | 
|  | 11338 | break; | 
|  | 11339 | } | 
|  | 11340 | } | 
|  | 11341 |  | 
|  | 11342 | return 0; | 
|  | 11343 | } | 
|  | 11344 |  | 
|  | 11345 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11346 | static int nl80211_update_connection_params( | 
|  | 11347 | void *priv, struct wpa_driver_associate_params *params, | 
|  | 11348 | enum wpa_drv_update_connect_params_mask mask) | 
|  | 11349 | { | 
|  | 11350 | struct i802_bss *bss = priv; | 
|  | 11351 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 11352 | struct nl_msg *msg; | 
|  | 11353 | int ret = -1; | 
|  | 11354 | enum nl80211_auth_type type; | 
|  | 11355 |  | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11356 | /* Update Connection Params is intended for drivers that implement | 
|  | 11357 | * internal SME and expect these updated connection params from | 
|  | 11358 | * wpa_supplicant. Do not send this request for the drivers using | 
|  | 11359 | * SME from wpa_supplicant. | 
|  | 11360 | */ | 
|  | 11361 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) | 
|  | 11362 | return 0; | 
|  | 11363 |  | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11364 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS); | 
|  | 11365 | if (!msg) | 
|  | 11366 | goto fail; | 
|  | 11367 |  | 
|  | 11368 | wpa_printf(MSG_DEBUG, "nl80211: Update connection params (ifindex=%d)", | 
|  | 11369 | drv->ifindex); | 
|  | 11370 |  | 
|  | 11371 | if ((mask & WPA_DRV_UPDATE_ASSOC_IES) && params->wpa_ie) { | 
|  | 11372 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, | 
|  | 11373 | params->wpa_ie)) | 
|  | 11374 | goto fail; | 
|  | 11375 | wpa_hexdump(MSG_DEBUG, "  * IEs", params->wpa_ie, | 
|  | 11376 | params->wpa_ie_len); | 
|  | 11377 | } | 
|  | 11378 |  | 
|  | 11379 | if (mask & WPA_DRV_UPDATE_AUTH_TYPE) { | 
|  | 11380 | type = get_nl_auth_type(params->auth_alg); | 
|  | 11381 | if (type == NL80211_AUTHTYPE_MAX || | 
|  | 11382 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) | 
|  | 11383 | goto fail; | 
|  | 11384 | wpa_printf(MSG_DEBUG, "  * Auth Type %d", type); | 
|  | 11385 | } | 
|  | 11386 |  | 
|  | 11387 | if ((mask & WPA_DRV_UPDATE_FILS_ERP_INFO) && | 
|  | 11388 | nl80211_put_fils_connect_params(drv, params, msg)) | 
|  | 11389 | goto fail; | 
|  | 11390 |  | 
|  | 11391 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 11392 | msg = NULL; | 
|  | 11393 | if (ret) | 
|  | 11394 | wpa_dbg(drv->ctx, MSG_DEBUG, | 
|  | 11395 | "nl80211: Update connect params command failed: ret=%d (%s)", | 
|  | 11396 | ret, strerror(-ret)); | 
|  | 11397 |  | 
|  | 11398 | fail: | 
|  | 11399 | nlmsg_free(msg); | 
|  | 11400 | return ret; | 
|  | 11401 | } | 
|  | 11402 |  | 
|  | 11403 |  | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11404 | static int nl80211_send_external_auth_status(void *priv, | 
|  | 11405 | struct external_auth *params) | 
|  | 11406 | { | 
|  | 11407 | struct i802_bss *bss = priv; | 
|  | 11408 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 11409 | struct nl_msg *msg = NULL; | 
|  | 11410 | int ret = -1; | 
|  | 11411 |  | 
| Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 11412 | /* External auth command/status is intended for drivers that implement | 
| Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 11413 | * internal SME but want to offload authentication processing (e.g., | 
|  | 11414 | * SAE) to hostapd/wpa_supplicant. Do not send the status to drivers | 
| Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 11415 | * which do not support AP SME or use wpa_supplicant/hostapd SME. | 
|  | 11416 | */ | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 11417 | if ((is_ap_interface(drv->nlmode) && !bss->drv->device_ap_sme) || | 
| Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 11418 | (drv->capa.flags & WPA_DRIVER_FLAGS_SME)) | 
|  | 11419 | return -1; | 
|  | 11420 |  | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11421 | wpa_dbg(drv->ctx, MSG_DEBUG, | 
|  | 11422 | "nl80211: External auth status: %u", params->status); | 
|  | 11423 |  | 
|  | 11424 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_EXTERNAL_AUTH); | 
|  | 11425 | if (!msg || | 
|  | 11426 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, params->status) || | 
| Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 11427 | (params->ssid && params->ssid_len && | 
|  | 11428 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || | 
|  | 11429 | (params->pmkid && | 
|  | 11430 | nla_put(msg, NL80211_ATTR_PMKID, PMKID_LEN, params->pmkid)) || | 
|  | 11431 | (params->bssid && | 
|  | 11432 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid))) | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11433 | goto fail; | 
|  | 11434 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 11435 | msg = NULL; | 
|  | 11436 | if (ret) { | 
|  | 11437 | wpa_printf(MSG_DEBUG, | 
|  | 11438 | "nl80211: External Auth status update failed: ret=%d (%s)", | 
|  | 11439 | ret, strerror(-ret)); | 
|  | 11440 | goto fail; | 
|  | 11441 | } | 
|  | 11442 | fail: | 
|  | 11443 | nlmsg_free(msg); | 
|  | 11444 | return ret; | 
|  | 11445 | } | 
|  | 11446 |  | 
|  | 11447 |  | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 11448 | static int nl80211_set_4addr_mode(void *priv, const char *bridge_ifname, | 
|  | 11449 | int val) | 
|  | 11450 | { | 
|  | 11451 | struct i802_bss *bss = priv; | 
|  | 11452 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 11453 | struct nl_msg *msg; | 
|  | 11454 | int ret = -ENOBUFS; | 
|  | 11455 |  | 
|  | 11456 | wpa_printf(MSG_DEBUG, "nl80211: %s 4addr mode (bridge_ifname: %s)", | 
|  | 11457 | val ? "Enable" : "Disable", bridge_ifname); | 
|  | 11458 |  | 
|  | 11459 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); | 
|  | 11460 | if (!msg || nla_put_u8(msg, NL80211_ATTR_4ADDR, val)) | 
|  | 11461 | goto fail; | 
|  | 11462 |  | 
|  | 11463 | if (bridge_ifname[0] && bss->added_if_into_bridge && !val) { | 
|  | 11464 | if (linux_br_del_if(drv->global->ioctl_sock, | 
|  | 11465 | bridge_ifname, bss->ifname)) { | 
|  | 11466 | wpa_printf(MSG_ERROR, | 
|  | 11467 | "nl80211: Failed to remove interface %s from bridge %s", | 
|  | 11468 | bss->ifname, bridge_ifname); | 
|  | 11469 | return -1; | 
|  | 11470 | } | 
|  | 11471 | bss->added_if_into_bridge = 0; | 
|  | 11472 | } | 
|  | 11473 |  | 
|  | 11474 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); | 
|  | 11475 | msg = NULL; | 
|  | 11476 | if (!ret) { | 
|  | 11477 | if (bridge_ifname[0] && val && | 
|  | 11478 | i802_check_bridge(drv, bss, bridge_ifname, bss->ifname) < 0) | 
|  | 11479 | return -1; | 
|  | 11480 | return 0; | 
|  | 11481 | } | 
|  | 11482 |  | 
|  | 11483 | fail: | 
|  | 11484 | nlmsg_free(msg); | 
|  | 11485 | wpa_printf(MSG_ERROR, "nl80211: Failed to enable/disable 4addr"); | 
|  | 11486 |  | 
|  | 11487 | return ret; | 
|  | 11488 | } | 
|  | 11489 |  | 
|  | 11490 |  | 
| Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 11491 | #ifdef CONFIG_DPP | 
|  | 11492 | static int nl80211_dpp_listen(void *priv, bool enable) | 
|  | 11493 | { | 
|  | 11494 | struct i802_bss *bss = priv; | 
|  | 11495 | struct wpa_driver_nl80211_data *drv = bss->drv; | 
|  | 11496 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); | 
|  | 11497 | struct nl_sock *handle; | 
|  | 11498 |  | 
|  | 11499 | if (!drv->multicast_registrations || !bss->nl_mgmt) | 
|  | 11500 | return 0; /* cannot do more than hope broadcast RX works */ | 
|  | 11501 |  | 
|  | 11502 | wpa_printf(MSG_DEBUG, | 
|  | 11503 | "nl80211: Update DPP Public Action frame registration (%s multicast RX)", | 
|  | 11504 | enable ? "enable" : "disable"); | 
|  | 11505 | handle = (void *) (((intptr_t) bss->nl_mgmt) ^ ELOOP_SOCKET_INVALID); | 
|  | 11506 | return nl80211_register_frame(bss, handle, type, | 
|  | 11507 | (u8 *) "\x04\x09\x50\x6f\x9a\x1a", 6, | 
|  | 11508 | enable); | 
|  | 11509 | } | 
|  | 11510 | #endif /* CONFIG_DPP */ | 
|  | 11511 |  | 
|  | 11512 |  | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11513 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { | 
|  | 11514 | .name = "nl80211", | 
|  | 11515 | .desc = "Linux nl80211/cfg80211", | 
|  | 11516 | .get_bssid = wpa_driver_nl80211_get_bssid, | 
|  | 11517 | .get_ssid = wpa_driver_nl80211_get_ssid, | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11518 | .set_key = driver_nl80211_set_key, | 
|  | 11519 | .scan2 = driver_nl80211_scan2, | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11520 | .sched_scan = wpa_driver_nl80211_sched_scan, | 
|  | 11521 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11522 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, | 
| Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 11523 | .abort_scan = wpa_driver_nl80211_abort_scan, | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11524 | .deauthenticate = driver_nl80211_deauthenticate, | 
|  | 11525 | .authenticate = driver_nl80211_authenticate, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11526 | .associate = wpa_driver_nl80211_associate, | 
|  | 11527 | .global_init = nl80211_global_init, | 
|  | 11528 | .global_deinit = nl80211_global_deinit, | 
|  | 11529 | .init2 = wpa_driver_nl80211_init, | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11530 | .deinit = driver_nl80211_deinit, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11531 | .get_capa = wpa_driver_nl80211_get_capa, | 
|  | 11532 | .set_operstate = wpa_driver_nl80211_set_operstate, | 
|  | 11533 | .set_supp_port = wpa_driver_nl80211_set_supp_port, | 
|  | 11534 | .set_country = wpa_driver_nl80211_set_country, | 
| Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 11535 | .get_country = wpa_driver_nl80211_get_country, | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11536 | .set_ap = wpa_driver_nl80211_set_ap, | 
| Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 11537 | .set_acl = wpa_driver_nl80211_set_acl, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11538 | .if_add = wpa_driver_nl80211_if_add, | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11539 | .if_remove = driver_nl80211_if_remove, | 
|  | 11540 | .send_mlme = driver_nl80211_send_mlme, | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11541 | .get_hw_feature_data = nl80211_get_hw_feature_data, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11542 | .sta_add = wpa_driver_nl80211_sta_add, | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11543 | .sta_remove = driver_nl80211_sta_remove, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11544 | .tx_control_port = nl80211_tx_control_port, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11545 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, | 
|  | 11546 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 11547 | .sta_set_airtime_weight = driver_nl80211_sta_set_airtime_weight, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11548 | .hapd_init = i802_init, | 
|  | 11549 | .hapd_deinit = i802_deinit, | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 11550 | .set_wds_sta = i802_set_wds_sta, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11551 | .get_seqnum = i802_get_seqnum, | 
|  | 11552 | .flush = i802_flush, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11553 | .get_inact_sec = i802_get_inact_sec, | 
|  | 11554 | .sta_clear_stats = i802_sta_clear_stats, | 
|  | 11555 | .set_rts = i802_set_rts, | 
|  | 11556 | .set_frag = i802_set_frag, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11557 | .set_tx_queue_params = i802_set_tx_queue_params, | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11558 | .set_sta_vlan = driver_nl80211_set_sta_vlan, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11559 | .sta_deauth = i802_sta_deauth, | 
|  | 11560 | .sta_disassoc = i802_sta_disassoc, | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11561 | .read_sta_data = driver_nl80211_read_sta_data, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11562 | .set_freq = i802_set_freq, | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11563 | .send_action = driver_nl80211_send_action, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11564 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, | 
|  | 11565 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, | 
|  | 11566 | .cancel_remain_on_channel = | 
|  | 11567 | wpa_driver_nl80211_cancel_remain_on_channel, | 
| Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11568 | .probe_req_report = driver_nl80211_probe_req_report, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11569 | .deinit_ap = wpa_driver_nl80211_deinit_ap, | 
| Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 11570 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11571 | .resume = wpa_driver_nl80211_resume, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11572 | .signal_monitor = nl80211_signal_monitor, | 
|  | 11573 | .signal_poll = nl80211_signal_poll, | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 11574 | .channel_info = nl80211_channel_info, | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11575 | .set_param = nl80211_set_param, | 
|  | 11576 | .get_radio_name = nl80211_get_radio_name, | 
| Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 11577 | .add_pmkid = nl80211_add_pmkid, | 
|  | 11578 | .remove_pmkid = nl80211_remove_pmkid, | 
|  | 11579 | .flush_pmkid = nl80211_flush_pmkid, | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11580 | .set_rekey_info = nl80211_set_rekey_info, | 
|  | 11581 | .poll_client = nl80211_poll_client, | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11582 | .set_p2p_powersave = nl80211_set_p2p_powersave, | 
| Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 11583 | .start_dfs_cac = nl80211_start_radar_detection, | 
|  | 11584 | .stop_ap = wpa_driver_nl80211_stop_ap, | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11585 | #ifdef CONFIG_TDLS | 
|  | 11586 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, | 
|  | 11587 | .tdls_oper = nl80211_tdls_oper, | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11588 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, | 
|  | 11589 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11590 | #endif /* CONFIG_TDLS */ | 
| Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 11591 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 11592 | .update_dh_ie = nl80211_update_dh_ie, | 
| Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 11593 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, | 
| Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 11594 | .get_survey = wpa_driver_nl80211_get_survey, | 
| Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11595 | .status = wpa_driver_nl80211_status, | 
| Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11596 | .switch_channel = nl80211_switch_channel, | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11597 | #ifdef ANDROID_P2P | 
| Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 11598 | .set_noa = wpa_driver_set_p2p_noa, | 
| Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11599 | .get_noa = wpa_driver_get_p2p_noa, | 
| Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 11600 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, | 
| Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 11601 | #endif /* ANDROID_P2P */ | 
| Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 11602 | #ifdef ANDROID | 
| Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 11603 | #ifndef ANDROID_LIB_STUB | 
| Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 11604 | .driver_cmd = wpa_driver_nl80211_driver_cmd, | 
| Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 11605 | #endif /* !ANDROID_LIB_STUB */ | 
| Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 11606 | #endif /* ANDROID */ | 
| Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 11607 | .vendor_cmd = nl80211_vendor_cmd, | 
| Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11608 | .set_qos_map = nl80211_set_qos_map, | 
| Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame] | 11609 | .get_wowlan = nl80211_get_wowlan, | 
| Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 11610 | .set_wowlan = nl80211_set_wowlan, | 
| Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11611 | .set_mac_addr = nl80211_set_mac_addr, | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11612 | #ifdef CONFIG_MESH | 
|  | 11613 | .init_mesh = wpa_driver_nl80211_init_mesh, | 
|  | 11614 | .join_mesh = wpa_driver_nl80211_join_mesh, | 
|  | 11615 | .leave_mesh = wpa_driver_nl80211_leave_mesh, | 
| Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 11616 | .probe_mesh_link = nl80211_probe_mesh_link, | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11617 | #endif /* CONFIG_MESH */ | 
|  | 11618 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, | 
|  | 11619 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, | 
|  | 11620 | .br_port_set_attr = wpa_driver_br_port_set_attr, | 
|  | 11621 | .br_set_net_param = wpa_driver_br_set_net_param, | 
|  | 11622 | .add_tx_ts = nl80211_add_ts, | 
|  | 11623 | .del_tx_ts = nl80211_del_ts, | 
| Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 11624 | .get_ifindex = nl80211_get_ifindex, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11625 | #ifdef CONFIG_DRIVER_NL80211_QCA | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 11626 | .roaming = nl80211_roaming, | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11627 | .disable_fils = nl80211_disable_fils, | 
| Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11628 | .do_acs = wpa_driver_do_acs, | 
| Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11629 | .set_band = nl80211_set_band, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11630 | .get_pref_freq_list = nl80211_get_pref_freq_list, | 
|  | 11631 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, | 
| Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 11632 | .p2p_lo_start = nl80211_p2p_lo_start, | 
|  | 11633 | .p2p_lo_stop = nl80211_p2p_lo_stop, | 
| Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 11634 | .set_default_scan_ies = nl80211_set_default_scan_ies, | 
| Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 11635 | .set_tdls_mode = nl80211_set_tdls_mode, | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11636 | #ifdef CONFIG_MBO | 
|  | 11637 | .get_bss_transition_status = nl80211_get_bss_transition_status, | 
|  | 11638 | .ignore_assoc_disallow = nl80211_ignore_assoc_disallow, | 
|  | 11639 | #endif /* CONFIG_MBO */ | 
|  | 11640 | .set_bssid_blacklist = nl80211_set_bssid_blacklist, | 
| Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11641 | .add_sta_node = nl80211_add_sta_node, | 
| Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11642 | #endif /* CONFIG_DRIVER_NL80211_QCA */ | 
| Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11643 | .configure_data_frame_filters = nl80211_configure_data_frame_filters, | 
| Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 11644 | .get_ext_capab = nl80211_get_ext_capab, | 
| Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11645 | .update_connect_params = nl80211_update_connection_params, | 
| Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11646 | .send_external_auth_status = nl80211_send_external_auth_status, | 
| Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 11647 | .set_4addr_mode = nl80211_set_4addr_mode, | 
| Hai Shalom | e21d4e8 | 2020-04-29 16:34:06 -0700 | [diff] [blame] | 11648 | #ifdef CONFIG_DPP | 
|  | 11649 | .dpp_listen = nl80211_dpp_listen, | 
|  | 11650 | #endif /* CONFIG_DPP */ | 
| Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11651 | }; |