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 | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 33 | #include "l2_packet/l2_packet.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 34 | #include "netlink.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 35 | #include "linux_defines.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 36 | #include "linux_ioctl.h" |
| 37 | #include "radiotap.h" |
| 38 | #include "radiotap_iter.h" |
| 39 | #include "rfkill.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 40 | #include "driver_nl80211.h" |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 41 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 42 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 43 | #ifndef NETLINK_CAP_ACK |
| 44 | #define NETLINK_CAP_ACK 10 |
| 45 | #endif /* NETLINK_CAP_ACK */ |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 46 | /* support for extack if compilation headers are too old */ |
| 47 | #ifndef NETLINK_EXT_ACK |
| 48 | #define NETLINK_EXT_ACK 11 |
| 49 | enum nlmsgerr_attrs { |
| 50 | NLMSGERR_ATTR_UNUSED, |
| 51 | NLMSGERR_ATTR_MSG, |
| 52 | NLMSGERR_ATTR_OFFS, |
| 53 | NLMSGERR_ATTR_COOKIE, |
| 54 | |
| 55 | __NLMSGERR_ATTR_MAX, |
| 56 | NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1 |
| 57 | }; |
| 58 | #endif |
| 59 | #ifndef NLM_F_CAPPED |
| 60 | #define NLM_F_CAPPED 0x100 |
| 61 | #endif |
| 62 | #ifndef NLM_F_ACK_TLVS |
| 63 | #define NLM_F_ACK_TLVS 0x200 |
| 64 | #endif |
| 65 | #ifndef SOL_NETLINK |
| 66 | #define SOL_NETLINK 270 |
| 67 | #endif |
| 68 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 69 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 70 | #ifdef ANDROID |
| 71 | /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */ |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 72 | #undef nl_socket_set_nonblocking |
| 73 | #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 74 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 75 | #endif /* ANDROID */ |
| 76 | |
| 77 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 78 | 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] | 79 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 80 | struct nl_sock *handle; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 81 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 82 | handle = nl_socket_alloc_cb(cb); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 83 | if (handle == NULL) { |
| 84 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 85 | "callbacks (%s)", dbg); |
| 86 | return NULL; |
| 87 | } |
| 88 | |
| 89 | if (genl_connect(handle)) { |
| 90 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " |
| 91 | "netlink (%s)", dbg); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 92 | nl_socket_free(handle); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 93 | return NULL; |
| 94 | } |
| 95 | |
| 96 | return handle; |
| 97 | } |
| 98 | |
| 99 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 100 | static void nl_destroy_handles(struct nl_sock **handle) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 101 | { |
| 102 | if (*handle == NULL) |
| 103 | return; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 104 | nl_socket_free(*handle); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 105 | *handle = NULL; |
| 106 | } |
| 107 | |
| 108 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 109 | #if __WORDSIZE == 64 |
| 110 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL |
| 111 | #else |
| 112 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL |
| 113 | #endif |
| 114 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 115 | static void nl80211_register_eloop_read(struct nl_sock **handle, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 116 | eloop_sock_handler handler, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 117 | void *eloop_data, int persist) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 118 | { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 119 | /* |
| 120 | * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB) |
| 121 | * by default. It is possible to hit that limit in some cases where |
| 122 | * operations are blocked, e.g., with a burst of Deauthentication frames |
| 123 | * to hostapd and STA entry deletion. Try to increase the buffer to make |
| 124 | * this less likely to occur. |
| 125 | */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 126 | int err; |
| 127 | |
| 128 | err = nl_socket_set_buffer_size(*handle, 262144, 0); |
| 129 | if (err < 0) { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 130 | wpa_printf(MSG_DEBUG, |
| 131 | "nl80211: Could not set nl_socket RX buffer size: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 132 | nl_geterror(err)); |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 133 | /* continue anyway with the default (smaller) buffer */ |
| 134 | } |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 135 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 136 | nl_socket_set_nonblocking(*handle); |
| 137 | eloop_register_read_sock(nl_socket_get_fd(*handle), handler, |
| 138 | eloop_data, *handle); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 139 | if (!persist) |
| 140 | *handle = (void *) (((intptr_t) *handle) ^ |
| 141 | ELOOP_SOCKET_INVALID); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 145 | static void nl80211_destroy_eloop_handle(struct nl_sock **handle, int persist) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 146 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 147 | if (!persist) |
| 148 | *handle = (void *) (((intptr_t) *handle) ^ |
| 149 | ELOOP_SOCKET_INVALID); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 150 | eloop_unregister_read_sock(nl_socket_get_fd(*handle)); |
| 151 | nl_destroy_handles(handle); |
| 152 | } |
| 153 | |
| 154 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 155 | static void nl80211_global_deinit(void *priv); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 156 | static void nl80211_check_global(struct nl80211_global *global); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 157 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 158 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 159 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 160 | struct hostapd_freq_params *freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 161 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 162 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 163 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 164 | const u8 *set_addr, int first, |
| 165 | const char *driver_params); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 166 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 167 | unsigned int freq, unsigned int wait, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 168 | const u8 *buf, size_t buf_len, |
| 169 | int save_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 170 | int no_cck, int no_ack, int offchanok, |
| 171 | const u16 *csa_offs, size_t csa_offs_len); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 172 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, |
| 173 | int report); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 174 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 175 | #define IFIDX_ANY -1 |
| 176 | |
| 177 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 178 | int ifidx_reason); |
| 179 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 180 | int ifidx_reason); |
| 181 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 182 | int ifidx_reason); |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 183 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 184 | static int nl80211_set_channel(struct i802_bss *bss, |
| 185 | struct hostapd_freq_params *freq, int set_chan); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 186 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 187 | int ifindex, int disabled); |
| 188 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 189 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 190 | int reset_mode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 191 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 192 | static int i802_set_iface_flags(struct i802_bss *bss, int up); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 193 | static int nl80211_set_param(void *priv, const char *param); |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 194 | #ifdef CONFIG_MESH |
| 195 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
| 196 | struct wpa_driver_mesh_bss_params *params); |
| 197 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 198 | 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] | 199 | u16 reason); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 200 | |
| 201 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 202 | /* Converts nl80211_chan_width to a common format */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 203 | enum chan_width convert2width(int width) |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 204 | { |
| 205 | switch (width) { |
| 206 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 207 | return CHAN_WIDTH_20_NOHT; |
| 208 | case NL80211_CHAN_WIDTH_20: |
| 209 | return CHAN_WIDTH_20; |
| 210 | case NL80211_CHAN_WIDTH_40: |
| 211 | return CHAN_WIDTH_40; |
| 212 | case NL80211_CHAN_WIDTH_80: |
| 213 | return CHAN_WIDTH_80; |
| 214 | case NL80211_CHAN_WIDTH_80P80: |
| 215 | return CHAN_WIDTH_80P80; |
| 216 | case NL80211_CHAN_WIDTH_160: |
| 217 | return CHAN_WIDTH_160; |
| 218 | } |
| 219 | return CHAN_WIDTH_UNKNOWN; |
| 220 | } |
| 221 | |
| 222 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 223 | int is_ap_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 224 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 225 | return nlmode == NL80211_IFTYPE_AP || |
| 226 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 230 | int is_sta_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 231 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 232 | return nlmode == NL80211_IFTYPE_STATION || |
| 233 | nlmode == NL80211_IFTYPE_P2P_CLIENT; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 237 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 238 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 239 | return nlmode == NL80211_IFTYPE_P2P_CLIENT || |
| 240 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 241 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 242 | |
| 243 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 244 | struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, |
| 245 | int ifindex) |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 246 | { |
| 247 | struct i802_bss *bss; |
| 248 | |
| 249 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 250 | if (bss->ifindex == ifindex) |
| 251 | return bss; |
| 252 | } |
| 253 | |
| 254 | return NULL; |
| 255 | } |
| 256 | |
| 257 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 258 | static int is_mesh_interface(enum nl80211_iftype nlmode) |
| 259 | { |
| 260 | return nlmode == NL80211_IFTYPE_MESH_POINT; |
| 261 | } |
| 262 | |
| 263 | |
| 264 | void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 265 | { |
| 266 | if (drv->associated) |
| 267 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); |
| 268 | drv->associated = 0; |
| 269 | os_memset(drv->bssid, 0, ETH_ALEN); |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 270 | drv->first_bss->freq = 0; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 274 | /* nl80211 code */ |
| 275 | static int ack_handler(struct nl_msg *msg, void *arg) |
| 276 | { |
| 277 | int *err = arg; |
| 278 | *err = 0; |
| 279 | return NL_STOP; |
| 280 | } |
| 281 | |
| 282 | static int finish_handler(struct nl_msg *msg, void *arg) |
| 283 | { |
| 284 | int *ret = arg; |
| 285 | *ret = 0; |
| 286 | return NL_SKIP; |
| 287 | } |
| 288 | |
| 289 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, |
| 290 | void *arg) |
| 291 | { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 292 | struct nlmsghdr *nlh = (struct nlmsghdr *) err - 1; |
| 293 | int len = nlh->nlmsg_len; |
| 294 | struct nlattr *attrs; |
| 295 | struct nlattr *tb[NLMSGERR_ATTR_MAX + 1]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 296 | int *ret = arg; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 297 | int ack_len = sizeof(*nlh) + sizeof(int) + sizeof(*nlh); |
| 298 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 299 | *ret = err->error; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 300 | |
| 301 | if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS)) |
| 302 | return NL_SKIP; |
| 303 | |
| 304 | if (!(nlh->nlmsg_flags & NLM_F_CAPPED)) |
| 305 | ack_len += err->msg.nlmsg_len - sizeof(*nlh); |
| 306 | |
| 307 | if (len <= ack_len) |
| 308 | return NL_STOP; |
| 309 | |
| 310 | attrs = (void *) ((unsigned char *) nlh + ack_len); |
| 311 | len -= ack_len; |
| 312 | |
| 313 | nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, len, NULL); |
| 314 | if (tb[NLMSGERR_ATTR_MSG]) { |
| 315 | len = strnlen((char *) nla_data(tb[NLMSGERR_ATTR_MSG]), |
| 316 | nla_len(tb[NLMSGERR_ATTR_MSG])); |
| 317 | wpa_printf(MSG_ERROR, "nl80211: kernel reports: %*s", |
| 318 | len, (char *) nla_data(tb[NLMSGERR_ATTR_MSG])); |
| 319 | } |
| 320 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 321 | return NL_SKIP; |
| 322 | } |
| 323 | |
| 324 | |
| 325 | static int no_seq_check(struct nl_msg *msg, void *arg) |
| 326 | { |
| 327 | return NL_OK; |
| 328 | } |
| 329 | |
| 330 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 331 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
| 332 | { |
| 333 | /* |
| 334 | * Clear nlmsg data, e.g., to make sure key material is not left in |
| 335 | * heap memory for unnecessarily long time. |
| 336 | */ |
| 337 | if (msg) { |
| 338 | struct nlmsghdr *hdr = nlmsg_hdr(msg); |
| 339 | void *data = nlmsg_data(hdr); |
| 340 | /* |
| 341 | * This would use nlmsg_datalen() or the older nlmsg_len() if |
| 342 | * only libnl were to maintain a stable API.. Neither will work |
| 343 | * with all released versions, so just calculate the length |
| 344 | * here. |
| 345 | */ |
| 346 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; |
| 347 | |
| 348 | os_memset(data, 0, len); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 353 | static int send_and_recv(struct nl80211_global *global, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 354 | struct nl_sock *nl_handle, struct nl_msg *msg, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 355 | int (*valid_handler)(struct nl_msg *, void *), |
| 356 | void *valid_data) |
| 357 | { |
| 358 | struct nl_cb *cb; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 359 | int err = -ENOMEM, opt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 360 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 361 | if (!msg) |
| 362 | return -ENOMEM; |
| 363 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 364 | cb = nl_cb_clone(global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 365 | if (!cb) |
| 366 | goto out; |
| 367 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 368 | /* try to set NETLINK_EXT_ACK to 1, ignoring errors */ |
| 369 | opt = 1; |
| 370 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, |
| 371 | NETLINK_EXT_ACK, &opt, sizeof(opt)); |
| 372 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 373 | /* try to set NETLINK_CAP_ACK to 1, ignoring errors */ |
| 374 | opt = 1; |
| 375 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, |
| 376 | NETLINK_CAP_ACK, &opt, sizeof(opt)); |
| 377 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 378 | err = nl_send_auto_complete(nl_handle, msg); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 379 | if (err < 0) { |
| 380 | wpa_printf(MSG_INFO, |
| 381 | "nl80211: nl_send_auto_complete() failed: %s", |
| 382 | nl_geterror(err)); |
| 383 | /* Need to convert libnl error code to an errno value. For now, |
| 384 | * just hardcode this to EBADF; the real error reason is shown |
| 385 | * in that error print above. */ |
| 386 | err = -EBADF; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 387 | goto out; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 388 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 389 | |
| 390 | err = 1; |
| 391 | |
| 392 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); |
| 393 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
| 394 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
| 395 | |
| 396 | if (valid_handler) |
| 397 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 398 | valid_handler, valid_data); |
| 399 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 400 | while (err > 0) { |
| 401 | int res = nl_recvmsgs(nl_handle, cb); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 402 | |
| 403 | if (res == -NLE_DUMP_INTR) { |
| 404 | /* Most likely one of the nl80211 dump routines hit a |
| 405 | * case where internal results changed while the dump |
| 406 | * was being sent. The most common known case for this |
| 407 | * is scan results fetching while associated were every |
| 408 | * received Beacon frame from the AP may end up |
| 409 | * incrementing bss_generation. This |
| 410 | * NL80211_CMD_GET_SCAN case tries again in the caller; |
| 411 | * other cases (of which there are no known common ones) |
| 412 | * will stop and return an error. */ |
| 413 | wpa_printf(MSG_DEBUG, "nl80211: %s; convert to -EAGAIN", |
| 414 | nl_geterror(res)); |
| 415 | err = -EAGAIN; |
| 416 | } else if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 417 | wpa_printf(MSG_INFO, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 418 | "nl80211: %s->nl_recvmsgs failed: %d (%s)", |
| 419 | __func__, res, nl_geterror(res)); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 420 | } |
| 421 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 422 | out: |
| 423 | nl_cb_put(cb); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 424 | if (!valid_handler && valid_data == (void *) -1) |
| 425 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 426 | nlmsg_free(msg); |
| 427 | return err; |
| 428 | } |
| 429 | |
| 430 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 431 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
| 432 | struct nl_msg *msg, |
| 433 | int (*valid_handler)(struct nl_msg *, void *), |
| 434 | void *valid_data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 435 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 436 | return send_and_recv(drv->global, drv->global->nl, msg, |
| 437 | valid_handler, valid_data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | |
| 441 | struct family_data { |
| 442 | const char *group; |
| 443 | int id; |
| 444 | }; |
| 445 | |
| 446 | |
| 447 | static int family_handler(struct nl_msg *msg, void *arg) |
| 448 | { |
| 449 | struct family_data *res = arg; |
| 450 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; |
| 451 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 452 | struct nlattr *mcgrp; |
| 453 | int i; |
| 454 | |
| 455 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 456 | genlmsg_attrlen(gnlh, 0), NULL); |
| 457 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) |
| 458 | return NL_SKIP; |
| 459 | |
| 460 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { |
| 461 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; |
| 462 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), |
| 463 | nla_len(mcgrp), NULL); |
| 464 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || |
| 465 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || |
| 466 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), |
| 467 | res->group, |
| 468 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) |
| 469 | continue; |
| 470 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); |
| 471 | break; |
| 472 | }; |
| 473 | |
| 474 | return NL_SKIP; |
| 475 | } |
| 476 | |
| 477 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 478 | static int nl_get_multicast_id(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 479 | const char *family, const char *group) |
| 480 | { |
| 481 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 482 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 483 | struct family_data res = { group, -ENOENT }; |
| 484 | |
| 485 | msg = nlmsg_alloc(); |
| 486 | if (!msg) |
| 487 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 488 | if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
| 489 | 0, 0, CTRL_CMD_GETFAMILY, 0) || |
| 490 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { |
| 491 | nlmsg_free(msg); |
| 492 | return -1; |
| 493 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 494 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 495 | ret = send_and_recv(global, global->nl, msg, family_handler, &res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 496 | if (ret == 0) |
| 497 | ret = res.id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 498 | return ret; |
| 499 | } |
| 500 | |
| 501 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 502 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
| 503 | struct nl_msg *msg, int flags, uint8_t cmd) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 504 | { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 505 | if (TEST_FAIL()) |
| 506 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 507 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
| 508 | 0, flags, cmd, 0); |
| 509 | } |
| 510 | |
| 511 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 512 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
| 513 | { |
| 514 | if (bss->wdev_id_set) |
| 515 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); |
| 516 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 517 | } |
| 518 | |
| 519 | |
| 520 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 521 | { |
| 522 | struct nl_msg *msg; |
| 523 | |
| 524 | msg = nlmsg_alloc(); |
| 525 | if (!msg) |
| 526 | return NULL; |
| 527 | |
| 528 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || |
| 529 | nl80211_set_iface_id(msg, bss) < 0) { |
| 530 | nlmsg_free(msg); |
| 531 | return NULL; |
| 532 | } |
| 533 | |
| 534 | return msg; |
| 535 | } |
| 536 | |
| 537 | |
| 538 | static struct nl_msg * |
| 539 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, |
| 540 | int flags, uint8_t cmd) |
| 541 | { |
| 542 | struct nl_msg *msg; |
| 543 | |
| 544 | msg = nlmsg_alloc(); |
| 545 | if (!msg) |
| 546 | return NULL; |
| 547 | |
| 548 | if (!nl80211_cmd(drv, msg, flags, cmd) || |
| 549 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { |
| 550 | nlmsg_free(msg); |
| 551 | return NULL; |
| 552 | } |
| 553 | |
| 554 | return msg; |
| 555 | } |
| 556 | |
| 557 | |
| 558 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, |
| 559 | uint8_t cmd) |
| 560 | { |
| 561 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); |
| 562 | } |
| 563 | |
| 564 | |
| 565 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 566 | { |
| 567 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); |
| 568 | } |
| 569 | |
| 570 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 571 | struct wiphy_idx_data { |
| 572 | int wiphy_idx; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 573 | enum nl80211_iftype nlmode; |
| 574 | u8 *macaddr; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 575 | }; |
| 576 | |
| 577 | |
| 578 | static int netdev_info_handler(struct nl_msg *msg, void *arg) |
| 579 | { |
| 580 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 581 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 582 | struct wiphy_idx_data *info = arg; |
| 583 | |
| 584 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 585 | genlmsg_attrlen(gnlh, 0), NULL); |
| 586 | |
| 587 | if (tb[NL80211_ATTR_WIPHY]) |
| 588 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 589 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 590 | if (tb[NL80211_ATTR_IFTYPE]) |
| 591 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); |
| 592 | |
| 593 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
| 594 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 595 | ETH_ALEN); |
| 596 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 597 | return NL_SKIP; |
| 598 | } |
| 599 | |
| 600 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 601 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 602 | { |
| 603 | struct nl_msg *msg; |
| 604 | struct wiphy_idx_data data = { |
| 605 | .wiphy_idx = -1, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 606 | .macaddr = NULL, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 607 | }; |
| 608 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 609 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 610 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 611 | |
| 612 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) |
| 613 | return data.wiphy_idx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 614 | return -1; |
| 615 | } |
| 616 | |
| 617 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 618 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
| 619 | { |
| 620 | struct nl_msg *msg; |
| 621 | struct wiphy_idx_data data = { |
| 622 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
| 623 | .macaddr = NULL, |
| 624 | }; |
| 625 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 626 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 627 | return NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 628 | |
| 629 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) |
| 630 | return data.nlmode; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 631 | return NL80211_IFTYPE_UNSPECIFIED; |
| 632 | } |
| 633 | |
| 634 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 635 | static int nl80211_get_macaddr(struct i802_bss *bss) |
| 636 | { |
| 637 | struct nl_msg *msg; |
| 638 | struct wiphy_idx_data data = { |
| 639 | .macaddr = bss->addr, |
| 640 | }; |
| 641 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 642 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 643 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 644 | |
| 645 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 646 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 647 | |
| 648 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 649 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
| 650 | struct nl80211_wiphy_data *w) |
| 651 | { |
| 652 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 653 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 654 | |
| 655 | msg = nlmsg_alloc(); |
| 656 | if (!msg) |
| 657 | return -1; |
| 658 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 659 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
| 660 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { |
| 661 | nlmsg_free(msg); |
| 662 | return -1; |
| 663 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 664 | |
| 665 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 666 | if (ret) { |
| 667 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " |
| 668 | "failed: ret=%d (%s)", |
| 669 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 670 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 671 | return ret; |
| 672 | } |
| 673 | |
| 674 | |
| 675 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) |
| 676 | { |
| 677 | struct nl80211_wiphy_data *w = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 678 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 679 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 680 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 681 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 682 | res = nl_recvmsgs(handle, w->nl_cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 683 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 684 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 685 | __func__, res); |
| 686 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 687 | } |
| 688 | |
| 689 | |
| 690 | static int process_beacon_event(struct nl_msg *msg, void *arg) |
| 691 | { |
| 692 | struct nl80211_wiphy_data *w = arg; |
| 693 | struct wpa_driver_nl80211_data *drv; |
| 694 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 695 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 696 | union wpa_event_data event; |
| 697 | |
| 698 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 699 | genlmsg_attrlen(gnlh, 0), NULL); |
| 700 | |
| 701 | if (gnlh->cmd != NL80211_CMD_FRAME) { |
| 702 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", |
| 703 | gnlh->cmd); |
| 704 | return NL_SKIP; |
| 705 | } |
| 706 | |
| 707 | if (!tb[NL80211_ATTR_FRAME]) |
| 708 | return NL_SKIP; |
| 709 | |
| 710 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, |
| 711 | wiphy_list) { |
| 712 | os_memset(&event, 0, sizeof(event)); |
| 713 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); |
| 714 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); |
| 715 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
| 716 | } |
| 717 | |
| 718 | return NL_SKIP; |
| 719 | } |
| 720 | |
| 721 | |
| 722 | static struct nl80211_wiphy_data * |
| 723 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) |
| 724 | { |
| 725 | static DEFINE_DL_LIST(nl80211_wiphys); |
| 726 | struct nl80211_wiphy_data *w; |
| 727 | int wiphy_idx, found = 0; |
| 728 | struct i802_bss *tmp_bss; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 729 | u8 channel; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 730 | |
| 731 | if (bss->wiphy_data != NULL) |
| 732 | return bss->wiphy_data; |
| 733 | |
| 734 | wiphy_idx = nl80211_get_wiphy_index(bss); |
| 735 | |
| 736 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { |
| 737 | if (w->wiphy_idx == wiphy_idx) |
| 738 | goto add; |
| 739 | } |
| 740 | |
| 741 | /* alloc new one */ |
| 742 | w = os_zalloc(sizeof(*w)); |
| 743 | if (w == NULL) |
| 744 | return NULL; |
| 745 | w->wiphy_idx = wiphy_idx; |
| 746 | dl_list_init(&w->bsss); |
| 747 | dl_list_init(&w->drvs); |
| 748 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 749 | /* Beacon frames not supported in IEEE 802.11ad */ |
| 750 | if (ieee80211_freq_to_chan(bss->freq, &channel) != |
| 751 | HOSTAPD_MODE_IEEE80211AD) { |
| 752 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 753 | if (!w->nl_cb) { |
| 754 | os_free(w); |
| 755 | return NULL; |
| 756 | } |
| 757 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 758 | no_seq_check, NULL); |
| 759 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 760 | process_beacon_event, w); |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 761 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 762 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, |
| 763 | "wiphy beacons"); |
| 764 | if (w->nl_beacons == NULL) { |
| 765 | os_free(w); |
| 766 | return NULL; |
| 767 | } |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 768 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 769 | if (nl80211_register_beacons(bss->drv, w)) { |
| 770 | nl_destroy_handles(&w->nl_beacons); |
| 771 | os_free(w); |
| 772 | return NULL; |
| 773 | } |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 774 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 775 | nl80211_register_eloop_read(&w->nl_beacons, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 776 | nl80211_recv_beacons, w, 0); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 777 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 778 | |
| 779 | dl_list_add(&nl80211_wiphys, &w->list); |
| 780 | |
| 781 | add: |
| 782 | /* drv entry for this bss already there? */ |
| 783 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 784 | if (tmp_bss->drv == bss->drv) { |
| 785 | found = 1; |
| 786 | break; |
| 787 | } |
| 788 | } |
| 789 | /* if not add it */ |
| 790 | if (!found) |
| 791 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); |
| 792 | |
| 793 | dl_list_add(&w->bsss, &bss->wiphy_list); |
| 794 | bss->wiphy_data = w; |
| 795 | return w; |
| 796 | } |
| 797 | |
| 798 | |
| 799 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) |
| 800 | { |
| 801 | struct nl80211_wiphy_data *w = bss->wiphy_data; |
| 802 | struct i802_bss *tmp_bss; |
| 803 | int found = 0; |
| 804 | |
| 805 | if (w == NULL) |
| 806 | return; |
| 807 | bss->wiphy_data = NULL; |
| 808 | dl_list_del(&bss->wiphy_list); |
| 809 | |
| 810 | /* still any for this drv present? */ |
| 811 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 812 | if (tmp_bss->drv == bss->drv) { |
| 813 | found = 1; |
| 814 | break; |
| 815 | } |
| 816 | } |
| 817 | /* if not remove it */ |
| 818 | if (!found) |
| 819 | dl_list_del(&bss->drv->wiphy_list); |
| 820 | |
| 821 | if (!dl_list_empty(&w->bsss)) |
| 822 | return; |
| 823 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 824 | if (w->nl_beacons) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 825 | nl80211_destroy_eloop_handle(&w->nl_beacons, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 826 | |
| 827 | nl_cb_put(w->nl_cb); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 828 | dl_list_del(&w->list); |
| 829 | os_free(w); |
| 830 | } |
| 831 | |
| 832 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 833 | static unsigned int nl80211_get_ifindex(void *priv) |
| 834 | { |
| 835 | struct i802_bss *bss = priv; |
| 836 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 837 | |
| 838 | return drv->ifindex; |
| 839 | } |
| 840 | |
| 841 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 842 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
| 843 | { |
| 844 | struct i802_bss *bss = priv; |
| 845 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 846 | if (!drv->associated) |
| 847 | return -1; |
| 848 | os_memcpy(bssid, drv->bssid, ETH_ALEN); |
| 849 | return 0; |
| 850 | } |
| 851 | |
| 852 | |
| 853 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
| 854 | { |
| 855 | struct i802_bss *bss = priv; |
| 856 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 857 | if (!drv->associated) |
| 858 | return -1; |
| 859 | os_memcpy(ssid, drv->ssid, drv->ssid_len); |
| 860 | return drv->ssid_len; |
| 861 | } |
| 862 | |
| 863 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 864 | static void wpa_driver_nl80211_event_newlink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 865 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 866 | int ifindex, const char *ifname) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 867 | { |
| 868 | union wpa_event_data event; |
| 869 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 870 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 871 | if (if_nametoindex(drv->first_bss->ifname) == 0) { |
| 872 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", |
| 873 | drv->first_bss->ifname); |
| 874 | return; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 875 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 876 | if (!drv->if_removed) |
| 877 | return; |
| 878 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", |
| 879 | drv->first_bss->ifname); |
| 880 | drv->if_removed = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 881 | } |
| 882 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 883 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 884 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 885 | os_strlcpy(event.interface_status.ifname, ifname, |
| 886 | sizeof(event.interface_status.ifname)); |
| 887 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 888 | if (drv) |
| 889 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 890 | else |
| 891 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 892 | &event); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | |
| 896 | static void wpa_driver_nl80211_event_dellink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 897 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 898 | int ifindex, const char *ifname) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 899 | { |
| 900 | union wpa_event_data event; |
| 901 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 902 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 903 | if (drv->if_removed) { |
| 904 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", |
| 905 | ifname); |
| 906 | return; |
| 907 | } |
| 908 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
| 909 | ifname); |
| 910 | drv->if_removed = 1; |
| 911 | } else { |
| 912 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", |
| 913 | ifname); |
| 914 | } |
| 915 | |
| 916 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 917 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 918 | os_strlcpy(event.interface_status.ifname, ifname, |
| 919 | sizeof(event.interface_status.ifname)); |
| 920 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 921 | if (drv) |
| 922 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 923 | else |
| 924 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 925 | &event); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | |
| 929 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
| 930 | u8 *buf, size_t len) |
| 931 | { |
| 932 | int attrlen, rta_len; |
| 933 | struct rtattr *attr; |
| 934 | |
| 935 | attrlen = len; |
| 936 | attr = (struct rtattr *) buf; |
| 937 | |
| 938 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
| 939 | while (RTA_OK(attr, attrlen)) { |
| 940 | if (attr->rta_type == IFLA_IFNAME) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 941 | if (os_strcmp(((char *) attr) + rta_len, |
| 942 | drv->first_bss->ifname) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 943 | return 1; |
| 944 | else |
| 945 | break; |
| 946 | } |
| 947 | attr = RTA_NEXT(attr, attrlen); |
| 948 | } |
| 949 | |
| 950 | return 0; |
| 951 | } |
| 952 | |
| 953 | |
| 954 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, |
| 955 | int ifindex, u8 *buf, size_t len) |
| 956 | { |
| 957 | if (drv->ifindex == ifindex) |
| 958 | return 1; |
| 959 | |
| 960 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 961 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 962 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
| 963 | "interface"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 964 | if (wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL) < 0) |
| 965 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 966 | return 1; |
| 967 | } |
| 968 | |
| 969 | return 0; |
| 970 | } |
| 971 | |
| 972 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 973 | static struct wpa_driver_nl80211_data * |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 974 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len, |
| 975 | int *init_failed) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 976 | { |
| 977 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 978 | int res; |
| 979 | |
| 980 | if (init_failed) |
| 981 | *init_failed = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 982 | dl_list_for_each(drv, &global->interfaces, |
| 983 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 984 | res = wpa_driver_nl80211_own_ifindex(drv, idx, buf, len); |
| 985 | if (res < 0) { |
| 986 | wpa_printf(MSG_DEBUG, |
| 987 | "nl80211: Found matching own interface, but failed to complete reinitialization"); |
| 988 | if (init_failed) |
| 989 | *init_failed = 1; |
| 990 | return drv; |
| 991 | } |
| 992 | if (res > 0 || have_ifidx(drv, idx, IFIDX_ANY)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 993 | return drv; |
| 994 | } |
| 995 | return NULL; |
| 996 | } |
| 997 | |
| 998 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 999 | static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1000 | int ifindex, int notify) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1001 | { |
| 1002 | struct i802_bss *bss; |
| 1003 | u8 addr[ETH_ALEN]; |
| 1004 | |
| 1005 | bss = get_bss_ifindex(drv, ifindex); |
| 1006 | if (bss && |
| 1007 | linux_get_ifhwaddr(drv->global->ioctl_sock, |
| 1008 | bss->ifname, addr) < 0) { |
| 1009 | wpa_printf(MSG_DEBUG, |
| 1010 | "nl80211: %s: failed to re-read MAC address", |
| 1011 | bss->ifname); |
| 1012 | } else if (bss && os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { |
| 1013 | wpa_printf(MSG_DEBUG, |
| 1014 | "nl80211: Own MAC address on ifindex %d (%s) changed from " |
| 1015 | MACSTR " to " MACSTR, |
| 1016 | ifindex, bss->ifname, |
| 1017 | MAC2STR(bss->addr), MAC2STR(addr)); |
| 1018 | os_memcpy(bss->addr, addr, ETH_ALEN); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1019 | if (notify) |
| 1020 | wpa_supplicant_event(drv->ctx, |
| 1021 | EVENT_INTERFACE_MAC_CHANGED, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1022 | } |
| 1023 | } |
| 1024 | |
| 1025 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1026 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
| 1027 | struct ifinfomsg *ifi, |
| 1028 | u8 *buf, size_t len) |
| 1029 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1030 | struct nl80211_global *global = ctx; |
| 1031 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1032 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1033 | struct rtattr *attr; |
| 1034 | u32 brid = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1035 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1036 | char ifname[IFNAMSIZ + 1]; |
| 1037 | char extra[100], *pos, *end; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1038 | int init_failed; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1039 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1040 | extra[0] = '\0'; |
| 1041 | pos = extra; |
| 1042 | end = pos + sizeof(extra); |
| 1043 | ifname[0] = '\0'; |
| 1044 | |
| 1045 | attrlen = len; |
| 1046 | attr = (struct rtattr *) buf; |
| 1047 | while (RTA_OK(attr, attrlen)) { |
| 1048 | switch (attr->rta_type) { |
| 1049 | case IFLA_IFNAME: |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1050 | if (RTA_PAYLOAD(attr) > IFNAMSIZ) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1051 | break; |
| 1052 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1053 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1054 | break; |
| 1055 | case IFLA_MASTER: |
| 1056 | brid = nla_get_u32((struct nlattr *) attr); |
| 1057 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1058 | break; |
| 1059 | case IFLA_WIRELESS: |
| 1060 | pos += os_snprintf(pos, end - pos, " wext"); |
| 1061 | break; |
| 1062 | case IFLA_OPERSTATE: |
| 1063 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1064 | nla_get_u32((struct nlattr *) attr)); |
| 1065 | break; |
| 1066 | case IFLA_LINKMODE: |
| 1067 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1068 | nla_get_u32((struct nlattr *) attr)); |
| 1069 | break; |
| 1070 | } |
| 1071 | attr = RTA_NEXT(attr, attrlen); |
| 1072 | } |
| 1073 | extra[sizeof(extra) - 1] = '\0'; |
| 1074 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1075 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1076 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1077 | ifi->ifi_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1078 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1079 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1080 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1081 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1082 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1083 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, &init_failed); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1084 | if (!drv) |
| 1085 | goto event_newlink; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1086 | if (init_failed) |
| 1087 | return; /* do not update interface state */ |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1088 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1089 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1090 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1091 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1092 | linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1093 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1094 | "event since interface %s is up", namebuf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1095 | drv->ignore_if_down_event = 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1096 | /* Re-read MAC address as it may have changed */ |
| 1097 | nl80211_refresh_mac(drv, ifi->ifi_index, 1); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1098 | return; |
| 1099 | } |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1100 | wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", |
| 1101 | namebuf, ifname); |
| 1102 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 1103 | wpa_printf(MSG_DEBUG, |
| 1104 | "nl80211: Not the main interface (%s) - do not indicate interface down", |
| 1105 | drv->first_bss->ifname); |
| 1106 | } else if (drv->ignore_if_down_event) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1107 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1108 | "event generated by mode change"); |
| 1109 | drv->ignore_if_down_event = 0; |
| 1110 | } else { |
| 1111 | drv->if_disabled = 1; |
| 1112 | wpa_supplicant_event(drv->ctx, |
| 1113 | EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1114 | |
| 1115 | /* |
| 1116 | * Try to get drv again, since it may be removed as |
| 1117 | * part of the EVENT_INTERFACE_DISABLED handling for |
| 1118 | * dynamic interfaces |
| 1119 | */ |
| 1120 | drv = nl80211_find_drv(global, ifi->ifi_index, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1121 | buf, len, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1122 | if (!drv) |
| 1123 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1124 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 1128 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1129 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1130 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1131 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1132 | "event since interface %s is down", |
| 1133 | namebuf); |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 1134 | return; |
| 1135 | } |
| 1136 | wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)", |
| 1137 | namebuf, ifname); |
| 1138 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 1139 | wpa_printf(MSG_DEBUG, |
| 1140 | "nl80211: Not the main interface (%s) - do not indicate interface up", |
| 1141 | drv->first_bss->ifname); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1142 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1143 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1144 | "event since interface %s does not exist", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1145 | drv->first_bss->ifname); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1146 | } else if (drv->if_removed) { |
| 1147 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1148 | "event since interface %s is marked " |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1149 | "removed", drv->first_bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1150 | } else { |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1151 | /* Re-read MAC address as it may have changed */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1152 | nl80211_refresh_mac(drv, ifi->ifi_index, 0); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1153 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1154 | drv->if_disabled = 0; |
| 1155 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, |
| 1156 | NULL); |
| 1157 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1158 | } |
| 1159 | |
| 1160 | /* |
| 1161 | * Some drivers send the association event before the operup event--in |
| 1162 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() |
| 1163 | * fails. This will hit us when wpa_supplicant does not need to do |
| 1164 | * IEEE 802.1X authentication |
| 1165 | */ |
| 1166 | if (drv->operstate == 1 && |
| 1167 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1168 | !(ifi->ifi_flags & IFF_RUNNING)) { |
| 1169 | 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] | 1170 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1171 | -1, IF_OPER_UP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1174 | event_newlink: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1175 | if (ifname[0]) |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1176 | wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index, |
| 1177 | ifname); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1178 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1179 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1180 | struct i802_bss *bss; |
| 1181 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1182 | /* device has been added to bridge */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1183 | if (!if_indextoname(brid, namebuf)) { |
| 1184 | wpa_printf(MSG_DEBUG, |
| 1185 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1186 | brid); |
| 1187 | return; |
| 1188 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1189 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
| 1190 | brid, namebuf); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1191 | add_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1192 | |
| 1193 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 1194 | if (os_strcmp(ifname, bss->ifname) == 0) { |
| 1195 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); |
| 1196 | break; |
| 1197 | } |
| 1198 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1199 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1200 | } |
| 1201 | |
| 1202 | |
| 1203 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
| 1204 | struct ifinfomsg *ifi, |
| 1205 | u8 *buf, size_t len) |
| 1206 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1207 | struct nl80211_global *global = ctx; |
| 1208 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1209 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1210 | struct rtattr *attr; |
| 1211 | u32 brid = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1212 | char ifname[IFNAMSIZ + 1]; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1213 | char extra[100], *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1214 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1215 | extra[0] = '\0'; |
| 1216 | pos = extra; |
| 1217 | end = pos + sizeof(extra); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1218 | ifname[0] = '\0'; |
| 1219 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1220 | attrlen = len; |
| 1221 | attr = (struct rtattr *) buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1222 | while (RTA_OK(attr, attrlen)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1223 | switch (attr->rta_type) { |
| 1224 | case IFLA_IFNAME: |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1225 | if (RTA_PAYLOAD(attr) > IFNAMSIZ) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1226 | break; |
| 1227 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1228 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1229 | break; |
| 1230 | case IFLA_MASTER: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1231 | brid = nla_get_u32((struct nlattr *) attr); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1232 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1233 | break; |
| 1234 | case IFLA_OPERSTATE: |
| 1235 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1236 | nla_get_u32((struct nlattr *) attr)); |
| 1237 | break; |
| 1238 | case IFLA_LINKMODE: |
| 1239 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1240 | nla_get_u32((struct nlattr *) attr)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1241 | break; |
| 1242 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1243 | attr = RTA_NEXT(attr, attrlen); |
| 1244 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1245 | extra[sizeof(extra) - 1] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1246 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1247 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1248 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1249 | ifi->ifi_flags, |
| 1250 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1251 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1252 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1253 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1254 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1255 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1256 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1257 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1258 | /* device has been removed from bridge */ |
| 1259 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1260 | |
| 1261 | if (!if_indextoname(brid, namebuf)) { |
| 1262 | wpa_printf(MSG_DEBUG, |
| 1263 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1264 | brid); |
| 1265 | } else { |
| 1266 | wpa_printf(MSG_DEBUG, |
| 1267 | "nl80211: Remove ifindex %u for bridge %s", |
| 1268 | brid, namebuf); |
| 1269 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1270 | del_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1271 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1272 | |
| 1273 | if (ifi->ifi_family != AF_BRIDGE || !brid) |
| 1274 | wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index, |
| 1275 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1279 | struct nl80211_get_assoc_freq_arg { |
| 1280 | struct wpa_driver_nl80211_data *drv; |
| 1281 | unsigned int assoc_freq; |
| 1282 | unsigned int ibss_freq; |
| 1283 | u8 assoc_bssid[ETH_ALEN]; |
| 1284 | u8 assoc_ssid[SSID_MAX_LEN]; |
| 1285 | u8 assoc_ssid_len; |
| 1286 | }; |
| 1287 | |
| 1288 | static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg) |
| 1289 | { |
| 1290 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1291 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1292 | struct nlattr *bss[NL80211_BSS_MAX + 1]; |
| 1293 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { |
| 1294 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, |
| 1295 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, |
| 1296 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, |
| 1297 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
| 1298 | }; |
| 1299 | struct nl80211_get_assoc_freq_arg *ctx = arg; |
| 1300 | enum nl80211_bss_status status; |
| 1301 | |
| 1302 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1303 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1304 | if (!tb[NL80211_ATTR_BSS] || |
| 1305 | nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], |
| 1306 | bss_policy) || |
| 1307 | !bss[NL80211_BSS_STATUS]) |
| 1308 | return NL_SKIP; |
| 1309 | |
| 1310 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); |
| 1311 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1312 | bss[NL80211_BSS_FREQUENCY]) { |
| 1313 | ctx->assoc_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1314 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", |
| 1315 | ctx->assoc_freq); |
| 1316 | } |
| 1317 | if (status == NL80211_BSS_STATUS_IBSS_JOINED && |
| 1318 | bss[NL80211_BSS_FREQUENCY]) { |
| 1319 | ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1320 | wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz", |
| 1321 | ctx->ibss_freq); |
| 1322 | } |
| 1323 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1324 | bss[NL80211_BSS_BSSID]) { |
| 1325 | os_memcpy(ctx->assoc_bssid, |
| 1326 | nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN); |
| 1327 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " |
| 1328 | MACSTR, MAC2STR(ctx->assoc_bssid)); |
| 1329 | } |
| 1330 | |
| 1331 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1332 | bss[NL80211_BSS_INFORMATION_ELEMENTS]) { |
| 1333 | const u8 *ie, *ssid; |
| 1334 | size_t ie_len; |
| 1335 | |
| 1336 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1337 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1338 | ssid = get_ie(ie, ie_len, WLAN_EID_SSID); |
| 1339 | if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) { |
| 1340 | ctx->assoc_ssid_len = ssid[1]; |
| 1341 | os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]); |
| 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | return NL_SKIP; |
| 1346 | } |
| 1347 | |
| 1348 | |
| 1349 | 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] | 1350 | { |
| 1351 | struct nl_msg *msg; |
| 1352 | int ret; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1353 | struct nl80211_get_assoc_freq_arg arg; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1354 | int count = 0; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1355 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1356 | try_again: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1357 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1358 | os_memset(&arg, 0, sizeof(arg)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1359 | arg.drv = drv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1360 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
| 1361 | &arg); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1362 | if (ret == -EAGAIN) { |
| 1363 | count++; |
| 1364 | if (count >= 10) { |
| 1365 | wpa_printf(MSG_INFO, |
| 1366 | "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid"); |
| 1367 | } else { |
| 1368 | wpa_printf(MSG_DEBUG, |
| 1369 | "nl80211: Failed to receive consistent scan result dump for get_assoc_ssid - try again"); |
| 1370 | goto try_again; |
| 1371 | } |
| 1372 | } |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1373 | if (ret == 0) { |
| 1374 | os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len); |
| 1375 | return arg.assoc_ssid_len; |
| 1376 | } |
| 1377 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)", |
| 1378 | ret, strerror(-ret)); |
| 1379 | return ret; |
| 1380 | } |
| 1381 | |
| 1382 | |
| 1383 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
| 1384 | { |
| 1385 | struct nl_msg *msg; |
| 1386 | int ret; |
| 1387 | struct nl80211_get_assoc_freq_arg arg; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1388 | int count = 0; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1389 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1390 | try_again: |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1391 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
| 1392 | os_memset(&arg, 0, sizeof(arg)); |
| 1393 | arg.drv = drv; |
| 1394 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
| 1395 | &arg); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1396 | if (ret == -EAGAIN) { |
| 1397 | count++; |
| 1398 | if (count >= 10) { |
| 1399 | wpa_printf(MSG_INFO, |
| 1400 | "nl80211: Failed to receive consistent scan result dump for get_assoc_freq"); |
| 1401 | } else { |
| 1402 | wpa_printf(MSG_DEBUG, |
| 1403 | "nl80211: Failed to receive consistent scan result dump for get_assoc_freq - try again"); |
| 1404 | goto try_again; |
| 1405 | } |
| 1406 | } |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1407 | if (ret == 0) { |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1408 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
| 1409 | arg.ibss_freq : arg.assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1410 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1411 | "associated BSS from scan results: %u MHz", freq); |
| 1412 | if (freq) |
| 1413 | drv->assoc_freq = freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1414 | return drv->assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1415 | } |
| 1416 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
| 1417 | "(%s)", ret, strerror(-ret)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1418 | return drv->assoc_freq; |
| 1419 | } |
| 1420 | |
| 1421 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1422 | static int get_link_signal(struct nl_msg *msg, void *arg) |
| 1423 | { |
| 1424 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1425 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1426 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; |
| 1427 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { |
| 1428 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1429 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1430 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1431 | }; |
| 1432 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
| 1433 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 1434 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 1435 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 1436 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, |
| 1437 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 1438 | }; |
| 1439 | struct wpa_signal_info *sig_change = arg; |
| 1440 | |
| 1441 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1442 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1443 | if (!tb[NL80211_ATTR_STA_INFO] || |
| 1444 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, |
| 1445 | tb[NL80211_ATTR_STA_INFO], policy)) |
| 1446 | return NL_SKIP; |
| 1447 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) |
| 1448 | return NL_SKIP; |
| 1449 | |
| 1450 | sig_change->current_signal = |
| 1451 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); |
| 1452 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1453 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
| 1454 | sig_change->avg_signal = |
| 1455 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); |
| 1456 | else |
| 1457 | sig_change->avg_signal = 0; |
| 1458 | |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1459 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
| 1460 | sig_change->avg_beacon_signal = |
| 1461 | (s8) |
| 1462 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); |
| 1463 | else |
| 1464 | sig_change->avg_beacon_signal = 0; |
| 1465 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1466 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
| 1467 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, |
| 1468 | sinfo[NL80211_STA_INFO_TX_BITRATE], |
| 1469 | rate_policy)) { |
| 1470 | sig_change->current_txrate = 0; |
| 1471 | } else { |
| 1472 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { |
| 1473 | sig_change->current_txrate = |
| 1474 | nla_get_u16(rinfo[ |
| 1475 | NL80211_RATE_INFO_BITRATE]) * 100; |
| 1476 | } |
| 1477 | } |
| 1478 | } |
| 1479 | |
| 1480 | return NL_SKIP; |
| 1481 | } |
| 1482 | |
| 1483 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1484 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
| 1485 | struct wpa_signal_info *sig) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1486 | { |
| 1487 | struct nl_msg *msg; |
| 1488 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1489 | sig->current_signal = -WPA_INVALID_NOISE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1490 | sig->current_txrate = 0; |
| 1491 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1492 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
| 1493 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) { |
| 1494 | nlmsg_free(msg); |
| 1495 | return -ENOBUFS; |
| 1496 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1497 | |
| 1498 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1499 | } |
| 1500 | |
| 1501 | |
| 1502 | static int get_link_noise(struct nl_msg *msg, void *arg) |
| 1503 | { |
| 1504 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1505 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1506 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 1507 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 1508 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 1509 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 1510 | }; |
| 1511 | struct wpa_signal_info *sig_change = arg; |
| 1512 | |
| 1513 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1514 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1515 | |
| 1516 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 1517 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); |
| 1518 | return NL_SKIP; |
| 1519 | } |
| 1520 | |
| 1521 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 1522 | tb[NL80211_ATTR_SURVEY_INFO], |
| 1523 | survey_policy)) { |
| 1524 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " |
| 1525 | "attributes!"); |
| 1526 | return NL_SKIP; |
| 1527 | } |
| 1528 | |
| 1529 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 1530 | return NL_SKIP; |
| 1531 | |
| 1532 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 1533 | sig_change->frequency) |
| 1534 | return NL_SKIP; |
| 1535 | |
| 1536 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 1537 | return NL_SKIP; |
| 1538 | |
| 1539 | sig_change->current_noise = |
| 1540 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 1541 | |
| 1542 | return NL_SKIP; |
| 1543 | } |
| 1544 | |
| 1545 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1546 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
| 1547 | struct wpa_signal_info *sig_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1548 | { |
| 1549 | struct nl_msg *msg; |
| 1550 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1551 | sig_change->current_noise = WPA_INVALID_NOISE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1552 | sig_change->frequency = drv->assoc_freq; |
| 1553 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1554 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1555 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1556 | } |
| 1557 | |
| 1558 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1559 | static int get_channel_info(struct nl_msg *msg, void *arg) |
| 1560 | { |
| 1561 | struct nlattr *tb[NL80211_ATTR_MAX + 1] = { 0 }; |
| 1562 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1563 | struct wpa_channel_info *chan_info = arg; |
| 1564 | |
| 1565 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1566 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1567 | |
| 1568 | os_memset(chan_info, 0, sizeof(struct wpa_channel_info)); |
| 1569 | chan_info->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 1570 | |
| 1571 | if (tb[NL80211_ATTR_WIPHY_FREQ]) |
| 1572 | chan_info->frequency = |
| 1573 | nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]); |
| 1574 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) |
| 1575 | chan_info->chanwidth = convert2width( |
| 1576 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 1577 | if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1578 | enum nl80211_channel_type ct = |
| 1579 | nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1580 | |
| 1581 | switch (ct) { |
| 1582 | case NL80211_CHAN_HT40MINUS: |
| 1583 | chan_info->sec_channel = -1; |
| 1584 | break; |
| 1585 | case NL80211_CHAN_HT40PLUS: |
| 1586 | chan_info->sec_channel = 1; |
| 1587 | break; |
| 1588 | default: |
| 1589 | chan_info->sec_channel = 0; |
| 1590 | break; |
| 1591 | } |
| 1592 | } |
| 1593 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 1594 | chan_info->center_frq1 = |
| 1595 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 1596 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 1597 | chan_info->center_frq2 = |
| 1598 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 1599 | |
| 1600 | if (chan_info->center_frq2) { |
| 1601 | u8 seg1_idx = 0; |
| 1602 | |
| 1603 | if (ieee80211_freq_to_chan(chan_info->center_frq2, &seg1_idx) != |
| 1604 | NUM_HOSTAPD_MODES) |
| 1605 | chan_info->seg1_idx = seg1_idx; |
| 1606 | } |
| 1607 | |
| 1608 | return NL_SKIP; |
| 1609 | } |
| 1610 | |
| 1611 | |
| 1612 | static int nl80211_channel_info(void *priv, struct wpa_channel_info *ci) |
| 1613 | { |
| 1614 | struct i802_bss *bss = priv; |
| 1615 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1616 | struct nl_msg *msg; |
| 1617 | |
| 1618 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
| 1619 | return send_and_recv_msgs(drv, msg, get_channel_info, ci); |
| 1620 | } |
| 1621 | |
| 1622 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1623 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
| 1624 | void *handle) |
| 1625 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1626 | struct nl_cb *cb = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1627 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1628 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1629 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1630 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1631 | res = nl_recvmsgs(handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 1632 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1633 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 1634 | __func__, res); |
| 1635 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | |
| 1639 | /** |
| 1640 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain |
| 1641 | * @priv: driver_nl80211 private data |
| 1642 | * @alpha2_arg: country to which to switch to |
| 1643 | * Returns: 0 on success, -1 on failure |
| 1644 | * |
| 1645 | * This asks nl80211 to set the regulatory domain for given |
| 1646 | * country ISO / IEC alpha2. |
| 1647 | */ |
| 1648 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) |
| 1649 | { |
| 1650 | struct i802_bss *bss = priv; |
| 1651 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1652 | char alpha2[3]; |
| 1653 | struct nl_msg *msg; |
| 1654 | |
| 1655 | msg = nlmsg_alloc(); |
| 1656 | if (!msg) |
| 1657 | return -ENOMEM; |
| 1658 | |
| 1659 | alpha2[0] = alpha2_arg[0]; |
| 1660 | alpha2[1] = alpha2_arg[1]; |
| 1661 | alpha2[2] = '\0'; |
| 1662 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1663 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
| 1664 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { |
| 1665 | nlmsg_free(msg); |
| 1666 | return -EINVAL; |
| 1667 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1668 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) |
| 1669 | return -EINVAL; |
| 1670 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1674 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
| 1675 | { |
| 1676 | char *alpha2 = arg; |
| 1677 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 1678 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1679 | |
| 1680 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1681 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1682 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { |
| 1683 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); |
| 1684 | return NL_SKIP; |
| 1685 | } |
| 1686 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); |
| 1687 | return NL_SKIP; |
| 1688 | } |
| 1689 | |
| 1690 | |
| 1691 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) |
| 1692 | { |
| 1693 | struct i802_bss *bss = priv; |
| 1694 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1695 | struct nl_msg *msg; |
| 1696 | int ret; |
| 1697 | |
| 1698 | msg = nlmsg_alloc(); |
| 1699 | if (!msg) |
| 1700 | return -ENOMEM; |
| 1701 | |
| 1702 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
| 1703 | alpha2[0] = '\0'; |
| 1704 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2); |
| 1705 | if (!alpha2[0]) |
| 1706 | ret = -1; |
| 1707 | |
| 1708 | return ret; |
| 1709 | } |
| 1710 | |
| 1711 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1712 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1713 | { |
| 1714 | int ret; |
| 1715 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1716 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1717 | if (global->nl_cb == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1718 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 1719 | "callbacks"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1720 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1721 | } |
| 1722 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1723 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
| 1724 | if (global->nl == NULL) |
| 1725 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1726 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1727 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
| 1728 | if (global->nl80211_id < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1729 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
| 1730 | "found"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1731 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1732 | } |
| 1733 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1734 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
| 1735 | if (global->nl_event == NULL) |
| 1736 | goto err; |
| 1737 | |
| 1738 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1739 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1740 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1741 | if (ret < 0) { |
| 1742 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1743 | "membership for scan events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1744 | ret, nl_geterror(ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1745 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1746 | } |
| 1747 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1748 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1749 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1750 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1751 | if (ret < 0) { |
| 1752 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1753 | "membership for mlme events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1754 | ret, nl_geterror(ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1755 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1756 | } |
| 1757 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1758 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1759 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1760 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1761 | if (ret < 0) { |
| 1762 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1763 | "membership for regulatory events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1764 | ret, nl_geterror(ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1765 | /* Continue without regulatory events */ |
| 1766 | } |
| 1767 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1768 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
| 1769 | if (ret >= 0) |
| 1770 | ret = nl_socket_add_membership(global->nl_event, ret); |
| 1771 | if (ret < 0) { |
| 1772 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1773 | "membership for vendor events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1774 | ret, nl_geterror(ret)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1775 | /* Continue without vendor events */ |
| 1776 | } |
| 1777 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1778 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1779 | no_seq_check, NULL); |
| 1780 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1781 | process_global_event, global); |
| 1782 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1783 | nl80211_register_eloop_read(&global->nl_event, |
| 1784 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1785 | global->nl_cb, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1786 | |
| 1787 | return 0; |
| 1788 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1789 | err: |
| 1790 | nl_destroy_handles(&global->nl_event); |
| 1791 | nl_destroy_handles(&global->nl); |
| 1792 | nl_cb_put(global->nl_cb); |
| 1793 | global->nl_cb = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1794 | return -1; |
| 1795 | } |
| 1796 | |
| 1797 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1798 | static void nl80211_check_global(struct nl80211_global *global) |
| 1799 | { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1800 | struct nl_sock *handle; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1801 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; |
| 1802 | int ret; |
| 1803 | unsigned int i; |
| 1804 | |
| 1805 | /* |
| 1806 | * Try to re-add memberships to handle case of cfg80211 getting reloaded |
| 1807 | * and all registration having been cleared. |
| 1808 | */ |
| 1809 | handle = (void *) (((intptr_t) global->nl_event) ^ |
| 1810 | ELOOP_SOCKET_INVALID); |
| 1811 | |
| 1812 | for (i = 0; groups[i]; i++) { |
| 1813 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); |
| 1814 | if (ret >= 0) |
| 1815 | ret = nl_socket_add_membership(handle, ret); |
| 1816 | if (ret < 0) { |
| 1817 | wpa_printf(MSG_INFO, |
| 1818 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 1819 | groups[i], ret, nl_geterror(ret)); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1820 | } |
| 1821 | } |
| 1822 | } |
| 1823 | |
| 1824 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1825 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
| 1826 | { |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1827 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1828 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1829 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1830 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1831 | /* |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1832 | * rtnetlink ifdown handler will report interfaces other than the P2P |
| 1833 | * Device interface as disabled. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1834 | */ |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1835 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 1836 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | |
| 1840 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) |
| 1841 | { |
| 1842 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1843 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1844 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1845 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
| 1846 | "after rfkill unblock"); |
| 1847 | return; |
| 1848 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1849 | |
| 1850 | if (is_p2p_net_interface(drv->nlmode)) |
| 1851 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
| 1852 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1853 | /* |
| 1854 | * rtnetlink ifup handler will report interfaces other than the P2P |
| 1855 | * Device interface as enabled. |
| 1856 | */ |
| 1857 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 1858 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1859 | } |
| 1860 | |
| 1861 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1862 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
| 1863 | void *eloop_ctx, |
| 1864 | void *handle) |
| 1865 | { |
| 1866 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 1867 | u8 data[2048]; |
| 1868 | struct msghdr msg; |
| 1869 | struct iovec entry; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1870 | u8 control[512]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1871 | struct cmsghdr *cmsg; |
| 1872 | int res, found_ee = 0, found_wifi = 0, acked = 0; |
| 1873 | union wpa_event_data event; |
| 1874 | |
| 1875 | memset(&msg, 0, sizeof(msg)); |
| 1876 | msg.msg_iov = &entry; |
| 1877 | msg.msg_iovlen = 1; |
| 1878 | entry.iov_base = data; |
| 1879 | entry.iov_len = sizeof(data); |
| 1880 | msg.msg_control = &control; |
| 1881 | msg.msg_controllen = sizeof(control); |
| 1882 | |
| 1883 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); |
| 1884 | /* if error or not fitting 802.3 header, return */ |
| 1885 | if (res < 14) |
| 1886 | return; |
| 1887 | |
| 1888 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
| 1889 | { |
| 1890 | if (cmsg->cmsg_level == SOL_SOCKET && |
| 1891 | cmsg->cmsg_type == SCM_WIFI_STATUS) { |
| 1892 | int *ack; |
| 1893 | |
| 1894 | found_wifi = 1; |
| 1895 | ack = (void *)CMSG_DATA(cmsg); |
| 1896 | acked = *ack; |
| 1897 | } |
| 1898 | |
| 1899 | if (cmsg->cmsg_level == SOL_PACKET && |
| 1900 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { |
| 1901 | struct sock_extended_err *err = |
| 1902 | (struct sock_extended_err *)CMSG_DATA(cmsg); |
| 1903 | |
| 1904 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) |
| 1905 | found_ee = 1; |
| 1906 | } |
| 1907 | } |
| 1908 | |
| 1909 | if (!found_ee || !found_wifi) |
| 1910 | return; |
| 1911 | |
| 1912 | memset(&event, 0, sizeof(event)); |
| 1913 | event.eapol_tx_status.dst = data; |
| 1914 | event.eapol_tx_status.data = data + 14; |
| 1915 | event.eapol_tx_status.data_len = res - 14; |
| 1916 | event.eapol_tx_status.ack = acked; |
| 1917 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); |
| 1918 | } |
| 1919 | |
| 1920 | |
| 1921 | static int nl80211_init_bss(struct i802_bss *bss) |
| 1922 | { |
| 1923 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1924 | if (!bss->nl_cb) |
| 1925 | return -1; |
| 1926 | |
| 1927 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1928 | no_seq_check, NULL); |
| 1929 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1930 | process_bss_event, bss); |
| 1931 | |
| 1932 | return 0; |
| 1933 | } |
| 1934 | |
| 1935 | |
| 1936 | static void nl80211_destroy_bss(struct i802_bss *bss) |
| 1937 | { |
| 1938 | nl_cb_put(bss->nl_cb); |
| 1939 | bss->nl_cb = NULL; |
| 1940 | } |
| 1941 | |
| 1942 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1943 | static void |
| 1944 | wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv) |
| 1945 | { |
| 1946 | struct rfkill_config *rcfg; |
| 1947 | |
| 1948 | if (drv->rfkill) |
| 1949 | return; |
| 1950 | |
| 1951 | rcfg = os_zalloc(sizeof(*rcfg)); |
| 1952 | if (!rcfg) |
| 1953 | return; |
| 1954 | |
| 1955 | rcfg->ctx = drv; |
| 1956 | |
| 1957 | /* rfkill uses netdev sysfs for initialization. However, P2P Device is |
| 1958 | * not associated with a netdev, so use the name of some other interface |
| 1959 | * sharing the same wiphy as the P2P Device interface. |
| 1960 | * |
| 1961 | * Note: This is valid, as a P2P Device interface is always dynamically |
| 1962 | * created and is created only once another wpa_s interface was added. |
| 1963 | */ |
| 1964 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 1965 | struct nl80211_global *global = drv->global; |
| 1966 | struct wpa_driver_nl80211_data *tmp1; |
| 1967 | |
| 1968 | dl_list_for_each(tmp1, &global->interfaces, |
| 1969 | struct wpa_driver_nl80211_data, list) { |
| 1970 | if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx || |
| 1971 | !tmp1->rfkill) |
| 1972 | continue; |
| 1973 | |
| 1974 | wpa_printf(MSG_DEBUG, |
| 1975 | "nl80211: Use (%s) to initialize P2P Device rfkill", |
| 1976 | tmp1->first_bss->ifname); |
| 1977 | os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname, |
| 1978 | sizeof(rcfg->ifname)); |
| 1979 | break; |
| 1980 | } |
| 1981 | } else { |
| 1982 | os_strlcpy(rcfg->ifname, drv->first_bss->ifname, |
| 1983 | sizeof(rcfg->ifname)); |
| 1984 | } |
| 1985 | |
| 1986 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; |
| 1987 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; |
| 1988 | drv->rfkill = rfkill_init(rcfg); |
| 1989 | if (!drv->rfkill) { |
| 1990 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
| 1991 | os_free(rcfg); |
| 1992 | } |
| 1993 | } |
| 1994 | |
| 1995 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1996 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
| 1997 | void *global_priv, int hostapd, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1998 | const u8 *set_addr, |
| 1999 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2000 | { |
| 2001 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2002 | struct i802_bss *bss; |
| 2003 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2004 | if (global_priv == NULL) |
| 2005 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2006 | drv = os_zalloc(sizeof(*drv)); |
| 2007 | if (drv == NULL) |
| 2008 | return NULL; |
| 2009 | drv->global = global_priv; |
| 2010 | drv->ctx = ctx; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2011 | drv->hostapd = !!hostapd; |
| 2012 | drv->eapol_sock = -1; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 2013 | |
| 2014 | /* |
| 2015 | * There is no driver capability flag for this, so assume it is |
| 2016 | * supported and disable this on first attempt to use if the driver |
| 2017 | * rejects the command due to missing support. |
| 2018 | */ |
| 2019 | drv->set_rekey_offload = 1; |
| 2020 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 2021 | drv->num_if_indices = ARRAY_SIZE(drv->default_if_indices); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2022 | drv->if_indices = drv->default_if_indices; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2023 | |
| 2024 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); |
| 2025 | if (!drv->first_bss) { |
| 2026 | os_free(drv); |
| 2027 | return NULL; |
| 2028 | } |
| 2029 | bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2030 | bss->drv = drv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2031 | bss->ctx = ctx; |
| 2032 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2033 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
| 2034 | drv->monitor_ifidx = -1; |
| 2035 | drv->monitor_sock = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2036 | drv->eapol_tx_sock = -1; |
| 2037 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2038 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2039 | if (nl80211_init_bss(bss)) |
| 2040 | goto failed; |
| 2041 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2042 | 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] | 2043 | goto failed; |
| 2044 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2045 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
| 2046 | if (drv->eapol_tx_sock < 0) |
| 2047 | goto failed; |
| 2048 | |
| 2049 | if (drv->data_tx_status) { |
| 2050 | int enabled = 1; |
| 2051 | |
| 2052 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, |
| 2053 | &enabled, sizeof(enabled)) < 0) { |
| 2054 | wpa_printf(MSG_DEBUG, |
| 2055 | "nl80211: wifi status sockopt failed\n"); |
| 2056 | drv->data_tx_status = 0; |
| 2057 | if (!drv->use_monitor) |
| 2058 | drv->capa.flags &= |
| 2059 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
| 2060 | } else { |
| 2061 | eloop_register_read_sock(drv->eapol_tx_sock, |
| 2062 | wpa_driver_nl80211_handle_eapol_tx_status, |
| 2063 | drv, NULL); |
| 2064 | } |
| 2065 | } |
| 2066 | |
| 2067 | if (drv->global) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2068 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2069 | dl_list_add(&drv->global->interfaces, &drv->list); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2070 | drv->in_interface_list = 1; |
| 2071 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2072 | |
| 2073 | return bss; |
| 2074 | |
| 2075 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2076 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2077 | return NULL; |
| 2078 | } |
| 2079 | |
| 2080 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2081 | /** |
| 2082 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface |
| 2083 | * @ctx: context to be used when calling wpa_supplicant functions, |
| 2084 | * e.g., wpa_supplicant_event() |
| 2085 | * @ifname: interface name, e.g., wlan0 |
| 2086 | * @global_priv: private driver global data from global_init() |
| 2087 | * Returns: Pointer to private data, %NULL on failure |
| 2088 | */ |
| 2089 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
| 2090 | void *global_priv) |
| 2091 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2092 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
| 2093 | NULL); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2094 | } |
| 2095 | |
| 2096 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2097 | static int nl80211_register_frame(struct i802_bss *bss, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 2098 | struct nl_sock *nl_handle, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2099 | u16 type, const u8 *match, size_t match_len) |
| 2100 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2101 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2102 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2103 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2104 | char buf[30]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2105 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2106 | buf[0] = '\0'; |
| 2107 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 2108 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s", |
| 2109 | type, fc2str(type), nl_handle, buf); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2110 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 2111 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_FRAME)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2112 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
| 2113 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { |
| 2114 | nlmsg_free(msg); |
| 2115 | return -1; |
| 2116 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2117 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2118 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2119 | if (ret) { |
| 2120 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
| 2121 | "failed (type=%u): ret=%d (%s)", |
| 2122 | type, ret, strerror(-ret)); |
| 2123 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", |
| 2124 | match, match_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2125 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2126 | return ret; |
| 2127 | } |
| 2128 | |
| 2129 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2130 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
| 2131 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2132 | if (bss->nl_mgmt) { |
| 2133 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
| 2134 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
| 2135 | return -1; |
| 2136 | } |
| 2137 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2138 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2139 | if (bss->nl_mgmt == NULL) |
| 2140 | return -1; |
| 2141 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2142 | return 0; |
| 2143 | } |
| 2144 | |
| 2145 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2146 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
| 2147 | { |
| 2148 | nl80211_register_eloop_read(&bss->nl_mgmt, |
| 2149 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2150 | bss->nl_cb, 0); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2151 | } |
| 2152 | |
| 2153 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2154 | static int nl80211_register_action_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2155 | const u8 *match, size_t match_len) |
| 2156 | { |
| 2157 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2158 | return nl80211_register_frame(bss, bss->nl_mgmt, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2159 | type, match, match_len); |
| 2160 | } |
| 2161 | |
| 2162 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2163 | static int nl80211_init_connect_handle(struct i802_bss *bss) |
| 2164 | { |
| 2165 | if (bss->nl_connect) { |
| 2166 | wpa_printf(MSG_DEBUG, |
| 2167 | "nl80211: Connect handle already created (nl_connect=%p)", |
| 2168 | bss->nl_connect); |
| 2169 | return -1; |
| 2170 | } |
| 2171 | |
| 2172 | bss->nl_connect = nl_create_handle(bss->nl_cb, "connect"); |
| 2173 | if (!bss->nl_connect) |
| 2174 | return -1; |
| 2175 | nl80211_register_eloop_read(&bss->nl_connect, |
| 2176 | wpa_driver_nl80211_event_receive, |
| 2177 | bss->nl_cb, 1); |
| 2178 | return 0; |
| 2179 | } |
| 2180 | |
| 2181 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2182 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2183 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2184 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 2185 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2186 | int ret = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2187 | |
| 2188 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2189 | return -1; |
| 2190 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
| 2191 | "handle %p", bss->nl_mgmt); |
| 2192 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 2193 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2194 | /* register for any AUTH message */ |
| 2195 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 2196 | } else if ((drv->capa.flags & WPA_DRIVER_FLAGS_SAE) && |
| 2197 | !(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
| 2198 | /* register for SAE Authentication frames */ |
| 2199 | nl80211_register_frame(bss, bss->nl_mgmt, type, |
| 2200 | (u8 *) "\x03\x00", 2); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2201 | } |
| 2202 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2203 | #ifdef CONFIG_INTERWORKING |
| 2204 | /* QoS Map Configure */ |
| 2205 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2206 | ret = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2207 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2208 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2209 | /* GAS Initial Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2210 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2211 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2212 | /* GAS Initial Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2213 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2214 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2215 | /* GAS Comeback Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2216 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2217 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2218 | /* GAS Comeback Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2219 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2220 | ret = -1; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2221 | /* Protected GAS Initial Request */ |
| 2222 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) |
| 2223 | ret = -1; |
| 2224 | /* Protected GAS Initial Response */ |
| 2225 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) |
| 2226 | ret = -1; |
| 2227 | /* Protected GAS Comeback Request */ |
| 2228 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) |
| 2229 | ret = -1; |
| 2230 | /* Protected GAS Comeback Response */ |
| 2231 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) |
| 2232 | ret = -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2233 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2234 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2235 | /* P2P Public Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2236 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2237 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
| 2238 | 6) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2239 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2240 | /* P2P Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2241 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2242 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
| 2243 | 5) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2244 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2245 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2246 | #ifdef CONFIG_DPP |
| 2247 | /* DPP Public Action */ |
| 2248 | if (nl80211_register_action_frame(bss, |
| 2249 | (u8 *) "\x04\x09\x50\x6f\x9a\x1a", |
| 2250 | 6) < 0) |
| 2251 | ret = -1; |
| 2252 | #endif /* CONFIG_DPP */ |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2253 | #ifdef CONFIG_OCV |
| 2254 | /* SA Query Request */ |
| 2255 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x00", 2) < 0) |
| 2256 | ret = -1; |
| 2257 | #endif /* CONFIG_OCV */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2258 | /* SA Query Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2259 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2260 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2261 | #ifdef CONFIG_TDLS |
| 2262 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { |
| 2263 | /* TDLS Discovery Response */ |
| 2264 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
| 2265 | 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2266 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2267 | } |
| 2268 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2269 | #ifdef CONFIG_FST |
| 2270 | /* FST Action frames */ |
| 2271 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2272 | ret = -1; |
| 2273 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2274 | |
| 2275 | /* FT Action frames */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2276 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2277 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2278 | else |
| 2279 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | |
| 2280 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; |
| 2281 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2282 | /* WNM - BSS Transition Management Request */ |
| 2283 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2284 | ret = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2285 | /* WNM-Sleep Mode Response */ |
| 2286 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2287 | ret = -1; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2288 | #ifdef CONFIG_WNM |
| 2289 | /* WNM - Collocated Interference Request */ |
| 2290 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x0b", 2) < 0) |
| 2291 | ret = -1; |
| 2292 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2293 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2294 | #ifdef CONFIG_HS20 |
| 2295 | /* WNM-Notification */ |
| 2296 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2297 | ret = -1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2298 | #endif /* CONFIG_HS20 */ |
| 2299 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2300 | /* WMM-AC ADDTS Response */ |
| 2301 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) |
| 2302 | ret = -1; |
| 2303 | |
| 2304 | /* WMM-AC DELTS */ |
| 2305 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) |
| 2306 | ret = -1; |
| 2307 | |
| 2308 | /* Radio Measurement - Neighbor Report Response */ |
| 2309 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) |
| 2310 | ret = -1; |
| 2311 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2312 | /* Radio Measurement - Radio Measurement Request */ |
| 2313 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0) |
| 2314 | ret = -1; |
| 2315 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2316 | /* Radio Measurement - Link Measurement Request */ |
| 2317 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && |
| 2318 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) |
| 2319 | ret = -1; |
| 2320 | |
| 2321 | nl80211_mgmt_handle_register_eloop(bss); |
| 2322 | |
| 2323 | return ret; |
| 2324 | } |
| 2325 | |
| 2326 | |
| 2327 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
| 2328 | { |
| 2329 | int ret = 0; |
| 2330 | |
| 2331 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2332 | return -1; |
| 2333 | |
| 2334 | wpa_printf(MSG_DEBUG, |
| 2335 | "nl80211: Subscribe to mgmt frames with mesh handle %p", |
| 2336 | bss->nl_mgmt); |
| 2337 | |
| 2338 | /* Auth frames for mesh SAE */ |
| 2339 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2340 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2341 | (WLAN_FC_STYPE_AUTH << 4), |
| 2342 | NULL, 0) < 0) |
| 2343 | ret = -1; |
| 2344 | |
| 2345 | /* Mesh peering open */ |
| 2346 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) |
| 2347 | ret = -1; |
| 2348 | /* Mesh peering confirm */ |
| 2349 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) |
| 2350 | ret = -1; |
| 2351 | /* Mesh peering close */ |
| 2352 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) |
| 2353 | ret = -1; |
| 2354 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2355 | nl80211_mgmt_handle_register_eloop(bss); |
| 2356 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2357 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2358 | } |
| 2359 | |
| 2360 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2361 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
| 2362 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2363 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2364 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2365 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2366 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
| 2367 | 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] | 2368 | if (ret) { |
| 2369 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " |
| 2370 | "failed: ret=%d (%s)", |
| 2371 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2372 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2373 | return ret; |
| 2374 | } |
| 2375 | |
| 2376 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2377 | static int nl80211_action_subscribe_ap(struct i802_bss *bss) |
| 2378 | { |
| 2379 | int ret = 0; |
| 2380 | |
| 2381 | /* Public Action frames */ |
| 2382 | if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0) |
| 2383 | ret = -1; |
| 2384 | /* RRM Measurement Report */ |
| 2385 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0) |
| 2386 | ret = -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2387 | /* RRM Link Measurement Report */ |
| 2388 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0) |
| 2389 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2390 | /* RRM Neighbor Report Request */ |
| 2391 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0) |
| 2392 | ret = -1; |
| 2393 | /* FT Action frames */ |
| 2394 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
| 2395 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2396 | /* SA Query */ |
| 2397 | if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0) |
| 2398 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2399 | /* Protected Dual of Public Action */ |
| 2400 | if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0) |
| 2401 | ret = -1; |
| 2402 | /* WNM */ |
| 2403 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0) |
| 2404 | ret = -1; |
| 2405 | /* WMM */ |
| 2406 | if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0) |
| 2407 | ret = -1; |
| 2408 | #ifdef CONFIG_FST |
| 2409 | /* FST Action frames */ |
| 2410 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2411 | ret = -1; |
| 2412 | #endif /* CONFIG_FST */ |
| 2413 | /* Vendor-specific */ |
| 2414 | if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0) |
| 2415 | ret = -1; |
| 2416 | |
| 2417 | return ret; |
| 2418 | } |
| 2419 | |
| 2420 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2421 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
| 2422 | { |
| 2423 | static const int stypes[] = { |
| 2424 | WLAN_FC_STYPE_AUTH, |
| 2425 | WLAN_FC_STYPE_ASSOC_REQ, |
| 2426 | WLAN_FC_STYPE_REASSOC_REQ, |
| 2427 | WLAN_FC_STYPE_DISASSOC, |
| 2428 | WLAN_FC_STYPE_DEAUTH, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2429 | WLAN_FC_STYPE_PROBE_REQ, |
| 2430 | /* Beacon doesn't work as mac80211 doesn't currently allow |
| 2431 | * it, but it wouldn't really be the right thing anyway as |
| 2432 | * it isn't per interface ... maybe just dump the scan |
| 2433 | * results periodically for OLBC? |
| 2434 | */ |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2435 | /* WLAN_FC_STYPE_BEACON, */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2436 | }; |
| 2437 | unsigned int i; |
| 2438 | |
| 2439 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2440 | return -1; |
| 2441 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2442 | "handle %p", bss->nl_mgmt); |
| 2443 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2444 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2445 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2446 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2447 | (stypes[i] << 4), |
| 2448 | NULL, 0) < 0) { |
| 2449 | goto out_err; |
| 2450 | } |
| 2451 | } |
| 2452 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2453 | if (nl80211_action_subscribe_ap(bss)) |
| 2454 | goto out_err; |
| 2455 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2456 | if (nl80211_register_spurious_class3(bss)) |
| 2457 | goto out_err; |
| 2458 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2459 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2460 | return 0; |
| 2461 | |
| 2462 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2463 | nl_destroy_handles(&bss->nl_mgmt); |
| 2464 | return -1; |
| 2465 | } |
| 2466 | |
| 2467 | |
| 2468 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
| 2469 | { |
| 2470 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2471 | return -1; |
| 2472 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2473 | "handle %p (device SME)", bss->nl_mgmt); |
| 2474 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2475 | if (nl80211_action_subscribe_ap(bss)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2476 | goto out_err; |
| 2477 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 2478 | if (bss->drv->device_ap_sme) { |
| 2479 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
| 2480 | |
| 2481 | /* Register for all Authentication frames */ |
| 2482 | if (nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0) |
| 2483 | < 0) |
| 2484 | wpa_printf(MSG_DEBUG, |
| 2485 | "nl80211: Failed to subscribe to handle Authentication frames - SAE offload may not work"); |
| 2486 | } |
| 2487 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2488 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2489 | return 0; |
| 2490 | |
| 2491 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2492 | nl_destroy_handles(&bss->nl_mgmt); |
| 2493 | return -1; |
| 2494 | } |
| 2495 | |
| 2496 | |
| 2497 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
| 2498 | { |
| 2499 | if (bss->nl_mgmt == NULL) |
| 2500 | return; |
| 2501 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
| 2502 | "(%s)", bss->nl_mgmt, reason); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2503 | nl80211_destroy_eloop_handle(&bss->nl_mgmt, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2504 | |
| 2505 | nl80211_put_wiphy_data_ap(bss); |
| 2506 | } |
| 2507 | |
| 2508 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2509 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
| 2510 | { |
| 2511 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); |
| 2512 | } |
| 2513 | |
| 2514 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2515 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
| 2516 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2517 | struct nl_msg *msg; |
| 2518 | int ret; |
| 2519 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2520 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
| 2521 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2522 | |
| 2523 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", |
| 2524 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2525 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2526 | } |
| 2527 | |
| 2528 | |
| 2529 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
| 2530 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2531 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2532 | int ret; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2533 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2534 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
| 2535 | NL80211_CMD_STOP_P2P_DEVICE); |
| 2536 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2537 | |
| 2538 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
| 2539 | start ? "Start" : "Stop", |
| 2540 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2541 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2542 | return ret; |
| 2543 | } |
| 2544 | |
| 2545 | |
| 2546 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
| 2547 | { |
| 2548 | enum nl80211_iftype nlmode; |
| 2549 | |
| 2550 | nlmode = nl80211_get_ifmode(bss); |
| 2551 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2552 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, |
| 2553 | bss->ifname, up); |
| 2554 | } |
| 2555 | |
| 2556 | /* P2P Device has start/stop which is equivalent */ |
| 2557 | return nl80211_set_p2pdev(bss, up); |
| 2558 | } |
| 2559 | |
| 2560 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2561 | #ifdef CONFIG_TESTING_OPTIONS |
| 2562 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) |
| 2563 | { |
| 2564 | /* struct wpa_driver_nl80211_data *drv = arg; */ |
| 2565 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 2566 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2567 | |
| 2568 | |
| 2569 | wpa_printf(MSG_DEBUG, |
| 2570 | "nl80211: QCA vendor test command response received"); |
| 2571 | |
| 2572 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2573 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2574 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { |
| 2575 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); |
| 2576 | return NL_SKIP; |
| 2577 | } |
| 2578 | |
| 2579 | wpa_hexdump(MSG_DEBUG, |
| 2580 | "nl80211: Received QCA vendor test command response", |
| 2581 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), |
| 2582 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); |
| 2583 | |
| 2584 | return NL_SKIP; |
| 2585 | } |
| 2586 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2587 | |
| 2588 | |
| 2589 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) |
| 2590 | { |
| 2591 | #ifdef CONFIG_TESTING_OPTIONS |
| 2592 | struct nl_msg *msg; |
| 2593 | struct nlattr *params; |
| 2594 | int ret; |
| 2595 | |
| 2596 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2597 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2598 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2599 | QCA_NL80211_VENDOR_SUBCMD_TEST) || |
| 2600 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 2601 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { |
| 2602 | nlmsg_free(msg); |
| 2603 | return; |
| 2604 | } |
| 2605 | nla_nest_end(msg, params); |
| 2606 | |
| 2607 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv); |
| 2608 | wpa_printf(MSG_DEBUG, |
| 2609 | "nl80211: QCA vendor test command returned %d (%s)", |
| 2610 | ret, strerror(-ret)); |
| 2611 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2612 | } |
| 2613 | |
| 2614 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2615 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2616 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2617 | const u8 *set_addr, int first, |
| 2618 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2619 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2620 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2621 | int send_rfkill_event = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2622 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2623 | |
| 2624 | drv->ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2625 | bss->ifindex = drv->ifindex; |
| 2626 | bss->wdev_id = drv->global->if_add_wdevid; |
| 2627 | bss->wdev_id_set = drv->global->if_add_wdevid_set; |
| 2628 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2629 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
| 2630 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2631 | drv->global->if_add_wdevid_set = 0; |
| 2632 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2633 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2634 | bss->static_ap = 1; |
| 2635 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 2636 | if (first && |
| 2637 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && |
| 2638 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) |
| 2639 | drv->start_iface_up = 1; |
| 2640 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2641 | if (wpa_driver_nl80211_capa(drv)) |
| 2642 | return -1; |
| 2643 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2644 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
| 2645 | return -1; |
| 2646 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2647 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
| 2648 | bss->ifname, drv->phyname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2649 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2650 | if (set_addr && |
| 2651 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || |
| 2652 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2653 | set_addr))) |
| 2654 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2655 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2656 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2657 | drv->start_mode_ap = 1; |
| 2658 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2659 | if (drv->hostapd || bss->static_ap) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2660 | nlmode = NL80211_IFTYPE_AP; |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 2661 | else if (bss->if_dynamic || |
| 2662 | nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2663 | nlmode = nl80211_get_ifmode(bss); |
| 2664 | else |
| 2665 | nlmode = NL80211_IFTYPE_STATION; |
| 2666 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2667 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2668 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2669 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2670 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2671 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2672 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2673 | nl80211_get_macaddr(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2674 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2675 | wpa_driver_nl80211_drv_init_rfkill(drv); |
| 2676 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2677 | if (!rfkill_is_blocked(drv->rfkill)) { |
| 2678 | int ret = i802_set_iface_flags(bss, 1); |
| 2679 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2680 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
| 2681 | "interface '%s' UP", bss->ifname); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2682 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2683 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2684 | |
| 2685 | if (is_p2p_net_interface(nlmode)) |
| 2686 | nl80211_disable_11b_rates(bss->drv, |
| 2687 | bss->drv->ifindex, 1); |
| 2688 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2689 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2690 | return ret; |
| 2691 | } else { |
| 2692 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " |
| 2693 | "interface '%s' due to rfkill", bss->ifname); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2694 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 2695 | drv->if_disabled = 1; |
| 2696 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2697 | send_rfkill_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2698 | } |
| 2699 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2700 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2701 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
| 2702 | 1, IF_OPER_DORMANT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2703 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2704 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2705 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2706 | bss->addr)) |
| 2707 | return -1; |
| 2708 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); |
| 2709 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2710 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2711 | if (send_rfkill_event) { |
| 2712 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, |
| 2713 | drv, drv->ctx); |
| 2714 | } |
| 2715 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2716 | if (drv->vendor_cmd_test_avail) |
| 2717 | qca_vendor_test(drv); |
| 2718 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2719 | nl80211_init_connect_handle(bss); |
| 2720 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2721 | return 0; |
| 2722 | } |
| 2723 | |
| 2724 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2725 | static int wpa_driver_nl80211_del_beacon(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2726 | { |
| 2727 | struct nl_msg *msg; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2728 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2729 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2730 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
| 2731 | drv->ifindex); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2732 | nl80211_put_wiphy_data_ap(bss); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2733 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2734 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2735 | } |
| 2736 | |
| 2737 | |
| 2738 | /** |
| 2739 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2740 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2741 | * |
| 2742 | * Shut down driver interface and processing of driver events. Free |
| 2743 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). |
| 2744 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2745 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2746 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2747 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2748 | unsigned int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2749 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2750 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
| 2751 | bss->ifname, drv->disabled_11b_rates); |
| 2752 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2753 | bss->in_deinit = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2754 | if (drv->data_tx_status) |
| 2755 | eloop_unregister_read_sock(drv->eapol_tx_sock); |
| 2756 | if (drv->eapol_tx_sock >= 0) |
| 2757 | close(drv->eapol_tx_sock); |
| 2758 | |
| 2759 | if (bss->nl_preq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2760 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 2761 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2762 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 2763 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2764 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2765 | "interface %s from bridge %s: %s", |
| 2766 | bss->ifname, bss->brname, strerror(errno)); |
| 2767 | } |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 2768 | |
| 2769 | if (drv->rtnl_sk) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 2770 | nl_socket_free(drv->rtnl_sk); |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 2771 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2772 | if (bss->added_bridge) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2773 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
| 2774 | 0) < 0) |
| 2775 | wpa_printf(MSG_INFO, |
| 2776 | "nl80211: Could not set bridge %s down", |
| 2777 | bss->brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2778 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2779 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2780 | "bridge %s: %s", |
| 2781 | bss->brname, strerror(errno)); |
| 2782 | } |
| 2783 | |
| 2784 | nl80211_remove_monitor_interface(drv); |
| 2785 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2786 | if (is_ap_interface(drv->nlmode)) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2787 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2788 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2789 | if (drv->eapol_sock >= 0) { |
| 2790 | eloop_unregister_read_sock(drv->eapol_sock); |
| 2791 | close(drv->eapol_sock); |
| 2792 | } |
| 2793 | |
| 2794 | if (drv->if_indices != drv->default_if_indices) |
| 2795 | os_free(drv->if_indices); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2796 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2797 | if (drv->disabled_11b_rates) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2798 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 2799 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2800 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
| 2801 | IF_OPER_UP); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 2802 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2803 | rfkill_deinit(drv->rfkill); |
| 2804 | |
| 2805 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 2806 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2807 | if (!drv->start_iface_up) |
| 2808 | (void) i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2809 | |
| 2810 | if (drv->addr_changed) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2811 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 2812 | 0) < 0) { |
| 2813 | wpa_printf(MSG_DEBUG, |
| 2814 | "nl80211: Could not set interface down to restore permanent MAC address"); |
| 2815 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2816 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2817 | drv->perm_addr) < 0) { |
| 2818 | wpa_printf(MSG_DEBUG, |
| 2819 | "nl80211: Could not restore permanent MAC address"); |
| 2820 | } |
| 2821 | } |
| 2822 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2823 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2824 | if (!drv->hostapd || !drv->start_mode_ap) |
| 2825 | wpa_driver_nl80211_set_mode(bss, |
| 2826 | NL80211_IFTYPE_STATION); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2827 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2828 | } else { |
| 2829 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
| 2830 | nl80211_del_p2pdev(bss); |
| 2831 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2832 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2833 | if (bss->nl_connect) |
| 2834 | nl80211_destroy_eloop_handle(&bss->nl_connect, 1); |
| 2835 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2836 | nl80211_destroy_bss(drv->first_bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2837 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2838 | os_free(drv->filter_ssids); |
| 2839 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2840 | os_free(drv->auth_ie); |
| 2841 | |
| 2842 | if (drv->in_interface_list) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2843 | dl_list_del(&drv->list); |
| 2844 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2845 | os_free(drv->extended_capa); |
| 2846 | os_free(drv->extended_capa_mask); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2847 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 2848 | os_free(drv->iface_ext_capa[i].ext_capa); |
| 2849 | os_free(drv->iface_ext_capa[i].ext_capa_mask); |
| 2850 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2851 | os_free(drv->first_bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2852 | os_free(drv); |
| 2853 | } |
| 2854 | |
| 2855 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2856 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
| 2857 | { |
| 2858 | switch (alg) { |
| 2859 | case WPA_ALG_WEP: |
| 2860 | if (key_len == 5) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2861 | return RSN_CIPHER_SUITE_WEP40; |
| 2862 | return RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2863 | case WPA_ALG_TKIP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2864 | return RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2865 | case WPA_ALG_CCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2866 | return RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2867 | case WPA_ALG_GCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2868 | return RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2869 | case WPA_ALG_CCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2870 | return RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2871 | case WPA_ALG_GCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2872 | return RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2873 | case WPA_ALG_IGTK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2874 | return RSN_CIPHER_SUITE_AES_128_CMAC; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2875 | case WPA_ALG_BIP_GMAC_128: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2876 | return RSN_CIPHER_SUITE_BIP_GMAC_128; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2877 | case WPA_ALG_BIP_GMAC_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2878 | return RSN_CIPHER_SUITE_BIP_GMAC_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2879 | case WPA_ALG_BIP_CMAC_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2880 | return RSN_CIPHER_SUITE_BIP_CMAC_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2881 | case WPA_ALG_SMS4: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2882 | return RSN_CIPHER_SUITE_SMS4; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2883 | case WPA_ALG_KRK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2884 | return RSN_CIPHER_SUITE_KRK; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2885 | case WPA_ALG_NONE: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2886 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", |
| 2887 | alg); |
| 2888 | return 0; |
| 2889 | } |
| 2890 | |
| 2891 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", |
| 2892 | alg); |
| 2893 | return 0; |
| 2894 | } |
| 2895 | |
| 2896 | |
| 2897 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) |
| 2898 | { |
| 2899 | switch (cipher) { |
| 2900 | case WPA_CIPHER_CCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2901 | return RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2902 | case WPA_CIPHER_GCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2903 | return RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2904 | case WPA_CIPHER_CCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2905 | return RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2906 | case WPA_CIPHER_GCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2907 | return RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2908 | case WPA_CIPHER_TKIP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2909 | return RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2910 | case WPA_CIPHER_WEP104: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2911 | return RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2912 | case WPA_CIPHER_WEP40: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2913 | return RSN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2914 | case WPA_CIPHER_GTK_NOT_USED: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2915 | return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2916 | } |
| 2917 | |
| 2918 | return 0; |
| 2919 | } |
| 2920 | |
| 2921 | |
| 2922 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], |
| 2923 | int max_suites) |
| 2924 | { |
| 2925 | int num_suites = 0; |
| 2926 | |
| 2927 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2928 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2929 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2930 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2931 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2932 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2933 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2934 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2935 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2936 | suites[num_suites++] = RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2937 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2938 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2939 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2940 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2941 | |
| 2942 | return num_suites; |
| 2943 | } |
| 2944 | |
| 2945 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 2946 | static int wpa_key_mgmt_to_suites(unsigned int key_mgmt_suites, u32 suites[], |
| 2947 | int max_suites) |
| 2948 | { |
| 2949 | int num_suites = 0; |
| 2950 | |
| 2951 | #define __AKM(a, b) \ |
| 2952 | if (num_suites < max_suites && \ |
| 2953 | (key_mgmt_suites & (WPA_KEY_MGMT_ ## a))) \ |
| 2954 | suites[num_suites++] = (RSN_AUTH_KEY_MGMT_ ## b) |
| 2955 | __AKM(IEEE8021X, UNSPEC_802_1X); |
| 2956 | __AKM(PSK, PSK_OVER_802_1X); |
| 2957 | __AKM(FT_IEEE8021X, FT_802_1X); |
| 2958 | __AKM(FT_PSK, FT_PSK); |
| 2959 | __AKM(IEEE8021X_SHA256, 802_1X_SHA256); |
| 2960 | __AKM(PSK_SHA256, PSK_SHA256); |
| 2961 | __AKM(SAE, SAE); |
| 2962 | __AKM(FT_SAE, FT_SAE); |
| 2963 | __AKM(CCKM, CCKM); |
| 2964 | __AKM(OSEN, OSEN); |
| 2965 | __AKM(IEEE8021X_SUITE_B, 802_1X_SUITE_B); |
| 2966 | __AKM(IEEE8021X_SUITE_B_192, 802_1X_SUITE_B_192); |
| 2967 | __AKM(FILS_SHA256, FILS_SHA256); |
| 2968 | __AKM(FILS_SHA384, FILS_SHA384); |
| 2969 | __AKM(FT_FILS_SHA256, FT_FILS_SHA256); |
| 2970 | __AKM(FT_FILS_SHA384, FT_FILS_SHA384); |
| 2971 | __AKM(OWE, OWE); |
| 2972 | __AKM(DPP, DPP); |
| 2973 | __AKM(FT_IEEE8021X_SHA384, FT_802_1X_SHA384); |
| 2974 | #undef __AKM |
| 2975 | |
| 2976 | return num_suites; |
| 2977 | } |
| 2978 | |
| 2979 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2980 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2981 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 2982 | const u8 *key, size_t key_len) |
| 2983 | { |
| 2984 | struct nl_msg *msg; |
| 2985 | int ret; |
| 2986 | |
| 2987 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
| 2988 | return 0; |
| 2989 | |
| 2990 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2991 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2992 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2993 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || |
| 2994 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { |
| 2995 | nl80211_nlmsg_clear(msg); |
| 2996 | nlmsg_free(msg); |
| 2997 | return -1; |
| 2998 | } |
| 2999 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 3000 | if (ret) { |
| 3001 | wpa_printf(MSG_DEBUG, |
| 3002 | "nl80211: Key management set key failed: ret=%d (%s)", |
| 3003 | ret, strerror(-ret)); |
| 3004 | } |
| 3005 | |
| 3006 | return ret; |
| 3007 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3008 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3009 | |
| 3010 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3011 | static int nl80211_set_pmk(struct wpa_driver_nl80211_data *drv, |
| 3012 | const u8 *key, size_t key_len, |
| 3013 | const u8 *addr) |
| 3014 | { |
| 3015 | struct nl_msg *msg = NULL; |
| 3016 | int ret; |
| 3017 | |
| 3018 | /* |
| 3019 | * If the authenticator address is not set, assume it is |
| 3020 | * the current BSSID. |
| 3021 | */ |
| 3022 | if (!addr && drv->associated) |
| 3023 | addr = drv->bssid; |
| 3024 | else if (!addr) |
| 3025 | return -1; |
| 3026 | |
| 3027 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK to the driver for " MACSTR, |
| 3028 | MAC2STR(addr)); |
| 3029 | wpa_hexdump_key(MSG_DEBUG, "nl80211: PMK", key, key_len); |
| 3030 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_PMK); |
| 3031 | if (!msg || |
| 3032 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 3033 | nla_put(msg, NL80211_ATTR_PMK, key_len, key)) { |
| 3034 | nl80211_nlmsg_clear(msg); |
| 3035 | nlmsg_free(msg); |
| 3036 | return -ENOBUFS; |
| 3037 | } |
| 3038 | |
| 3039 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 3040 | if (ret) { |
| 3041 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK failed: ret=%d (%s)", |
| 3042 | ret, strerror(-ret)); |
| 3043 | } |
| 3044 | |
| 3045 | return ret; |
| 3046 | } |
| 3047 | |
| 3048 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3049 | static int wpa_driver_nl80211_set_key(struct i802_bss *bss, |
| 3050 | struct wpa_driver_set_key_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3051 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3052 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3053 | int ifindex; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3054 | struct nl_msg *msg; |
| 3055 | struct nl_msg *key_msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3056 | int ret; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3057 | int skip_set_key = 1; |
| 3058 | const char *ifname = params->ifname; |
| 3059 | enum wpa_alg alg = params->alg; |
| 3060 | const u8 *addr = params->addr; |
| 3061 | int key_idx = params->key_idx; |
| 3062 | int set_tx = params->set_tx; |
| 3063 | const u8 *seq = params->seq; |
| 3064 | size_t seq_len = params->seq_len; |
| 3065 | const u8 *key = params->key; |
| 3066 | size_t key_len = params->key_len; |
| 3067 | int vlan_id = params->vlan_id; |
| 3068 | enum key_flag key_flag = params->key_flag; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3069 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3070 | /* Ignore for P2P Device */ |
| 3071 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 3072 | return 0; |
| 3073 | |
| 3074 | ifindex = if_nametoindex(ifname); |
| 3075 | 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^] | 3076 | "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] | 3077 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3078 | (unsigned long) seq_len, (unsigned long) key_len, key_flag); |
| 3079 | |
| 3080 | if (check_key_flag(key_flag)) { |
| 3081 | wpa_printf(MSG_DEBUG, "%s: invalid key_flag", __func__); |
| 3082 | return -EINVAL; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 3083 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3084 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3085 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3086 | if ((key_flag & KEY_FLAG_PMK) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3087 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { |
| 3088 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
| 3089 | __func__); |
| 3090 | ret = issue_key_mgmt_set_key(drv, key, key_len); |
| 3091 | return ret; |
| 3092 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3093 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3094 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3095 | if (key_flag & KEY_FLAG_PMK) { |
| 3096 | if (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X) |
| 3097 | return nl80211_set_pmk(drv, key, key_len, addr); |
| 3098 | /* The driver does not have any offload mechanism for PMK, so |
| 3099 | * there is no need to configure this key. */ |
| 3100 | return 0; |
| 3101 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3102 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3103 | ret = -ENOBUFS; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3104 | key_msg = nlmsg_alloc(); |
| 3105 | if (!key_msg) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3106 | return ret; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3107 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3108 | if ((key_flag & KEY_FLAG_PAIRWISE_MASK) == |
| 3109 | KEY_FLAG_PAIRWISE_RX_TX_MODIFY) { |
| 3110 | wpa_printf(MSG_DEBUG, |
| 3111 | "nl80211: SET_KEY (pairwise RX/TX modify)"); |
| 3112 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
| 3113 | if (!msg) |
| 3114 | goto fail2; |
| 3115 | } else if (alg == WPA_ALG_NONE && (key_flag & KEY_FLAG_RX_TX)) { |
| 3116 | wpa_printf(MSG_DEBUG, "%s: invalid key_flag to delete key", |
| 3117 | __func__); |
| 3118 | ret = -EINVAL; |
| 3119 | goto fail2; |
| 3120 | } else if (alg == WPA_ALG_NONE) { |
| 3121 | wpa_printf(MSG_DEBUG, "nl80211: DEL_KEY"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3122 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
| 3123 | if (!msg) |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3124 | goto fail2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3125 | } else { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3126 | u32 suite; |
| 3127 | |
| 3128 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3129 | if (!suite) { |
| 3130 | ret = -EINVAL; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3131 | goto fail2; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3132 | } |
| 3133 | wpa_printf(MSG_DEBUG, "nl80211: NEW_KEY"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3134 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3135 | if (!msg) |
| 3136 | goto fail2; |
| 3137 | if (nla_put(key_msg, NL80211_KEY_DATA, key_len, key) || |
| 3138 | nla_put_u32(key_msg, NL80211_KEY_CIPHER, suite)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3139 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3140 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3141 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3142 | if (seq && seq_len) { |
| 3143 | if (nla_put(key_msg, NL80211_KEY_SEQ, seq_len, seq)) |
| 3144 | goto fail; |
| 3145 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", |
| 3146 | seq, seq_len); |
| 3147 | } |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3148 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3149 | |
| 3150 | if (addr && !is_broadcast_ether_addr(addr)) { |
| 3151 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3152 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 3153 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3154 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3155 | if ((key_flag & KEY_FLAG_PAIRWISE_MASK) == |
| 3156 | KEY_FLAG_PAIRWISE_RX || |
| 3157 | (key_flag & KEY_FLAG_PAIRWISE_MASK) == |
| 3158 | KEY_FLAG_PAIRWISE_RX_TX_MODIFY) { |
| 3159 | if (nla_put_u8(key_msg, NL80211_KEY_MODE, |
| 3160 | key_flag == KEY_FLAG_PAIRWISE_RX ? |
| 3161 | NL80211_KEY_NO_TX : NL80211_KEY_SET_TX)) |
| 3162 | goto fail; |
| 3163 | } else if ((key_flag & KEY_FLAG_GROUP_MASK) == |
| 3164 | KEY_FLAG_GROUP_RX) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3165 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3166 | if (nla_put_u32(key_msg, NL80211_KEY_TYPE, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3167 | NL80211_KEYTYPE_GROUP)) |
| 3168 | goto fail; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3169 | } else if (!(key_flag & KEY_FLAG_PAIRWISE)) { |
| 3170 | wpa_printf(MSG_DEBUG, |
| 3171 | " key_flag missing PAIRWISE when setting a pairwise key"); |
| 3172 | ret = -EINVAL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3173 | goto fail; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3174 | } else if (alg == WPA_ALG_WEP && |
| 3175 | (key_flag & KEY_FLAG_RX_TX) == KEY_FLAG_RX_TX) { |
| 3176 | wpa_printf(MSG_DEBUG, " unicast WEP key"); |
| 3177 | skip_set_key = 0; |
| 3178 | } else { |
| 3179 | wpa_printf(MSG_DEBUG, " pairwise key"); |
| 3180 | } |
| 3181 | } else if ((key_flag & KEY_FLAG_PAIRWISE) || |
| 3182 | !(key_flag & KEY_FLAG_GROUP)) { |
| 3183 | wpa_printf(MSG_DEBUG, |
| 3184 | " invalid key_flag for a broadcast key"); |
| 3185 | ret = -EINVAL; |
| 3186 | goto fail; |
| 3187 | } else { |
| 3188 | wpa_printf(MSG_DEBUG, " broadcast key"); |
| 3189 | if (key_flag & KEY_FLAG_DEFAULT) |
| 3190 | skip_set_key = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3191 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3192 | if (nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) || |
| 3193 | nla_put_nested(msg, NL80211_ATTR_KEY, key_msg)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3194 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3195 | nl80211_nlmsg_clear(key_msg); |
| 3196 | nlmsg_free(key_msg); |
| 3197 | key_msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3198 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3199 | if (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) { |
| 3200 | wpa_printf(MSG_DEBUG, "nl80211: VLAN ID %d", vlan_id); |
| 3201 | if (nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) |
| 3202 | goto fail; |
| 3203 | } |
| 3204 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3205 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3206 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
| 3207 | ret = 0; |
| 3208 | if (ret) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3209 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3210 | ret, strerror(-ret)); |
| 3211 | |
| 3212 | /* |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3213 | * 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] | 3214 | * we're done here. |
| 3215 | */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3216 | if (ret || skip_set_key) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3217 | return ret; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3218 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_SET_KEY - default key"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3219 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3220 | ret = -ENOBUFS; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3221 | key_msg = nlmsg_alloc(); |
| 3222 | if (!key_msg) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3223 | return ret; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3224 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3225 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3226 | if (!msg) |
| 3227 | goto fail2; |
| 3228 | if (!key_msg || |
| 3229 | nla_put_u8(key_msg, NL80211_KEY_IDX, key_idx) || |
| 3230 | nla_put_flag(key_msg, (alg == WPA_ALG_IGTK || |
| 3231 | alg == WPA_ALG_BIP_GMAC_128 || |
| 3232 | alg == WPA_ALG_BIP_GMAC_256 || |
| 3233 | alg == WPA_ALG_BIP_CMAC_256) ? |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3234 | (key_idx == 6 || key_idx == 7 ? |
| 3235 | NL80211_KEY_DEFAULT_BEACON : |
| 3236 | NL80211_KEY_DEFAULT_MGMT) : |
| 3237 | NL80211_KEY_DEFAULT)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3238 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3239 | if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3240 | struct nlattr *types; |
| 3241 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3242 | types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3243 | if (!types || |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3244 | nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3245 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3246 | nla_nest_end(key_msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3247 | } else if (addr) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3248 | struct nlattr *types; |
| 3249 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3250 | types = nla_nest_start(key_msg, NL80211_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3251 | if (!types || |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3252 | nla_put_flag(key_msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3253 | goto fail; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3254 | nla_nest_end(key_msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3255 | } |
| 3256 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3257 | if (nla_put_nested(msg, NL80211_ATTR_KEY, key_msg)) |
| 3258 | goto fail; |
| 3259 | nl80211_nlmsg_clear(key_msg); |
| 3260 | nlmsg_free(key_msg); |
| 3261 | key_msg = NULL; |
| 3262 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3263 | if (vlan_id && (drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD)) { |
| 3264 | wpa_printf(MSG_DEBUG, "nl80211: set_key default - VLAN ID %d", |
| 3265 | vlan_id); |
| 3266 | if (nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) |
| 3267 | goto fail; |
| 3268 | } |
| 3269 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3270 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3271 | if (ret) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3272 | wpa_printf(MSG_DEBUG, |
| 3273 | "nl80211: set_key default failed; err=%d %s", |
| 3274 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3275 | return ret; |
| 3276 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3277 | fail: |
| 3278 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3279 | nlmsg_free(msg); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 3280 | fail2: |
| 3281 | nl80211_nlmsg_clear(key_msg); |
| 3282 | nlmsg_free(key_msg); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3283 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3284 | } |
| 3285 | |
| 3286 | |
| 3287 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
| 3288 | int key_idx, int defkey, |
| 3289 | const u8 *seq, size_t seq_len, |
| 3290 | const u8 *key, size_t key_len) |
| 3291 | { |
| 3292 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3293 | u32 suite; |
| 3294 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3295 | if (!key_attr) |
| 3296 | return -1; |
| 3297 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3298 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 3299 | if (!suite) |
| 3300 | return -1; |
| 3301 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3302 | if (defkey && alg == WPA_ALG_IGTK) { |
| 3303 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) |
| 3304 | return -1; |
| 3305 | } else if (defkey) { |
| 3306 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) |
| 3307 | return -1; |
| 3308 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3309 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3310 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3311 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3312 | (seq && seq_len && |
| 3313 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || |
| 3314 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) |
| 3315 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3316 | |
| 3317 | nla_nest_end(msg, key_attr); |
| 3318 | |
| 3319 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3320 | } |
| 3321 | |
| 3322 | |
| 3323 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
| 3324 | struct nl_msg *msg) |
| 3325 | { |
| 3326 | int i, privacy = 0; |
| 3327 | struct nlattr *nl_keys, *nl_key; |
| 3328 | |
| 3329 | for (i = 0; i < 4; i++) { |
| 3330 | if (!params->wep_key[i]) |
| 3331 | continue; |
| 3332 | privacy = 1; |
| 3333 | break; |
| 3334 | } |
| 3335 | if (params->wps == WPS_MODE_PRIVACY) |
| 3336 | privacy = 1; |
| 3337 | if (params->pairwise_suite && |
| 3338 | params->pairwise_suite != WPA_CIPHER_NONE) |
| 3339 | privacy = 1; |
| 3340 | |
| 3341 | if (!privacy) |
| 3342 | return 0; |
| 3343 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3344 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 3345 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3346 | |
| 3347 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); |
| 3348 | if (!nl_keys) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3349 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3350 | |
| 3351 | for (i = 0; i < 4; i++) { |
| 3352 | if (!params->wep_key[i]) |
| 3353 | continue; |
| 3354 | |
| 3355 | nl_key = nla_nest_start(msg, i); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3356 | if (!nl_key || |
| 3357 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], |
| 3358 | params->wep_key[i]) || |
| 3359 | nla_put_u32(msg, NL80211_KEY_CIPHER, |
| 3360 | params->wep_key_len[i] == 5 ? |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3361 | RSN_CIPHER_SUITE_WEP40 : |
| 3362 | RSN_CIPHER_SUITE_WEP104) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3363 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
| 3364 | (i == params->wep_tx_keyidx && |
| 3365 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) |
| 3366 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3367 | |
| 3368 | nla_nest_end(msg, nl_key); |
| 3369 | } |
| 3370 | nla_nest_end(msg, nl_keys); |
| 3371 | |
| 3372 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3373 | } |
| 3374 | |
| 3375 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3376 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 3377 | const u8 *addr, int cmd, u16 reason_code, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3378 | int local_state_change, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3379 | struct nl_sock *nl_connect) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3380 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3381 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3382 | struct nl_msg *msg; |
| 3383 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3384 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
| 3385 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
| 3386 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 3387 | (local_state_change && |
| 3388 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { |
| 3389 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3390 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3391 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3392 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3393 | if (nl_connect) |
| 3394 | ret = send_and_recv(drv->global, nl_connect, msg, NULL, NULL); |
| 3395 | else |
| 3396 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3397 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3398 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 3399 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", |
| 3400 | reason_code, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3401 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3402 | return ret; |
| 3403 | } |
| 3404 | |
| 3405 | |
| 3406 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3407 | u16 reason_code, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3408 | struct nl_sock *nl_connect) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3409 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3410 | int ret; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3411 | int drv_associated = drv->associated; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3412 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3413 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3414 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3415 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3416 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3417 | reason_code, 0, nl_connect); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3418 | /* |
| 3419 | * For locally generated disconnect, supplicant already generates a |
| 3420 | * DEAUTH event, so ignore the event from NL80211. |
| 3421 | */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3422 | drv->ignore_next_local_disconnect = drv_associated && (ret == 0); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3423 | |
| 3424 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3425 | } |
| 3426 | |
| 3427 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3428 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 3429 | const u8 *addr, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3430 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3431 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3432 | int ret; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3433 | int drv_associated = drv->associated; |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3434 | |
| 3435 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3436 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3437 | return nl80211_leave_ibss(drv, 1); |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3438 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3439 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3440 | struct nl_sock *nl_connect = NULL; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3441 | |
| 3442 | if (bss->use_nl_connect) |
| 3443 | nl_connect = bss->nl_connect; |
| 3444 | return wpa_driver_nl80211_disconnect(drv, reason_code, |
| 3445 | nl_connect); |
| 3446 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3447 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
| 3448 | __func__, MAC2STR(addr), reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3449 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3450 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3451 | reason_code, 0, NULL); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3452 | /* |
| 3453 | * For locally generated deauthenticate, supplicant already generates a |
| 3454 | * DEAUTH event, so ignore the event from NL80211. |
| 3455 | */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3456 | drv->ignore_next_local_deauth = drv_associated && (ret == 0); |
| 3457 | |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3458 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3459 | } |
| 3460 | |
| 3461 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3462 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
| 3463 | struct wpa_driver_auth_params *params) |
| 3464 | { |
| 3465 | int i; |
| 3466 | |
| 3467 | drv->auth_freq = params->freq; |
| 3468 | drv->auth_alg = params->auth_alg; |
| 3469 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; |
| 3470 | drv->auth_local_state_change = params->local_state_change; |
| 3471 | drv->auth_p2p = params->p2p; |
| 3472 | |
| 3473 | if (params->bssid) |
| 3474 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); |
| 3475 | else |
| 3476 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); |
| 3477 | |
| 3478 | if (params->ssid) { |
| 3479 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); |
| 3480 | drv->auth_ssid_len = params->ssid_len; |
| 3481 | } else |
| 3482 | drv->auth_ssid_len = 0; |
| 3483 | |
| 3484 | |
| 3485 | os_free(drv->auth_ie); |
| 3486 | drv->auth_ie = NULL; |
| 3487 | drv->auth_ie_len = 0; |
| 3488 | if (params->ie) { |
| 3489 | drv->auth_ie = os_malloc(params->ie_len); |
| 3490 | if (drv->auth_ie) { |
| 3491 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); |
| 3492 | drv->auth_ie_len = params->ie_len; |
| 3493 | } |
| 3494 | } |
| 3495 | |
| 3496 | for (i = 0; i < 4; i++) { |
| 3497 | if (params->wep_key[i] && params->wep_key_len[i] && |
| 3498 | params->wep_key_len[i] <= 16) { |
| 3499 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], |
| 3500 | params->wep_key_len[i]); |
| 3501 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; |
| 3502 | } else |
| 3503 | drv->auth_wep_key_len[i] = 0; |
| 3504 | } |
| 3505 | } |
| 3506 | |
| 3507 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3508 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
| 3509 | { |
| 3510 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3511 | |
| 3512 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) |
| 3513 | return; |
| 3514 | |
| 3515 | /* |
| 3516 | * Looks like we failed to unmask 11b rates previously. This could |
| 3517 | * happen, e.g., if the interface was down at the point in time when a |
| 3518 | * P2P group was terminated. |
| 3519 | */ |
| 3520 | wpa_printf(MSG_DEBUG, |
| 3521 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", |
| 3522 | bss->ifname); |
| 3523 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 3524 | } |
| 3525 | |
| 3526 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3527 | static enum nl80211_auth_type get_nl_auth_type(int wpa_auth_alg) |
| 3528 | { |
| 3529 | if (wpa_auth_alg & WPA_AUTH_ALG_OPEN) |
| 3530 | return NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 3531 | if (wpa_auth_alg & WPA_AUTH_ALG_SHARED) |
| 3532 | return NL80211_AUTHTYPE_SHARED_KEY; |
| 3533 | if (wpa_auth_alg & WPA_AUTH_ALG_LEAP) |
| 3534 | return NL80211_AUTHTYPE_NETWORK_EAP; |
| 3535 | if (wpa_auth_alg & WPA_AUTH_ALG_FT) |
| 3536 | return NL80211_AUTHTYPE_FT; |
| 3537 | if (wpa_auth_alg & WPA_AUTH_ALG_SAE) |
| 3538 | return NL80211_AUTHTYPE_SAE; |
| 3539 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS) |
| 3540 | return NL80211_AUTHTYPE_FILS_SK; |
| 3541 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS_SK_PFS) |
| 3542 | return NL80211_AUTHTYPE_FILS_SK_PFS; |
| 3543 | |
| 3544 | return NL80211_AUTHTYPE_MAX; |
| 3545 | } |
| 3546 | |
| 3547 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3548 | static int wpa_driver_nl80211_authenticate( |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3549 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3550 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3551 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3552 | int ret = -1, i; |
| 3553 | struct nl_msg *msg; |
| 3554 | enum nl80211_auth_type type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3555 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3556 | int count = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3557 | int is_retry; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3558 | struct wpa_driver_set_key_params p; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3559 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3560 | nl80211_unmask_11b_rates(bss); |
| 3561 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3562 | is_retry = drv->retry_auth; |
| 3563 | drv->retry_auth = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3564 | drv->ignore_deauth_event = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3565 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3566 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3567 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3568 | if (params->bssid) |
| 3569 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 3570 | else |
| 3571 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3572 | /* FIX: IBSS mode */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3573 | nlmode = params->p2p ? |
| 3574 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 3575 | if (drv->nlmode != nlmode && |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3576 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3577 | return -1; |
| 3578 | |
| 3579 | retry: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3580 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
| 3581 | drv->ifindex); |
| 3582 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3583 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
| 3584 | if (!msg) |
| 3585 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3586 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3587 | os_memset(&p, 0, sizeof(p)); |
| 3588 | p.ifname = bss->ifname; |
| 3589 | p.alg = WPA_ALG_WEP; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3590 | for (i = 0; i < 4; i++) { |
| 3591 | if (!params->wep_key[i]) |
| 3592 | continue; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3593 | p.key_idx = i; |
| 3594 | p.set_tx = i == params->wep_tx_keyidx; |
| 3595 | p.key = params->wep_key[i]; |
| 3596 | p.key_len = params->wep_key_len[i]; |
| 3597 | p.key_flag = i == params->wep_tx_keyidx ? |
| 3598 | KEY_FLAG_GROUP_RX_TX_DEFAULT : |
| 3599 | KEY_FLAG_GROUP_RX_TX; |
| 3600 | wpa_driver_nl80211_set_key(bss, &p); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3601 | if (params->wep_tx_keyidx != i) |
| 3602 | continue; |
| 3603 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3604 | params->wep_key[i], params->wep_key_len[i])) |
| 3605 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3606 | } |
| 3607 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3608 | if (params->bssid) { |
| 3609 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 3610 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3611 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 3612 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3613 | } |
| 3614 | if (params->freq) { |
| 3615 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3616 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
| 3617 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3618 | } |
| 3619 | if (params->ssid) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3620 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
| 3621 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3622 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 3623 | params->ssid)) |
| 3624 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3625 | } |
| 3626 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3627 | if (params->ie && |
| 3628 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) |
| 3629 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3630 | if (params->auth_data) { |
| 3631 | wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data, |
| 3632 | params->auth_data_len); |
| 3633 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len, |
| 3634 | params->auth_data)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3635 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3636 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3637 | type = get_nl_auth_type(params->auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3638 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3639 | if (type == NL80211_AUTHTYPE_MAX || |
| 3640 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3641 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3642 | if (params->local_state_change) { |
| 3643 | wpa_printf(MSG_DEBUG, " * Local state change only"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3644 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
| 3645 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3646 | } |
| 3647 | |
| 3648 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3649 | msg = NULL; |
| 3650 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3651 | wpa_dbg(drv->ctx, MSG_DEBUG, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3652 | "nl80211: MLME command failed (auth): count=%d ret=%d (%s)", |
| 3653 | count, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3654 | count++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3655 | if ((ret == -EALREADY || ret == -EEXIST) && count == 1 && |
| 3656 | params->bssid && !params->local_state_change) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3657 | /* |
| 3658 | * mac80211 does not currently accept new |
| 3659 | * authentication if we are already authenticated. As a |
| 3660 | * workaround, force deauthentication and try again. |
| 3661 | */ |
| 3662 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " |
| 3663 | "after forced deauthentication"); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3664 | drv->ignore_deauth_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3665 | wpa_driver_nl80211_deauthenticate( |
| 3666 | bss, params->bssid, |
| 3667 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 3668 | nlmsg_free(msg); |
| 3669 | goto retry; |
| 3670 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3671 | |
| 3672 | if (ret == -ENOENT && params->freq && !is_retry) { |
| 3673 | /* |
| 3674 | * cfg80211 has likely expired the BSS entry even |
| 3675 | * though it was previously available in our internal |
| 3676 | * BSS table. To recover quickly, start a single |
| 3677 | * channel scan on the specified channel. |
| 3678 | */ |
| 3679 | struct wpa_driver_scan_params scan; |
| 3680 | int freqs[2]; |
| 3681 | |
| 3682 | os_memset(&scan, 0, sizeof(scan)); |
| 3683 | scan.num_ssids = 1; |
| 3684 | if (params->ssid) { |
| 3685 | scan.ssids[0].ssid = params->ssid; |
| 3686 | scan.ssids[0].ssid_len = params->ssid_len; |
| 3687 | } |
| 3688 | freqs[0] = params->freq; |
| 3689 | freqs[1] = 0; |
| 3690 | scan.freqs = freqs; |
| 3691 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " |
| 3692 | "channel scan to refresh cfg80211 BSS " |
| 3693 | "entry"); |
| 3694 | ret = wpa_driver_nl80211_scan(bss, &scan); |
| 3695 | if (ret == 0) { |
| 3696 | nl80211_copy_auth_params(drv, params); |
| 3697 | drv->scan_for_auth = 1; |
| 3698 | } |
| 3699 | } else if (is_retry) { |
| 3700 | /* |
| 3701 | * Need to indicate this with an event since the return |
| 3702 | * value from the retry is not delivered to core code. |
| 3703 | */ |
| 3704 | union wpa_event_data event; |
| 3705 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " |
| 3706 | "failed"); |
| 3707 | os_memset(&event, 0, sizeof(event)); |
| 3708 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, |
| 3709 | ETH_ALEN); |
| 3710 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, |
| 3711 | &event); |
| 3712 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3713 | } else { |
| 3714 | wpa_printf(MSG_DEBUG, |
| 3715 | "nl80211: Authentication request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3716 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3717 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3718 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3719 | nlmsg_free(msg); |
| 3720 | return ret; |
| 3721 | } |
| 3722 | |
| 3723 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3724 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3725 | { |
| 3726 | struct wpa_driver_auth_params params; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3727 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3728 | int i; |
| 3729 | |
| 3730 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); |
| 3731 | |
| 3732 | os_memset(¶ms, 0, sizeof(params)); |
| 3733 | params.freq = drv->auth_freq; |
| 3734 | params.auth_alg = drv->auth_alg; |
| 3735 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; |
| 3736 | params.local_state_change = drv->auth_local_state_change; |
| 3737 | params.p2p = drv->auth_p2p; |
| 3738 | |
| 3739 | if (!is_zero_ether_addr(drv->auth_bssid_)) |
| 3740 | params.bssid = drv->auth_bssid_; |
| 3741 | |
| 3742 | if (drv->auth_ssid_len) { |
| 3743 | params.ssid = drv->auth_ssid; |
| 3744 | params.ssid_len = drv->auth_ssid_len; |
| 3745 | } |
| 3746 | |
| 3747 | params.ie = drv->auth_ie; |
| 3748 | params.ie_len = drv->auth_ie_len; |
| 3749 | |
| 3750 | for (i = 0; i < 4; i++) { |
| 3751 | if (drv->auth_wep_key_len[i]) { |
| 3752 | params.wep_key[i] = drv->auth_wep_key[i]; |
| 3753 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; |
| 3754 | } |
| 3755 | } |
| 3756 | |
| 3757 | drv->retry_auth = 1; |
| 3758 | return wpa_driver_nl80211_authenticate(bss, ¶ms); |
| 3759 | } |
| 3760 | |
| 3761 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3762 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
| 3763 | size_t data_len, int noack, |
| 3764 | unsigned int freq, int no_cck, |
| 3765 | int offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3766 | unsigned int wait_time, |
| 3767 | const u16 *csa_offs, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3768 | size_t csa_offs_len, int no_encrypt) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3769 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3770 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3771 | struct ieee80211_mgmt *mgmt; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3772 | int encrypt = !no_encrypt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3773 | u16 fc; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3774 | int use_cookie = 1; |
| 3775 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3776 | |
| 3777 | mgmt = (struct ieee80211_mgmt *) data; |
| 3778 | fc = le_to_host16(mgmt->frame_control); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3779 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da=" MACSTR |
| 3780 | " 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] | 3781 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3782 | no_encrypt, fc, fc2str(fc), drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3783 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3784 | if ((is_sta_interface(drv->nlmode) || |
| 3785 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3786 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3787 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { |
| 3788 | /* |
| 3789 | * The use of last_mgmt_freq is a bit of a hack, |
| 3790 | * but it works due to the single-threaded nature |
| 3791 | * of wpa_supplicant. |
| 3792 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3793 | if (freq == 0) { |
| 3794 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", |
| 3795 | drv->last_mgmt_freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3796 | freq = drv->last_mgmt_freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3797 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3798 | wait_time = 0; |
| 3799 | use_cookie = 0; |
| 3800 | no_cck = 1; |
| 3801 | offchanok = 1; |
| 3802 | goto send_frame_cmd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3803 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3804 | |
| 3805 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3806 | if (freq == 0) { |
| 3807 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", |
| 3808 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3809 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3810 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3811 | if ((int) freq == bss->freq) |
| 3812 | wait_time = 0; |
| 3813 | goto send_frame_cmd; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 3814 | } |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 3815 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3816 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3817 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 3818 | /* |
| 3819 | * Only one of the authentication frame types is encrypted. |
| 3820 | * In order for static WEP encryption to work properly (i.e., |
| 3821 | * to not encrypt the frame), we need to tell mac80211 about |
| 3822 | * the frames that must not be encrypted. |
| 3823 | */ |
| 3824 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 3825 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); |
| 3826 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
| 3827 | encrypt = 0; |
| 3828 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3829 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 3830 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_STATION && |
| 3831 | (drv->capa.flags & WPA_DRIVER_FLAGS_SAE) && |
| 3832 | !(drv->capa.flags & WPA_DRIVER_FLAGS_SME) && |
| 3833 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3834 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 3835 | freq = nl80211_get_assoc_freq(drv); |
| 3836 | wpa_printf(MSG_DEBUG, |
| 3837 | "nl80211: send_mlme - Use assoc_freq=%u for external auth", |
| 3838 | freq); |
| 3839 | } |
| 3840 | |
| 3841 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3842 | freq = nl80211_get_assoc_freq(drv); |
| 3843 | wpa_printf(MSG_DEBUG, |
| 3844 | "nl80211: send_mlme - Use assoc_freq=%u for IBSS", |
| 3845 | freq); |
| 3846 | } |
| 3847 | if (freq == 0) { |
| 3848 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - Use bss->freq=%u", |
| 3849 | bss->freq); |
| 3850 | freq = bss->freq; |
| 3851 | } |
| 3852 | |
| 3853 | if (drv->use_monitor) { |
| 3854 | wpa_printf(MSG_DEBUG, |
| 3855 | "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor", |
| 3856 | freq, bss->freq); |
| 3857 | return nl80211_send_monitor(drv, data, data_len, encrypt, |
| 3858 | noack); |
| 3859 | } |
| 3860 | |
| 3861 | if (noack || WLAN_FC_GET_TYPE(fc) != WLAN_FC_TYPE_MGMT || |
| 3862 | WLAN_FC_GET_STYPE(fc) != WLAN_FC_STYPE_ACTION) |
| 3863 | use_cookie = 0; |
| 3864 | send_frame_cmd: |
| 3865 | #ifdef CONFIG_TESTING_OPTIONS |
| 3866 | if (no_encrypt && !encrypt && !drv->use_monitor) { |
| 3867 | wpa_printf(MSG_DEBUG, |
| 3868 | "nl80211: Request to send an unencrypted frame - use a monitor interface for this"); |
| 3869 | if (nl80211_create_monitor_interface(drv) < 0) |
| 3870 | return -1; |
| 3871 | res = nl80211_send_monitor(drv, data, data_len, encrypt, |
| 3872 | noack); |
| 3873 | nl80211_remove_monitor_interface(drv); |
| 3874 | return res; |
| 3875 | } |
| 3876 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 3877 | |
| 3878 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame_cmd"); |
| 3879 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, data_len, |
| 3880 | use_cookie, no_cck, noack, offchanok, |
| 3881 | csa_offs, csa_offs_len); |
| 3882 | |
| 3883 | return res; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3884 | } |
| 3885 | |
| 3886 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3887 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
| 3888 | { |
| 3889 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 3890 | u8 rates_len = 0; |
| 3891 | int i; |
| 3892 | |
| 3893 | if (!basic_rates) |
| 3894 | return 0; |
| 3895 | |
| 3896 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) |
| 3897 | rates[rates_len++] = basic_rates[i] / 5; |
| 3898 | |
| 3899 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); |
| 3900 | } |
| 3901 | |
| 3902 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3903 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
| 3904 | int slot, int ht_opmode, int ap_isolate, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3905 | const int *basic_rates) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3906 | { |
| 3907 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3908 | struct nl_msg *msg; |
| 3909 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3910 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
| 3911 | (cts >= 0 && |
| 3912 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || |
| 3913 | (preamble >= 0 && |
| 3914 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || |
| 3915 | (slot >= 0 && |
| 3916 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || |
| 3917 | (ht_opmode >= 0 && |
| 3918 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || |
| 3919 | (ap_isolate >= 0 && |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3920 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
| 3921 | nl80211_put_basic_rates(msg, basic_rates)) { |
| 3922 | nlmsg_free(msg); |
| 3923 | return -ENOBUFS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3924 | } |
| 3925 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3926 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3927 | } |
| 3928 | |
| 3929 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3930 | static int wpa_driver_nl80211_set_acl(void *priv, |
| 3931 | struct hostapd_acl_params *params) |
| 3932 | { |
| 3933 | struct i802_bss *bss = priv; |
| 3934 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3935 | struct nl_msg *msg; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3936 | struct nl_msg *acl; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3937 | unsigned int i; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3938 | int ret; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3939 | |
| 3940 | if (!(drv->capa.max_acl_mac_addrs)) |
| 3941 | return -ENOTSUP; |
| 3942 | |
| 3943 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) |
| 3944 | return -ENOTSUP; |
| 3945 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3946 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
| 3947 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); |
| 3948 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3949 | acl = nlmsg_alloc(); |
| 3950 | if (!acl) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3951 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3952 | for (i = 0; i < params->num_mac_acl; i++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3953 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { |
| 3954 | nlmsg_free(acl); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3955 | return -ENOMEM; |
| 3956 | } |
| 3957 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3958 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3959 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
| 3960 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
| 3961 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : |
| 3962 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || |
| 3963 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
| 3964 | nlmsg_free(msg); |
| 3965 | nlmsg_free(acl); |
| 3966 | return -ENOMEM; |
| 3967 | } |
| 3968 | nlmsg_free(acl); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3969 | |
| 3970 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3971 | if (ret) { |
| 3972 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", |
| 3973 | ret, strerror(-ret)); |
| 3974 | } |
| 3975 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3976 | return ret; |
| 3977 | } |
| 3978 | |
| 3979 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3980 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
| 3981 | { |
| 3982 | if (beacon_int > 0) { |
| 3983 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); |
| 3984 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 3985 | beacon_int); |
| 3986 | } |
| 3987 | |
| 3988 | return 0; |
| 3989 | } |
| 3990 | |
| 3991 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3992 | static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period) |
| 3993 | { |
| 3994 | if (dtim_period > 0) { |
| 3995 | wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period); |
| 3996 | return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); |
| 3997 | } |
| 3998 | |
| 3999 | return 0; |
| 4000 | } |
| 4001 | |
| 4002 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4003 | #ifdef CONFIG_MESH |
| 4004 | static int nl80211_set_mesh_config(void *priv, |
| 4005 | struct wpa_driver_mesh_bss_params *params) |
| 4006 | { |
| 4007 | struct i802_bss *bss = priv; |
| 4008 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4009 | struct nl_msg *msg; |
| 4010 | int ret; |
| 4011 | |
| 4012 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG); |
| 4013 | if (!msg) |
| 4014 | return -1; |
| 4015 | |
| 4016 | ret = nl80211_put_mesh_config(msg, params); |
| 4017 | if (ret < 0) { |
| 4018 | nlmsg_free(msg); |
| 4019 | return ret; |
| 4020 | } |
| 4021 | |
| 4022 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4023 | if (ret) { |
| 4024 | wpa_printf(MSG_ERROR, |
| 4025 | "nl80211: Mesh config set failed: %d (%s)", |
| 4026 | ret, strerror(-ret)); |
| 4027 | return ret; |
| 4028 | } |
| 4029 | return 0; |
| 4030 | } |
| 4031 | #endif /* CONFIG_MESH */ |
| 4032 | |
| 4033 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4034 | static int nl80211_put_beacon_rate(struct nl_msg *msg, const u64 flags, |
| 4035 | struct wpa_driver_ap_params *params) |
| 4036 | { |
| 4037 | struct nlattr *bands, *band; |
| 4038 | struct nl80211_txrate_vht vht_rate; |
| 4039 | |
| 4040 | if (!params->freq || |
| 4041 | (params->beacon_rate == 0 && |
| 4042 | params->rate_type == BEACON_RATE_LEGACY)) |
| 4043 | return 0; |
| 4044 | |
| 4045 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 4046 | if (!bands) |
| 4047 | return -1; |
| 4048 | |
| 4049 | switch (params->freq->mode) { |
| 4050 | case HOSTAPD_MODE_IEEE80211B: |
| 4051 | case HOSTAPD_MODE_IEEE80211G: |
| 4052 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
| 4053 | break; |
| 4054 | case HOSTAPD_MODE_IEEE80211A: |
| 4055 | band = nla_nest_start(msg, NL80211_BAND_5GHZ); |
| 4056 | break; |
| 4057 | case HOSTAPD_MODE_IEEE80211AD: |
| 4058 | band = nla_nest_start(msg, NL80211_BAND_60GHZ); |
| 4059 | break; |
| 4060 | default: |
| 4061 | return 0; |
| 4062 | } |
| 4063 | |
| 4064 | if (!band) |
| 4065 | return -1; |
| 4066 | |
| 4067 | os_memset(&vht_rate, 0, sizeof(vht_rate)); |
| 4068 | |
| 4069 | switch (params->rate_type) { |
| 4070 | case BEACON_RATE_LEGACY: |
| 4071 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) { |
| 4072 | wpa_printf(MSG_INFO, |
| 4073 | "nl80211: Driver does not support setting Beacon frame rate (legacy)"); |
| 4074 | return -1; |
| 4075 | } |
| 4076 | |
| 4077 | if (nla_put_u8(msg, NL80211_TXRATE_LEGACY, |
| 4078 | (u8) params->beacon_rate / 5) || |
| 4079 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || |
| 4080 | (params->freq->vht_enabled && |
| 4081 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4082 | &vht_rate))) |
| 4083 | return -1; |
| 4084 | |
| 4085 | wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)", |
| 4086 | params->beacon_rate); |
| 4087 | break; |
| 4088 | case BEACON_RATE_HT: |
| 4089 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) { |
| 4090 | wpa_printf(MSG_INFO, |
| 4091 | "nl80211: Driver does not support setting Beacon frame rate (HT)"); |
| 4092 | return -1; |
| 4093 | } |
| 4094 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || |
| 4095 | nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) || |
| 4096 | (params->freq->vht_enabled && |
| 4097 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4098 | &vht_rate))) |
| 4099 | return -1; |
| 4100 | wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u", |
| 4101 | params->beacon_rate); |
| 4102 | break; |
| 4103 | case BEACON_RATE_VHT: |
| 4104 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) { |
| 4105 | wpa_printf(MSG_INFO, |
| 4106 | "nl80211: Driver does not support setting Beacon frame rate (VHT)"); |
| 4107 | return -1; |
| 4108 | } |
| 4109 | vht_rate.mcs[0] = BIT(params->beacon_rate); |
| 4110 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL)) |
| 4111 | return -1; |
| 4112 | if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL)) |
| 4113 | return -1; |
| 4114 | if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 4115 | &vht_rate)) |
| 4116 | return -1; |
| 4117 | wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u", |
| 4118 | params->beacon_rate); |
| 4119 | break; |
| 4120 | } |
| 4121 | |
| 4122 | nla_nest_end(msg, band); |
| 4123 | nla_nest_end(msg, bands); |
| 4124 | |
| 4125 | return 0; |
| 4126 | } |
| 4127 | |
| 4128 | |
| 4129 | static int nl80211_set_multicast_to_unicast(struct i802_bss *bss, |
| 4130 | int multicast_to_unicast) |
| 4131 | { |
| 4132 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4133 | struct nl_msg *msg; |
| 4134 | int ret; |
| 4135 | |
| 4136 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST); |
| 4137 | if (!msg || |
| 4138 | (multicast_to_unicast && |
| 4139 | nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) { |
| 4140 | wpa_printf(MSG_ERROR, |
| 4141 | "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s", |
| 4142 | bss->ifname); |
| 4143 | nlmsg_free(msg); |
| 4144 | return -ENOBUFS; |
| 4145 | } |
| 4146 | |
| 4147 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4148 | |
| 4149 | switch (ret) { |
| 4150 | case 0: |
| 4151 | wpa_printf(MSG_DEBUG, |
| 4152 | "nl80211: multicast to unicast %s on interface %s", |
| 4153 | multicast_to_unicast ? "enabled" : "disabled", |
| 4154 | bss->ifname); |
| 4155 | break; |
| 4156 | case -EOPNOTSUPP: |
| 4157 | if (!multicast_to_unicast) |
| 4158 | break; |
| 4159 | wpa_printf(MSG_INFO, |
| 4160 | "nl80211: multicast to unicast not supported on interface %s", |
| 4161 | bss->ifname); |
| 4162 | break; |
| 4163 | default: |
| 4164 | wpa_printf(MSG_ERROR, |
| 4165 | "nl80211: %s multicast to unicast failed with %d (%s) on interface %s", |
| 4166 | multicast_to_unicast ? "enabling" : "disabling", |
| 4167 | ret, strerror(-ret), bss->ifname); |
| 4168 | break; |
| 4169 | } |
| 4170 | |
| 4171 | return ret; |
| 4172 | } |
| 4173 | |
| 4174 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4175 | static int wpa_driver_nl80211_set_ap(void *priv, |
| 4176 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4177 | { |
| 4178 | struct i802_bss *bss = priv; |
| 4179 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4180 | struct nl_msg *msg; |
| 4181 | u8 cmd = NL80211_CMD_NEW_BEACON; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4182 | int ret = -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4183 | int beacon_set; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4184 | int num_suites; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 4185 | u32 suites[20], suite; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4186 | u32 ver; |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4187 | #ifdef CONFIG_MESH |
| 4188 | struct wpa_driver_mesh_bss_params mesh_params; |
| 4189 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4190 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4191 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4192 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4193 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
| 4194 | beacon_set); |
| 4195 | if (beacon_set) |
| 4196 | cmd = NL80211_CMD_SET_BEACON; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4197 | else if (!drv->device_ap_sme && !drv->use_monitor && |
| 4198 | !nl80211_get_wiphy_data_ap(bss)) |
| 4199 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4200 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4201 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
| 4202 | params->head, params->head_len); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4203 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
| 4204 | params->tail, params->tail_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4205 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4206 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4207 | wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate); |
| 4208 | wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4209 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4210 | wpa_printf(MSG_DEBUG, "nl80211: ssid=%s", |
| 4211 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4212 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 4213 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
| 4214 | params->head) || |
| 4215 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, |
| 4216 | params->tail) || |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4217 | nl80211_put_beacon_int(msg, params->beacon_int) || |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4218 | nl80211_put_beacon_rate(msg, drv->capa.flags, params) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4219 | nl80211_put_dtim_period(msg, params->dtim_period) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4220 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 4221 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4222 | if (params->proberesp && params->proberesp_len) { |
| 4223 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", |
| 4224 | params->proberesp, params->proberesp_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4225 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
| 4226 | params->proberesp)) |
| 4227 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4228 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4229 | switch (params->hide_ssid) { |
| 4230 | case NO_SSID_HIDING: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4231 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4232 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 4233 | NL80211_HIDDEN_SSID_NOT_IN_USE)) |
| 4234 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4235 | break; |
| 4236 | case HIDDEN_SSID_ZERO_LEN: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4237 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4238 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 4239 | NL80211_HIDDEN_SSID_ZERO_LEN)) |
| 4240 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4241 | break; |
| 4242 | case HIDDEN_SSID_ZERO_CONTENTS: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4243 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4244 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 4245 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) |
| 4246 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4247 | break; |
| 4248 | } |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4249 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4250 | if (params->privacy && |
| 4251 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 4252 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4253 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4254 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
| 4255 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { |
| 4256 | /* Leave out the attribute */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4257 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
| 4258 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 4259 | NL80211_AUTHTYPE_SHARED_KEY)) |
| 4260 | goto fail; |
| 4261 | } else { |
| 4262 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 4263 | NL80211_AUTHTYPE_OPEN_SYSTEM)) |
| 4264 | goto fail; |
| 4265 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4266 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4267 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4268 | ver = 0; |
| 4269 | if (params->wpa_version & WPA_PROTO_WPA) |
| 4270 | ver |= NL80211_WPA_VERSION_1; |
| 4271 | if (params->wpa_version & WPA_PROTO_RSN) |
| 4272 | ver |= NL80211_WPA_VERSION_2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4273 | if (ver && |
| 4274 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 4275 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4276 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4277 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
| 4278 | params->key_mgmt_suites); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 4279 | num_suites = wpa_key_mgmt_to_suites(params->key_mgmt_suites, |
| 4280 | suites, ARRAY_SIZE(suites)); |
| 4281 | if (num_suites > NL80211_MAX_NR_AKM_SUITES) |
| 4282 | wpa_printf(MSG_WARNING, |
| 4283 | "nl80211: Not enough room for all AKM suites (num_suites=%d > NL80211_MAX_NR_AKM_SUITES)", |
| 4284 | num_suites); |
| 4285 | else if (num_suites && |
| 4286 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), |
| 4287 | suites)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4288 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4289 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4290 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4291 | (!params->pairwise_ciphers || |
| 4292 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) && |
| 4293 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 4294 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4295 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4296 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4297 | if (drv->device_ap_sme && |
| 4298 | (params->key_mgmt_suites & WPA_KEY_MGMT_SAE) && |
| 4299 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) |
| 4300 | goto fail; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 4301 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4302 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
| 4303 | params->pairwise_ciphers); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4304 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
| 4305 | suites, ARRAY_SIZE(suites)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4306 | if (num_suites && |
| 4307 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 4308 | num_suites * sizeof(u32), suites)) |
| 4309 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4310 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4311 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
| 4312 | params->group_cipher); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4313 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4314 | if (suite && |
| 4315 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) |
| 4316 | goto fail; |
| 4317 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4318 | if (params->beacon_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4319 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
| 4320 | params->beacon_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4321 | if (nla_put(msg, NL80211_ATTR_IE, |
| 4322 | wpabuf_len(params->beacon_ies), |
| 4323 | wpabuf_head(params->beacon_ies))) |
| 4324 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4325 | } |
| 4326 | if (params->proberesp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4327 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
| 4328 | params->proberesp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4329 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 4330 | wpabuf_len(params->proberesp_ies), |
| 4331 | wpabuf_head(params->proberesp_ies))) |
| 4332 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4333 | } |
| 4334 | if (params->assocresp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4335 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
| 4336 | params->assocresp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4337 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 4338 | wpabuf_len(params->assocresp_ies), |
| 4339 | wpabuf_head(params->assocresp_ies))) |
| 4340 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4341 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4342 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4343 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4344 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
| 4345 | params->ap_max_inactivity); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4346 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
| 4347 | params->ap_max_inactivity)) |
| 4348 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4349 | } |
| 4350 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4351 | #ifdef CONFIG_P2P |
| 4352 | if (params->p2p_go_ctwindow > 0) { |
| 4353 | if (drv->p2p_go_ctwindow_supported) { |
| 4354 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", |
| 4355 | params->p2p_go_ctwindow); |
| 4356 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, |
| 4357 | params->p2p_go_ctwindow)) |
| 4358 | goto fail; |
| 4359 | } else { |
| 4360 | wpa_printf(MSG_INFO, |
| 4361 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); |
| 4362 | } |
| 4363 | } |
| 4364 | #endif /* CONFIG_P2P */ |
| 4365 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4366 | if (params->pbss) { |
| 4367 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); |
| 4368 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 4369 | goto fail; |
| 4370 | } |
| 4371 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4372 | if (params->ftm_responder) { |
| 4373 | struct nlattr *ftm; |
| 4374 | |
| 4375 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_FTM_RESPONDER)) { |
| 4376 | ret = -ENOTSUP; |
| 4377 | goto fail; |
| 4378 | } |
| 4379 | |
| 4380 | ftm = nla_nest_start(msg, NL80211_ATTR_FTM_RESPONDER); |
| 4381 | if (!ftm || |
| 4382 | nla_put_flag(msg, NL80211_FTM_RESP_ATTR_ENABLED) || |
| 4383 | (params->lci && |
| 4384 | nla_put(msg, NL80211_FTM_RESP_ATTR_LCI, |
| 4385 | wpabuf_len(params->lci), |
| 4386 | wpabuf_head(params->lci))) || |
| 4387 | (params->civic && |
| 4388 | nla_put(msg, NL80211_FTM_RESP_ATTR_CIVICLOC, |
| 4389 | wpabuf_len(params->civic), |
| 4390 | wpabuf_head(params->civic)))) |
| 4391 | goto fail; |
| 4392 | nla_nest_end(msg, ftm); |
| 4393 | } |
| 4394 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4395 | #ifdef CONFIG_IEEE80211AX |
| 4396 | if (params->he_spr) { |
| 4397 | struct nlattr *spr; |
| 4398 | |
| 4399 | spr = nla_nest_start(msg, NL80211_ATTR_HE_OBSS_PD); |
| 4400 | wpa_printf(MSG_DEBUG, "nl80211: he_spr=%d", params->he_spr); |
| 4401 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 4402 | if (!spr || |
| 4403 | nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MIN_OFFSET, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4404 | params->he_spr_srg_obss_pd_min_offset) || |
| 4405 | nla_put_u8(msg, NL80211_HE_OBSS_PD_ATTR_MAX_OFFSET, |
| 4406 | params->he_spr_srg_obss_pd_max_offset)) |
| 4407 | goto fail; |
| 4408 | |
| 4409 | nla_nest_end(msg, spr); |
| 4410 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 4411 | |
| 4412 | if (params->freq && params->freq->he_enabled) { |
| 4413 | struct nlattr *bss_color; |
| 4414 | |
| 4415 | bss_color = nla_nest_start(msg, NL80211_ATTR_HE_BSS_COLOR); |
| 4416 | if (!bss_color || |
| 4417 | (params->he_bss_color_disabled && |
| 4418 | nla_put_flag(msg, NL80211_HE_BSS_COLOR_ATTR_DISABLED)) || |
| 4419 | (params->he_bss_color_partial && |
| 4420 | nla_put_flag(msg, NL80211_HE_BSS_COLOR_ATTR_PARTIAL)) || |
| 4421 | nla_put_u8(msg, NL80211_HE_BSS_COLOR_ATTR_COLOR, |
| 4422 | params->he_bss_color)) |
| 4423 | goto fail; |
| 4424 | nla_nest_end(msg, bss_color); |
| 4425 | } |
| 4426 | |
| 4427 | if (params->twt_responder) { |
| 4428 | wpa_printf(MSG_DEBUG, "nl80211: twt_responder=%d", |
| 4429 | params->twt_responder); |
| 4430 | if (nla_put_flag(msg, NL80211_ATTR_TWT_RESPONDER)) |
| 4431 | goto fail; |
| 4432 | } |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4433 | #endif /* CONFIG_IEEE80211AX */ |
| 4434 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4435 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4436 | if (ret) { |
| 4437 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", |
| 4438 | ret, strerror(-ret)); |
| 4439 | } else { |
| 4440 | bss->beacon_set = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4441 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
| 4442 | params->short_slot_time, params->ht_opmode, |
| 4443 | params->isolate, params->basic_rates); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4444 | nl80211_set_multicast_to_unicast(bss, |
| 4445 | params->multicast_to_unicast); |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4446 | if (beacon_set && params->freq && |
| 4447 | params->freq->bandwidth != bss->bandwidth) { |
| 4448 | wpa_printf(MSG_DEBUG, |
| 4449 | "nl80211: Update BSS %s bandwidth: %d -> %d", |
| 4450 | bss->ifname, bss->bandwidth, |
| 4451 | params->freq->bandwidth); |
| 4452 | ret = nl80211_set_channel(bss, params->freq, 1); |
| 4453 | if (ret) { |
| 4454 | wpa_printf(MSG_DEBUG, |
| 4455 | "nl80211: Frequency set failed: %d (%s)", |
| 4456 | ret, strerror(-ret)); |
| 4457 | } else { |
| 4458 | wpa_printf(MSG_DEBUG, |
| 4459 | "nl80211: Frequency set succeeded for ht2040 coex"); |
| 4460 | bss->bandwidth = params->freq->bandwidth; |
| 4461 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4462 | } else if (!beacon_set && params->freq) { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4463 | /* |
| 4464 | * cfg80211 updates the driver on frequence change in AP |
| 4465 | * mode only at the point when beaconing is started, so |
| 4466 | * set the initial value here. |
| 4467 | */ |
| 4468 | bss->bandwidth = params->freq->bandwidth; |
| 4469 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4470 | } |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4471 | |
| 4472 | #ifdef CONFIG_MESH |
| 4473 | if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) { |
| 4474 | os_memset(&mesh_params, 0, sizeof(mesh_params)); |
| 4475 | mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE; |
| 4476 | mesh_params.ht_opmode = params->ht_opmode; |
| 4477 | ret = nl80211_set_mesh_config(priv, &mesh_params); |
| 4478 | if (ret < 0) |
| 4479 | return ret; |
| 4480 | } |
| 4481 | #endif /* CONFIG_MESH */ |
| 4482 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4483 | return ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4484 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4485 | nlmsg_free(msg); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4486 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4487 | } |
| 4488 | |
| 4489 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4490 | static int nl80211_put_freq_params(struct nl_msg *msg, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4491 | const struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4492 | { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4493 | enum hostapd_hw_mode hw_mode; |
| 4494 | int is_24ghz; |
| 4495 | u8 channel; |
| 4496 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4497 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4498 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
| 4499 | return -ENOBUFS; |
| 4500 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4501 | wpa_printf(MSG_DEBUG, " * he_enabled=%d", freq->he_enabled); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4502 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
| 4503 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); |
| 4504 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4505 | hw_mode = ieee80211_freq_to_chan(freq->freq, &channel); |
| 4506 | is_24ghz = hw_mode == HOSTAPD_MODE_IEEE80211G || |
| 4507 | hw_mode == HOSTAPD_MODE_IEEE80211B; |
| 4508 | |
| 4509 | if (freq->vht_enabled || (freq->he_enabled && !is_24ghz)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4510 | enum nl80211_chan_width cw; |
| 4511 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4512 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4513 | switch (freq->bandwidth) { |
| 4514 | case 20: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4515 | cw = NL80211_CHAN_WIDTH_20; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4516 | break; |
| 4517 | case 40: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4518 | cw = NL80211_CHAN_WIDTH_40; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4519 | break; |
| 4520 | case 80: |
| 4521 | if (freq->center_freq2) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4522 | cw = NL80211_CHAN_WIDTH_80P80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4523 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4524 | cw = NL80211_CHAN_WIDTH_80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4525 | break; |
| 4526 | case 160: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4527 | cw = NL80211_CHAN_WIDTH_160; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4528 | break; |
| 4529 | default: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4530 | return -EINVAL; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4531 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4532 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4533 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
| 4534 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", |
| 4535 | freq->center_freq1); |
| 4536 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", |
| 4537 | freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4538 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
| 4539 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, |
| 4540 | freq->center_freq1) || |
| 4541 | (freq->center_freq2 && |
| 4542 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 4543 | freq->center_freq2))) |
| 4544 | return -ENOBUFS; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4545 | } else if (freq->ht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4546 | enum nl80211_channel_type ct; |
| 4547 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4548 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
| 4549 | freq->sec_channel_offset); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4550 | switch (freq->sec_channel_offset) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4551 | case -1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4552 | ct = NL80211_CHAN_HT40MINUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4553 | break; |
| 4554 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4555 | ct = NL80211_CHAN_HT40PLUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4556 | break; |
| 4557 | default: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4558 | ct = NL80211_CHAN_HT20; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4559 | break; |
| 4560 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4561 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4562 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4563 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
| 4564 | return -ENOBUFS; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4565 | } else if (freq->edmg.channels && freq->edmg.bw_config) { |
| 4566 | wpa_printf(MSG_DEBUG, |
| 4567 | " * EDMG configuration: channels=0x%x bw_config=%d", |
| 4568 | freq->edmg.channels, freq->edmg.bw_config); |
| 4569 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS, |
| 4570 | freq->edmg.channels) || |
| 4571 | nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG, |
| 4572 | freq->edmg.bw_config)) |
| 4573 | return -1; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4574 | } else { |
| 4575 | wpa_printf(MSG_DEBUG, " * channel_type=%d", |
| 4576 | NL80211_CHAN_NO_HT); |
| 4577 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 4578 | NL80211_CHAN_NO_HT)) |
| 4579 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4580 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4581 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4582 | } |
| 4583 | |
| 4584 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4585 | static int nl80211_set_channel(struct i802_bss *bss, |
| 4586 | struct hostapd_freq_params *freq, int set_chan) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4587 | { |
| 4588 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4589 | struct nl_msg *msg; |
| 4590 | int ret; |
| 4591 | |
| 4592 | wpa_printf(MSG_DEBUG, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4593 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, he_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
| 4594 | freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4595 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4596 | |
| 4597 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
| 4598 | NL80211_CMD_SET_WIPHY); |
| 4599 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { |
| 4600 | nlmsg_free(msg); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4601 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4602 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4603 | |
| 4604 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4605 | if (ret == 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4606 | bss->freq = freq->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4607 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4608 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4609 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4610 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4611 | return -1; |
| 4612 | } |
| 4613 | |
| 4614 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4615 | static u32 sta_flags_nl80211(int flags) |
| 4616 | { |
| 4617 | u32 f = 0; |
| 4618 | |
| 4619 | if (flags & WPA_STA_AUTHORIZED) |
| 4620 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 4621 | if (flags & WPA_STA_WMM) |
| 4622 | f |= BIT(NL80211_STA_FLAG_WME); |
| 4623 | if (flags & WPA_STA_SHORT_PREAMBLE) |
| 4624 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
| 4625 | if (flags & WPA_STA_MFP) |
| 4626 | f |= BIT(NL80211_STA_FLAG_MFP); |
| 4627 | if (flags & WPA_STA_TDLS_PEER) |
| 4628 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4629 | if (flags & WPA_STA_AUTHENTICATED) |
| 4630 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4631 | if (flags & WPA_STA_ASSOCIATED) |
| 4632 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4633 | |
| 4634 | return f; |
| 4635 | } |
| 4636 | |
| 4637 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4638 | #ifdef CONFIG_MESH |
| 4639 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) |
| 4640 | { |
| 4641 | switch (state) { |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4642 | case PLINK_IDLE: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4643 | return NL80211_PLINK_LISTEN; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4644 | case PLINK_OPN_SNT: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4645 | return NL80211_PLINK_OPN_SNT; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4646 | case PLINK_OPN_RCVD: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4647 | return NL80211_PLINK_OPN_RCVD; |
| 4648 | case PLINK_CNF_RCVD: |
| 4649 | return NL80211_PLINK_CNF_RCVD; |
| 4650 | case PLINK_ESTAB: |
| 4651 | return NL80211_PLINK_ESTAB; |
| 4652 | case PLINK_HOLDING: |
| 4653 | return NL80211_PLINK_HOLDING; |
| 4654 | case PLINK_BLOCKED: |
| 4655 | return NL80211_PLINK_BLOCKED; |
| 4656 | default: |
| 4657 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", |
| 4658 | state); |
| 4659 | } |
| 4660 | return -1; |
| 4661 | } |
| 4662 | #endif /* CONFIG_MESH */ |
| 4663 | |
| 4664 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4665 | static int wpa_driver_nl80211_sta_add(void *priv, |
| 4666 | struct hostapd_sta_add_params *params) |
| 4667 | { |
| 4668 | struct i802_bss *bss = priv; |
| 4669 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4670 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4671 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4672 | int ret = -ENOBUFS; |
| 4673 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4674 | if ((params->flags & WPA_STA_TDLS_PEER) && |
| 4675 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 4676 | return -EOPNOTSUPP; |
| 4677 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4678 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
| 4679 | params->set ? "Set" : "Add", MAC2STR(params->addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4680 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
| 4681 | NL80211_CMD_NEW_STATION); |
| 4682 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) |
| 4683 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4684 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4685 | /* |
| 4686 | * Set the below properties only in one of the following cases: |
| 4687 | * 1. New station is added, already associated. |
| 4688 | * 2. Set WPA_STA_TDLS_PEER station. |
| 4689 | * 3. Set an already added unassociated station, if driver supports |
| 4690 | * full AP client state. (Set these properties after station became |
| 4691 | * associated will be rejected by the driver). |
| 4692 | */ |
| 4693 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
| 4694 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 4695 | (params->flags & WPA_STA_ASSOCIATED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4696 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
| 4697 | params->supp_rates, params->supp_rates_len); |
| 4698 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
| 4699 | params->capability); |
| 4700 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, |
| 4701 | params->supp_rates_len, params->supp_rates) || |
| 4702 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, |
| 4703 | params->capability)) |
| 4704 | goto fail; |
| 4705 | |
| 4706 | if (params->ht_capabilities) { |
| 4707 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
| 4708 | (u8 *) params->ht_capabilities, |
| 4709 | sizeof(*params->ht_capabilities)); |
| 4710 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
| 4711 | sizeof(*params->ht_capabilities), |
| 4712 | params->ht_capabilities)) |
| 4713 | goto fail; |
| 4714 | } |
| 4715 | |
| 4716 | if (params->vht_capabilities) { |
| 4717 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
| 4718 | (u8 *) params->vht_capabilities, |
| 4719 | sizeof(*params->vht_capabilities)); |
| 4720 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
| 4721 | sizeof(*params->vht_capabilities), |
| 4722 | params->vht_capabilities)) |
| 4723 | goto fail; |
| 4724 | } |
| 4725 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 4726 | if (params->he_capab) { |
| 4727 | wpa_hexdump(MSG_DEBUG, " * he_capab", |
| 4728 | params->he_capab, params->he_capab_len); |
| 4729 | if (nla_put(msg, NL80211_ATTR_HE_CAPABILITY, |
| 4730 | params->he_capab_len, params->he_capab)) |
| 4731 | goto fail; |
| 4732 | } |
| 4733 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4734 | if (params->ext_capab) { |
| 4735 | wpa_hexdump(MSG_DEBUG, " * ext_capab", |
| 4736 | params->ext_capab, params->ext_capab_len); |
| 4737 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
| 4738 | params->ext_capab_len, params->ext_capab)) |
| 4739 | goto fail; |
| 4740 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4741 | |
| 4742 | if (is_ap_interface(drv->nlmode) && |
| 4743 | nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS, |
| 4744 | params->support_p2p_ps ? |
| 4745 | NL80211_P2P_PS_SUPPORTED : |
| 4746 | NL80211_P2P_PS_UNSUPPORTED)) |
| 4747 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4748 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4749 | if (!params->set) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4750 | if (params->aid) { |
| 4751 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4752 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
| 4753 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4754 | } else { |
| 4755 | /* |
| 4756 | * cfg80211 validates that AID is non-zero, so we have |
| 4757 | * to make this a non-zero value for the TDLS case where |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4758 | * a dummy STA entry is used for now and for a station |
| 4759 | * that is still not associated. |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4760 | */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4761 | wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)", |
| 4762 | (params->flags & WPA_STA_TDLS_PEER) ? |
| 4763 | "TDLS" : "UNASSOC_STA"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4764 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
| 4765 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4766 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4767 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 4768 | params->listen_interval); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4769 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 4770 | params->listen_interval)) |
| 4771 | goto fail; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4772 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
| 4773 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4774 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
| 4775 | goto fail; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4776 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 4777 | (params->flags & WPA_STA_ASSOCIATED)) { |
| 4778 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
| 4779 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 4780 | params->listen_interval); |
| 4781 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || |
| 4782 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 4783 | params->listen_interval)) |
| 4784 | goto fail; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4785 | } |
| 4786 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 4787 | if (params->vht_opmode_enabled) { |
| 4788 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4789 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
| 4790 | params->vht_opmode)) |
| 4791 | goto fail; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4792 | } |
| 4793 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4794 | if (params->supp_channels) { |
| 4795 | wpa_hexdump(MSG_DEBUG, " * supported channels", |
| 4796 | params->supp_channels, params->supp_channels_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4797 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
| 4798 | params->supp_channels_len, params->supp_channels)) |
| 4799 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4800 | } |
| 4801 | |
| 4802 | if (params->supp_oper_classes) { |
| 4803 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", |
| 4804 | params->supp_oper_classes, |
| 4805 | params->supp_oper_classes_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4806 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
| 4807 | params->supp_oper_classes_len, |
| 4808 | params->supp_oper_classes)) |
| 4809 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4810 | } |
| 4811 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4812 | os_memset(&upd, 0, sizeof(upd)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4813 | upd.set = sta_flags_nl80211(params->flags); |
| 4814 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4815 | |
| 4816 | /* |
| 4817 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH |
| 4818 | * flags, as nl80211 driver moves a new station, by default, into |
| 4819 | * associated state. |
| 4820 | * |
| 4821 | * On the other hand, if the driver supports that feature and the |
| 4822 | * station is added in unauthenticated state, set the |
| 4823 | * authenticated/associated bits in the mask to prevent moving this |
| 4824 | * station to associated state before it is actually associated. |
| 4825 | * |
| 4826 | * This is irrelevant for mesh mode where the station is added to the |
| 4827 | * driver as authenticated already, and ASSOCIATED isn't part of the |
| 4828 | * nl80211 API. |
| 4829 | */ |
| 4830 | if (!is_mesh_interface(drv->nlmode)) { |
| 4831 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { |
| 4832 | wpa_printf(MSG_DEBUG, |
| 4833 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); |
| 4834 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4835 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); |
| 4836 | } else if (!params->set && |
| 4837 | !(params->flags & WPA_STA_TDLS_PEER)) { |
| 4838 | if (!(params->flags & WPA_STA_AUTHENTICATED)) |
| 4839 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
| 4840 | if (!(params->flags & WPA_STA_ASSOCIATED)) |
| 4841 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 4842 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4843 | #ifdef CONFIG_MESH |
| 4844 | } else { |
| 4845 | if (params->plink_state == PLINK_ESTAB && params->peer_aid) { |
| 4846 | ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID, |
| 4847 | params->peer_aid); |
| 4848 | if (ret) |
| 4849 | goto fail; |
| 4850 | } |
| 4851 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4852 | } |
| 4853 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4854 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
| 4855 | upd.set, upd.mask); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4856 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 4857 | goto fail; |
| 4858 | |
| 4859 | #ifdef CONFIG_MESH |
| 4860 | if (params->plink_state && |
| 4861 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, |
| 4862 | sta_plink_state_nl80211(params->plink_state))) |
| 4863 | goto fail; |
| 4864 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4865 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 4866 | if ((!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
| 4867 | FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) && |
| 4868 | (params->flags & WPA_STA_WMM)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4869 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 4870 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4871 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4872 | if (!wme || |
| 4873 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 4874 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || |
| 4875 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, |
| 4876 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
| 4877 | WMM_QOSINFO_STA_SP_MASK)) |
| 4878 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4879 | nla_nest_end(msg, wme); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4880 | } |
| 4881 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4882 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4883 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4884 | if (ret) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4885 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
| 4886 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, |
| 4887 | strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4888 | if (ret == -EEXIST) |
| 4889 | ret = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4890 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4891 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4892 | return ret; |
| 4893 | } |
| 4894 | |
| 4895 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4896 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
| 4897 | { |
| 4898 | #ifdef CONFIG_LIBNL3_ROUTE |
| 4899 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4900 | struct rtnl_neigh *rn; |
| 4901 | struct nl_addr *nl_addr; |
| 4902 | int err; |
| 4903 | |
| 4904 | rn = rtnl_neigh_alloc(); |
| 4905 | if (!rn) |
| 4906 | return; |
| 4907 | |
| 4908 | rtnl_neigh_set_family(rn, AF_BRIDGE); |
| 4909 | rtnl_neigh_set_ifindex(rn, bss->ifindex); |
| 4910 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); |
| 4911 | if (!nl_addr) { |
| 4912 | rtnl_neigh_put(rn); |
| 4913 | return; |
| 4914 | } |
| 4915 | rtnl_neigh_set_lladdr(rn, nl_addr); |
| 4916 | |
| 4917 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 4918 | if (err < 0) { |
| 4919 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " |
| 4920 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), |
| 4921 | bss->ifindex, nl_geterror(err)); |
| 4922 | } else { |
| 4923 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " |
| 4924 | MACSTR, MAC2STR(addr)); |
| 4925 | } |
| 4926 | |
| 4927 | nl_addr_put(nl_addr); |
| 4928 | rtnl_neigh_put(rn); |
| 4929 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 4930 | } |
| 4931 | |
| 4932 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4933 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
| 4934 | int deauth, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4935 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4936 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4937 | struct nl_msg *msg; |
| 4938 | int ret; |
| 4939 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4940 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
| 4941 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 4942 | (deauth == 0 && |
| 4943 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 4944 | WLAN_FC_STYPE_DISASSOC)) || |
| 4945 | (deauth == 1 && |
| 4946 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 4947 | WLAN_FC_STYPE_DEAUTH)) || |
| 4948 | (reason_code && |
| 4949 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { |
| 4950 | nlmsg_free(msg); |
| 4951 | return -ENOBUFS; |
| 4952 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4953 | |
| 4954 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 4955 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
| 4956 | " --> %d (%s)", |
| 4957 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4958 | |
| 4959 | if (drv->rtnl_sk) |
| 4960 | rtnl_neigh_delete_fdb_entry(bss, addr); |
| 4961 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4962 | if (ret == -ENOENT) |
| 4963 | return 0; |
| 4964 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4965 | } |
| 4966 | |
| 4967 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4968 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4969 | { |
| 4970 | struct nl_msg *msg; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4971 | struct wpa_driver_nl80211_data *drv2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4972 | |
| 4973 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
| 4974 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4975 | /* stop listening for EAPOL on this interface */ |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4976 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 4977 | struct wpa_driver_nl80211_data, list) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4978 | { |
| 4979 | del_ifidx(drv2, ifidx, IFIDX_ANY); |
| 4980 | /* Remove all bridges learned for this iface */ |
| 4981 | del_ifidx(drv2, IFIDX_ANY, ifidx); |
| 4982 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4983 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4984 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4985 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 4986 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4987 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
| 4988 | } |
| 4989 | |
| 4990 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 4991 | const char * nl80211_iftype_str(enum nl80211_iftype mode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4992 | { |
| 4993 | switch (mode) { |
| 4994 | case NL80211_IFTYPE_ADHOC: |
| 4995 | return "ADHOC"; |
| 4996 | case NL80211_IFTYPE_STATION: |
| 4997 | return "STATION"; |
| 4998 | case NL80211_IFTYPE_AP: |
| 4999 | return "AP"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 5000 | case NL80211_IFTYPE_AP_VLAN: |
| 5001 | return "AP_VLAN"; |
| 5002 | case NL80211_IFTYPE_WDS: |
| 5003 | return "WDS"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5004 | case NL80211_IFTYPE_MONITOR: |
| 5005 | return "MONITOR"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 5006 | case NL80211_IFTYPE_MESH_POINT: |
| 5007 | return "MESH_POINT"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5008 | case NL80211_IFTYPE_P2P_CLIENT: |
| 5009 | return "P2P_CLIENT"; |
| 5010 | case NL80211_IFTYPE_P2P_GO: |
| 5011 | return "P2P_GO"; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5012 | case NL80211_IFTYPE_P2P_DEVICE: |
| 5013 | return "P2P_DEVICE"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5014 | default: |
| 5015 | return "unknown"; |
| 5016 | } |
| 5017 | } |
| 5018 | |
| 5019 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5020 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
| 5021 | const char *ifname, |
| 5022 | enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5023 | const u8 *addr, int wds, |
| 5024 | int (*handler)(struct nl_msg *, void *), |
| 5025 | void *arg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5026 | { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5027 | struct nl_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5028 | int ifidx; |
| 5029 | int ret = -ENOBUFS; |
| 5030 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5031 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
| 5032 | iftype, nl80211_iftype_str(iftype)); |
| 5033 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5034 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
| 5035 | if (!msg || |
| 5036 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
| 5037 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) |
| 5038 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5039 | |
| 5040 | if (iftype == NL80211_IFTYPE_MONITOR) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5041 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5042 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5043 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5044 | if (!flags || |
| 5045 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) |
| 5046 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5047 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5048 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5049 | } else if (wds) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5050 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
| 5051 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5052 | } |
| 5053 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 5054 | /* |
| 5055 | * Tell cfg80211 that the interface belongs to the socket that created |
| 5056 | * it, and the interface should be deleted when the socket is closed. |
| 5057 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5058 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 5059 | goto fail; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 5060 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5061 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5062 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5063 | if (ret) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5064 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5065 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5066 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
| 5067 | ifname, ret, strerror(-ret)); |
| 5068 | return ret; |
| 5069 | } |
| 5070 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5071 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
| 5072 | return 0; |
| 5073 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5074 | ifidx = if_nametoindex(ifname); |
| 5075 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
| 5076 | ifname, ifidx); |
| 5077 | |
| 5078 | if (ifidx <= 0) |
| 5079 | return -1; |
| 5080 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5081 | /* |
| 5082 | * Some virtual interfaces need to process EAPOL packets and events on |
| 5083 | * the parent interface. This is used mainly with hostapd. |
| 5084 | */ |
| 5085 | if (drv->hostapd || |
| 5086 | iftype == NL80211_IFTYPE_AP_VLAN || |
| 5087 | iftype == NL80211_IFTYPE_WDS || |
| 5088 | iftype == NL80211_IFTYPE_MONITOR) { |
| 5089 | /* start listening for EAPOL on this interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5090 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 5091 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5092 | |
| 5093 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5094 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5095 | nl80211_remove_iface(drv, ifidx); |
| 5096 | return -1; |
| 5097 | } |
| 5098 | |
| 5099 | return ifidx; |
| 5100 | } |
| 5101 | |
| 5102 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5103 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
| 5104 | const char *ifname, enum nl80211_iftype iftype, |
| 5105 | const u8 *addr, int wds, |
| 5106 | int (*handler)(struct nl_msg *, void *), |
| 5107 | void *arg, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5108 | { |
| 5109 | int ret; |
| 5110 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5111 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
| 5112 | arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5113 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5114 | /* if error occurred and interface exists already */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5115 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5116 | if (use_existing) { |
| 5117 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", |
| 5118 | ifname); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5119 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
| 5120 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 5121 | addr) < 0 && |
| 5122 | (linux_set_iface_flags(drv->global->ioctl_sock, |
| 5123 | ifname, 0) < 0 || |
| 5124 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 5125 | addr) < 0 || |
| 5126 | linux_set_iface_flags(drv->global->ioctl_sock, |
| 5127 | ifname, 1) < 0)) |
| 5128 | return -1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5129 | return -ENFILE; |
| 5130 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5131 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
| 5132 | |
| 5133 | /* Try to remove the interface that was already there. */ |
| 5134 | nl80211_remove_iface(drv, if_nametoindex(ifname)); |
| 5135 | |
| 5136 | /* Try to create the interface again */ |
| 5137 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5138 | wds, handler, arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5139 | } |
| 5140 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5141 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
| 5142 | wpa_printf(MSG_DEBUG, |
| 5143 | "nl80211: Interface %s created for P2P - disable 11b rates", |
| 5144 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5145 | nl80211_disable_11b_rates(drv, ret, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5146 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5147 | |
| 5148 | return ret; |
| 5149 | } |
| 5150 | |
| 5151 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5152 | static int nl80211_setup_ap(struct i802_bss *bss) |
| 5153 | { |
| 5154 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5155 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5156 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 5157 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5158 | |
| 5159 | /* |
| 5160 | * Disable Probe Request reporting unless we need it in this way for |
| 5161 | * devices that include the AP SME, in the other case (unless using |
| 5162 | * monitor iface) we'll get it through the nl_mgmt socket instead. |
| 5163 | */ |
| 5164 | if (!drv->device_ap_sme) |
| 5165 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 5166 | |
| 5167 | if (!drv->device_ap_sme && !drv->use_monitor) |
| 5168 | if (nl80211_mgmt_subscribe_ap(bss)) |
| 5169 | return -1; |
| 5170 | |
| 5171 | if (drv->device_ap_sme && !drv->use_monitor) |
| 5172 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5173 | wpa_printf(MSG_DEBUG, |
| 5174 | "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] | 5175 | |
| 5176 | if (!drv->device_ap_sme && drv->use_monitor && |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 5177 | nl80211_create_monitor_interface(drv) && |
| 5178 | !drv->device_ap_sme) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5179 | return -1; |
| 5180 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5181 | if (drv->device_ap_sme && |
| 5182 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { |
| 5183 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " |
| 5184 | "Probe Request frame reporting in AP mode"); |
| 5185 | /* Try to survive without this */ |
| 5186 | } |
| 5187 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5188 | return 0; |
| 5189 | } |
| 5190 | |
| 5191 | |
| 5192 | static void nl80211_teardown_ap(struct i802_bss *bss) |
| 5193 | { |
| 5194 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5195 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5196 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 5197 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5198 | if (drv->device_ap_sme) { |
| 5199 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 5200 | if (!drv->use_monitor) |
| 5201 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); |
| 5202 | } else if (drv->use_monitor) |
| 5203 | nl80211_remove_monitor_interface(drv); |
| 5204 | else |
| 5205 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
| 5206 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5207 | nl80211_put_wiphy_data_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5208 | bss->beacon_set = 0; |
| 5209 | } |
| 5210 | |
| 5211 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 5212 | static int nl80211_tx_control_port(void *priv, const u8 *dest, |
| 5213 | u16 proto, const u8 *buf, size_t len, |
| 5214 | int no_encrypt) |
| 5215 | { |
| 5216 | struct i802_bss *bss = priv; |
| 5217 | struct nl_msg *msg; |
| 5218 | int ret; |
| 5219 | |
| 5220 | wpa_printf(MSG_DEBUG, |
| 5221 | "nl80211: Send over control port dest=" MACSTR |
| 5222 | " proto=0x%04x len=%u no_encrypt=%d", |
| 5223 | MAC2STR(dest), proto, (unsigned int) len, no_encrypt); |
| 5224 | |
| 5225 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CONTROL_PORT_FRAME); |
| 5226 | if (!msg || |
| 5227 | nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, proto) || |
| 5228 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dest) || |
| 5229 | nla_put(msg, NL80211_ATTR_FRAME, len, buf) || |
| 5230 | (no_encrypt && |
| 5231 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) { |
| 5232 | nlmsg_free(msg); |
| 5233 | return -ENOBUFS; |
| 5234 | } |
| 5235 | |
| 5236 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 5237 | if (ret) |
| 5238 | wpa_printf(MSG_DEBUG, |
| 5239 | "nl80211: tx_control_port failed: ret=%d (%s)", |
| 5240 | ret, strerror(-ret)); |
| 5241 | |
| 5242 | return ret; |
| 5243 | } |
| 5244 | |
| 5245 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5246 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
| 5247 | const u8 *addr, const u8 *data, |
| 5248 | size_t data_len) |
| 5249 | { |
| 5250 | struct sockaddr_ll ll; |
| 5251 | int ret; |
| 5252 | |
| 5253 | if (bss->drv->eapol_tx_sock < 0) { |
| 5254 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); |
| 5255 | return -1; |
| 5256 | } |
| 5257 | |
| 5258 | os_memset(&ll, 0, sizeof(ll)); |
| 5259 | ll.sll_family = AF_PACKET; |
| 5260 | ll.sll_ifindex = bss->ifindex; |
| 5261 | ll.sll_protocol = htons(ETH_P_PAE); |
| 5262 | ll.sll_halen = ETH_ALEN; |
| 5263 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); |
| 5264 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, |
| 5265 | (struct sockaddr *) &ll, sizeof(ll)); |
| 5266 | if (ret < 0) |
| 5267 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", |
| 5268 | strerror(errno)); |
| 5269 | |
| 5270 | return ret; |
| 5271 | } |
| 5272 | |
| 5273 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5274 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 5275 | |
| 5276 | static int wpa_driver_nl80211_hapd_send_eapol( |
| 5277 | void *priv, const u8 *addr, const u8 *data, |
| 5278 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
| 5279 | { |
| 5280 | struct i802_bss *bss = priv; |
| 5281 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5282 | struct ieee80211_hdr *hdr; |
| 5283 | size_t len; |
| 5284 | u8 *pos; |
| 5285 | int res; |
| 5286 | int qos = flags & WPA_STA_WMM; |
Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 5287 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 5288 | if (drv->capa.flags & WPA_DRIVER_FLAGS_CONTROL_PORT) |
| 5289 | return nl80211_tx_control_port(bss, addr, ETH_P_EAPOL, |
| 5290 | data, data_len, !encrypt); |
| 5291 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5292 | if (drv->device_ap_sme || !drv->use_monitor) |
| 5293 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
| 5294 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5295 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
| 5296 | data_len; |
| 5297 | hdr = os_zalloc(len); |
| 5298 | if (hdr == NULL) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5299 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
| 5300 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5301 | return -1; |
| 5302 | } |
| 5303 | |
| 5304 | hdr->frame_control = |
| 5305 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); |
| 5306 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 5307 | if (encrypt) |
| 5308 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); |
| 5309 | if (qos) { |
| 5310 | hdr->frame_control |= |
| 5311 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); |
| 5312 | } |
| 5313 | |
| 5314 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 5315 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 5316 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 5317 | pos = (u8 *) (hdr + 1); |
| 5318 | |
| 5319 | if (qos) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 5320 | /* Set highest priority in QoS header */ |
| 5321 | pos[0] = 7; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5322 | pos[1] = 0; |
| 5323 | pos += 2; |
| 5324 | } |
| 5325 | |
| 5326 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); |
| 5327 | pos += sizeof(rfc1042_header); |
| 5328 | WPA_PUT_BE16(pos, ETH_P_PAE); |
| 5329 | pos += 2; |
| 5330 | memcpy(pos, data, data_len); |
| 5331 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 5332 | res = nl80211_send_monitor(drv, hdr, len, encrypt, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5333 | if (res < 0) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 5334 | wpa_printf(MSG_ERROR, |
| 5335 | "hapd_send_eapol - packet len: %lu - failed", |
| 5336 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5337 | } |
| 5338 | os_free(hdr); |
| 5339 | |
| 5340 | return res; |
| 5341 | } |
| 5342 | |
| 5343 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5344 | 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] | 5345 | unsigned int total_flags, |
| 5346 | unsigned int flags_or, |
| 5347 | unsigned int flags_and) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5348 | { |
| 5349 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5350 | struct nl_msg *msg; |
| 5351 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5352 | struct nl80211_sta_flag_update upd; |
| 5353 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5354 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
| 5355 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", |
| 5356 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, |
| 5357 | !!(total_flags & WPA_STA_AUTHORIZED)); |
| 5358 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5359 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5360 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 5361 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5362 | |
| 5363 | /* |
| 5364 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This |
| 5365 | * can be removed eventually. |
| 5366 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5367 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5368 | if (!flags || |
| 5369 | ((total_flags & WPA_STA_AUTHORIZED) && |
| 5370 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || |
| 5371 | ((total_flags & WPA_STA_WMM) && |
| 5372 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || |
| 5373 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && |
| 5374 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || |
| 5375 | ((total_flags & WPA_STA_MFP) && |
| 5376 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || |
| 5377 | ((total_flags & WPA_STA_TDLS_PEER) && |
| 5378 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) |
| 5379 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5380 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5381 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5382 | |
| 5383 | os_memset(&upd, 0, sizeof(upd)); |
| 5384 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); |
| 5385 | upd.set = sta_flags_nl80211(flags_or); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5386 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 5387 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5388 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5389 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 5390 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5391 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5392 | return -ENOBUFS; |
| 5393 | } |
| 5394 | |
| 5395 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 5396 | static int driver_nl80211_sta_set_airtime_weight(void *priv, const u8 *addr, |
| 5397 | unsigned int weight) |
| 5398 | { |
| 5399 | struct i802_bss *bss = priv; |
| 5400 | struct nl_msg *msg; |
| 5401 | |
| 5402 | wpa_printf(MSG_DEBUG, |
| 5403 | "nl80211: Set STA airtime weight - ifname=%s addr=" MACSTR |
| 5404 | " weight=%u", bss->ifname, MAC2STR(addr), weight); |
| 5405 | |
| 5406 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5407 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 5408 | nla_put_u16(msg, NL80211_ATTR_AIRTIME_WEIGHT, weight)) |
| 5409 | goto fail; |
| 5410 | |
| 5411 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 5412 | fail: |
| 5413 | nlmsg_free(msg); |
| 5414 | return -ENOBUFS; |
| 5415 | } |
| 5416 | |
| 5417 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5418 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
| 5419 | struct wpa_driver_associate_params *params) |
| 5420 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5421 | enum nl80211_iftype nlmode, old_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5422 | |
| 5423 | if (params->p2p) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5424 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
| 5425 | "group (GO)"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5426 | nlmode = NL80211_IFTYPE_P2P_GO; |
| 5427 | } else |
| 5428 | nlmode = NL80211_IFTYPE_AP; |
| 5429 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5430 | old_mode = drv->nlmode; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5431 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5432 | nl80211_remove_monitor_interface(drv); |
| 5433 | return -1; |
| 5434 | } |
| 5435 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5436 | if (params->freq.freq && |
| 5437 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5438 | if (old_mode != nlmode) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5439 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5440 | nl80211_remove_monitor_interface(drv); |
| 5441 | return -1; |
| 5442 | } |
| 5443 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5444 | return 0; |
| 5445 | } |
| 5446 | |
| 5447 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5448 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 5449 | int reset_mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5450 | { |
| 5451 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5452 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5453 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5454 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5455 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5456 | if (ret) { |
| 5457 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " |
| 5458 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5459 | } else { |
| 5460 | wpa_printf(MSG_DEBUG, |
| 5461 | "nl80211: Leave IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5462 | } |
| 5463 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5464 | if (reset_mode && |
| 5465 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 5466 | NL80211_IFTYPE_STATION)) { |
| 5467 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 5468 | "station mode"); |
| 5469 | } |
| 5470 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5471 | return ret; |
| 5472 | } |
| 5473 | |
| 5474 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5475 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
| 5476 | struct wpa_driver_associate_params *params) |
| 5477 | { |
| 5478 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) |
| 5479 | return -1; |
| 5480 | |
| 5481 | if (params->htcaps && params->htcaps_mask) { |
| 5482 | int sz = sizeof(struct ieee80211_ht_capabilities); |
| 5483 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); |
| 5484 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", |
| 5485 | params->htcaps_mask, sz); |
| 5486 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, |
| 5487 | params->htcaps) || |
| 5488 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 5489 | params->htcaps_mask)) |
| 5490 | return -1; |
| 5491 | } |
| 5492 | |
| 5493 | #ifdef CONFIG_VHT_OVERRIDES |
| 5494 | if (params->disable_vht) { |
| 5495 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
| 5496 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) |
| 5497 | return -1; |
| 5498 | } |
| 5499 | |
| 5500 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 5501 | int sz = sizeof(struct ieee80211_vht_capabilities); |
| 5502 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); |
| 5503 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", |
| 5504 | params->vhtcaps_mask, sz); |
| 5505 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, |
| 5506 | params->vhtcaps) || |
| 5507 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 5508 | params->vhtcaps_mask)) |
| 5509 | return -1; |
| 5510 | } |
| 5511 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 5512 | |
| 5513 | return 0; |
| 5514 | } |
| 5515 | |
| 5516 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5517 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
| 5518 | struct wpa_driver_associate_params *params) |
| 5519 | { |
| 5520 | struct nl_msg *msg; |
| 5521 | int ret = -1; |
| 5522 | int count = 0; |
| 5523 | |
| 5524 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); |
| 5525 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5526 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5527 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 5528 | "IBSS mode"); |
| 5529 | return -1; |
| 5530 | } |
| 5531 | |
| 5532 | retry: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5533 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
| 5534 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
| 5535 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5536 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5537 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
| 5538 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5539 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 5540 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5541 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 5542 | drv->ssid_len = params->ssid_len; |
| 5543 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5544 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
| 5545 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5546 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5547 | |
| 5548 | ret = nl80211_set_conn_keys(params, msg); |
| 5549 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5550 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5551 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5552 | if (params->bssid && params->fixed_bssid) { |
| 5553 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, |
| 5554 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5555 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 5556 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5557 | } |
| 5558 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5559 | if (params->fixed_freq) { |
| 5560 | wpa_printf(MSG_DEBUG, " * fixed_freq"); |
| 5561 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) |
| 5562 | goto fail; |
| 5563 | } |
| 5564 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5565 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 5566 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 5567 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
| 5568 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5569 | wpa_printf(MSG_DEBUG, " * control port"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5570 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 5571 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5572 | } |
| 5573 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5574 | if (params->wpa_ie) { |
| 5575 | wpa_hexdump(MSG_DEBUG, |
| 5576 | " * Extra IEs for Beacon/Probe Response frames", |
| 5577 | params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5578 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 5579 | params->wpa_ie)) |
| 5580 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5581 | } |
| 5582 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 5583 | ret = nl80211_ht_vht_overrides(msg, params); |
| 5584 | if (ret < 0) |
| 5585 | goto fail; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5586 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5587 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5588 | msg = NULL; |
| 5589 | if (ret) { |
| 5590 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", |
| 5591 | ret, strerror(-ret)); |
| 5592 | count++; |
| 5593 | if (ret == -EALREADY && count == 1) { |
| 5594 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " |
| 5595 | "forced leave"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5596 | nl80211_leave_ibss(drv, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5597 | nlmsg_free(msg); |
| 5598 | goto retry; |
| 5599 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5600 | } else { |
| 5601 | wpa_printf(MSG_DEBUG, |
| 5602 | "nl80211: Join IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5603 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5604 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5605 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5606 | nlmsg_free(msg); |
| 5607 | return ret; |
| 5608 | } |
| 5609 | |
| 5610 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5611 | static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data *drv, |
| 5612 | struct wpa_driver_associate_params *params, |
| 5613 | struct nl_msg *msg) |
| 5614 | { |
| 5615 | if (params->fils_erp_username_len) { |
| 5616 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP EMSKname/username", |
| 5617 | params->fils_erp_username, |
| 5618 | params->fils_erp_username_len); |
| 5619 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_USERNAME, |
| 5620 | params->fils_erp_username_len, |
| 5621 | params->fils_erp_username)) |
| 5622 | return -1; |
| 5623 | } |
| 5624 | |
| 5625 | if (params->fils_erp_realm_len) { |
| 5626 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP Realm", |
| 5627 | params->fils_erp_realm, |
| 5628 | params->fils_erp_realm_len); |
| 5629 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_REALM, |
| 5630 | params->fils_erp_realm_len, params->fils_erp_realm)) |
| 5631 | return -1; |
| 5632 | } |
| 5633 | |
| 5634 | wpa_printf(MSG_DEBUG, " * FILS ERP next seq %u", |
| 5635 | params->fils_erp_next_seq_num); |
| 5636 | if (nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 5637 | params->fils_erp_next_seq_num)) |
| 5638 | return -1; |
| 5639 | |
| 5640 | if (params->fils_erp_rrk_len) { |
| 5641 | wpa_printf(MSG_DEBUG, " * FILS ERP rRK (len=%lu)", |
| 5642 | (unsigned long) params->fils_erp_rrk_len); |
| 5643 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_RRK, |
| 5644 | params->fils_erp_rrk_len, params->fils_erp_rrk)) |
| 5645 | return -1; |
| 5646 | } |
| 5647 | |
| 5648 | return 0; |
| 5649 | } |
| 5650 | |
| 5651 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5652 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
| 5653 | struct wpa_driver_associate_params *params, |
| 5654 | struct nl_msg *msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5655 | { |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5656 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 5657 | return -1; |
| 5658 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5659 | if (params->bssid) { |
| 5660 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 5661 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5662 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 5663 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5664 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5665 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5666 | if (params->bssid_hint) { |
| 5667 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, |
| 5668 | MAC2STR(params->bssid_hint)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5669 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
| 5670 | params->bssid_hint)) |
| 5671 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5672 | } |
| 5673 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5674 | if (params->freq.freq) { |
| 5675 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5676 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 5677 | params->freq.freq)) |
| 5678 | return -1; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5679 | drv->assoc_freq = params->freq.freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5680 | } else |
| 5681 | drv->assoc_freq = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5682 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5683 | if (params->freq_hint) { |
| 5684 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5685 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
| 5686 | params->freq_hint)) |
| 5687 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5688 | } |
| 5689 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5690 | if (params->freq.edmg.channels && params->freq.edmg.bw_config) { |
| 5691 | wpa_printf(MSG_DEBUG, |
| 5692 | " * EDMG configuration: channels=0x%x bw_config=%d", |
| 5693 | params->freq.edmg.channels, |
| 5694 | params->freq.edmg.bw_config); |
| 5695 | if (nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_CHANNELS, |
| 5696 | params->freq.edmg.channels) || |
| 5697 | nla_put_u8(msg, NL80211_ATTR_WIPHY_EDMG_BW_CONFIG, |
| 5698 | params->freq.edmg.bw_config)) |
| 5699 | return -1; |
| 5700 | } |
| 5701 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5702 | if (params->bg_scan_period >= 0) { |
| 5703 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 5704 | params->bg_scan_period); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5705 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 5706 | params->bg_scan_period)) |
| 5707 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5708 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5709 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5710 | if (params->ssid) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5711 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
| 5712 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5713 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 5714 | params->ssid)) |
| 5715 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5716 | if (params->ssid_len > sizeof(drv->ssid)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5717 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5718 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 5719 | drv->ssid_len = params->ssid_len; |
| 5720 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5721 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5722 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5723 | if (params->wpa_ie && |
| 5724 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) |
| 5725 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5726 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5727 | if (params->wpa_proto) { |
| 5728 | enum nl80211_wpa_versions ver = 0; |
| 5729 | |
| 5730 | if (params->wpa_proto & WPA_PROTO_WPA) |
| 5731 | ver |= NL80211_WPA_VERSION_1; |
| 5732 | if (params->wpa_proto & WPA_PROTO_RSN) |
| 5733 | ver |= NL80211_WPA_VERSION_2; |
| 5734 | |
| 5735 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5736 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 5737 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5738 | } |
| 5739 | |
| 5740 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
| 5741 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
| 5742 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5743 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 5744 | cipher)) |
| 5745 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5746 | } |
| 5747 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 5748 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
| 5749 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { |
| 5750 | /* |
| 5751 | * This is likely to work even though many drivers do not |
| 5752 | * advertise support for operations without GTK. |
| 5753 | */ |
| 5754 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); |
| 5755 | } else if (params->group_suite != WPA_CIPHER_NONE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5756 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
| 5757 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5758 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
| 5759 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5760 | } |
| 5761 | |
| 5762 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 5763 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 5764 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || |
| 5765 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5766 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5767 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
| 5768 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5769 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 5770 | params->key_mgmt_suite == WPA_KEY_MGMT_SAE || |
| 5771 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5772 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5773 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 5774 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X_SHA384 || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5775 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA256 || |
| 5776 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA384 || |
| 5777 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA256 || |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5778 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA384 || |
| 5779 | params->key_mgmt_suite == WPA_KEY_MGMT_OWE || |
| 5780 | params->key_mgmt_suite == WPA_KEY_MGMT_DPP) { |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5781 | int mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5782 | |
| 5783 | switch (params->key_mgmt_suite) { |
| 5784 | case WPA_KEY_MGMT_CCKM: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5785 | mgmt = RSN_AUTH_KEY_MGMT_CCKM; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5786 | break; |
| 5787 | case WPA_KEY_MGMT_IEEE8021X: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5788 | mgmt = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5789 | break; |
| 5790 | case WPA_KEY_MGMT_FT_IEEE8021X: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5791 | mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5792 | break; |
| 5793 | case WPA_KEY_MGMT_FT_PSK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5794 | mgmt = RSN_AUTH_KEY_MGMT_FT_PSK; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5795 | break; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5796 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5797 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SHA256; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5798 | break; |
| 5799 | case WPA_KEY_MGMT_PSK_SHA256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5800 | mgmt = RSN_AUTH_KEY_MGMT_PSK_SHA256; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5801 | break; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5802 | case WPA_KEY_MGMT_OSEN: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5803 | mgmt = RSN_AUTH_KEY_MGMT_OSEN; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5804 | break; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 5805 | case WPA_KEY_MGMT_SAE: |
| 5806 | mgmt = RSN_AUTH_KEY_MGMT_SAE; |
| 5807 | break; |
| 5808 | case WPA_KEY_MGMT_FT_SAE: |
| 5809 | mgmt = RSN_AUTH_KEY_MGMT_FT_SAE; |
| 5810 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5811 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5812 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5813 | break; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5814 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5815 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5816 | break; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 5817 | case WPA_KEY_MGMT_FT_IEEE8021X_SHA384: |
| 5818 | mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384; |
| 5819 | break; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5820 | case WPA_KEY_MGMT_FILS_SHA256: |
| 5821 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA256; |
| 5822 | break; |
| 5823 | case WPA_KEY_MGMT_FILS_SHA384: |
| 5824 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA384; |
| 5825 | break; |
| 5826 | case WPA_KEY_MGMT_FT_FILS_SHA256: |
| 5827 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256; |
| 5828 | break; |
| 5829 | case WPA_KEY_MGMT_FT_FILS_SHA384: |
| 5830 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384; |
| 5831 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5832 | case WPA_KEY_MGMT_OWE: |
| 5833 | mgmt = RSN_AUTH_KEY_MGMT_OWE; |
| 5834 | break; |
| 5835 | case WPA_KEY_MGMT_DPP: |
| 5836 | mgmt = RSN_AUTH_KEY_MGMT_DPP; |
| 5837 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5838 | case WPA_KEY_MGMT_PSK: |
| 5839 | default: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5840 | mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5841 | break; |
| 5842 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5843 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5844 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
| 5845 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5846 | } |
| 5847 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5848 | if (params->req_handshake_offload && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5849 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)) { |
| 5850 | wpa_printf(MSG_DEBUG, " * WANT_1X_4WAY_HS"); |
| 5851 | if (nla_put_flag(msg, NL80211_ATTR_WANT_1X_4WAY_HS)) |
| 5852 | return -1; |
| 5853 | } |
| 5854 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5855 | /* Add PSK in case of 4-way handshake offload */ |
| 5856 | if (params->psk && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5857 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5858 | wpa_hexdump_key(MSG_DEBUG, " * PSK", params->psk, 32); |
| 5859 | if (nla_put(msg, NL80211_ATTR_PMK, 32, params->psk)) |
| 5860 | return -1; |
| 5861 | } |
| 5862 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5863 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 5864 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5865 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 5866 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 5867 | (params->pairwise_suite == WPA_CIPHER_NONE || |
| 5868 | params->pairwise_suite == WPA_CIPHER_WEP104 || |
| 5869 | params->pairwise_suite == WPA_CIPHER_WEP40) && |
| 5870 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 5871 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
| 5872 | return -1; |
| 5873 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5874 | if (params->rrm_used) { |
| 5875 | u32 drv_rrm_flags = drv->capa.rrm_flags; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5876 | if ((!((drv_rrm_flags & |
| 5877 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && |
| 5878 | (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && |
| 5879 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5880 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
| 5881 | return -1; |
| 5882 | } |
| 5883 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5884 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5885 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5886 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5887 | if (params->p2p) |
| 5888 | wpa_printf(MSG_DEBUG, " * P2P group"); |
| 5889 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5890 | if (params->pbss) { |
| 5891 | wpa_printf(MSG_DEBUG, " * PBSS"); |
| 5892 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 5893 | return -1; |
| 5894 | } |
| 5895 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 5896 | drv->connect_reassoc = 0; |
| 5897 | if (params->prev_bssid) { |
| 5898 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, |
| 5899 | MAC2STR(params->prev_bssid)); |
| 5900 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
| 5901 | params->prev_bssid)) |
| 5902 | return -1; |
| 5903 | drv->connect_reassoc = 1; |
| 5904 | } |
| 5905 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5906 | if ((params->auth_alg & WPA_AUTH_ALG_FILS) && |
| 5907 | nl80211_put_fils_connect_params(drv, params, msg) != 0) |
| 5908 | return -1; |
| 5909 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 5910 | if ((params->key_mgmt_suite == WPA_KEY_MGMT_SAE || |
| 5911 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5912 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) && |
| 5913 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) |
| 5914 | return -1; |
| 5915 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5916 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5917 | } |
| 5918 | |
| 5919 | |
| 5920 | static int wpa_driver_nl80211_try_connect( |
| 5921 | struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5922 | struct wpa_driver_associate_params *params, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 5923 | struct nl_sock *nl_connect) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5924 | { |
| 5925 | struct nl_msg *msg; |
| 5926 | enum nl80211_auth_type type; |
| 5927 | int ret; |
| 5928 | int algs; |
| 5929 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5930 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5931 | if (params->req_key_mgmt_offload && params->psk && |
| 5932 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 5933 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
| 5934 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { |
| 5935 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); |
| 5936 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); |
| 5937 | if (ret) |
| 5938 | return ret; |
| 5939 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5940 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5941 | |
| 5942 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
| 5943 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5944 | if (!msg) |
| 5945 | return -1; |
| 5946 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5947 | ret = nl80211_connect_common(drv, params, msg); |
| 5948 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5949 | goto fail; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5950 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5951 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 5952 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 5953 | goto fail; |
| 5954 | |
| 5955 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_OPTIONAL && |
| 5956 | (drv->capa.flags & WPA_DRIVER_FLAGS_MFP_OPTIONAL) && |
| 5957 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_OPTIONAL)) |
| 5958 | goto fail; |
| 5959 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5960 | algs = 0; |
| 5961 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 5962 | algs++; |
| 5963 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 5964 | algs++; |
| 5965 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 5966 | algs++; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5967 | if (params->auth_alg & WPA_AUTH_ALG_FILS) |
| 5968 | algs++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5969 | if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 5970 | algs++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5971 | if (algs > 1) { |
| 5972 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " |
| 5973 | "selection"); |
| 5974 | goto skip_auth_type; |
| 5975 | } |
| 5976 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5977 | type = get_nl_auth_type(params->auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5978 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5979 | if (type == NL80211_AUTHTYPE_MAX || |
| 5980 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5981 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5982 | |
| 5983 | skip_auth_type: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5984 | ret = nl80211_set_conn_keys(params, msg); |
| 5985 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5986 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5987 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5988 | if (nl_connect) |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5989 | ret = send_and_recv(drv->global, nl_connect, msg, |
| 5990 | NULL, (void *) -1); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5991 | else |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5992 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5993 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5994 | msg = NULL; |
| 5995 | if (ret) { |
| 5996 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " |
| 5997 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5998 | } else { |
| 5999 | wpa_printf(MSG_DEBUG, |
| 6000 | "nl80211: Connect request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6001 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6002 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6003 | fail: |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6004 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6005 | nlmsg_free(msg); |
| 6006 | return ret; |
| 6007 | |
| 6008 | } |
| 6009 | |
| 6010 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6011 | static int wpa_driver_nl80211_connect( |
| 6012 | struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6013 | struct wpa_driver_associate_params *params, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 6014 | struct nl_sock *nl_connect) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6015 | { |
Jithu Jance | a7c60b4 | 2014-12-03 18:54:40 +0530 | [diff] [blame] | 6016 | int ret; |
| 6017 | |
| 6018 | /* Store the connection attempted bssid for future use */ |
| 6019 | if (params->bssid) |
| 6020 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 6021 | else |
| 6022 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
| 6023 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6024 | ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6025 | if (ret == -EALREADY) { |
| 6026 | /* |
| 6027 | * cfg80211 does not currently accept new connections if |
| 6028 | * we are already connected. As a workaround, force |
| 6029 | * disconnection and try again. |
| 6030 | */ |
| 6031 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " |
| 6032 | "disconnecting before reassociation " |
| 6033 | "attempt"); |
| 6034 | if (wpa_driver_nl80211_disconnect( |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6035 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID, nl_connect)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6036 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6037 | ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 6038 | } |
| 6039 | return ret; |
| 6040 | } |
| 6041 | |
| 6042 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6043 | static int wpa_driver_nl80211_associate( |
| 6044 | void *priv, struct wpa_driver_associate_params *params) |
| 6045 | { |
| 6046 | struct i802_bss *bss = priv; |
| 6047 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6048 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6049 | struct nl_msg *msg; |
| 6050 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6051 | nl80211_unmask_11b_rates(bss); |
| 6052 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6053 | if (params->mode == IEEE80211_MODE_AP) |
| 6054 | return wpa_driver_nl80211_ap(drv, params); |
| 6055 | |
| 6056 | if (params->mode == IEEE80211_MODE_IBSS) |
| 6057 | return wpa_driver_nl80211_ibss(drv, params); |
| 6058 | |
| 6059 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6060 | enum nl80211_iftype nlmode = params->p2p ? |
| 6061 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 6062 | struct nl_sock *nl_connect = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6063 | |
| 6064 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6065 | return -1; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 6066 | if (params->key_mgmt_suite == WPA_KEY_MGMT_SAE || |
| 6067 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6068 | nl_connect = bss->nl_connect; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6069 | bss->use_nl_connect = 1; |
| 6070 | } else { |
| 6071 | bss->use_nl_connect = 0; |
| 6072 | } |
| 6073 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6074 | return wpa_driver_nl80211_connect(drv, params, nl_connect); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6075 | } |
| 6076 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6077 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6078 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6079 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
| 6080 | drv->ifindex); |
| 6081 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6082 | if (!msg) |
| 6083 | return -1; |
| 6084 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6085 | ret = nl80211_connect_common(drv, params, msg); |
| 6086 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6087 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6088 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6089 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 6090 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 6091 | goto fail; |
| 6092 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 6093 | if (params->fils_kek) { |
| 6094 | wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)", |
| 6095 | (unsigned int) params->fils_kek_len); |
| 6096 | if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len, |
| 6097 | params->fils_kek)) |
| 6098 | goto fail; |
| 6099 | } |
| 6100 | if (params->fils_nonces) { |
| 6101 | wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)", |
| 6102 | params->fils_nonces, |
| 6103 | params->fils_nonces_len); |
| 6104 | if (nla_put(msg, NL80211_ATTR_FILS_NONCES, |
| 6105 | params->fils_nonces_len, params->fils_nonces)) |
| 6106 | goto fail; |
| 6107 | } |
| 6108 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6109 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6110 | msg = NULL; |
| 6111 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6112 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 6113 | "nl80211: MLME command failed (assoc): ret=%d (%s)", |
| 6114 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6115 | nl80211_dump_scan(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6116 | } else { |
| 6117 | wpa_printf(MSG_DEBUG, |
| 6118 | "nl80211: Association request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6119 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6120 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6121 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6122 | nlmsg_free(msg); |
| 6123 | return ret; |
| 6124 | } |
| 6125 | |
| 6126 | |
| 6127 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6128 | int ifindex, enum nl80211_iftype mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6129 | { |
| 6130 | struct nl_msg *msg; |
| 6131 | int ret = -ENOBUFS; |
| 6132 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6133 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
| 6134 | ifindex, mode, nl80211_iftype_str(mode)); |
| 6135 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6136 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 6137 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) |
| 6138 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6139 | |
| 6140 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6141 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6142 | if (!ret) |
| 6143 | return 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6144 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6145 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6146 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
| 6147 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); |
| 6148 | return ret; |
| 6149 | } |
| 6150 | |
| 6151 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6152 | static int wpa_driver_nl80211_set_mode_impl( |
| 6153 | struct i802_bss *bss, |
| 6154 | enum nl80211_iftype nlmode, |
| 6155 | struct hostapd_freq_params *desired_freq_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6156 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6157 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6158 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6159 | int i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6160 | int was_ap = is_ap_interface(drv->nlmode); |
| 6161 | int res; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6162 | int mode_switch_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6163 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 6164 | if (TEST_FAIL()) |
| 6165 | return -1; |
| 6166 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6167 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 6168 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) |
| 6169 | mode_switch_res = 0; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6170 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6171 | if (mode_switch_res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6172 | drv->nlmode = nlmode; |
| 6173 | ret = 0; |
| 6174 | goto done; |
| 6175 | } |
| 6176 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6177 | if (mode_switch_res == -ENODEV) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6178 | return -1; |
| 6179 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6180 | if (nlmode == drv->nlmode) { |
| 6181 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
| 6182 | "requested mode - ignore error"); |
| 6183 | ret = 0; |
| 6184 | goto done; /* Already in the requested mode */ |
| 6185 | } |
| 6186 | |
| 6187 | /* mac80211 doesn't allow mode changes while the device is up, so |
| 6188 | * take the device down, try to set the mode again, and bring the |
| 6189 | * device back up. |
| 6190 | */ |
| 6191 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
| 6192 | "interface down"); |
| 6193 | for (i = 0; i < 10; i++) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6194 | res = i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6195 | if (res == -EACCES || res == -ENODEV) |
| 6196 | break; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6197 | if (res != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6198 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
| 6199 | "interface down"); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6200 | os_sleep(0, 100000); |
| 6201 | continue; |
| 6202 | } |
| 6203 | |
| 6204 | /* |
| 6205 | * Setting the mode will fail for some drivers if the phy is |
| 6206 | * on a frequency that the mode is disallowed in. |
| 6207 | */ |
| 6208 | if (desired_freq_params) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6209 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6210 | if (res) { |
| 6211 | wpa_printf(MSG_DEBUG, |
| 6212 | "nl80211: Failed to set frequency on interface"); |
| 6213 | } |
| 6214 | } |
| 6215 | |
| 6216 | /* Try to set the mode again while the interface is down */ |
| 6217 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 6218 | if (mode_switch_res == -EBUSY) { |
| 6219 | wpa_printf(MSG_DEBUG, |
| 6220 | "nl80211: Delaying mode set while interface going down"); |
| 6221 | os_sleep(0, 100000); |
| 6222 | continue; |
| 6223 | } |
| 6224 | ret = mode_switch_res; |
| 6225 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6226 | } |
| 6227 | |
| 6228 | if (!ret) { |
| 6229 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " |
| 6230 | "interface is down"); |
| 6231 | drv->nlmode = nlmode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6232 | drv->ignore_if_down_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6233 | } |
| 6234 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6235 | /* Bring the interface back up */ |
| 6236 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); |
| 6237 | if (res != 0) { |
| 6238 | wpa_printf(MSG_DEBUG, |
| 6239 | "nl80211: Failed to set interface up after switching mode"); |
| 6240 | ret = -1; |
| 6241 | } |
| 6242 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6243 | done: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6244 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6245 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " |
| 6246 | "from %d failed", nlmode, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6247 | return ret; |
| 6248 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6249 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6250 | if (is_p2p_net_interface(nlmode)) { |
| 6251 | wpa_printf(MSG_DEBUG, |
| 6252 | "nl80211: Interface %s mode change to P2P - disable 11b rates", |
| 6253 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6254 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6255 | } else if (drv->disabled_11b_rates) { |
| 6256 | wpa_printf(MSG_DEBUG, |
| 6257 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", |
| 6258 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6259 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6260 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6261 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6262 | if (is_ap_interface(nlmode)) { |
| 6263 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
| 6264 | /* Setup additional AP mode functionality if needed */ |
| 6265 | if (nl80211_setup_ap(bss)) |
| 6266 | return -1; |
| 6267 | } else if (was_ap) { |
| 6268 | /* Remove additional AP mode functionality */ |
| 6269 | nl80211_teardown_ap(bss); |
| 6270 | } else { |
| 6271 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
| 6272 | } |
| 6273 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6274 | if (is_mesh_interface(nlmode) && |
| 6275 | nl80211_mgmt_subscribe_mesh(bss)) |
| 6276 | return -1; |
| 6277 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6278 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6279 | !is_mesh_interface(nlmode) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6280 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 6281 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " |
| 6282 | "frame processing - ignore for now"); |
| 6283 | |
| 6284 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6285 | } |
| 6286 | |
| 6287 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6288 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 6289 | enum nl80211_iftype nlmode) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6290 | { |
| 6291 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); |
| 6292 | } |
| 6293 | |
| 6294 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6295 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 6296 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6297 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6298 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6299 | freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6300 | } |
| 6301 | |
| 6302 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6303 | static int wpa_driver_nl80211_get_capa(void *priv, |
| 6304 | struct wpa_driver_capa *capa) |
| 6305 | { |
| 6306 | struct i802_bss *bss = priv; |
| 6307 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 6308 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6309 | if (!drv->has_capability) |
| 6310 | return -1; |
| 6311 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 6312 | if (drv->extended_capa && drv->extended_capa_mask) { |
| 6313 | capa->extended_capa = drv->extended_capa; |
| 6314 | capa->extended_capa_mask = drv->extended_capa_mask; |
| 6315 | capa->extended_capa_len = drv->extended_capa_len; |
| 6316 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6317 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6318 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6319 | } |
| 6320 | |
| 6321 | |
| 6322 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) |
| 6323 | { |
| 6324 | struct i802_bss *bss = priv; |
| 6325 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6326 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6327 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
| 6328 | bss->ifname, drv->operstate, state, |
| 6329 | state ? "UP" : "DORMANT"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6330 | drv->operstate = state; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6331 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6332 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
| 6333 | } |
| 6334 | |
| 6335 | |
| 6336 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) |
| 6337 | { |
| 6338 | struct i802_bss *bss = priv; |
| 6339 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6340 | struct nl_msg *msg; |
| 6341 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6342 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6343 | |
| 6344 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { |
| 6345 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); |
| 6346 | return 0; |
| 6347 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6348 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6349 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
| 6350 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); |
| 6351 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6352 | os_memset(&upd, 0, sizeof(upd)); |
| 6353 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 6354 | if (authorized) |
| 6355 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6356 | |
| 6357 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 6358 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
| 6359 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { |
| 6360 | nlmsg_free(msg); |
| 6361 | return -ENOBUFS; |
| 6362 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6363 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6364 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6365 | if (!ret) |
| 6366 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6367 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
| 6368 | ret, strerror(-ret)); |
| 6369 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6370 | } |
| 6371 | |
| 6372 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6373 | /* Set kernel driver on given frequency (MHz) */ |
| 6374 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6375 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6376 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 6377 | return nl80211_set_channel(bss, freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6378 | } |
| 6379 | |
| 6380 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6381 | static inline int min_int(int a, int b) |
| 6382 | { |
| 6383 | if (a < b) |
| 6384 | return a; |
| 6385 | return b; |
| 6386 | } |
| 6387 | |
| 6388 | |
| 6389 | static int get_key_handler(struct nl_msg *msg, void *arg) |
| 6390 | { |
| 6391 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6392 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6393 | |
| 6394 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6395 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6396 | |
| 6397 | /* |
| 6398 | * TODO: validate the key index and mac address! |
| 6399 | * Otherwise, there's a race condition as soon as |
| 6400 | * the kernel starts sending key notifications. |
| 6401 | */ |
| 6402 | |
| 6403 | if (tb[NL80211_ATTR_KEY_SEQ]) |
| 6404 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 6405 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6406 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6407 | return NL_SKIP; |
| 6408 | } |
| 6409 | |
| 6410 | |
| 6411 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, |
| 6412 | int idx, u8 *seq) |
| 6413 | { |
| 6414 | struct i802_bss *bss = priv; |
| 6415 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6416 | struct nl_msg *msg; |
| 6417 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6418 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
| 6419 | NL80211_CMD_GET_KEY); |
| 6420 | if (!msg || |
| 6421 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 6422 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
| 6423 | nlmsg_free(msg); |
| 6424 | return -ENOBUFS; |
| 6425 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6426 | |
| 6427 | memset(seq, 0, 6); |
| 6428 | |
| 6429 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6430 | } |
| 6431 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6432 | |
| 6433 | static int i802_set_rts(void *priv, int rts) |
| 6434 | { |
| 6435 | struct i802_bss *bss = priv; |
| 6436 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6437 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6438 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6439 | u32 val; |
| 6440 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6441 | if (rts >= 2347 || rts == -1) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6442 | val = (u32) -1; |
| 6443 | else |
| 6444 | val = rts; |
| 6445 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6446 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 6447 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
| 6448 | nlmsg_free(msg); |
| 6449 | return -ENOBUFS; |
| 6450 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6451 | |
| 6452 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6453 | if (!ret) |
| 6454 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6455 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
| 6456 | "%d (%s)", rts, ret, strerror(-ret)); |
| 6457 | return ret; |
| 6458 | } |
| 6459 | |
| 6460 | |
| 6461 | static int i802_set_frag(void *priv, int frag) |
| 6462 | { |
| 6463 | struct i802_bss *bss = priv; |
| 6464 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6465 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6466 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6467 | u32 val; |
| 6468 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6469 | if (frag >= 2346 || frag == -1) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6470 | val = (u32) -1; |
| 6471 | else |
| 6472 | val = frag; |
| 6473 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6474 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 6475 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
| 6476 | nlmsg_free(msg); |
| 6477 | return -ENOBUFS; |
| 6478 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6479 | |
| 6480 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6481 | if (!ret) |
| 6482 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6483 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
| 6484 | "%d: %d (%s)", frag, ret, strerror(-ret)); |
| 6485 | return ret; |
| 6486 | } |
| 6487 | |
| 6488 | |
| 6489 | static int i802_flush(void *priv) |
| 6490 | { |
| 6491 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6492 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6493 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6494 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6495 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
| 6496 | bss->ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6497 | |
| 6498 | /* |
| 6499 | * XXX: FIX! this needs to flush all VLANs too |
| 6500 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6501 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
| 6502 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6503 | if (res) { |
| 6504 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " |
| 6505 | "(%s)", res, strerror(-res)); |
| 6506 | } |
| 6507 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6508 | } |
| 6509 | |
| 6510 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6511 | static void get_sta_tid_stats(struct hostap_sta_driver_data *data, |
| 6512 | struct nlattr *attr) |
| 6513 | { |
| 6514 | struct nlattr *tid_stats[NL80211_TID_STATS_MAX + 1], *tidattr; |
| 6515 | struct nlattr *txq_stats[NL80211_TXQ_STATS_MAX + 1]; |
| 6516 | static struct nla_policy txq_stats_policy[NL80211_TXQ_STATS_MAX + 1] = { |
| 6517 | [NL80211_TXQ_STATS_BACKLOG_BYTES] = { .type = NLA_U32 }, |
| 6518 | [NL80211_TXQ_STATS_BACKLOG_PACKETS] = { .type = NLA_U32 }, |
| 6519 | }; |
| 6520 | int rem; |
| 6521 | |
| 6522 | nla_for_each_nested(tidattr, attr, rem) { |
| 6523 | if (nla_parse_nested(tid_stats, NL80211_TID_STATS_MAX, |
| 6524 | tidattr, NULL) != 0 || |
| 6525 | !tid_stats[NL80211_TID_STATS_TXQ_STATS] || |
| 6526 | nla_parse_nested(txq_stats, NL80211_TXQ_STATS_MAX, |
| 6527 | tid_stats[NL80211_TID_STATS_TXQ_STATS], |
| 6528 | txq_stats_policy) != 0) |
| 6529 | continue; |
| 6530 | /* sum the backlogs over all TIDs for station */ |
| 6531 | if (txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]) |
| 6532 | data->backlog_bytes += nla_get_u32( |
| 6533 | txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]); |
| 6534 | if (txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]) |
| 6535 | data->backlog_bytes += nla_get_u32( |
| 6536 | txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]); |
| 6537 | } |
| 6538 | } |
| 6539 | |
| 6540 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6541 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
| 6542 | { |
| 6543 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6544 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6545 | struct hostap_sta_driver_data *data = arg; |
| 6546 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; |
| 6547 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
| 6548 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, |
| 6549 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, |
| 6550 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, |
| 6551 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
| 6552 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 6553 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6554 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
| 6555 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6556 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6557 | [NL80211_STA_INFO_ACK_SIGNAL] = { .type = NLA_U8 }, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6558 | [NL80211_STA_INFO_RX_DURATION] = { .type = NLA_U64 }, |
| 6559 | [NL80211_STA_INFO_TX_DURATION] = { .type = NLA_U64 }, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6560 | }; |
| 6561 | struct nlattr *rate[NL80211_RATE_INFO_MAX + 1]; |
| 6562 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 6563 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 6564 | [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 }, |
| 6565 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 6566 | [NL80211_RATE_INFO_VHT_MCS] = { .type = NLA_U8 }, |
| 6567 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 6568 | [NL80211_RATE_INFO_VHT_NSS] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6569 | }; |
| 6570 | |
| 6571 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6572 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6573 | |
| 6574 | /* |
| 6575 | * TODO: validate the interface and mac address! |
| 6576 | * Otherwise, there's a race condition as soon as |
| 6577 | * the kernel starts sending station notifications. |
| 6578 | */ |
| 6579 | |
| 6580 | if (!tb[NL80211_ATTR_STA_INFO]) { |
| 6581 | wpa_printf(MSG_DEBUG, "sta stats missing!"); |
| 6582 | return NL_SKIP; |
| 6583 | } |
| 6584 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, |
| 6585 | tb[NL80211_ATTR_STA_INFO], |
| 6586 | stats_policy)) { |
| 6587 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); |
| 6588 | return NL_SKIP; |
| 6589 | } |
| 6590 | |
| 6591 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) |
| 6592 | data->inactive_msec = |
| 6593 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6594 | /* For backwards compatibility, fetch the 32-bit counters first. */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6595 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
| 6596 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); |
| 6597 | if (stats[NL80211_STA_INFO_TX_BYTES]) |
| 6598 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6599 | if (stats[NL80211_STA_INFO_RX_BYTES64] && |
| 6600 | stats[NL80211_STA_INFO_TX_BYTES64]) { |
| 6601 | /* |
| 6602 | * The driver supports 64-bit counters, so use them to override |
| 6603 | * the 32-bit values. |
| 6604 | */ |
| 6605 | data->rx_bytes = |
| 6606 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); |
| 6607 | data->tx_bytes = |
| 6608 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); |
| 6609 | data->bytes_64bit = 1; |
| 6610 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6611 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
| 6612 | data->rx_packets = |
| 6613 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); |
| 6614 | if (stats[NL80211_STA_INFO_TX_PACKETS]) |
| 6615 | data->tx_packets = |
| 6616 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6617 | if (stats[NL80211_STA_INFO_RX_DURATION]) |
| 6618 | data->rx_airtime = |
| 6619 | nla_get_u64(stats[NL80211_STA_INFO_RX_DURATION]); |
| 6620 | if (stats[NL80211_STA_INFO_TX_DURATION]) |
| 6621 | data->tx_airtime = |
| 6622 | nla_get_u64(stats[NL80211_STA_INFO_TX_DURATION]); |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 6623 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
| 6624 | data->tx_retry_failed = |
| 6625 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6626 | if (stats[NL80211_STA_INFO_SIGNAL]) |
| 6627 | data->signal = nla_get_u8(stats[NL80211_STA_INFO_SIGNAL]); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6628 | if (stats[NL80211_STA_INFO_ACK_SIGNAL]) { |
| 6629 | data->last_ack_rssi = |
| 6630 | nla_get_u8(stats[NL80211_STA_INFO_ACK_SIGNAL]); |
| 6631 | data->flags |= STA_DRV_DATA_LAST_ACK_RSSI; |
| 6632 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6633 | |
| 6634 | if (stats[NL80211_STA_INFO_TX_BITRATE] && |
| 6635 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, |
| 6636 | stats[NL80211_STA_INFO_TX_BITRATE], |
| 6637 | rate_policy) == 0) { |
| 6638 | if (rate[NL80211_RATE_INFO_BITRATE32]) |
| 6639 | data->current_tx_rate = |
| 6640 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); |
| 6641 | else if (rate[NL80211_RATE_INFO_BITRATE]) |
| 6642 | data->current_tx_rate = |
| 6643 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); |
| 6644 | |
| 6645 | if (rate[NL80211_RATE_INFO_MCS]) { |
| 6646 | data->tx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]); |
| 6647 | data->flags |= STA_DRV_DATA_TX_MCS; |
| 6648 | } |
| 6649 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { |
| 6650 | data->tx_vhtmcs = |
| 6651 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); |
| 6652 | data->flags |= STA_DRV_DATA_TX_VHT_MCS; |
| 6653 | } |
| 6654 | if (rate[NL80211_RATE_INFO_SHORT_GI]) |
| 6655 | data->flags |= STA_DRV_DATA_TX_SHORT_GI; |
| 6656 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { |
| 6657 | data->tx_vht_nss = |
| 6658 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); |
| 6659 | data->flags |= STA_DRV_DATA_TX_VHT_NSS; |
| 6660 | } |
| 6661 | } |
| 6662 | |
| 6663 | if (stats[NL80211_STA_INFO_RX_BITRATE] && |
| 6664 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, |
| 6665 | stats[NL80211_STA_INFO_RX_BITRATE], |
| 6666 | rate_policy) == 0) { |
| 6667 | if (rate[NL80211_RATE_INFO_BITRATE32]) |
| 6668 | data->current_rx_rate = |
| 6669 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); |
| 6670 | else if (rate[NL80211_RATE_INFO_BITRATE]) |
| 6671 | data->current_rx_rate = |
| 6672 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); |
| 6673 | |
| 6674 | if (rate[NL80211_RATE_INFO_MCS]) { |
| 6675 | data->rx_mcs = |
| 6676 | nla_get_u8(rate[NL80211_RATE_INFO_MCS]); |
| 6677 | data->flags |= STA_DRV_DATA_RX_MCS; |
| 6678 | } |
| 6679 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { |
| 6680 | data->rx_vhtmcs = |
| 6681 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); |
| 6682 | data->flags |= STA_DRV_DATA_RX_VHT_MCS; |
| 6683 | } |
| 6684 | if (rate[NL80211_RATE_INFO_SHORT_GI]) |
| 6685 | data->flags |= STA_DRV_DATA_RX_SHORT_GI; |
| 6686 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { |
| 6687 | data->rx_vht_nss = |
| 6688 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); |
| 6689 | data->flags |= STA_DRV_DATA_RX_VHT_NSS; |
| 6690 | } |
| 6691 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6692 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6693 | if (stats[NL80211_STA_INFO_TID_STATS]) |
| 6694 | get_sta_tid_stats(data, stats[NL80211_STA_INFO_TID_STATS]); |
| 6695 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6696 | return NL_SKIP; |
| 6697 | } |
| 6698 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6699 | static int i802_read_sta_data(struct i802_bss *bss, |
| 6700 | struct hostap_sta_driver_data *data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6701 | const u8 *addr) |
| 6702 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6703 | struct nl_msg *msg; |
| 6704 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6705 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
| 6706 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 6707 | nlmsg_free(msg); |
| 6708 | return -ENOBUFS; |
| 6709 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6710 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6711 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6712 | } |
| 6713 | |
| 6714 | |
| 6715 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
| 6716 | int cw_min, int cw_max, int burst_time) |
| 6717 | { |
| 6718 | struct i802_bss *bss = priv; |
| 6719 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6720 | struct nl_msg *msg; |
| 6721 | struct nlattr *txq, *params; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6722 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6723 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6724 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6725 | if (!msg) |
| 6726 | return -1; |
| 6727 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6728 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
| 6729 | if (!txq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6730 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6731 | |
| 6732 | /* We are only sending parameters for a single TXQ at a time */ |
| 6733 | params = nla_nest_start(msg, 1); |
| 6734 | if (!params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6735 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6736 | |
| 6737 | switch (queue) { |
| 6738 | case 0: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6739 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
| 6740 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6741 | break; |
| 6742 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6743 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
| 6744 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6745 | break; |
| 6746 | case 2: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6747 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
| 6748 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6749 | break; |
| 6750 | case 3: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6751 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
| 6752 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6753 | break; |
| 6754 | } |
| 6755 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
| 6756 | * 32 usec, so need to convert the value here. */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6757 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
| 6758 | (burst_time * 100 + 16) / 32) || |
| 6759 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || |
| 6760 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || |
| 6761 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) |
| 6762 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6763 | |
| 6764 | nla_nest_end(msg, params); |
| 6765 | |
| 6766 | nla_nest_end(msg, txq); |
| 6767 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6768 | res = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6769 | wpa_printf(MSG_DEBUG, |
| 6770 | "nl80211: TX queue param set: queue=%d aifs=%d cw_min=%d cw_max=%d burst_time=%d --> res=%d", |
| 6771 | queue, aifs, cw_min, cw_max, burst_time, res); |
| 6772 | if (res == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6773 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6774 | msg = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6775 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6776 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6777 | return -1; |
| 6778 | } |
| 6779 | |
| 6780 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6781 | 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] | 6782 | const char *ifname, int vlan_id) |
| 6783 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6784 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6785 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6786 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6787 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6788 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
| 6789 | ", ifname=%s[%d], vlan_id=%d)", |
| 6790 | bss->ifname, if_nametoindex(bss->ifname), |
| 6791 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6792 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 6793 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 6794 | ((drv->capa.flags & WPA_DRIVER_FLAGS_VLAN_OFFLOAD) && |
| 6795 | nla_put_u16(msg, NL80211_ATTR_VLAN_ID, vlan_id)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6796 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { |
| 6797 | nlmsg_free(msg); |
| 6798 | return -ENOBUFS; |
| 6799 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6800 | |
| 6801 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6802 | if (ret < 0) { |
| 6803 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" |
| 6804 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", |
| 6805 | MAC2STR(addr), ifname, vlan_id, ret, |
| 6806 | strerror(-ret)); |
| 6807 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6808 | return ret; |
| 6809 | } |
| 6810 | |
| 6811 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6812 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
| 6813 | { |
| 6814 | struct hostap_sta_driver_data data; |
| 6815 | int ret; |
| 6816 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 6817 | os_memset(&data, 0, sizeof(data)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6818 | data.inactive_msec = (unsigned long) -1; |
| 6819 | ret = i802_read_sta_data(priv, &data, addr); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6820 | if (ret == -ENOENT) |
| 6821 | return -ENOENT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6822 | if (ret || data.inactive_msec == (unsigned long) -1) |
| 6823 | return -1; |
| 6824 | return data.inactive_msec / 1000; |
| 6825 | } |
| 6826 | |
| 6827 | |
| 6828 | static int i802_sta_clear_stats(void *priv, const u8 *addr) |
| 6829 | { |
| 6830 | #if 0 |
| 6831 | /* TODO */ |
| 6832 | #endif |
| 6833 | return 0; |
| 6834 | } |
| 6835 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6836 | |
| 6837 | 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] | 6838 | u16 reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6839 | { |
| 6840 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6841 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6842 | struct ieee80211_mgmt mgmt; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 6843 | u8 channel; |
| 6844 | |
| 6845 | if (ieee80211_freq_to_chan(bss->freq, &channel) == |
| 6846 | HOSTAPD_MODE_IEEE80211AD) { |
| 6847 | /* Deauthentication is not used in DMG/IEEE 802.11ad; |
| 6848 | * disassociate the STA instead. */ |
| 6849 | return i802_sta_disassoc(priv, own_addr, addr, reason); |
| 6850 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6851 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6852 | if (is_mesh_interface(drv->nlmode)) |
| 6853 | return -1; |
| 6854 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6855 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6856 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6857 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6858 | memset(&mgmt, 0, sizeof(mgmt)); |
| 6859 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 6860 | WLAN_FC_STYPE_DEAUTH); |
| 6861 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 6862 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 6863 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 6864 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
| 6865 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 6866 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6867 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 6868 | 0, NULL, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6869 | } |
| 6870 | |
| 6871 | |
| 6872 | 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] | 6873 | u16 reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6874 | { |
| 6875 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6876 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6877 | struct ieee80211_mgmt mgmt; |
| 6878 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6879 | if (is_mesh_interface(drv->nlmode)) |
| 6880 | return -1; |
| 6881 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6882 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6883 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6884 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6885 | memset(&mgmt, 0, sizeof(mgmt)); |
| 6886 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 6887 | WLAN_FC_STYPE_DISASSOC); |
| 6888 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 6889 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 6890 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 6891 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
| 6892 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 6893 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6894 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 6895 | 0, NULL, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6896 | } |
| 6897 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6898 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6899 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
| 6900 | { |
| 6901 | char buf[200], *pos, *end; |
| 6902 | int i, res; |
| 6903 | |
| 6904 | pos = buf; |
| 6905 | end = pos + sizeof(buf); |
| 6906 | |
| 6907 | for (i = 0; i < drv->num_if_indices; i++) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6908 | if (!drv->if_indices[i].ifindex) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6909 | continue; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6910 | res = os_snprintf(pos, end - pos, " %d(%d)", |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6911 | drv->if_indices[i].ifindex, |
| 6912 | drv->if_indices[i].reason); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6913 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6914 | break; |
| 6915 | pos += res; |
| 6916 | } |
| 6917 | *pos = '\0'; |
| 6918 | |
| 6919 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", |
| 6920 | drv->num_if_indices, buf); |
| 6921 | } |
| 6922 | |
| 6923 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6924 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 6925 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6926 | { |
| 6927 | int i; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6928 | struct drv_nl80211_if_info *old; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6929 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6930 | wpa_printf(MSG_DEBUG, |
| 6931 | "nl80211: Add own interface ifindex %d (ifidx_reason %d)", |
| 6932 | ifidx, ifidx_reason); |
| 6933 | if (have_ifidx(drv, ifidx, ifidx_reason)) { |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6934 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
| 6935 | ifidx); |
| 6936 | return; |
| 6937 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6938 | for (i = 0; i < drv->num_if_indices; i++) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6939 | if (drv->if_indices[i].ifindex == 0) { |
| 6940 | drv->if_indices[i].ifindex = ifidx; |
| 6941 | drv->if_indices[i].reason = ifidx_reason; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6942 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6943 | return; |
| 6944 | } |
| 6945 | } |
| 6946 | |
| 6947 | if (drv->if_indices != drv->default_if_indices) |
| 6948 | old = drv->if_indices; |
| 6949 | else |
| 6950 | old = NULL; |
| 6951 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6952 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6953 | sizeof(*old)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6954 | if (!drv->if_indices) { |
| 6955 | if (!old) |
| 6956 | drv->if_indices = drv->default_if_indices; |
| 6957 | else |
| 6958 | drv->if_indices = old; |
| 6959 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
| 6960 | "interfaces"); |
| 6961 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); |
| 6962 | return; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6963 | } |
| 6964 | if (!old) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6965 | os_memcpy(drv->if_indices, drv->default_if_indices, |
| 6966 | sizeof(drv->default_if_indices)); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6967 | drv->if_indices[drv->num_if_indices].ifindex = ifidx; |
| 6968 | drv->if_indices[drv->num_if_indices].reason = ifidx_reason; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6969 | drv->num_if_indices++; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6970 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6971 | } |
| 6972 | |
| 6973 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6974 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 6975 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6976 | { |
| 6977 | int i; |
| 6978 | |
| 6979 | for (i = 0; i < drv->num_if_indices; i++) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6980 | if ((drv->if_indices[i].ifindex == ifidx || |
| 6981 | ifidx == IFIDX_ANY) && |
| 6982 | (drv->if_indices[i].reason == ifidx_reason || |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6983 | ifidx_reason == IFIDX_ANY)) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6984 | drv->if_indices[i].ifindex = 0; |
| 6985 | drv->if_indices[i].reason = 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6986 | break; |
| 6987 | } |
| 6988 | } |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6989 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6990 | } |
| 6991 | |
| 6992 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6993 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 6994 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6995 | { |
| 6996 | int i; |
| 6997 | |
| 6998 | for (i = 0; i < drv->num_if_indices; i++) |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 6999 | if (drv->if_indices[i].ifindex == ifidx && |
| 7000 | (drv->if_indices[i].reason == ifidx_reason || |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7001 | ifidx_reason == IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7002 | return 1; |
| 7003 | |
| 7004 | return 0; |
| 7005 | } |
| 7006 | |
| 7007 | |
| 7008 | 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] | 7009 | const char *bridge_ifname, char *ifname_wds) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7010 | { |
| 7011 | struct i802_bss *bss = priv; |
| 7012 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7013 | char name[IFNAMSIZ + 1]; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7014 | union wpa_event_data event; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 7015 | int ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7016 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 7017 | ret = os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
| 7018 | if (ret >= (int) sizeof(name)) |
| 7019 | wpa_printf(MSG_WARNING, |
| 7020 | "nl80211: WDS interface name was truncated"); |
| 7021 | else if (ret < 0) |
| 7022 | return ret; |
| 7023 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7024 | if (ifname_wds) |
| 7025 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); |
| 7026 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7027 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
| 7028 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); |
| 7029 | if (val) { |
| 7030 | if (!if_nametoindex(name)) { |
| 7031 | if (nl80211_create_iface(drv, name, |
| 7032 | NL80211_IFTYPE_AP_VLAN, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7033 | bss->addr, 1, NULL, NULL, 0) < |
| 7034 | 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7035 | return -1; |
| 7036 | if (bridge_ifname && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7037 | linux_br_add_if(drv->global->ioctl_sock, |
| 7038 | bridge_ifname, name) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7039 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7040 | |
| 7041 | os_memset(&event, 0, sizeof(event)); |
| 7042 | event.wds_sta_interface.sta_addr = addr; |
| 7043 | event.wds_sta_interface.ifname = name; |
| 7044 | event.wds_sta_interface.istatus = INTERFACE_ADDED; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 7045 | wpa_supplicant_event(bss->ctx, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7046 | EVENT_WDS_STA_INTERFACE_STATUS, |
| 7047 | &event); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7048 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7049 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
| 7050 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " |
| 7051 | "interface %s up", name); |
| 7052 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7053 | return i802_set_sta_vlan(priv, addr, name, 0); |
| 7054 | } else { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 7055 | if (bridge_ifname && |
| 7056 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, |
| 7057 | name) < 0) |
| 7058 | wpa_printf(MSG_INFO, |
| 7059 | "nl80211: Failed to remove interface %s from bridge %s: %s", |
| 7060 | name, bridge_ifname, strerror(errno)); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7061 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7062 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7063 | nl80211_remove_iface(drv, if_nametoindex(name)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7064 | os_memset(&event, 0, sizeof(event)); |
| 7065 | event.wds_sta_interface.sta_addr = addr; |
| 7066 | event.wds_sta_interface.ifname = name; |
| 7067 | event.wds_sta_interface.istatus = INTERFACE_REMOVED; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 7068 | wpa_supplicant_event(bss->ctx, EVENT_WDS_STA_INTERFACE_STATUS, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7069 | &event); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 7070 | return 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7071 | } |
| 7072 | } |
| 7073 | |
| 7074 | |
| 7075 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
| 7076 | { |
| 7077 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 7078 | struct sockaddr_ll lladdr; |
| 7079 | unsigned char buf[3000]; |
| 7080 | int len; |
| 7081 | socklen_t fromlen = sizeof(lladdr); |
| 7082 | |
| 7083 | len = recvfrom(sock, buf, sizeof(buf), 0, |
| 7084 | (struct sockaddr *)&lladdr, &fromlen); |
| 7085 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7086 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
| 7087 | strerror(errno)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7088 | return; |
| 7089 | } |
| 7090 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7091 | if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7092 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
| 7093 | } |
| 7094 | |
| 7095 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7096 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
| 7097 | struct i802_bss *bss, |
| 7098 | const char *brname, const char *ifname) |
| 7099 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7100 | int br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7101 | char in_br[IFNAMSIZ]; |
| 7102 | |
| 7103 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7104 | br_ifindex = if_nametoindex(brname); |
| 7105 | if (br_ifindex == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7106 | /* |
| 7107 | * Bridge was configured, but the bridge device does |
| 7108 | * not exist. Try to add it now. |
| 7109 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7110 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7111 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
| 7112 | "bridge interface %s: %s", |
| 7113 | brname, strerror(errno)); |
| 7114 | return -1; |
| 7115 | } |
| 7116 | bss->added_bridge = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7117 | br_ifindex = if_nametoindex(brname); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7118 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7119 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7120 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7121 | |
| 7122 | if (linux_br_get(in_br, ifname) == 0) { |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 7123 | if (os_strcmp(in_br, brname) == 0) { |
| 7124 | bss->already_in_bridge = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7125 | return 0; /* already in the bridge */ |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 7126 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7127 | |
| 7128 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " |
| 7129 | "bridge %s", ifname, in_br); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7130 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
| 7131 | 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7132 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
| 7133 | "remove interface %s from bridge " |
| 7134 | "%s: %s", |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7135 | ifname, in_br, strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7136 | return -1; |
| 7137 | } |
| 7138 | } |
| 7139 | |
| 7140 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", |
| 7141 | ifname, brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7142 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7143 | wpa_printf(MSG_WARNING, |
| 7144 | "nl80211: Failed to add interface %s into bridge %s: %s", |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7145 | ifname, brname, strerror(errno)); |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 7146 | /* Try to continue without the interface being in a bridge. This |
| 7147 | * may be needed for some cases, e.g., with Open vSwitch, where |
| 7148 | * an external component will need to handle bridge |
| 7149 | * configuration. */ |
| 7150 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7151 | } |
| 7152 | bss->added_if_into_bridge = 1; |
| 7153 | |
| 7154 | return 0; |
| 7155 | } |
| 7156 | |
| 7157 | |
| 7158 | static void *i802_init(struct hostapd_data *hapd, |
| 7159 | struct wpa_init_params *params) |
| 7160 | { |
| 7161 | struct wpa_driver_nl80211_data *drv; |
| 7162 | struct i802_bss *bss; |
| 7163 | size_t i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7164 | char master_ifname[IFNAMSIZ]; |
| 7165 | int ifindex, br_ifindex = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7166 | int br_added = 0; |
| 7167 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 7168 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
| 7169 | params->global_priv, 1, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7170 | params->bssid, params->driver_params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7171 | if (bss == NULL) |
| 7172 | return NULL; |
| 7173 | |
| 7174 | drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7175 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7176 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7177 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7178 | params->ifname, master_ifname); |
| 7179 | br_ifindex = if_nametoindex(master_ifname); |
| 7180 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 7181 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && |
| 7182 | linux_master_get(master_ifname, params->ifname) == 0) { |
| 7183 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", |
| 7184 | params->ifname, master_ifname); |
| 7185 | /* start listening for EAPOL on the master interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7186 | add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 7187 | |
| 7188 | /* check if master itself is under bridge */ |
| 7189 | if (linux_br_get(master_ifname, master_ifname) == 0) { |
| 7190 | wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s", |
| 7191 | master_ifname); |
| 7192 | br_ifindex = if_nametoindex(master_ifname); |
| 7193 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 7194 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7195 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7196 | master_ifname[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7197 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7198 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7199 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7200 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7201 | for (i = 0; i < params->num_bridge; i++) { |
| 7202 | if (params->bridge[i]) { |
| 7203 | ifindex = if_nametoindex(params->bridge[i]); |
| 7204 | if (ifindex) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7205 | add_ifidx(drv, ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7206 | if (ifindex == br_ifindex) |
| 7207 | br_added = 1; |
| 7208 | } |
| 7209 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7210 | |
| 7211 | /* start listening for EAPOL on the default AP interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7212 | add_ifidx(drv, drv->ifindex, IFIDX_ANY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7213 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7214 | if (params->num_bridge && params->bridge[0]) { |
| 7215 | if (i802_check_bridge(drv, bss, params->bridge[0], |
| 7216 | params->ifname) < 0) |
| 7217 | goto failed; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7218 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7219 | br_added = 1; |
| 7220 | } |
| 7221 | |
| 7222 | if (!br_added && br_ifindex && |
| 7223 | (params->num_bridge == 0 || !params->bridge[0])) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7224 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7225 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7226 | #ifdef CONFIG_LIBNL3_ROUTE |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 7227 | if (bss->added_if_into_bridge || bss->already_in_bridge) { |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 7228 | int err; |
| 7229 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7230 | drv->rtnl_sk = nl_socket_alloc(); |
| 7231 | if (drv->rtnl_sk == NULL) { |
| 7232 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); |
| 7233 | goto failed; |
| 7234 | } |
| 7235 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 7236 | err = nl_connect(drv->rtnl_sk, NETLINK_ROUTE); |
| 7237 | if (err) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7238 | 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^] | 7239 | nl_geterror(err)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7240 | goto failed; |
| 7241 | } |
| 7242 | } |
| 7243 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 7244 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7245 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
| 7246 | if (drv->eapol_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7247 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
| 7248 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7249 | goto failed; |
| 7250 | } |
| 7251 | |
| 7252 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) |
| 7253 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7254 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7255 | goto failed; |
| 7256 | } |
| 7257 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7258 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 7259 | params->own_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7260 | goto failed; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7261 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7262 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7263 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
| 7264 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7265 | return bss; |
| 7266 | |
| 7267 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7268 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7269 | return NULL; |
| 7270 | } |
| 7271 | |
| 7272 | |
| 7273 | static void i802_deinit(void *priv) |
| 7274 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7275 | struct i802_bss *bss = priv; |
| 7276 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7277 | } |
| 7278 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7279 | |
| 7280 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
| 7281 | enum wpa_driver_if_type type) |
| 7282 | { |
| 7283 | switch (type) { |
| 7284 | case WPA_IF_STATION: |
| 7285 | return NL80211_IFTYPE_STATION; |
| 7286 | case WPA_IF_P2P_CLIENT: |
| 7287 | case WPA_IF_P2P_GROUP: |
| 7288 | return NL80211_IFTYPE_P2P_CLIENT; |
| 7289 | case WPA_IF_AP_VLAN: |
| 7290 | return NL80211_IFTYPE_AP_VLAN; |
| 7291 | case WPA_IF_AP_BSS: |
| 7292 | return NL80211_IFTYPE_AP; |
| 7293 | case WPA_IF_P2P_GO: |
| 7294 | return NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7295 | case WPA_IF_P2P_DEVICE: |
| 7296 | return NL80211_IFTYPE_P2P_DEVICE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7297 | case WPA_IF_MESH: |
| 7298 | return NL80211_IFTYPE_MESH_POINT; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7299 | default: |
| 7300 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7301 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7302 | } |
| 7303 | |
| 7304 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7305 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
| 7306 | { |
| 7307 | struct wpa_driver_nl80211_data *drv; |
| 7308 | dl_list_for_each(drv, &global->interfaces, |
| 7309 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7310 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7311 | return 1; |
| 7312 | } |
| 7313 | return 0; |
| 7314 | } |
| 7315 | |
| 7316 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7317 | 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] | 7318 | { |
| 7319 | unsigned int idx; |
| 7320 | |
| 7321 | if (!drv->global) |
| 7322 | return -1; |
| 7323 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7324 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7325 | for (idx = 0; idx < 64; idx++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7326 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7327 | new_addr[0] ^= idx << 2; |
| 7328 | if (!nl80211_addr_in_use(drv->global, new_addr)) |
| 7329 | break; |
| 7330 | } |
| 7331 | if (idx == 64) |
| 7332 | return -1; |
| 7333 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7334 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7335 | MACSTR, MAC2STR(new_addr)); |
| 7336 | |
| 7337 | return 0; |
| 7338 | } |
| 7339 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7340 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7341 | struct wdev_info { |
| 7342 | u64 wdev_id; |
| 7343 | int wdev_id_set; |
| 7344 | u8 macaddr[ETH_ALEN]; |
| 7345 | }; |
| 7346 | |
| 7347 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) |
| 7348 | { |
| 7349 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7350 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7351 | struct wdev_info *wi = arg; |
| 7352 | |
| 7353 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7354 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7355 | if (tb[NL80211_ATTR_WDEV]) { |
| 7356 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 7357 | wi->wdev_id_set = 1; |
| 7358 | } |
| 7359 | |
| 7360 | if (tb[NL80211_ATTR_MAC]) |
| 7361 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 7362 | ETH_ALEN); |
| 7363 | |
| 7364 | return NL_SKIP; |
| 7365 | } |
| 7366 | |
| 7367 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7368 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
| 7369 | const char *ifname, const u8 *addr, |
| 7370 | void *bss_ctx, void **drv_priv, |
| 7371 | char *force_ifname, u8 *if_addr, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7372 | const char *bridge, int use_existing, |
| 7373 | int setup_ap) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7374 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7375 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7376 | struct i802_bss *bss = priv; |
| 7377 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7378 | int ifidx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7379 | int added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7380 | |
| 7381 | if (addr) |
| 7382 | os_memcpy(if_addr, addr, ETH_ALEN); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7383 | nlmode = wpa_driver_nl80211_if_type(type); |
| 7384 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 7385 | struct wdev_info p2pdev_info; |
| 7386 | |
| 7387 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); |
| 7388 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
| 7389 | 0, nl80211_wdev_handler, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7390 | &p2pdev_info, use_existing); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7391 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
| 7392 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
| 7393 | ifname); |
| 7394 | return -1; |
| 7395 | } |
| 7396 | |
| 7397 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; |
| 7398 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; |
| 7399 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) |
| 7400 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); |
| 7401 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", |
| 7402 | ifname, |
| 7403 | (long long unsigned int) p2pdev_info.wdev_id); |
| 7404 | } else { |
| 7405 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7406 | 0, NULL, NULL, use_existing); |
| 7407 | if (use_existing && ifidx == -ENFILE) { |
| 7408 | added = 0; |
| 7409 | ifidx = if_nametoindex(ifname); |
| 7410 | } else if (ifidx < 0) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7411 | return -1; |
| 7412 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7413 | } |
| 7414 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7415 | if (!addr) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 7416 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7417 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
| 7418 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 7419 | ifname, if_addr) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7420 | if (added) |
| 7421 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7422 | return -1; |
| 7423 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7424 | } |
| 7425 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7426 | if (!addr && |
| 7427 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 7428 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
| 7429 | type == WPA_IF_STATION)) { |
| 7430 | /* Enforce unique address */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7431 | u8 new_addr[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7432 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7433 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7434 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 7435 | if (added) |
| 7436 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7437 | return -1; |
| 7438 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7439 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7440 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 7441 | "for interface %s type %d", ifname, type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7442 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 7443 | if (added) |
| 7444 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7445 | return -1; |
| 7446 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7447 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7448 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 7449 | if (added) |
| 7450 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7451 | return -1; |
| 7452 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7453 | } |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 7454 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7455 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7456 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7457 | if (type == WPA_IF_AP_BSS && setup_ap) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7458 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
| 7459 | if (new_bss == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7460 | if (added) |
| 7461 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7462 | return -1; |
| 7463 | } |
| 7464 | |
| 7465 | if (bridge && |
| 7466 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { |
| 7467 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " |
| 7468 | "interface %s to a bridge %s", |
| 7469 | ifname, bridge); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7470 | if (added) |
| 7471 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7472 | os_free(new_bss); |
| 7473 | return -1; |
| 7474 | } |
| 7475 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7476 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
| 7477 | { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 7478 | if (added) |
| 7479 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7480 | os_free(new_bss); |
| 7481 | return -1; |
| 7482 | } |
| 7483 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7484 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7485 | new_bss->ifindex = ifidx; |
| 7486 | new_bss->drv = drv; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7487 | new_bss->next = drv->first_bss->next; |
| 7488 | new_bss->freq = drv->first_bss->freq; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7489 | new_bss->ctx = bss_ctx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7490 | new_bss->added_if = added; |
| 7491 | drv->first_bss->next = new_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7492 | if (drv_priv) |
| 7493 | *drv_priv = new_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7494 | nl80211_init_bss(new_bss); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7495 | |
| 7496 | /* Subscribe management frames for this WPA_IF_AP_BSS */ |
| 7497 | if (nl80211_setup_ap(new_bss)) |
| 7498 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7499 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7500 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7501 | if (drv->global) |
| 7502 | drv->global->if_add_ifindex = ifidx; |
| 7503 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7504 | /* |
| 7505 | * Some virtual interfaces need to process EAPOL packets and events on |
| 7506 | * the parent interface. This is used mainly with hostapd. |
| 7507 | */ |
| 7508 | if (ifidx > 0 && |
| 7509 | (drv->hostapd || |
| 7510 | nlmode == NL80211_IFTYPE_AP_VLAN || |
| 7511 | nlmode == NL80211_IFTYPE_WDS || |
| 7512 | nlmode == NL80211_IFTYPE_MONITOR)) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7513 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7514 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7515 | return 0; |
| 7516 | } |
| 7517 | |
| 7518 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7519 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7520 | enum wpa_driver_if_type type, |
| 7521 | const char *ifname) |
| 7522 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7523 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7524 | int ifindex = if_nametoindex(ifname); |
| 7525 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7526 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
| 7527 | __func__, type, ifname, ifindex, bss->added_if); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 7528 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7529 | nl80211_remove_iface(drv, ifindex); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 7530 | else if (ifindex > 0 && !bss->added_if) { |
| 7531 | struct wpa_driver_nl80211_data *drv2; |
| 7532 | dl_list_for_each(drv2, &drv->global->interfaces, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7533 | struct wpa_driver_nl80211_data, list) { |
| 7534 | del_ifidx(drv2, ifindex, IFIDX_ANY); |
| 7535 | del_ifidx(drv2, IFIDX_ANY, ifindex); |
| 7536 | } |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 7537 | } |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7538 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7539 | if (type != WPA_IF_AP_BSS) |
| 7540 | return 0; |
| 7541 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7542 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7543 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 7544 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7545 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 7546 | "interface %s from bridge %s: %s", |
| 7547 | bss->ifname, bss->brname, strerror(errno)); |
| 7548 | } |
| 7549 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7550 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7551 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 7552 | "bridge %s: %s", |
| 7553 | bss->brname, strerror(errno)); |
| 7554 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7555 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7556 | if (bss != drv->first_bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7557 | struct i802_bss *tbss; |
| 7558 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7559 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
| 7560 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7561 | if (tbss->next == bss) { |
| 7562 | tbss->next = bss->next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7563 | /* Unsubscribe management frames */ |
| 7564 | nl80211_teardown_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7565 | nl80211_destroy_bss(bss); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7566 | if (!bss->added_if) |
| 7567 | i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7568 | os_free(bss); |
| 7569 | bss = NULL; |
| 7570 | break; |
| 7571 | } |
| 7572 | } |
| 7573 | if (bss) |
| 7574 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " |
| 7575 | "BSS %p in the list", __func__, bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7576 | } else { |
| 7577 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
| 7578 | nl80211_teardown_ap(bss); |
| 7579 | if (!bss->added_if && !drv->first_bss->next) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 7580 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7581 | nl80211_destroy_bss(bss); |
| 7582 | if (!bss->added_if) |
| 7583 | i802_set_iface_flags(bss, 0); |
| 7584 | if (drv->first_bss->next) { |
| 7585 | drv->first_bss = drv->first_bss->next; |
| 7586 | drv->ctx = drv->first_bss->ctx; |
| 7587 | os_free(bss); |
| 7588 | } else { |
| 7589 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); |
| 7590 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7591 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7592 | |
| 7593 | return 0; |
| 7594 | } |
| 7595 | |
| 7596 | |
| 7597 | static int cookie_handler(struct nl_msg *msg, void *arg) |
| 7598 | { |
| 7599 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7600 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7601 | u64 *cookie = arg; |
| 7602 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7603 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7604 | if (tb[NL80211_ATTR_COOKIE]) |
| 7605 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 7606 | return NL_SKIP; |
| 7607 | } |
| 7608 | |
| 7609 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7610 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7611 | unsigned int freq, unsigned int wait, |
| 7612 | const u8 *buf, size_t buf_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 7613 | int save_cookie, int no_cck, int no_ack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7614 | int offchanok, const u16 *csa_offs, |
| 7615 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7616 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7617 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7618 | struct nl_msg *msg; |
| 7619 | u64 cookie; |
| 7620 | int ret = -1; |
| 7621 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7622 | 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] | 7623 | "no_ack=%d offchanok=%d", |
| 7624 | freq, wait, no_cck, no_ack, offchanok); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7625 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7626 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7627 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
| 7628 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 7629 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || |
| 7630 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 7631 | drv->test_use_roc_tx) && |
| 7632 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || |
| 7633 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || |
| 7634 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7635 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
| 7636 | csa_offs_len * sizeof(u16), csa_offs)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7637 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
| 7638 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7639 | |
| 7640 | cookie = 0; |
| 7641 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 7642 | msg = NULL; |
| 7643 | if (ret) { |
| 7644 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 7645 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
| 7646 | freq, wait); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7647 | } else { |
| 7648 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " |
| 7649 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
| 7650 | (long long unsigned int) cookie); |
| 7651 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 7652 | if (save_cookie) |
| 7653 | drv->send_frame_cookie = no_ack ? (u64) -1 : cookie; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7654 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 7655 | if (drv->num_send_frame_cookies == MAX_SEND_FRAME_COOKIES) { |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7656 | wpa_printf(MSG_DEBUG, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 7657 | "nl80211: Drop oldest pending send frame cookie 0x%llx", |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7658 | (long long unsigned int) |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 7659 | drv->send_frame_cookies[0]); |
| 7660 | os_memmove(&drv->send_frame_cookies[0], |
| 7661 | &drv->send_frame_cookies[1], |
| 7662 | (MAX_SEND_FRAME_COOKIES - 1) * |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7663 | sizeof(u64)); |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 7664 | drv->num_send_frame_cookies--; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7665 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 7666 | drv->send_frame_cookies[drv->num_send_frame_cookies] = cookie; |
| 7667 | drv->num_send_frame_cookies++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7668 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7669 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7670 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7671 | nlmsg_free(msg); |
| 7672 | return ret; |
| 7673 | } |
| 7674 | |
| 7675 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7676 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
| 7677 | unsigned int freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7678 | unsigned int wait_time, |
| 7679 | const u8 *dst, const u8 *src, |
| 7680 | const u8 *bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7681 | const u8 *data, size_t data_len, |
| 7682 | int no_cck) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7683 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7684 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7685 | int ret = -1; |
| 7686 | u8 *buf; |
| 7687 | struct ieee80211_hdr *hdr; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 7688 | int offchanok = 1; |
| 7689 | |
| 7690 | if (is_ap_interface(drv->nlmode) && (int) freq == bss->freq) |
| 7691 | offchanok = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7692 | |
| 7693 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 7694 | "freq=%u MHz wait=%d ms no_cck=%d offchanok=%d)", |
| 7695 | drv->ifindex, freq, wait_time, no_cck, offchanok); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7696 | |
| 7697 | buf = os_zalloc(24 + data_len); |
| 7698 | if (buf == NULL) |
| 7699 | return ret; |
| 7700 | os_memcpy(buf + 24, data, data_len); |
| 7701 | hdr = (struct ieee80211_hdr *) buf; |
| 7702 | hdr->frame_control = |
| 7703 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); |
| 7704 | os_memcpy(hdr->addr1, dst, ETH_ALEN); |
| 7705 | os_memcpy(hdr->addr2, src, ETH_ALEN); |
| 7706 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); |
| 7707 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 7708 | if (os_memcmp(bss->addr, src, ETH_ALEN) != 0) { |
| 7709 | wpa_printf(MSG_DEBUG, "nl80211: Use random TA " MACSTR, |
| 7710 | MAC2STR(src)); |
| 7711 | os_memcpy(bss->rand_addr, src, ETH_ALEN); |
| 7712 | } else { |
| 7713 | os_memset(bss->rand_addr, 0, ETH_ALEN); |
| 7714 | } |
| 7715 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7716 | if (is_ap_interface(drv->nlmode) && |
| 7717 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 7718 | (int) freq == bss->freq || drv->device_ap_sme || |
| 7719 | !drv->use_monitor)) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7720 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 7721 | 0, freq, no_cck, offchanok, |
| 7722 | wait_time, NULL, 0, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7723 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7724 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7725 | 24 + data_len, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 7726 | 1, no_cck, 0, offchanok, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7727 | |
| 7728 | os_free(buf); |
| 7729 | return ret; |
| 7730 | } |
| 7731 | |
| 7732 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7733 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7734 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7735 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7736 | struct nl_msg *msg; |
| 7737 | int ret; |
| 7738 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 7739 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7740 | (long long unsigned int) cookie); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7741 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7742 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7743 | nlmsg_free(msg); |
| 7744 | return; |
| 7745 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7746 | |
| 7747 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7748 | if (ret) |
| 7749 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " |
| 7750 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7751 | } |
| 7752 | |
| 7753 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7754 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
| 7755 | { |
| 7756 | struct i802_bss *bss = priv; |
| 7757 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7758 | unsigned int i; |
| 7759 | u64 cookie; |
| 7760 | |
| 7761 | /* Cancel the last pending TX cookie */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 7762 | nl80211_frame_wait_cancel(bss, drv->send_frame_cookie); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7763 | |
| 7764 | /* |
| 7765 | * Cancel the other pending TX cookies, if any. This is needed since |
| 7766 | * the driver may keep a list of all pending offchannel TX operations |
| 7767 | * and free up the radio only once they have expired or cancelled. |
| 7768 | */ |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 7769 | for (i = drv->num_send_frame_cookies; i > 0; i--) { |
| 7770 | cookie = drv->send_frame_cookies[i - 1]; |
| 7771 | if (cookie != drv->send_frame_cookie) |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7772 | nl80211_frame_wait_cancel(bss, cookie); |
| 7773 | } |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 7774 | drv->num_send_frame_cookies = 0; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7775 | } |
| 7776 | |
| 7777 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7778 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
| 7779 | unsigned int duration) |
| 7780 | { |
| 7781 | struct i802_bss *bss = priv; |
| 7782 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7783 | struct nl_msg *msg; |
| 7784 | int ret; |
| 7785 | u64 cookie; |
| 7786 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7787 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
| 7788 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 7789 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { |
| 7790 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7791 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7792 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7793 | |
| 7794 | cookie = 0; |
| 7795 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 7796 | if (ret == 0) { |
| 7797 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " |
| 7798 | "0x%llx for freq=%u MHz duration=%u", |
| 7799 | (long long unsigned int) cookie, freq, duration); |
| 7800 | drv->remain_on_chan_cookie = cookie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7801 | drv->pending_remain_on_chan = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7802 | return 0; |
| 7803 | } |
| 7804 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " |
| 7805 | "(freq=%d duration=%u): %d (%s)", |
| 7806 | freq, duration, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7807 | return -1; |
| 7808 | } |
| 7809 | |
| 7810 | |
| 7811 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) |
| 7812 | { |
| 7813 | struct i802_bss *bss = priv; |
| 7814 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7815 | struct nl_msg *msg; |
| 7816 | int ret; |
| 7817 | |
| 7818 | if (!drv->pending_remain_on_chan) { |
| 7819 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " |
| 7820 | "to cancel"); |
| 7821 | return -1; |
| 7822 | } |
| 7823 | |
| 7824 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " |
| 7825 | "0x%llx", |
| 7826 | (long long unsigned int) drv->remain_on_chan_cookie); |
| 7827 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7828 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
| 7829 | if (!msg || |
| 7830 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
| 7831 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7832 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7833 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7834 | |
| 7835 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7836 | if (ret == 0) |
| 7837 | return 0; |
| 7838 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " |
| 7839 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7840 | return -1; |
| 7841 | } |
| 7842 | |
| 7843 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7844 | 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] | 7845 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7846 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 7847 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7848 | if (!report) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7849 | if (bss->nl_preq && drv->device_ap_sme && |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 7850 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
| 7851 | !bss->static_ap) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7852 | /* |
| 7853 | * Do not disable Probe Request reporting that was |
| 7854 | * enabled in nl80211_setup_ap(). |
| 7855 | */ |
| 7856 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " |
| 7857 | "Probe Request reporting nl_preq=%p while " |
| 7858 | "in AP mode", bss->nl_preq); |
| 7859 | } else if (bss->nl_preq) { |
| 7860 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
| 7861 | "reporting nl_preq=%p", bss->nl_preq); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7862 | nl80211_destroy_eloop_handle(&bss->nl_preq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7863 | } |
| 7864 | return 0; |
| 7865 | } |
| 7866 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7867 | if (bss->nl_preq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7868 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7869 | "already on! nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7870 | return 0; |
| 7871 | } |
| 7872 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7873 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
| 7874 | if (bss->nl_preq == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7875 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7876 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
| 7877 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7878 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7879 | if (nl80211_register_frame(bss, bss->nl_preq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7880 | (WLAN_FC_TYPE_MGMT << 2) | |
| 7881 | (WLAN_FC_STYPE_PROBE_REQ << 4), |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7882 | NULL, 0) < 0) |
| 7883 | goto out_err; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 7884 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7885 | nl80211_register_eloop_read(&bss->nl_preq, |
| 7886 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7887 | bss->nl_cb, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7888 | |
| 7889 | return 0; |
| 7890 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7891 | out_err: |
| 7892 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7893 | return -1; |
| 7894 | } |
| 7895 | |
| 7896 | |
| 7897 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 7898 | int ifindex, int disabled) |
| 7899 | { |
| 7900 | struct nl_msg *msg; |
| 7901 | struct nlattr *bands, *band; |
| 7902 | int ret; |
| 7903 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7904 | wpa_printf(MSG_DEBUG, |
| 7905 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", |
| 7906 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : |
| 7907 | "no NL80211_TXRATE_LEGACY constraint"); |
| 7908 | |
| 7909 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
| 7910 | NL80211_CMD_SET_TX_BITRATE_MASK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7911 | if (!msg) |
| 7912 | return -1; |
| 7913 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7914 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 7915 | if (!bands) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7916 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7917 | |
| 7918 | /* |
| 7919 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything |
| 7920 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS |
| 7921 | * rates. All 5 GHz rates are left enabled. |
| 7922 | */ |
| 7923 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7924 | if (!band || |
| 7925 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, |
| 7926 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) |
| 7927 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7928 | nla_nest_end(msg, band); |
| 7929 | |
| 7930 | nla_nest_end(msg, bands); |
| 7931 | |
| 7932 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7933 | if (ret) { |
| 7934 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " |
| 7935 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7936 | } else |
| 7937 | drv->disabled_11b_rates = disabled; |
| 7938 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7939 | return ret; |
| 7940 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7941 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7942 | nlmsg_free(msg); |
| 7943 | return -1; |
| 7944 | } |
| 7945 | |
| 7946 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7947 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
| 7948 | { |
| 7949 | struct i802_bss *bss = priv; |
| 7950 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7951 | if (!is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7952 | return -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 7953 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7954 | bss->beacon_set = 0; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7955 | |
| 7956 | /* |
| 7957 | * If the P2P GO interface was dynamically added, then it is |
| 7958 | * possible that the interface change to station is not possible. |
| 7959 | */ |
| 7960 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) |
| 7961 | return 0; |
| 7962 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7963 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7964 | } |
| 7965 | |
| 7966 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7967 | static int wpa_driver_nl80211_stop_ap(void *priv) |
| 7968 | { |
| 7969 | struct i802_bss *bss = priv; |
| 7970 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7971 | if (!is_ap_interface(drv->nlmode)) |
| 7972 | return -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 7973 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7974 | bss->beacon_set = 0; |
| 7975 | return 0; |
| 7976 | } |
| 7977 | |
| 7978 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7979 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
| 7980 | { |
| 7981 | struct i802_bss *bss = priv; |
| 7982 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7983 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) |
| 7984 | return -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7985 | |
| 7986 | /* |
| 7987 | * If the P2P Client interface was dynamically added, then it is |
| 7988 | * possible that the interface change to station is not possible. |
| 7989 | */ |
| 7990 | if (bss->if_dynamic) |
| 7991 | return 0; |
| 7992 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7993 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
| 7994 | } |
| 7995 | |
| 7996 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7997 | static void wpa_driver_nl80211_resume(void *priv) |
| 7998 | { |
| 7999 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8000 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8001 | |
| 8002 | if (i802_set_iface_flags(bss, 1)) |
| 8003 | 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] | 8004 | |
| 8005 | if (is_p2p_net_interface(nlmode)) |
| 8006 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8007 | } |
| 8008 | |
| 8009 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8010 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
| 8011 | { |
| 8012 | struct i802_bss *bss = priv; |
| 8013 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8014 | struct nl_msg *msg; |
| 8015 | struct nlattr *cqm; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8016 | |
| 8017 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " |
| 8018 | "hysteresis=%d", threshold, hysteresis); |
| 8019 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8020 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
| 8021 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
| 8022 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || |
| 8023 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { |
| 8024 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8025 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8026 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 8027 | nla_nest_end(msg, cqm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8028 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8029 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8030 | } |
| 8031 | |
| 8032 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8033 | static int get_channel_width(struct nl_msg *msg, void *arg) |
| 8034 | { |
| 8035 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8036 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8037 | struct wpa_signal_info *sig_change = arg; |
| 8038 | |
| 8039 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8040 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8041 | |
| 8042 | sig_change->center_frq1 = -1; |
| 8043 | sig_change->center_frq2 = -1; |
| 8044 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 8045 | |
| 8046 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 8047 | sig_change->chanwidth = convert2width( |
| 8048 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 8049 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 8050 | sig_change->center_frq1 = |
| 8051 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 8052 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 8053 | sig_change->center_frq2 = |
| 8054 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 8055 | } |
| 8056 | |
| 8057 | return NL_SKIP; |
| 8058 | } |
| 8059 | |
| 8060 | |
| 8061 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, |
| 8062 | struct wpa_signal_info *sig) |
| 8063 | { |
| 8064 | struct nl_msg *msg; |
| 8065 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8066 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8067 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8068 | } |
| 8069 | |
| 8070 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8071 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
| 8072 | { |
| 8073 | struct i802_bss *bss = priv; |
| 8074 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8075 | int res; |
| 8076 | |
| 8077 | os_memset(si, 0, sizeof(*si)); |
| 8078 | res = nl80211_get_link_signal(drv, si); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8079 | if (res) { |
| 8080 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && |
| 8081 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
| 8082 | return res; |
| 8083 | si->current_signal = 0; |
| 8084 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8085 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8086 | res = nl80211_get_channel_width(drv, si); |
| 8087 | if (res != 0) |
| 8088 | return res; |
| 8089 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8090 | return nl80211_get_link_noise(drv, si); |
| 8091 | } |
| 8092 | |
| 8093 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8094 | static int nl80211_set_param(void *priv, const char *param) |
| 8095 | { |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 8096 | struct i802_bss *bss = priv; |
| 8097 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8098 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8099 | if (param == NULL) |
| 8100 | return 0; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 8101 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8102 | |
| 8103 | #ifdef CONFIG_P2P |
| 8104 | if (os_strstr(param, "use_p2p_group_interface=1")) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8105 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 8106 | "interface"); |
| 8107 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 8108 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 8109 | } |
| 8110 | #endif /* CONFIG_P2P */ |
| 8111 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 8112 | if (os_strstr(param, "use_monitor=1")) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8113 | drv->use_monitor = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8114 | |
| 8115 | if (os_strstr(param, "force_connect_cmd=1")) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8116 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8117 | drv->force_connect_cmd = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8118 | } |
| 8119 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 8120 | if (os_strstr(param, "force_bss_selection=1")) |
| 8121 | drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
| 8122 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 8123 | if (os_strstr(param, "no_offchannel_tx=1")) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 8124 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 8125 | drv->test_use_roc_tx = 1; |
| 8126 | } |
| 8127 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 8128 | if (os_strstr(param, "control_port=0")) |
| 8129 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_CONTROL_PORT; |
| 8130 | |
| 8131 | if (os_strstr(param, "full_ap_client_state=0")) |
| 8132 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_FULL_AP_CLIENT_STATE; |
| 8133 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8134 | return 0; |
| 8135 | } |
| 8136 | |
| 8137 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 8138 | static void * nl80211_global_init(void *ctx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8139 | { |
| 8140 | struct nl80211_global *global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8141 | struct netlink_config *cfg; |
| 8142 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8143 | global = os_zalloc(sizeof(*global)); |
| 8144 | if (global == NULL) |
| 8145 | return NULL; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 8146 | global->ctx = ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8147 | global->ioctl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8148 | dl_list_init(&global->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8149 | global->if_add_ifindex = -1; |
| 8150 | |
| 8151 | cfg = os_zalloc(sizeof(*cfg)); |
| 8152 | if (cfg == NULL) |
| 8153 | goto err; |
| 8154 | |
| 8155 | cfg->ctx = global; |
| 8156 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; |
| 8157 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; |
| 8158 | global->netlink = netlink_init(cfg); |
| 8159 | if (global->netlink == NULL) { |
| 8160 | os_free(cfg); |
| 8161 | goto err; |
| 8162 | } |
| 8163 | |
| 8164 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
| 8165 | goto err; |
| 8166 | |
| 8167 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 8168 | if (global->ioctl_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8169 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
| 8170 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8171 | goto err; |
| 8172 | } |
| 8173 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8174 | return global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8175 | |
| 8176 | err: |
| 8177 | nl80211_global_deinit(global); |
| 8178 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8179 | } |
| 8180 | |
| 8181 | |
| 8182 | static void nl80211_global_deinit(void *priv) |
| 8183 | { |
| 8184 | struct nl80211_global *global = priv; |
| 8185 | if (global == NULL) |
| 8186 | return; |
| 8187 | if (!dl_list_empty(&global->interfaces)) { |
| 8188 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " |
| 8189 | "nl80211_global_deinit", |
| 8190 | dl_list_len(&global->interfaces)); |
| 8191 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8192 | |
| 8193 | if (global->netlink) |
| 8194 | netlink_deinit(global->netlink); |
| 8195 | |
| 8196 | nl_destroy_handles(&global->nl); |
| 8197 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 8198 | if (global->nl_event) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8199 | nl80211_destroy_eloop_handle(&global->nl_event, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8200 | |
| 8201 | nl_cb_put(global->nl_cb); |
| 8202 | |
| 8203 | if (global->ioctl_sock >= 0) |
| 8204 | close(global->ioctl_sock); |
| 8205 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 8206 | os_free(global); |
| 8207 | } |
| 8208 | |
| 8209 | |
| 8210 | static const char * nl80211_get_radio_name(void *priv) |
| 8211 | { |
| 8212 | struct i802_bss *bss = priv; |
| 8213 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8214 | return drv->phyname; |
| 8215 | } |
| 8216 | |
| 8217 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8218 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, |
| 8219 | struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8220 | { |
| 8221 | struct nl_msg *msg; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8222 | const size_t PMK_MAX_LEN = 48; /* current cfg80211 limit */ |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8223 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8224 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8225 | (params->pmkid && |
| 8226 | nla_put(msg, NL80211_ATTR_PMKID, 16, params->pmkid)) || |
| 8227 | (params->bssid && |
| 8228 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) || |
| 8229 | (params->ssid_len && |
| 8230 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || |
| 8231 | (params->fils_cache_id && |
| 8232 | nla_put(msg, NL80211_ATTR_FILS_CACHE_ID, 2, |
| 8233 | params->fils_cache_id)) || |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 8234 | (params->pmk_lifetime && |
| 8235 | nla_put_u32(msg, NL80211_ATTR_PMK_LIFETIME, |
| 8236 | params->pmk_lifetime)) || |
| 8237 | (params->pmk_reauth_threshold && |
| 8238 | nla_put_u8(msg, NL80211_ATTR_PMK_REAUTH_THRESHOLD, |
| 8239 | params->pmk_reauth_threshold)) || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 8240 | (cmd != NL80211_CMD_DEL_PMKSA && |
| 8241 | params->pmk_len && params->pmk_len <= PMK_MAX_LEN && |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8242 | nla_put(msg, NL80211_ATTR_PMK, params->pmk_len, params->pmk))) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8243 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8244 | nlmsg_free(msg); |
| 8245 | return -ENOBUFS; |
| 8246 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8247 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8248 | return send_and_recv_msgs(bss->drv, msg, NULL, (void *) -1); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8249 | } |
| 8250 | |
| 8251 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8252 | static int nl80211_add_pmkid(void *priv, struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8253 | { |
| 8254 | struct i802_bss *bss = priv; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8255 | int ret; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8256 | |
| 8257 | if (params->bssid) |
| 8258 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, |
| 8259 | MAC2STR(params->bssid)); |
| 8260 | else if (params->fils_cache_id && params->ssid_len) { |
| 8261 | wpa_printf(MSG_DEBUG, |
| 8262 | "nl80211: Add PMKSA for cache id %02x%02x SSID %s", |
| 8263 | params->fils_cache_id[0], params->fils_cache_id[1], |
| 8264 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
| 8265 | } |
| 8266 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8267 | ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params); |
| 8268 | if (ret < 0) { |
| 8269 | wpa_printf(MSG_DEBUG, |
| 8270 | "nl80211: NL80211_CMD_SET_PMKSA failed: %d (%s)", |
| 8271 | ret, strerror(-ret)); |
| 8272 | } |
| 8273 | |
| 8274 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8275 | } |
| 8276 | |
| 8277 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8278 | static int nl80211_remove_pmkid(void *priv, struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8279 | { |
| 8280 | struct i802_bss *bss = priv; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8281 | int ret; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8282 | |
| 8283 | if (params->bssid) |
| 8284 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, |
| 8285 | MAC2STR(params->bssid)); |
| 8286 | else if (params->fils_cache_id && params->ssid_len) { |
| 8287 | wpa_printf(MSG_DEBUG, |
| 8288 | "nl80211: Delete PMKSA for cache id %02x%02x SSID %s", |
| 8289 | params->fils_cache_id[0], params->fils_cache_id[1], |
| 8290 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
| 8291 | } |
| 8292 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8293 | ret = nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, params); |
| 8294 | if (ret < 0) { |
| 8295 | wpa_printf(MSG_DEBUG, |
| 8296 | "nl80211: NL80211_CMD_DEL_PMKSA failed: %d (%s)", |
| 8297 | ret, strerror(-ret)); |
| 8298 | } |
| 8299 | |
| 8300 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8301 | } |
| 8302 | |
| 8303 | |
| 8304 | static int nl80211_flush_pmkid(void *priv) |
| 8305 | { |
| 8306 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8307 | struct nl_msg *msg; |
| 8308 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8309 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8310 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_FLUSH_PMKSA); |
| 8311 | if (!msg) |
| 8312 | return -ENOBUFS; |
| 8313 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8314 | } |
| 8315 | |
| 8316 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8317 | static void clean_survey_results(struct survey_results *survey_results) |
| 8318 | { |
| 8319 | struct freq_survey *survey, *tmp; |
| 8320 | |
| 8321 | if (dl_list_empty(&survey_results->survey_list)) |
| 8322 | return; |
| 8323 | |
| 8324 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 8325 | struct freq_survey, list) { |
| 8326 | dl_list_del(&survey->list); |
| 8327 | os_free(survey); |
| 8328 | } |
| 8329 | } |
| 8330 | |
| 8331 | |
| 8332 | static void add_survey(struct nlattr **sinfo, u32 ifidx, |
| 8333 | struct dl_list *survey_list) |
| 8334 | { |
| 8335 | struct freq_survey *survey; |
| 8336 | |
| 8337 | survey = os_zalloc(sizeof(struct freq_survey)); |
| 8338 | if (!survey) |
| 8339 | return; |
| 8340 | |
| 8341 | survey->ifidx = ifidx; |
| 8342 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 8343 | survey->filled = 0; |
| 8344 | |
| 8345 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { |
| 8346 | survey->nf = (int8_t) |
| 8347 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 8348 | survey->filled |= SURVEY_HAS_NF; |
| 8349 | } |
| 8350 | |
| 8351 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { |
| 8352 | survey->channel_time = |
| 8353 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); |
| 8354 | survey->filled |= SURVEY_HAS_CHAN_TIME; |
| 8355 | } |
| 8356 | |
| 8357 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { |
| 8358 | survey->channel_time_busy = |
| 8359 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); |
| 8360 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; |
| 8361 | } |
| 8362 | |
| 8363 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { |
| 8364 | survey->channel_time_rx = |
| 8365 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); |
| 8366 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; |
| 8367 | } |
| 8368 | |
| 8369 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { |
| 8370 | survey->channel_time_tx = |
| 8371 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); |
| 8372 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; |
| 8373 | } |
| 8374 | |
| 8375 | 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)", |
| 8376 | survey->freq, |
| 8377 | survey->nf, |
| 8378 | (unsigned long int) survey->channel_time, |
| 8379 | (unsigned long int) survey->channel_time_busy, |
| 8380 | (unsigned long int) survey->channel_time_tx, |
| 8381 | (unsigned long int) survey->channel_time_rx, |
| 8382 | survey->filled); |
| 8383 | |
| 8384 | dl_list_add_tail(survey_list, &survey->list); |
| 8385 | } |
| 8386 | |
| 8387 | |
| 8388 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, |
| 8389 | unsigned int freq_filter) |
| 8390 | { |
| 8391 | if (!freq_filter) |
| 8392 | return 1; |
| 8393 | |
| 8394 | return freq_filter == surveyed_freq; |
| 8395 | } |
| 8396 | |
| 8397 | |
| 8398 | static int survey_handler(struct nl_msg *msg, void *arg) |
| 8399 | { |
| 8400 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8401 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8402 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 8403 | struct survey_results *survey_results; |
| 8404 | u32 surveyed_freq = 0; |
| 8405 | u32 ifidx; |
| 8406 | |
| 8407 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 8408 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 8409 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 8410 | }; |
| 8411 | |
| 8412 | survey_results = (struct survey_results *) arg; |
| 8413 | |
| 8414 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8415 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8416 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 8417 | if (!tb[NL80211_ATTR_IFINDEX]) |
| 8418 | return NL_SKIP; |
| 8419 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8420 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 8421 | |
| 8422 | if (!tb[NL80211_ATTR_SURVEY_INFO]) |
| 8423 | return NL_SKIP; |
| 8424 | |
| 8425 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 8426 | tb[NL80211_ATTR_SURVEY_INFO], |
| 8427 | survey_policy)) |
| 8428 | return NL_SKIP; |
| 8429 | |
| 8430 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { |
| 8431 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); |
| 8432 | return NL_SKIP; |
| 8433 | } |
| 8434 | |
| 8435 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 8436 | |
| 8437 | if (!check_survey_ok(sinfo, surveyed_freq, |
| 8438 | survey_results->freq_filter)) |
| 8439 | return NL_SKIP; |
| 8440 | |
| 8441 | if (survey_results->freq_filter && |
| 8442 | survey_results->freq_filter != surveyed_freq) { |
| 8443 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", |
| 8444 | surveyed_freq); |
| 8445 | return NL_SKIP; |
| 8446 | } |
| 8447 | |
| 8448 | add_survey(sinfo, ifidx, &survey_results->survey_list); |
| 8449 | |
| 8450 | return NL_SKIP; |
| 8451 | } |
| 8452 | |
| 8453 | |
| 8454 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) |
| 8455 | { |
| 8456 | struct i802_bss *bss = priv; |
| 8457 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8458 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8459 | int err; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8460 | union wpa_event_data data; |
| 8461 | struct survey_results *survey_results; |
| 8462 | |
| 8463 | os_memset(&data, 0, sizeof(data)); |
| 8464 | survey_results = &data.survey_results; |
| 8465 | |
| 8466 | dl_list_init(&survey_results->survey_list); |
| 8467 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8468 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8469 | if (!msg) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8470 | return -ENOBUFS; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8471 | |
| 8472 | if (freq) |
| 8473 | data.survey_results.freq_filter = freq; |
| 8474 | |
| 8475 | do { |
| 8476 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); |
| 8477 | err = send_and_recv_msgs(drv, msg, survey_handler, |
| 8478 | survey_results); |
| 8479 | } while (err > 0); |
| 8480 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8481 | if (err) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8482 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8483 | else |
| 8484 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8485 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8486 | clean_survey_results(survey_results); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8487 | return err; |
| 8488 | } |
| 8489 | |
| 8490 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 8491 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
| 8492 | const u8 *kck, size_t kck_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8493 | const u8 *replay_ctr) |
| 8494 | { |
| 8495 | struct i802_bss *bss = priv; |
| 8496 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8497 | struct nlattr *replay_nested; |
| 8498 | struct nl_msg *msg; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8499 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8500 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8501 | if (!drv->set_rekey_offload) |
| 8502 | return; |
| 8503 | |
| 8504 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8505 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
| 8506 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 8507 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8508 | (kck_len && nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8509 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
| 8510 | replay_ctr)) { |
| 8511 | nl80211_nlmsg_clear(msg); |
| 8512 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8513 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8514 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8515 | |
| 8516 | nla_nest_end(msg, replay_nested); |
| 8517 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8518 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 8519 | if (ret == -EOPNOTSUPP) { |
| 8520 | wpa_printf(MSG_DEBUG, |
| 8521 | "nl80211: Driver does not support rekey offload"); |
| 8522 | drv->set_rekey_offload = 0; |
| 8523 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8524 | } |
| 8525 | |
| 8526 | |
| 8527 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
| 8528 | const u8 *addr, int qos) |
| 8529 | { |
| 8530 | /* send data frame to poll STA and check whether |
| 8531 | * this frame is ACKed */ |
| 8532 | struct { |
| 8533 | struct ieee80211_hdr hdr; |
| 8534 | u16 qos_ctl; |
| 8535 | } STRUCT_PACKED nulldata; |
| 8536 | size_t size; |
| 8537 | |
| 8538 | /* Send data frame to poll STA and check whether this frame is ACKed */ |
| 8539 | |
| 8540 | os_memset(&nulldata, 0, sizeof(nulldata)); |
| 8541 | |
| 8542 | if (qos) { |
| 8543 | nulldata.hdr.frame_control = |
| 8544 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 8545 | WLAN_FC_STYPE_QOS_NULL); |
| 8546 | size = sizeof(nulldata); |
| 8547 | } else { |
| 8548 | nulldata.hdr.frame_control = |
| 8549 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 8550 | WLAN_FC_STYPE_NULLFUNC); |
| 8551 | size = sizeof(struct ieee80211_hdr); |
| 8552 | } |
| 8553 | |
| 8554 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 8555 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 8556 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 8557 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 8558 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8559 | 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^] | 8560 | 0, 0, NULL, 0, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8561 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
| 8562 | "send poll frame"); |
| 8563 | } |
| 8564 | |
| 8565 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
| 8566 | int qos) |
| 8567 | { |
| 8568 | struct i802_bss *bss = priv; |
| 8569 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8570 | struct nl_msg *msg; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 8571 | u64 cookie; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8572 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8573 | |
| 8574 | if (!drv->poll_command_supported) { |
| 8575 | nl80211_send_null_frame(bss, own_addr, addr, qos); |
| 8576 | return; |
| 8577 | } |
| 8578 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8579 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
| 8580 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 8581 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8582 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8583 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8584 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 8585 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8586 | if (ret < 0) { |
| 8587 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " |
| 8588 | MACSTR " failed: ret=%d (%s)", |
| 8589 | MAC2STR(addr), ret, strerror(-ret)); |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 8590 | } else { |
| 8591 | wpa_printf(MSG_DEBUG, |
| 8592 | "nl80211: Client probe request addr=" MACSTR |
| 8593 | " cookie=%llu", MAC2STR(addr), |
| 8594 | (long long unsigned int) cookie); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8595 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8596 | } |
| 8597 | |
| 8598 | |
| 8599 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
| 8600 | { |
| 8601 | struct nl_msg *msg; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8602 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8603 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8604 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
| 8605 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
| 8606 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { |
| 8607 | nlmsg_free(msg); |
| 8608 | return -ENOBUFS; |
| 8609 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8610 | |
| 8611 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 8612 | if (ret < 0) { |
| 8613 | wpa_printf(MSG_DEBUG, |
| 8614 | "nl80211: Setting PS state %s failed: %d (%s)", |
| 8615 | enabled ? "enabled" : "disabled", |
| 8616 | ret, strerror(-ret)); |
| 8617 | } |
| 8618 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8619 | } |
| 8620 | |
| 8621 | |
| 8622 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, |
| 8623 | int ctwindow) |
| 8624 | { |
| 8625 | struct i802_bss *bss = priv; |
| 8626 | |
| 8627 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " |
| 8628 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); |
| 8629 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8630 | if (opp_ps != -1 || ctwindow != -1) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8631 | #ifdef ANDROID_P2P |
| 8632 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8633 | #else /* ANDROID_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8634 | return -1; /* Not yet supported */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8635 | #endif /* ANDROID_P2P */ |
| 8636 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8637 | |
| 8638 | if (legacy_ps == -1) |
| 8639 | return 0; |
| 8640 | if (legacy_ps != 0 && legacy_ps != 1) |
| 8641 | return -1; /* Not yet supported */ |
| 8642 | |
| 8643 | return nl80211_set_power_save(bss, legacy_ps); |
| 8644 | } |
| 8645 | |
| 8646 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8647 | static int nl80211_start_radar_detection(void *priv, |
| 8648 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8649 | { |
| 8650 | struct i802_bss *bss = priv; |
| 8651 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8652 | struct nl_msg *msg; |
| 8653 | int ret; |
| 8654 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 8655 | 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)", |
| 8656 | freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8657 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 8658 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8659 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
| 8660 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " |
| 8661 | "detection"); |
| 8662 | return -1; |
| 8663 | } |
| 8664 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8665 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
| 8666 | nl80211_put_freq_params(msg, freq) < 0) { |
| 8667 | nlmsg_free(msg); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8668 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8669 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8670 | |
| 8671 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8672 | if (ret == 0) |
| 8673 | return 0; |
| 8674 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " |
| 8675 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8676 | return -1; |
| 8677 | } |
| 8678 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8679 | #ifdef CONFIG_TDLS |
| 8680 | |
| 8681 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, |
| 8682 | u8 dialog_token, u16 status_code, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 8683 | u32 peer_capab, int initiator, const u8 *buf, |
| 8684 | size_t len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8685 | { |
| 8686 | struct i802_bss *bss = priv; |
| 8687 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8688 | struct nl_msg *msg; |
| 8689 | |
| 8690 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 8691 | return -EOPNOTSUPP; |
| 8692 | |
| 8693 | if (!dst) |
| 8694 | return -EINVAL; |
| 8695 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8696 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
| 8697 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 8698 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || |
| 8699 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || |
| 8700 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) |
| 8701 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8702 | if (peer_capab) { |
| 8703 | /* |
| 8704 | * The internal enum tdls_peer_capability definition is |
| 8705 | * currently identical with the nl80211 enum |
| 8706 | * nl80211_tdls_peer_capability, so no conversion is needed |
| 8707 | * here. |
| 8708 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8709 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
| 8710 | peer_capab)) |
| 8711 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8712 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8713 | if ((initiator && |
| 8714 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || |
| 8715 | nla_put(msg, NL80211_ATTR_IE, len, buf)) |
| 8716 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8717 | |
| 8718 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8719 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8720 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8721 | nlmsg_free(msg); |
| 8722 | return -ENOBUFS; |
| 8723 | } |
| 8724 | |
| 8725 | |
| 8726 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) |
| 8727 | { |
| 8728 | struct i802_bss *bss = priv; |
| 8729 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8730 | struct nl_msg *msg; |
| 8731 | enum nl80211_tdls_operation nl80211_oper; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8732 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8733 | |
| 8734 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 8735 | return -EOPNOTSUPP; |
| 8736 | |
| 8737 | switch (oper) { |
| 8738 | case TDLS_DISCOVERY_REQ: |
| 8739 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; |
| 8740 | break; |
| 8741 | case TDLS_SETUP: |
| 8742 | nl80211_oper = NL80211_TDLS_SETUP; |
| 8743 | break; |
| 8744 | case TDLS_TEARDOWN: |
| 8745 | nl80211_oper = NL80211_TDLS_TEARDOWN; |
| 8746 | break; |
| 8747 | case TDLS_ENABLE_LINK: |
| 8748 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; |
| 8749 | break; |
| 8750 | case TDLS_DISABLE_LINK: |
| 8751 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; |
| 8752 | break; |
| 8753 | case TDLS_ENABLE: |
| 8754 | return 0; |
| 8755 | case TDLS_DISABLE: |
| 8756 | return 0; |
| 8757 | default: |
| 8758 | return -EINVAL; |
| 8759 | } |
| 8760 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8761 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
| 8762 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
| 8763 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
| 8764 | nlmsg_free(msg); |
| 8765 | return -ENOBUFS; |
| 8766 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8767 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8768 | res = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8769 | wpa_printf(MSG_DEBUG, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR |
| 8770 | " --> res=%d (%s)", nl80211_oper, MAC2STR(peer), res, |
| 8771 | strerror(-res)); |
| 8772 | return res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8773 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8774 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8775 | |
| 8776 | static int |
| 8777 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, |
| 8778 | const struct hostapd_freq_params *params) |
| 8779 | { |
| 8780 | struct i802_bss *bss = priv; |
| 8781 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8782 | struct nl_msg *msg; |
| 8783 | int ret = -ENOBUFS; |
| 8784 | |
| 8785 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 8786 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 8787 | return -EOPNOTSUPP; |
| 8788 | |
| 8789 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR |
| 8790 | " oper_class=%u freq=%u", |
| 8791 | MAC2STR(addr), oper_class, params->freq); |
| 8792 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); |
| 8793 | if (!msg || |
| 8794 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 8795 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || |
| 8796 | (ret = nl80211_put_freq_params(msg, params))) { |
| 8797 | nlmsg_free(msg); |
| 8798 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); |
| 8799 | return ret; |
| 8800 | } |
| 8801 | |
| 8802 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8803 | } |
| 8804 | |
| 8805 | |
| 8806 | static int |
| 8807 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) |
| 8808 | { |
| 8809 | struct i802_bss *bss = priv; |
| 8810 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8811 | struct nl_msg *msg; |
| 8812 | |
| 8813 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 8814 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 8815 | return -EOPNOTSUPP; |
| 8816 | |
| 8817 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, |
| 8818 | MAC2STR(addr)); |
| 8819 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); |
| 8820 | if (!msg || |
| 8821 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 8822 | nlmsg_free(msg); |
| 8823 | wpa_printf(MSG_DEBUG, |
| 8824 | "nl80211: Could not build TDLS cancel chan switch"); |
| 8825 | return -ENOBUFS; |
| 8826 | } |
| 8827 | |
| 8828 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8829 | } |
| 8830 | |
| 8831 | #endif /* CONFIG TDLS */ |
| 8832 | |
| 8833 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 8834 | static int driver_nl80211_set_key(void *priv, |
| 8835 | struct wpa_driver_set_key_params *params) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8836 | { |
| 8837 | struct i802_bss *bss = priv; |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 8838 | |
| 8839 | return wpa_driver_nl80211_set_key(bss, params); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8840 | } |
| 8841 | |
| 8842 | |
| 8843 | static int driver_nl80211_scan2(void *priv, |
| 8844 | struct wpa_driver_scan_params *params) |
| 8845 | { |
| 8846 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8847 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 8848 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8849 | |
| 8850 | /* |
| 8851 | * Do a vendor specific scan if possible. If only_new_results is |
| 8852 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush |
| 8853 | * cannot be achieved through a vendor scan. The below condition may |
| 8854 | * need to be modified if new scan flags are added in the future whose |
| 8855 | * functionality can only be achieved through a normal scan. |
| 8856 | */ |
| 8857 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) |
| 8858 | return wpa_driver_nl80211_vendor_scan(bss, params); |
| 8859 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8860 | return wpa_driver_nl80211_scan(bss, params); |
| 8861 | } |
| 8862 | |
| 8863 | |
| 8864 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 8865 | u16 reason_code) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8866 | { |
| 8867 | struct i802_bss *bss = priv; |
| 8868 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); |
| 8869 | } |
| 8870 | |
| 8871 | |
| 8872 | static int driver_nl80211_authenticate(void *priv, |
| 8873 | struct wpa_driver_auth_params *params) |
| 8874 | { |
| 8875 | struct i802_bss *bss = priv; |
| 8876 | return wpa_driver_nl80211_authenticate(bss, params); |
| 8877 | } |
| 8878 | |
| 8879 | |
| 8880 | static void driver_nl80211_deinit(void *priv) |
| 8881 | { |
| 8882 | struct i802_bss *bss = priv; |
| 8883 | wpa_driver_nl80211_deinit(bss); |
| 8884 | } |
| 8885 | |
| 8886 | |
| 8887 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, |
| 8888 | const char *ifname) |
| 8889 | { |
| 8890 | struct i802_bss *bss = priv; |
| 8891 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 8892 | } |
| 8893 | |
| 8894 | |
| 8895 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8896 | size_t data_len, int noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8897 | unsigned int freq, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 8898 | const u16 *csa_offs, size_t csa_offs_len, |
| 8899 | int no_encrypt, unsigned int wait) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8900 | { |
| 8901 | struct i802_bss *bss = priv; |
| 8902 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 8903 | freq, 0, 0, wait, csa_offs, |
| 8904 | csa_offs_len, no_encrypt); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8905 | } |
| 8906 | |
| 8907 | |
| 8908 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) |
| 8909 | { |
| 8910 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8911 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8912 | } |
| 8913 | |
| 8914 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8915 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
| 8916 | const char *ifname, int vlan_id) |
| 8917 | { |
| 8918 | struct i802_bss *bss = priv; |
| 8919 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); |
| 8920 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8921 | |
| 8922 | |
| 8923 | static int driver_nl80211_read_sta_data(void *priv, |
| 8924 | struct hostap_sta_driver_data *data, |
| 8925 | const u8 *addr) |
| 8926 | { |
| 8927 | struct i802_bss *bss = priv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 8928 | |
| 8929 | os_memset(data, 0, sizeof(*data)); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8930 | return i802_read_sta_data(bss, data, addr); |
| 8931 | } |
| 8932 | |
| 8933 | |
| 8934 | static int driver_nl80211_send_action(void *priv, unsigned int freq, |
| 8935 | unsigned int wait_time, |
| 8936 | const u8 *dst, const u8 *src, |
| 8937 | const u8 *bssid, |
| 8938 | const u8 *data, size_t data_len, |
| 8939 | int no_cck) |
| 8940 | { |
| 8941 | struct i802_bss *bss = priv; |
| 8942 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, |
| 8943 | bssid, data, data_len, no_cck); |
| 8944 | } |
| 8945 | |
| 8946 | |
| 8947 | static int driver_nl80211_probe_req_report(void *priv, int report) |
| 8948 | { |
| 8949 | struct i802_bss *bss = priv; |
| 8950 | return wpa_driver_nl80211_probe_req_report(bss, report); |
| 8951 | } |
| 8952 | |
| 8953 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8954 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
| 8955 | const u8 *ies, size_t ies_len) |
| 8956 | { |
| 8957 | int ret; |
| 8958 | struct nl_msg *msg; |
| 8959 | struct i802_bss *bss = priv; |
| 8960 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8961 | u16 mdid = WPA_GET_LE16(md); |
| 8962 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8963 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8964 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
| 8965 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
| 8966 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { |
| 8967 | nlmsg_free(msg); |
| 8968 | return -ENOBUFS; |
| 8969 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8970 | |
| 8971 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8972 | if (ret) { |
| 8973 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " |
| 8974 | "err=%d (%s)", ret, strerror(-ret)); |
| 8975 | } |
| 8976 | |
| 8977 | return ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8978 | } |
| 8979 | |
| 8980 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 8981 | static int nl80211_update_dh_ie(void *priv, const u8 *peer_mac, |
| 8982 | u16 reason_code, const u8 *ie, size_t ie_len) |
| 8983 | { |
| 8984 | int ret; |
| 8985 | struct nl_msg *msg; |
| 8986 | struct i802_bss *bss = priv; |
| 8987 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8988 | |
| 8989 | wpa_printf(MSG_DEBUG, "nl80211: Updating DH IE peer: " MACSTR |
| 8990 | " reason %u", MAC2STR(peer_mac), reason_code); |
| 8991 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UPDATE_OWE_INFO)) || |
| 8992 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer_mac) || |
| 8993 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, reason_code) || |
| 8994 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) { |
| 8995 | nlmsg_free(msg); |
| 8996 | return -ENOBUFS; |
| 8997 | } |
| 8998 | |
| 8999 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9000 | if (ret) { |
| 9001 | wpa_printf(MSG_DEBUG, |
| 9002 | "nl80211: update_dh_ie failed err=%d (%s)", |
| 9003 | ret, strerror(-ret)); |
| 9004 | } |
| 9005 | |
| 9006 | return ret; |
| 9007 | } |
| 9008 | |
| 9009 | |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 9010 | static const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9011 | { |
| 9012 | struct i802_bss *bss = priv; |
| 9013 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9014 | |
| 9015 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 9016 | return NULL; |
| 9017 | |
| 9018 | return bss->addr; |
| 9019 | } |
| 9020 | |
| 9021 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9022 | static const char * scan_state_str(enum scan_states scan_state) |
| 9023 | { |
| 9024 | switch (scan_state) { |
| 9025 | case NO_SCAN: |
| 9026 | return "NO_SCAN"; |
| 9027 | case SCAN_REQUESTED: |
| 9028 | return "SCAN_REQUESTED"; |
| 9029 | case SCAN_STARTED: |
| 9030 | return "SCAN_STARTED"; |
| 9031 | case SCAN_COMPLETED: |
| 9032 | return "SCAN_COMPLETED"; |
| 9033 | case SCAN_ABORTED: |
| 9034 | return "SCAN_ABORTED"; |
| 9035 | case SCHED_SCAN_STARTED: |
| 9036 | return "SCHED_SCAN_STARTED"; |
| 9037 | case SCHED_SCAN_STOPPED: |
| 9038 | return "SCHED_SCAN_STOPPED"; |
| 9039 | case SCHED_SCAN_RESULTS: |
| 9040 | return "SCHED_SCAN_RESULTS"; |
| 9041 | } |
| 9042 | |
| 9043 | return "??"; |
| 9044 | } |
| 9045 | |
| 9046 | |
| 9047 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) |
| 9048 | { |
| 9049 | struct i802_bss *bss = priv; |
| 9050 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9051 | int res; |
| 9052 | char *pos, *end; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9053 | struct nl_msg *msg; |
| 9054 | char alpha2[3] = { 0, 0, 0 }; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9055 | |
| 9056 | pos = buf; |
| 9057 | end = buf + buflen; |
| 9058 | |
| 9059 | res = os_snprintf(pos, end - pos, |
| 9060 | "ifindex=%d\n" |
| 9061 | "ifname=%s\n" |
| 9062 | "brname=%s\n" |
| 9063 | "addr=" MACSTR "\n" |
| 9064 | "freq=%d\n" |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 9065 | "%s%s%s%s%s%s", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9066 | bss->ifindex, |
| 9067 | bss->ifname, |
| 9068 | bss->brname, |
| 9069 | MAC2STR(bss->addr), |
| 9070 | bss->freq, |
| 9071 | bss->beacon_set ? "beacon_set=1\n" : "", |
| 9072 | bss->added_if_into_bridge ? |
| 9073 | "added_if_into_bridge=1\n" : "", |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 9074 | bss->already_in_bridge ? "already_in_bridge=1\n" : "", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9075 | bss->added_bridge ? "added_bridge=1\n" : "", |
| 9076 | bss->in_deinit ? "in_deinit=1\n" : "", |
| 9077 | bss->if_dynamic ? "if_dynamic=1\n" : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9078 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9079 | return pos - buf; |
| 9080 | pos += res; |
| 9081 | |
| 9082 | if (bss->wdev_id_set) { |
| 9083 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", |
| 9084 | (unsigned long long) bss->wdev_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9085 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9086 | return pos - buf; |
| 9087 | pos += res; |
| 9088 | } |
| 9089 | |
| 9090 | res = os_snprintf(pos, end - pos, |
| 9091 | "phyname=%s\n" |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9092 | "perm_addr=" MACSTR "\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9093 | "drv_ifindex=%d\n" |
| 9094 | "operstate=%d\n" |
| 9095 | "scan_state=%s\n" |
| 9096 | "auth_bssid=" MACSTR "\n" |
| 9097 | "auth_attempt_bssid=" MACSTR "\n" |
| 9098 | "bssid=" MACSTR "\n" |
| 9099 | "prev_bssid=" MACSTR "\n" |
| 9100 | "associated=%d\n" |
| 9101 | "assoc_freq=%u\n" |
| 9102 | "monitor_sock=%d\n" |
| 9103 | "monitor_ifidx=%d\n" |
| 9104 | "monitor_refcount=%d\n" |
| 9105 | "last_mgmt_freq=%u\n" |
| 9106 | "eapol_tx_sock=%d\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9107 | "%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] | 9108 | drv->phyname, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9109 | MAC2STR(drv->perm_addr), |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9110 | drv->ifindex, |
| 9111 | drv->operstate, |
| 9112 | scan_state_str(drv->scan_state), |
| 9113 | MAC2STR(drv->auth_bssid), |
| 9114 | MAC2STR(drv->auth_attempt_bssid), |
| 9115 | MAC2STR(drv->bssid), |
| 9116 | MAC2STR(drv->prev_bssid), |
| 9117 | drv->associated, |
| 9118 | drv->assoc_freq, |
| 9119 | drv->monitor_sock, |
| 9120 | drv->monitor_ifidx, |
| 9121 | drv->monitor_refcount, |
| 9122 | drv->last_mgmt_freq, |
| 9123 | drv->eapol_tx_sock, |
| 9124 | drv->ignore_if_down_event ? |
| 9125 | "ignore_if_down_event=1\n" : "", |
| 9126 | drv->scan_complete_events ? |
| 9127 | "scan_complete_events=1\n" : "", |
| 9128 | drv->disabled_11b_rates ? |
| 9129 | "disabled_11b_rates=1\n" : "", |
| 9130 | drv->pending_remain_on_chan ? |
| 9131 | "pending_remain_on_chan=1\n" : "", |
| 9132 | drv->in_interface_list ? "in_interface_list=1\n" : "", |
| 9133 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", |
| 9134 | drv->poll_command_supported ? |
| 9135 | "poll_command_supported=1\n" : "", |
| 9136 | drv->data_tx_status ? "data_tx_status=1\n" : "", |
| 9137 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", |
| 9138 | drv->retry_auth ? "retry_auth=1\n" : "", |
| 9139 | drv->use_monitor ? "use_monitor=1\n" : "", |
| 9140 | drv->ignore_next_local_disconnect ? |
| 9141 | "ignore_next_local_disconnect=1\n" : "", |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 9142 | drv->ignore_next_local_deauth ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9143 | "ignore_next_local_deauth=1\n" : ""); |
| 9144 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9145 | return pos - buf; |
| 9146 | pos += res; |
| 9147 | |
| 9148 | if (drv->has_capability) { |
| 9149 | res = os_snprintf(pos, end - pos, |
| 9150 | "capa.key_mgmt=0x%x\n" |
| 9151 | "capa.enc=0x%x\n" |
| 9152 | "capa.auth=0x%x\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9153 | "capa.flags=0x%llx\n" |
| 9154 | "capa.rrm_flags=0x%x\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9155 | "capa.max_scan_ssids=%d\n" |
| 9156 | "capa.max_sched_scan_ssids=%d\n" |
| 9157 | "capa.sched_scan_supported=%d\n" |
| 9158 | "capa.max_match_sets=%d\n" |
| 9159 | "capa.max_remain_on_chan=%u\n" |
| 9160 | "capa.max_stations=%u\n" |
| 9161 | "capa.probe_resp_offloads=0x%x\n" |
| 9162 | "capa.max_acl_mac_addrs=%u\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9163 | "capa.num_multichan_concurrent=%u\n" |
| 9164 | "capa.mac_addr_rand_sched_scan_supported=%d\n" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9165 | "capa.mac_addr_rand_scan_supported=%d\n" |
| 9166 | "capa.conc_capab=%u\n" |
| 9167 | "capa.max_conc_chan_2_4=%u\n" |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9168 | "capa.max_conc_chan_5_0=%u\n" |
| 9169 | "capa.max_sched_scan_plans=%u\n" |
| 9170 | "capa.max_sched_scan_plan_interval=%u\n" |
| 9171 | "capa.max_sched_scan_plan_iterations=%u\n", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9172 | drv->capa.key_mgmt, |
| 9173 | drv->capa.enc, |
| 9174 | drv->capa.auth, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9175 | (unsigned long long) drv->capa.flags, |
| 9176 | drv->capa.rrm_flags, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9177 | drv->capa.max_scan_ssids, |
| 9178 | drv->capa.max_sched_scan_ssids, |
| 9179 | drv->capa.sched_scan_supported, |
| 9180 | drv->capa.max_match_sets, |
| 9181 | drv->capa.max_remain_on_chan, |
| 9182 | drv->capa.max_stations, |
| 9183 | drv->capa.probe_resp_offloads, |
| 9184 | drv->capa.max_acl_mac_addrs, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9185 | drv->capa.num_multichan_concurrent, |
| 9186 | drv->capa.mac_addr_rand_sched_scan_supported, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9187 | drv->capa.mac_addr_rand_scan_supported, |
| 9188 | drv->capa.conc_capab, |
| 9189 | drv->capa.max_conc_chan_2_4, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9190 | drv->capa.max_conc_chan_5_0, |
| 9191 | drv->capa.max_sched_scan_plans, |
| 9192 | drv->capa.max_sched_scan_plan_interval, |
| 9193 | drv->capa.max_sched_scan_plan_iterations); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9194 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9195 | return pos - buf; |
| 9196 | pos += res; |
| 9197 | } |
| 9198 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9199 | msg = nlmsg_alloc(); |
| 9200 | if (msg && |
| 9201 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG) && |
| 9202 | nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx) == 0) { |
| 9203 | if (send_and_recv_msgs(drv, msg, nl80211_get_country, |
| 9204 | alpha2) == 0 && |
| 9205 | alpha2[0]) { |
| 9206 | res = os_snprintf(pos, end - pos, "country=%s\n", |
| 9207 | alpha2); |
| 9208 | if (os_snprintf_error(end - pos, res)) |
| 9209 | return pos - buf; |
| 9210 | pos += res; |
| 9211 | } |
| 9212 | } else { |
| 9213 | nlmsg_free(msg); |
| 9214 | } |
| 9215 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9216 | return pos - buf; |
| 9217 | } |
| 9218 | |
| 9219 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9220 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
| 9221 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9222 | if ((settings->head && |
| 9223 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, |
| 9224 | settings->head_len, settings->head)) || |
| 9225 | (settings->tail && |
| 9226 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, |
| 9227 | settings->tail_len, settings->tail)) || |
| 9228 | (settings->beacon_ies && |
| 9229 | nla_put(msg, NL80211_ATTR_IE, |
| 9230 | settings->beacon_ies_len, settings->beacon_ies)) || |
| 9231 | (settings->proberesp_ies && |
| 9232 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 9233 | settings->proberesp_ies_len, settings->proberesp_ies)) || |
| 9234 | (settings->assocresp_ies && |
| 9235 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 9236 | settings->assocresp_ies_len, settings->assocresp_ies)) || |
| 9237 | (settings->probe_resp && |
| 9238 | nla_put(msg, NL80211_ATTR_PROBE_RESP, |
| 9239 | settings->probe_resp_len, settings->probe_resp))) |
| 9240 | return -ENOBUFS; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9241 | |
| 9242 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9243 | } |
| 9244 | |
| 9245 | |
| 9246 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) |
| 9247 | { |
| 9248 | struct nl_msg *msg; |
| 9249 | struct i802_bss *bss = priv; |
| 9250 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9251 | struct nlattr *beacon_csa; |
| 9252 | int ret = -ENOBUFS; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9253 | int csa_off_len = 0; |
| 9254 | int i; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9255 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 9256 | 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] | 9257 | settings->cs_count, settings->block_tx, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 9258 | settings->freq_params.freq, settings->freq_params.bandwidth, |
| 9259 | settings->freq_params.center_freq1, |
| 9260 | settings->freq_params.center_freq2); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9261 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9262 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9263 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
| 9264 | return -EOPNOTSUPP; |
| 9265 | } |
| 9266 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9267 | if (drv->nlmode != NL80211_IFTYPE_AP && |
| 9268 | drv->nlmode != NL80211_IFTYPE_P2P_GO && |
| 9269 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9270 | return -EOPNOTSUPP; |
| 9271 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9272 | /* |
| 9273 | * Remove empty counters, assuming Probe Response and Beacon frame |
| 9274 | * counters match. This implementation assumes that there are only two |
| 9275 | * counters. |
| 9276 | */ |
| 9277 | if (settings->counter_offset_beacon[0] && |
| 9278 | !settings->counter_offset_beacon[1]) { |
| 9279 | csa_off_len = 1; |
| 9280 | } else if (settings->counter_offset_beacon[1] && |
| 9281 | !settings->counter_offset_beacon[0]) { |
| 9282 | csa_off_len = 1; |
| 9283 | settings->counter_offset_beacon[0] = |
| 9284 | settings->counter_offset_beacon[1]; |
| 9285 | settings->counter_offset_presp[0] = |
| 9286 | settings->counter_offset_presp[1]; |
| 9287 | } else if (settings->counter_offset_beacon[1] && |
| 9288 | settings->counter_offset_beacon[0]) { |
| 9289 | csa_off_len = 2; |
| 9290 | } else { |
| 9291 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); |
| 9292 | return -EINVAL; |
| 9293 | } |
| 9294 | |
| 9295 | /* Check CSA counters validity */ |
| 9296 | if (drv->capa.max_csa_counters && |
| 9297 | csa_off_len > drv->capa.max_csa_counters) { |
| 9298 | wpa_printf(MSG_ERROR, |
| 9299 | "nl80211: Too many CSA counters provided"); |
| 9300 | return -EINVAL; |
| 9301 | } |
| 9302 | |
| 9303 | if (!settings->beacon_csa.tail) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9304 | return -EINVAL; |
| 9305 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9306 | for (i = 0; i < csa_off_len; i++) { |
| 9307 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; |
| 9308 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; |
| 9309 | |
| 9310 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || |
| 9311 | (settings->beacon_csa.tail[csa_c_off_bcn] != |
| 9312 | settings->cs_count)) |
| 9313 | return -EINVAL; |
| 9314 | |
| 9315 | if (settings->beacon_csa.probe_resp && |
| 9316 | ((settings->beacon_csa.probe_resp_len <= |
| 9317 | csa_c_off_presp) || |
| 9318 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != |
| 9319 | settings->cs_count))) |
| 9320 | return -EINVAL; |
| 9321 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9322 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9323 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
| 9324 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
| 9325 | settings->cs_count) || |
| 9326 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || |
| 9327 | (settings->block_tx && |
| 9328 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9329 | goto error; |
| 9330 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9331 | /* beacon_after params */ |
| 9332 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 9333 | if (ret) |
| 9334 | goto error; |
| 9335 | |
| 9336 | /* beacon_csa params */ |
| 9337 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); |
| 9338 | if (!beacon_csa) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9339 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9340 | |
| 9341 | ret = set_beacon_data(msg, &settings->beacon_csa); |
| 9342 | if (ret) |
| 9343 | goto error; |
| 9344 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9345 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
| 9346 | csa_off_len * sizeof(u16), |
| 9347 | settings->counter_offset_beacon) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9348 | (settings->beacon_csa.probe_resp && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9349 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
| 9350 | csa_off_len * sizeof(u16), |
| 9351 | settings->counter_offset_presp))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9352 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9353 | |
| 9354 | nla_nest_end(msg, beacon_csa); |
| 9355 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9356 | if (ret) { |
| 9357 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", |
| 9358 | ret, strerror(-ret)); |
| 9359 | } |
| 9360 | return ret; |
| 9361 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9362 | fail: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9363 | ret = -ENOBUFS; |
| 9364 | error: |
| 9365 | nlmsg_free(msg); |
| 9366 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); |
| 9367 | return ret; |
| 9368 | } |
| 9369 | |
| 9370 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9371 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
| 9372 | u8 user_priority, u16 admitted_time) |
| 9373 | { |
| 9374 | struct i802_bss *bss = priv; |
| 9375 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9376 | struct nl_msg *msg; |
| 9377 | int ret; |
| 9378 | |
| 9379 | wpa_printf(MSG_DEBUG, |
| 9380 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", |
| 9381 | tsid, admitted_time, user_priority); |
| 9382 | |
| 9383 | if (!is_sta_interface(drv->nlmode)) |
| 9384 | return -ENOTSUP; |
| 9385 | |
| 9386 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
| 9387 | if (!msg || |
| 9388 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 9389 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 9390 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || |
| 9391 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { |
| 9392 | nlmsg_free(msg); |
| 9393 | return -ENOBUFS; |
| 9394 | } |
| 9395 | |
| 9396 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9397 | if (ret) |
| 9398 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", |
| 9399 | ret, strerror(-ret)); |
| 9400 | return ret; |
| 9401 | } |
| 9402 | |
| 9403 | |
| 9404 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) |
| 9405 | { |
| 9406 | struct i802_bss *bss = priv; |
| 9407 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9408 | struct nl_msg *msg; |
| 9409 | int ret; |
| 9410 | |
| 9411 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); |
| 9412 | |
| 9413 | if (!is_sta_interface(drv->nlmode)) |
| 9414 | return -ENOTSUP; |
| 9415 | |
| 9416 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
| 9417 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 9418 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 9419 | nlmsg_free(msg); |
| 9420 | return -ENOBUFS; |
| 9421 | } |
| 9422 | |
| 9423 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9424 | if (ret) |
| 9425 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", |
| 9426 | ret, strerror(-ret)); |
| 9427 | return ret; |
| 9428 | } |
| 9429 | |
| 9430 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9431 | #ifdef CONFIG_TESTING_OPTIONS |
| 9432 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) |
| 9433 | { |
| 9434 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9435 | struct wpabuf *buf = arg; |
| 9436 | |
| 9437 | if (!buf) |
| 9438 | return NL_SKIP; |
| 9439 | |
| 9440 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { |
| 9441 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); |
| 9442 | return NL_SKIP; |
| 9443 | } |
| 9444 | |
| 9445 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), |
| 9446 | genlmsg_attrlen(gnlh, 0)); |
| 9447 | |
| 9448 | return NL_SKIP; |
| 9449 | } |
| 9450 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 9451 | |
| 9452 | |
| 9453 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
| 9454 | { |
| 9455 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9456 | struct nlattr *nl_vendor_reply, *nl; |
| 9457 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9458 | struct wpabuf *buf = arg; |
| 9459 | int rem; |
| 9460 | |
| 9461 | if (!buf) |
| 9462 | return NL_SKIP; |
| 9463 | |
| 9464 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9465 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9466 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; |
| 9467 | |
| 9468 | if (!nl_vendor_reply) |
| 9469 | return NL_SKIP; |
| 9470 | |
| 9471 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { |
| 9472 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); |
| 9473 | return NL_SKIP; |
| 9474 | } |
| 9475 | |
| 9476 | nla_for_each_nested(nl, nl_vendor_reply, rem) { |
| 9477 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); |
| 9478 | } |
| 9479 | |
| 9480 | return NL_SKIP; |
| 9481 | } |
| 9482 | |
| 9483 | |
| 9484 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, |
| 9485 | unsigned int subcmd, const u8 *data, |
| 9486 | size_t data_len, struct wpabuf *buf) |
| 9487 | { |
| 9488 | struct i802_bss *bss = priv; |
| 9489 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9490 | struct nl_msg *msg; |
| 9491 | int ret; |
| 9492 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9493 | #ifdef CONFIG_TESTING_OPTIONS |
| 9494 | if (vendor_id == 0xffffffff) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9495 | msg = nlmsg_alloc(); |
| 9496 | if (!msg) |
| 9497 | return -ENOMEM; |
| 9498 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9499 | nl80211_cmd(drv, msg, 0, subcmd); |
| 9500 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < |
| 9501 | 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9502 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9503 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
| 9504 | if (ret) |
| 9505 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", |
| 9506 | ret); |
| 9507 | return ret; |
| 9508 | } |
| 9509 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 9510 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9511 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 9512 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
| 9513 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || |
| 9514 | (data && |
| 9515 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) |
| 9516 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9517 | |
| 9518 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); |
| 9519 | if (ret) |
| 9520 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", |
| 9521 | ret); |
| 9522 | return ret; |
| 9523 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9524 | fail: |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9525 | nlmsg_free(msg); |
| 9526 | return -ENOBUFS; |
| 9527 | } |
| 9528 | |
| 9529 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9530 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
| 9531 | u8 qos_map_set_len) |
| 9532 | { |
| 9533 | struct i802_bss *bss = priv; |
| 9534 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9535 | struct nl_msg *msg; |
| 9536 | int ret; |
| 9537 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9538 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
| 9539 | qos_map_set, qos_map_set_len); |
| 9540 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9541 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
| 9542 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
| 9543 | nlmsg_free(msg); |
| 9544 | return -ENOBUFS; |
| 9545 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9546 | |
| 9547 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9548 | if (ret) |
| 9549 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); |
| 9550 | |
| 9551 | return ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9552 | } |
| 9553 | |
| 9554 | |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 9555 | static int get_wowlan_handler(struct nl_msg *msg, void *arg) |
| 9556 | { |
| 9557 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9558 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9559 | int *wowlan_enabled = arg; |
| 9560 | |
| 9561 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9562 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9563 | |
| 9564 | *wowlan_enabled = !!tb[NL80211_ATTR_WOWLAN_TRIGGERS]; |
| 9565 | |
| 9566 | return NL_SKIP; |
| 9567 | } |
| 9568 | |
| 9569 | |
| 9570 | static int nl80211_get_wowlan(void *priv) |
| 9571 | { |
| 9572 | struct i802_bss *bss = priv; |
| 9573 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9574 | struct nl_msg *msg; |
| 9575 | int wowlan_enabled; |
| 9576 | int ret; |
| 9577 | |
| 9578 | wpa_printf(MSG_DEBUG, "nl80211: Getting wowlan status"); |
| 9579 | |
| 9580 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_WOWLAN); |
| 9581 | |
| 9582 | ret = send_and_recv_msgs(drv, msg, get_wowlan_handler, &wowlan_enabled); |
| 9583 | if (ret) { |
| 9584 | wpa_printf(MSG_DEBUG, "nl80211: Getting wowlan status failed"); |
| 9585 | return 0; |
| 9586 | } |
| 9587 | |
| 9588 | wpa_printf(MSG_DEBUG, "nl80211: wowlan is %s", |
| 9589 | wowlan_enabled ? "enabled" : "disabled"); |
| 9590 | |
| 9591 | return wowlan_enabled; |
| 9592 | } |
| 9593 | |
| 9594 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9595 | static int nl80211_set_wowlan(void *priv, |
| 9596 | const struct wowlan_triggers *triggers) |
| 9597 | { |
| 9598 | struct i802_bss *bss = priv; |
| 9599 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9600 | struct nl_msg *msg; |
| 9601 | struct nlattr *wowlan_triggers; |
| 9602 | int ret; |
| 9603 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9604 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
| 9605 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 9606 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9607 | !(wowlan_triggers = nla_nest_start(msg, |
| 9608 | NL80211_ATTR_WOWLAN_TRIGGERS)) || |
| 9609 | (triggers->any && |
| 9610 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 9611 | (triggers->disconnect && |
| 9612 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 9613 | (triggers->magic_pkt && |
| 9614 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 9615 | (triggers->gtk_rekey_failure && |
| 9616 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 9617 | (triggers->eap_identity_req && |
| 9618 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 9619 | (triggers->four_way_handshake && |
| 9620 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 9621 | (triggers->rfkill_release && |
| 9622 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { |
| 9623 | nlmsg_free(msg); |
| 9624 | return -ENOBUFS; |
| 9625 | } |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9626 | |
| 9627 | nla_nest_end(msg, wowlan_triggers); |
| 9628 | |
| 9629 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9630 | if (ret) |
| 9631 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); |
| 9632 | |
| 9633 | return ret; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9634 | } |
| 9635 | |
| 9636 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9637 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9638 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
| 9639 | { |
| 9640 | struct i802_bss *bss = priv; |
| 9641 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9642 | struct nl_msg *msg; |
| 9643 | struct nlattr *params; |
| 9644 | |
| 9645 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); |
| 9646 | |
| 9647 | if (!drv->roaming_vendor_cmd_avail) { |
| 9648 | wpa_printf(MSG_DEBUG, |
| 9649 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); |
| 9650 | return -1; |
| 9651 | } |
| 9652 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9653 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9654 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9655 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9656 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || |
| 9657 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9658 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, |
| 9659 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : |
| 9660 | QCA_ROAMING_NOT_ALLOWED) || |
| 9661 | (bssid && |
| 9662 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { |
| 9663 | nlmsg_free(msg); |
| 9664 | return -1; |
| 9665 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9666 | nla_nest_end(msg, params); |
| 9667 | |
| 9668 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9669 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9670 | |
| 9671 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9672 | static int nl80211_disable_fils(void *priv, int disable) |
| 9673 | { |
| 9674 | struct i802_bss *bss = priv; |
| 9675 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9676 | struct nl_msg *msg; |
| 9677 | struct nlattr *params; |
| 9678 | |
| 9679 | wpa_printf(MSG_DEBUG, "nl80211: Disable FILS=%d", disable); |
| 9680 | |
| 9681 | if (!drv->set_wifi_conf_vendor_cmd_avail) |
| 9682 | return -1; |
| 9683 | |
| 9684 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9685 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9686 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9687 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) || |
| 9688 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9689 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS, |
| 9690 | disable)) { |
| 9691 | nlmsg_free(msg); |
| 9692 | return -1; |
| 9693 | } |
| 9694 | nla_nest_end(msg, params); |
| 9695 | |
| 9696 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9697 | } |
| 9698 | |
| 9699 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9700 | /* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */ |
| 9701 | #define WPA_SUPPLICANT_CLIENT_ID 1 |
| 9702 | |
| 9703 | static int nl80211_set_bssid_blacklist(void *priv, unsigned int num_bssid, |
| 9704 | const u8 *bssid) |
| 9705 | { |
| 9706 | struct i802_bss *bss = priv; |
| 9707 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9708 | struct nl_msg *msg; |
| 9709 | struct nlattr *params, *nlbssids, *attr; |
| 9710 | unsigned int i; |
| 9711 | |
| 9712 | wpa_printf(MSG_DEBUG, "nl80211: Set blacklist BSSID (num=%u)", |
| 9713 | num_bssid); |
| 9714 | |
| 9715 | if (!drv->roam_vendor_cmd_avail) |
| 9716 | return -1; |
| 9717 | |
| 9718 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9719 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9720 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9721 | QCA_NL80211_VENDOR_SUBCMD_ROAM) || |
| 9722 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9723 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 9724 | QCA_WLAN_VENDOR_ROAMING_SUBCMD_SET_BLACKLIST_BSSID) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9725 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID, |
| 9726 | WPA_SUPPLICANT_CLIENT_ID) || |
| 9727 | nla_put_u32(msg, |
| 9728 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID, |
| 9729 | num_bssid)) |
| 9730 | goto fail; |
| 9731 | |
| 9732 | nlbssids = nla_nest_start( |
| 9733 | msg, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS); |
| 9734 | if (!nlbssids) |
| 9735 | goto fail; |
| 9736 | |
| 9737 | for (i = 0; i < num_bssid; i++) { |
| 9738 | attr = nla_nest_start(msg, i); |
| 9739 | if (!attr) |
| 9740 | goto fail; |
| 9741 | if (nla_put(msg, |
| 9742 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID, |
| 9743 | ETH_ALEN, &bssid[i * ETH_ALEN])) |
| 9744 | goto fail; |
| 9745 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%u]: " MACSTR, i, |
| 9746 | MAC2STR(&bssid[i * ETH_ALEN])); |
| 9747 | nla_nest_end(msg, attr); |
| 9748 | } |
| 9749 | nla_nest_end(msg, nlbssids); |
| 9750 | nla_nest_end(msg, params); |
| 9751 | |
| 9752 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9753 | |
| 9754 | fail: |
| 9755 | nlmsg_free(msg); |
| 9756 | return -1; |
| 9757 | } |
| 9758 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 9759 | |
| 9760 | static int nl80211_add_sta_node(void *priv, const u8 *addr, u16 auth_alg) |
| 9761 | { |
| 9762 | struct i802_bss *bss = priv; |
| 9763 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9764 | struct nl_msg *msg; |
| 9765 | struct nlattr *params; |
| 9766 | |
| 9767 | if (!drv->add_sta_node_vendor_cmd_avail) |
| 9768 | return -EOPNOTSUPP; |
| 9769 | |
| 9770 | wpa_printf(MSG_DEBUG, "nl80211: Add STA node"); |
| 9771 | |
| 9772 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9773 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9774 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9775 | QCA_NL80211_VENDOR_SUBCMD_ADD_STA_NODE) || |
| 9776 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9777 | (addr && |
| 9778 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_MAC_ADDR, ETH_ALEN, |
| 9779 | addr)) || |
| 9780 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ADD_STA_NODE_AUTH_ALGO, |
| 9781 | auth_alg)) { |
| 9782 | nlmsg_free(msg); |
| 9783 | wpa_printf(MSG_ERROR, |
| 9784 | "%s: err in adding vendor_cmd and vendor_data", |
| 9785 | __func__); |
| 9786 | return -1; |
| 9787 | } |
| 9788 | nla_nest_end(msg, params); |
| 9789 | |
| 9790 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9791 | } |
| 9792 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9793 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9794 | |
| 9795 | |
| 9796 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
| 9797 | { |
| 9798 | struct i802_bss *bss = priv; |
| 9799 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9800 | int new_addr = addr != NULL; |
| 9801 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9802 | if (TEST_FAIL()) |
| 9803 | return -1; |
| 9804 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9805 | if (!addr) |
| 9806 | addr = drv->perm_addr; |
| 9807 | |
| 9808 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) |
| 9809 | return -1; |
| 9810 | |
| 9811 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) |
| 9812 | { |
| 9813 | wpa_printf(MSG_DEBUG, |
| 9814 | "nl80211: failed to set_mac_addr for %s to " MACSTR, |
| 9815 | bss->ifname, MAC2STR(addr)); |
| 9816 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 9817 | 1) < 0) { |
| 9818 | wpa_printf(MSG_DEBUG, |
| 9819 | "nl80211: Could not restore interface UP after failed set_mac_addr"); |
| 9820 | } |
| 9821 | return -1; |
| 9822 | } |
| 9823 | |
| 9824 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, |
| 9825 | bss->ifname, MAC2STR(addr)); |
| 9826 | drv->addr_changed = new_addr; |
| 9827 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 9828 | |
| 9829 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) |
| 9830 | { |
| 9831 | wpa_printf(MSG_DEBUG, |
| 9832 | "nl80211: Could not restore interface UP after set_mac_addr"); |
| 9833 | } |
| 9834 | |
| 9835 | return 0; |
| 9836 | } |
| 9837 | |
| 9838 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9839 | #ifdef CONFIG_MESH |
| 9840 | |
| 9841 | static int wpa_driver_nl80211_init_mesh(void *priv) |
| 9842 | { |
| 9843 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { |
| 9844 | wpa_printf(MSG_INFO, |
| 9845 | "nl80211: Failed to set interface into mesh mode"); |
| 9846 | return -1; |
| 9847 | } |
| 9848 | return 0; |
| 9849 | } |
| 9850 | |
| 9851 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9852 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
| 9853 | size_t mesh_id_len) |
| 9854 | { |
| 9855 | if (mesh_id) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9856 | wpa_printf(MSG_DEBUG, " * Mesh ID (SSID)=%s", |
| 9857 | wpa_ssid_txt(mesh_id, mesh_id_len)); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9858 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); |
| 9859 | } |
| 9860 | |
| 9861 | return 0; |
| 9862 | } |
| 9863 | |
| 9864 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9865 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
| 9866 | struct wpa_driver_mesh_bss_params *params) |
| 9867 | { |
| 9868 | struct nlattr *container; |
| 9869 | |
| 9870 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
| 9871 | if (!container) |
| 9872 | return -1; |
| 9873 | |
| 9874 | if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9875 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 9876 | params->auto_plinks)) || |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9877 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) && |
| 9878 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9879 | params->max_peer_links)) || |
| 9880 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD) && |
| 9881 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 9882 | params->rssi_threshold))) |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9883 | return -1; |
| 9884 | |
| 9885 | /* |
| 9886 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because |
| 9887 | * the timer could disconnect stations even in that case. |
| 9888 | */ |
| 9889 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) && |
| 9890 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 9891 | params->peer_link_timeout)) { |
| 9892 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); |
| 9893 | return -1; |
| 9894 | } |
| 9895 | |
| 9896 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) && |
| 9897 | nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) { |
| 9898 | wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE"); |
| 9899 | return -1; |
| 9900 | } |
| 9901 | |
| 9902 | nla_nest_end(msg, container); |
| 9903 | |
| 9904 | return 0; |
| 9905 | } |
| 9906 | |
| 9907 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9908 | static int nl80211_join_mesh(struct i802_bss *bss, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9909 | struct wpa_driver_mesh_join_params *params) |
| 9910 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9911 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9912 | struct nl_msg *msg; |
| 9913 | struct nlattr *container; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 9914 | int ret = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9915 | |
| 9916 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
| 9917 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9918 | if (!msg || |
| 9919 | nl80211_put_freq_params(msg, ¶ms->freq) || |
| 9920 | nl80211_put_basic_rates(msg, params->basic_rates) || |
| 9921 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 9922 | nl80211_put_beacon_int(msg, params->beacon_int) || |
| 9923 | nl80211_put_dtim_period(msg, params->dtim_period)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9924 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9925 | |
| 9926 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
| 9927 | |
| 9928 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); |
| 9929 | if (!container) |
| 9930 | goto fail; |
| 9931 | |
| 9932 | if (params->ies) { |
| 9933 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); |
| 9934 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
| 9935 | params->ies)) |
| 9936 | goto fail; |
| 9937 | } |
| 9938 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ |
| 9939 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { |
| 9940 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
| 9941 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) |
| 9942 | goto fail; |
| 9943 | } |
| 9944 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
| 9945 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) |
| 9946 | goto fail; |
| 9947 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && |
| 9948 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) |
| 9949 | goto fail; |
| 9950 | nla_nest_end(msg, container); |
| 9951 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9952 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS; |
| 9953 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT; |
| 9954 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS; |
| 9955 | if (nl80211_put_mesh_config(msg, ¶ms->conf) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9956 | goto fail; |
| 9957 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9958 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9959 | msg = NULL; |
| 9960 | if (ret) { |
| 9961 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", |
| 9962 | ret, strerror(-ret)); |
| 9963 | goto fail; |
| 9964 | } |
| 9965 | ret = 0; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 9966 | drv->assoc_freq = bss->freq = params->freq.freq; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9967 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
| 9968 | |
| 9969 | fail: |
| 9970 | nlmsg_free(msg); |
| 9971 | return ret; |
| 9972 | } |
| 9973 | |
| 9974 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9975 | static int |
| 9976 | wpa_driver_nl80211_join_mesh(void *priv, |
| 9977 | struct wpa_driver_mesh_join_params *params) |
| 9978 | { |
| 9979 | struct i802_bss *bss = priv; |
| 9980 | int ret, timeout; |
| 9981 | |
| 9982 | timeout = params->conf.peer_link_timeout; |
| 9983 | |
| 9984 | /* Disable kernel inactivity timer */ |
| 9985 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) |
| 9986 | params->conf.peer_link_timeout = 0; |
| 9987 | |
| 9988 | ret = nl80211_join_mesh(bss, params); |
| 9989 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { |
| 9990 | wpa_printf(MSG_DEBUG, |
| 9991 | "nl80211: Mesh join retry for peer_link_timeout"); |
| 9992 | /* |
| 9993 | * Old kernel does not support setting |
| 9994 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds |
| 9995 | * into future from peer_link_timeout. |
| 9996 | */ |
| 9997 | params->conf.peer_link_timeout = timeout + 60; |
| 9998 | ret = nl80211_join_mesh(priv, params); |
| 9999 | } |
| 10000 | |
| 10001 | params->conf.peer_link_timeout = timeout; |
| 10002 | return ret; |
| 10003 | } |
| 10004 | |
| 10005 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10006 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
| 10007 | { |
| 10008 | struct i802_bss *bss = priv; |
| 10009 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10010 | struct nl_msg *msg; |
| 10011 | int ret; |
| 10012 | |
| 10013 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); |
| 10014 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
| 10015 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10016 | if (ret) { |
| 10017 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", |
| 10018 | ret, strerror(-ret)); |
| 10019 | } else { |
| 10020 | wpa_printf(MSG_DEBUG, |
| 10021 | "nl80211: mesh leave request send successfully"); |
| 10022 | } |
| 10023 | |
| 10024 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
| 10025 | NL80211_IFTYPE_STATION)) { |
| 10026 | wpa_printf(MSG_INFO, |
| 10027 | "nl80211: Failed to set interface into station mode"); |
| 10028 | } |
| 10029 | return ret; |
| 10030 | } |
| 10031 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 10032 | |
| 10033 | static int nl80211_probe_mesh_link(void *priv, const u8 *addr, const u8 *eth, |
| 10034 | size_t len) |
| 10035 | { |
| 10036 | struct i802_bss *bss = priv; |
| 10037 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10038 | struct nl_msg *msg; |
| 10039 | int ret; |
| 10040 | |
| 10041 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_PROBE_MESH_LINK); |
| 10042 | if (!msg || |
| 10043 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 10044 | nla_put(msg, NL80211_ATTR_FRAME, len, eth)) { |
| 10045 | nlmsg_free(msg); |
| 10046 | return -ENOBUFS; |
| 10047 | } |
| 10048 | |
| 10049 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10050 | if (ret) { |
| 10051 | wpa_printf(MSG_DEBUG, "nl80211: mesh link probe to " MACSTR |
| 10052 | " failed: ret=%d (%s)", |
| 10053 | MAC2STR(addr), ret, strerror(-ret)); |
| 10054 | } else { |
| 10055 | wpa_printf(MSG_DEBUG, "nl80211: Mesh link to " MACSTR |
| 10056 | " probed successfully", MAC2STR(addr)); |
| 10057 | } |
| 10058 | |
| 10059 | return ret; |
| 10060 | } |
| 10061 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10062 | #endif /* CONFIG_MESH */ |
| 10063 | |
| 10064 | |
| 10065 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
| 10066 | const u8 *ipaddr, int prefixlen, |
| 10067 | const u8 *addr) |
| 10068 | { |
| 10069 | #ifdef CONFIG_LIBNL3_ROUTE |
| 10070 | struct i802_bss *bss = priv; |
| 10071 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10072 | struct rtnl_neigh *rn; |
| 10073 | struct nl_addr *nl_ipaddr = NULL; |
| 10074 | struct nl_addr *nl_lladdr = NULL; |
| 10075 | int family, addrsize; |
| 10076 | int res; |
| 10077 | |
| 10078 | if (!ipaddr || prefixlen == 0 || !addr) |
| 10079 | return -EINVAL; |
| 10080 | |
| 10081 | if (bss->br_ifindex == 0) { |
| 10082 | wpa_printf(MSG_DEBUG, |
| 10083 | "nl80211: bridge must be set before adding an ip neigh to it"); |
| 10084 | return -1; |
| 10085 | } |
| 10086 | |
| 10087 | if (!drv->rtnl_sk) { |
| 10088 | wpa_printf(MSG_DEBUG, |
| 10089 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 10090 | return -1; |
| 10091 | } |
| 10092 | |
| 10093 | if (version == 4) { |
| 10094 | family = AF_INET; |
| 10095 | addrsize = 4; |
| 10096 | } else if (version == 6) { |
| 10097 | family = AF_INET6; |
| 10098 | addrsize = 16; |
| 10099 | } else { |
| 10100 | return -EINVAL; |
| 10101 | } |
| 10102 | |
| 10103 | rn = rtnl_neigh_alloc(); |
| 10104 | if (rn == NULL) |
| 10105 | return -ENOMEM; |
| 10106 | |
| 10107 | /* set the destination ip address for neigh */ |
| 10108 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 10109 | if (nl_ipaddr == NULL) { |
| 10110 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 10111 | res = -ENOMEM; |
| 10112 | goto errout; |
| 10113 | } |
| 10114 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); |
| 10115 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 10116 | if (res) { |
| 10117 | wpa_printf(MSG_DEBUG, |
| 10118 | "nl80211: neigh set destination addr failed"); |
| 10119 | goto errout; |
| 10120 | } |
| 10121 | |
| 10122 | /* set the corresponding lladdr for neigh */ |
| 10123 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); |
| 10124 | if (nl_lladdr == NULL) { |
| 10125 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); |
| 10126 | res = -ENOMEM; |
| 10127 | goto errout; |
| 10128 | } |
| 10129 | rtnl_neigh_set_lladdr(rn, nl_lladdr); |
| 10130 | |
| 10131 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 10132 | rtnl_neigh_set_state(rn, NUD_PERMANENT); |
| 10133 | |
| 10134 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); |
| 10135 | if (res) { |
| 10136 | wpa_printf(MSG_DEBUG, |
| 10137 | "nl80211: Adding bridge ip neigh failed: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 10138 | nl_geterror(res)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10139 | } |
| 10140 | errout: |
| 10141 | if (nl_lladdr) |
| 10142 | nl_addr_put(nl_lladdr); |
| 10143 | if (nl_ipaddr) |
| 10144 | nl_addr_put(nl_ipaddr); |
| 10145 | if (rn) |
| 10146 | rtnl_neigh_put(rn); |
| 10147 | return res; |
| 10148 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 10149 | return -1; |
| 10150 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 10151 | } |
| 10152 | |
| 10153 | |
| 10154 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
| 10155 | const u8 *ipaddr) |
| 10156 | { |
| 10157 | #ifdef CONFIG_LIBNL3_ROUTE |
| 10158 | struct i802_bss *bss = priv; |
| 10159 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10160 | struct rtnl_neigh *rn; |
| 10161 | struct nl_addr *nl_ipaddr; |
| 10162 | int family, addrsize; |
| 10163 | int res; |
| 10164 | |
| 10165 | if (!ipaddr) |
| 10166 | return -EINVAL; |
| 10167 | |
| 10168 | if (version == 4) { |
| 10169 | family = AF_INET; |
| 10170 | addrsize = 4; |
| 10171 | } else if (version == 6) { |
| 10172 | family = AF_INET6; |
| 10173 | addrsize = 16; |
| 10174 | } else { |
| 10175 | return -EINVAL; |
| 10176 | } |
| 10177 | |
| 10178 | if (bss->br_ifindex == 0) { |
| 10179 | wpa_printf(MSG_DEBUG, |
| 10180 | "nl80211: bridge must be set to delete an ip neigh"); |
| 10181 | return -1; |
| 10182 | } |
| 10183 | |
| 10184 | if (!drv->rtnl_sk) { |
| 10185 | wpa_printf(MSG_DEBUG, |
| 10186 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 10187 | return -1; |
| 10188 | } |
| 10189 | |
| 10190 | rn = rtnl_neigh_alloc(); |
| 10191 | if (rn == NULL) |
| 10192 | return -ENOMEM; |
| 10193 | |
| 10194 | /* set the destination ip address for neigh */ |
| 10195 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 10196 | if (nl_ipaddr == NULL) { |
| 10197 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 10198 | res = -ENOMEM; |
| 10199 | goto errout; |
| 10200 | } |
| 10201 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 10202 | if (res) { |
| 10203 | wpa_printf(MSG_DEBUG, |
| 10204 | "nl80211: neigh set destination addr failed"); |
| 10205 | goto errout; |
| 10206 | } |
| 10207 | |
| 10208 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 10209 | |
| 10210 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 10211 | if (res) { |
| 10212 | wpa_printf(MSG_DEBUG, |
| 10213 | "nl80211: Deleting bridge ip neigh failed: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 10214 | nl_geterror(res)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10215 | } |
| 10216 | errout: |
| 10217 | if (nl_ipaddr) |
| 10218 | nl_addr_put(nl_ipaddr); |
| 10219 | if (rn) |
| 10220 | rtnl_neigh_put(rn); |
| 10221 | return res; |
| 10222 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 10223 | return -1; |
| 10224 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 10225 | } |
| 10226 | |
| 10227 | |
| 10228 | static int linux_write_system_file(const char *path, unsigned int val) |
| 10229 | { |
| 10230 | char buf[50]; |
| 10231 | int fd, len; |
| 10232 | |
| 10233 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); |
| 10234 | if (os_snprintf_error(sizeof(buf), len)) |
| 10235 | return -1; |
| 10236 | |
| 10237 | fd = open(path, O_WRONLY); |
| 10238 | if (fd < 0) |
| 10239 | return -1; |
| 10240 | |
| 10241 | if (write(fd, buf, len) < 0) { |
| 10242 | wpa_printf(MSG_DEBUG, |
| 10243 | "nl80211: Failed to write Linux system file: %s with the value of %d", |
| 10244 | path, val); |
| 10245 | close(fd); |
| 10246 | return -1; |
| 10247 | } |
| 10248 | close(fd); |
| 10249 | |
| 10250 | return 0; |
| 10251 | } |
| 10252 | |
| 10253 | |
| 10254 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) |
| 10255 | { |
| 10256 | switch (attr) { |
| 10257 | case DRV_BR_PORT_ATTR_PROXYARP: |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 10258 | return "proxyarp_wifi"; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10259 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
| 10260 | return "hairpin_mode"; |
| 10261 | } |
| 10262 | |
| 10263 | return NULL; |
| 10264 | } |
| 10265 | |
| 10266 | |
| 10267 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, |
| 10268 | unsigned int val) |
| 10269 | { |
| 10270 | struct i802_bss *bss = priv; |
| 10271 | char path[128]; |
| 10272 | const char *attr_txt; |
| 10273 | |
| 10274 | attr_txt = drv_br_port_attr_str(attr); |
| 10275 | if (attr_txt == NULL) |
| 10276 | return -EINVAL; |
| 10277 | |
| 10278 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", |
| 10279 | bss->ifname, attr_txt); |
| 10280 | |
| 10281 | if (linux_write_system_file(path, val)) |
| 10282 | return -1; |
| 10283 | |
| 10284 | return 0; |
| 10285 | } |
| 10286 | |
| 10287 | |
| 10288 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
| 10289 | { |
| 10290 | switch (param) { |
| 10291 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 10292 | return "arp_accept"; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 10293 | default: |
| 10294 | return NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10295 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10296 | } |
| 10297 | |
| 10298 | |
| 10299 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, |
| 10300 | unsigned int val) |
| 10301 | { |
| 10302 | struct i802_bss *bss = priv; |
| 10303 | char path[128]; |
| 10304 | const char *param_txt; |
| 10305 | int ip_version = 4; |
| 10306 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 10307 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
| 10308 | os_snprintf(path, sizeof(path), |
| 10309 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", |
| 10310 | bss->brname); |
| 10311 | goto set_val; |
| 10312 | } |
| 10313 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10314 | param_txt = drv_br_net_param_str(param); |
| 10315 | if (param_txt == NULL) |
| 10316 | return -EINVAL; |
| 10317 | |
| 10318 | switch (param) { |
| 10319 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 10320 | ip_version = 4; |
| 10321 | break; |
| 10322 | default: |
| 10323 | return -EINVAL; |
| 10324 | } |
| 10325 | |
| 10326 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", |
| 10327 | ip_version, bss->brname, param_txt); |
| 10328 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 10329 | set_val: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10330 | if (linux_write_system_file(path, val)) |
| 10331 | return -1; |
| 10332 | |
| 10333 | return 0; |
| 10334 | } |
| 10335 | |
| 10336 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10337 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 10338 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10339 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
| 10340 | { |
| 10341 | switch (hw_mode) { |
| 10342 | case HOSTAPD_MODE_IEEE80211B: |
| 10343 | return QCA_ACS_MODE_IEEE80211B; |
| 10344 | case HOSTAPD_MODE_IEEE80211G: |
| 10345 | return QCA_ACS_MODE_IEEE80211G; |
| 10346 | case HOSTAPD_MODE_IEEE80211A: |
| 10347 | return QCA_ACS_MODE_IEEE80211A; |
| 10348 | case HOSTAPD_MODE_IEEE80211AD: |
| 10349 | return QCA_ACS_MODE_IEEE80211AD; |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 10350 | case HOSTAPD_MODE_IEEE80211ANY: |
| 10351 | return QCA_ACS_MODE_IEEE80211ANY; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10352 | default: |
| 10353 | return -1; |
| 10354 | } |
| 10355 | } |
| 10356 | |
| 10357 | |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 10358 | static int add_acs_ch_list(struct nl_msg *msg, const int *freq_list) |
| 10359 | { |
| 10360 | int num_channels = 0, num_freqs; |
| 10361 | u8 *ch_list; |
| 10362 | enum hostapd_hw_mode hw_mode; |
| 10363 | int ret = 0; |
| 10364 | int i; |
| 10365 | |
| 10366 | if (!freq_list) |
| 10367 | return 0; |
| 10368 | |
| 10369 | num_freqs = int_array_len(freq_list); |
| 10370 | ch_list = os_malloc(sizeof(u8) * num_freqs); |
| 10371 | if (!ch_list) |
| 10372 | return -1; |
| 10373 | |
| 10374 | for (i = 0; i < num_freqs; i++) { |
| 10375 | const int freq = freq_list[i]; |
| 10376 | |
| 10377 | if (freq == 0) |
| 10378 | break; |
| 10379 | /* Send 2.4 GHz and 5 GHz channels with |
| 10380 | * QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST to maintain backwards |
| 10381 | * compatibility. |
| 10382 | */ |
| 10383 | if (!(freq >= 2412 && freq <= 2484) && |
| 10384 | !(freq >= 5180 && freq <= 5900)) |
| 10385 | continue; |
| 10386 | hw_mode = ieee80211_freq_to_chan(freq, &ch_list[num_channels]); |
| 10387 | if (hw_mode != NUM_HOSTAPD_MODES) |
| 10388 | num_channels++; |
| 10389 | } |
| 10390 | |
| 10391 | if (num_channels) |
| 10392 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, |
| 10393 | num_channels, ch_list); |
| 10394 | |
| 10395 | os_free(ch_list); |
| 10396 | return ret; |
| 10397 | } |
| 10398 | |
| 10399 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10400 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
| 10401 | { |
| 10402 | int i, len, ret; |
| 10403 | u32 *freqs; |
| 10404 | |
| 10405 | if (!freq_list) |
| 10406 | return 0; |
| 10407 | len = int_array_len(freq_list); |
| 10408 | freqs = os_malloc(sizeof(u32) * len); |
| 10409 | if (!freqs) |
| 10410 | return -1; |
| 10411 | for (i = 0; i < len; i++) |
| 10412 | freqs[i] = freq_list[i]; |
| 10413 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, |
| 10414 | sizeof(u32) * len, freqs); |
| 10415 | os_free(freqs); |
| 10416 | return ret; |
| 10417 | } |
| 10418 | |
| 10419 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10420 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
| 10421 | { |
| 10422 | struct i802_bss *bss = priv; |
| 10423 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10424 | struct nl_msg *msg; |
| 10425 | struct nlattr *data; |
| 10426 | int ret; |
| 10427 | int mode; |
| 10428 | |
| 10429 | mode = hw_mode_to_qca_acs(params->hw_mode); |
| 10430 | if (mode < 0) |
| 10431 | return -1; |
| 10432 | |
| 10433 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10434 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10435 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10436 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || |
| 10437 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10438 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || |
| 10439 | (params->ht_enabled && |
| 10440 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || |
| 10441 | (params->ht40_enabled && |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 10442 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
| 10443 | (params->vht_enabled && |
| 10444 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || |
| 10445 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, |
| 10446 | params->ch_width) || |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 10447 | add_acs_ch_list(msg, params->freq_list) || |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 10448 | add_acs_freq_list(msg, params->freq_list) || |
| 10449 | (params->edmg_enabled && |
| 10450 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_EDMG_ENABLED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10451 | nlmsg_free(msg); |
| 10452 | return -ENOBUFS; |
| 10453 | } |
| 10454 | nla_nest_end(msg, data); |
| 10455 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 10456 | wpa_printf(MSG_DEBUG, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 10457 | "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] | 10458 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 10459 | params->vht_enabled, params->ch_width, params->edmg_enabled); |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 10460 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10461 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10462 | if (ret) { |
| 10463 | wpa_printf(MSG_DEBUG, |
| 10464 | "nl80211: Failed to invoke driver ACS function: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 10465 | strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10466 | } |
| 10467 | return ret; |
| 10468 | } |
| 10469 | |
| 10470 | |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 10471 | static int nl80211_set_band(void *priv, enum set_band band) |
| 10472 | { |
| 10473 | struct i802_bss *bss = priv; |
| 10474 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10475 | struct nl_msg *msg; |
| 10476 | struct nlattr *data; |
| 10477 | int ret; |
| 10478 | enum qca_set_band qca_band; |
| 10479 | |
| 10480 | if (!drv->setband_vendor_cmd_avail) |
| 10481 | return -1; |
| 10482 | |
| 10483 | switch (band) { |
| 10484 | case WPA_SETBAND_AUTO: |
| 10485 | qca_band = QCA_SETBAND_AUTO; |
| 10486 | break; |
| 10487 | case WPA_SETBAND_5G: |
| 10488 | qca_band = QCA_SETBAND_5G; |
| 10489 | break; |
| 10490 | case WPA_SETBAND_2G: |
| 10491 | qca_band = QCA_SETBAND_2G; |
| 10492 | break; |
| 10493 | default: |
| 10494 | return -1; |
| 10495 | } |
| 10496 | |
| 10497 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10498 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10499 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10500 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || |
| 10501 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10502 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) { |
| 10503 | nlmsg_free(msg); |
| 10504 | return -ENOBUFS; |
| 10505 | } |
| 10506 | nla_nest_end(msg, data); |
| 10507 | |
| 10508 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10509 | if (ret) { |
| 10510 | wpa_printf(MSG_DEBUG, |
| 10511 | "nl80211: Driver setband function failed: %s", |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 10512 | strerror(-ret)); |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 10513 | } |
| 10514 | return ret; |
| 10515 | } |
| 10516 | |
| 10517 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10518 | struct nl80211_pcl { |
| 10519 | unsigned int num; |
| 10520 | unsigned int *freq_list; |
| 10521 | }; |
| 10522 | |
| 10523 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) |
| 10524 | { |
| 10525 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 10526 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 10527 | struct nl80211_pcl *param = arg; |
| 10528 | struct nlattr *nl_vend, *attr; |
| 10529 | enum qca_iface_type iface_type; |
| 10530 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 10531 | unsigned int num, max_num; |
| 10532 | u32 *freqs; |
| 10533 | |
| 10534 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 10535 | genlmsg_attrlen(gnlh, 0), NULL); |
| 10536 | |
| 10537 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; |
| 10538 | if (!nl_vend) |
| 10539 | return NL_SKIP; |
| 10540 | |
| 10541 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 10542 | nla_data(nl_vend), nla_len(nl_vend), NULL); |
| 10543 | |
| 10544 | attr = tb_vendor[ |
| 10545 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; |
| 10546 | if (!attr) { |
| 10547 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); |
| 10548 | param->num = 0; |
| 10549 | return NL_SKIP; |
| 10550 | } |
| 10551 | |
| 10552 | iface_type = (enum qca_iface_type) nla_get_u32(attr); |
| 10553 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", |
| 10554 | iface_type); |
| 10555 | |
| 10556 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; |
| 10557 | if (!attr) { |
| 10558 | wpa_printf(MSG_ERROR, |
| 10559 | "nl80211: preferred_freq_list couldn't be found"); |
| 10560 | param->num = 0; |
| 10561 | return NL_SKIP; |
| 10562 | } |
| 10563 | |
| 10564 | /* |
| 10565 | * param->num has the maximum number of entries for which there |
| 10566 | * is room in the freq_list provided by the caller. |
| 10567 | */ |
| 10568 | freqs = nla_data(attr); |
| 10569 | max_num = nla_len(attr) / sizeof(u32); |
| 10570 | if (max_num > param->num) |
| 10571 | max_num = param->num; |
| 10572 | for (num = 0; num < max_num; num++) |
| 10573 | param->freq_list[num] = freqs[num]; |
| 10574 | param->num = num; |
| 10575 | |
| 10576 | return NL_SKIP; |
| 10577 | } |
| 10578 | |
| 10579 | |
| 10580 | static int nl80211_get_pref_freq_list(void *priv, |
| 10581 | enum wpa_driver_if_type if_type, |
| 10582 | unsigned int *num, |
| 10583 | unsigned int *freq_list) |
| 10584 | { |
| 10585 | struct i802_bss *bss = priv; |
| 10586 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10587 | struct nl_msg *msg; |
| 10588 | int ret; |
| 10589 | unsigned int i; |
| 10590 | struct nlattr *params; |
| 10591 | struct nl80211_pcl param; |
| 10592 | enum qca_iface_type iface_type; |
| 10593 | |
| 10594 | if (!drv->get_pref_freq_list) |
| 10595 | return -1; |
| 10596 | |
| 10597 | switch (if_type) { |
| 10598 | case WPA_IF_STATION: |
| 10599 | iface_type = QCA_IFACE_TYPE_STA; |
| 10600 | break; |
| 10601 | case WPA_IF_AP_BSS: |
| 10602 | iface_type = QCA_IFACE_TYPE_AP; |
| 10603 | break; |
| 10604 | case WPA_IF_P2P_GO: |
| 10605 | iface_type = QCA_IFACE_TYPE_P2P_GO; |
| 10606 | break; |
| 10607 | case WPA_IF_P2P_CLIENT: |
| 10608 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; |
| 10609 | break; |
| 10610 | case WPA_IF_IBSS: |
| 10611 | iface_type = QCA_IFACE_TYPE_IBSS; |
| 10612 | break; |
| 10613 | case WPA_IF_TDLS: |
| 10614 | iface_type = QCA_IFACE_TYPE_TDLS; |
| 10615 | break; |
| 10616 | default: |
| 10617 | return -1; |
| 10618 | } |
| 10619 | |
| 10620 | param.num = *num; |
| 10621 | param.freq_list = freq_list; |
| 10622 | |
| 10623 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10624 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || |
| 10625 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10626 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10627 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || |
| 10628 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10629 | nla_put_u32(msg, |
| 10630 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, |
| 10631 | iface_type)) { |
| 10632 | wpa_printf(MSG_ERROR, |
| 10633 | "%s: err in adding vendor_cmd and vendor_data", |
| 10634 | __func__); |
| 10635 | nlmsg_free(msg); |
| 10636 | return -1; |
| 10637 | } |
| 10638 | nla_nest_end(msg, params); |
| 10639 | |
| 10640 | os_memset(freq_list, 0, *num * sizeof(freq_list[0])); |
| 10641 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m); |
| 10642 | if (ret) { |
| 10643 | wpa_printf(MSG_ERROR, |
| 10644 | "%s: err in send_and_recv_msgs", __func__); |
| 10645 | return ret; |
| 10646 | } |
| 10647 | |
| 10648 | *num = param.num; |
| 10649 | |
| 10650 | for (i = 0; i < *num; i++) { |
| 10651 | wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d", |
| 10652 | i, freq_list[i]); |
| 10653 | } |
| 10654 | |
| 10655 | return 0; |
| 10656 | } |
| 10657 | |
| 10658 | |
| 10659 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
| 10660 | { |
| 10661 | struct i802_bss *bss = priv; |
| 10662 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10663 | struct nl_msg *msg; |
| 10664 | int ret; |
| 10665 | struct nlattr *params; |
| 10666 | |
| 10667 | if (!drv->set_prob_oper_freq) |
| 10668 | return -1; |
| 10669 | |
| 10670 | wpa_printf(MSG_DEBUG, |
| 10671 | "nl80211: Set P2P probable operating freq %u for ifindex %d", |
| 10672 | freq, bss->ifindex); |
| 10673 | |
| 10674 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10675 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10676 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10677 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || |
| 10678 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10679 | nla_put_u32(msg, |
| 10680 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, |
| 10681 | QCA_IFACE_TYPE_P2P_CLIENT) || |
| 10682 | nla_put_u32(msg, |
| 10683 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, |
| 10684 | freq)) { |
| 10685 | wpa_printf(MSG_ERROR, |
| 10686 | "%s: err in adding vendor_cmd and vendor_data", |
| 10687 | __func__); |
| 10688 | nlmsg_free(msg); |
| 10689 | return -1; |
| 10690 | } |
| 10691 | nla_nest_end(msg, params); |
| 10692 | |
| 10693 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10694 | msg = NULL; |
| 10695 | if (ret) { |
| 10696 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", |
| 10697 | __func__); |
| 10698 | return ret; |
| 10699 | } |
| 10700 | nlmsg_free(msg); |
| 10701 | return 0; |
| 10702 | } |
| 10703 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 10704 | |
| 10705 | static int nl80211_p2p_lo_start(void *priv, unsigned int freq, |
| 10706 | unsigned int period, unsigned int interval, |
| 10707 | unsigned int count, const u8 *device_types, |
| 10708 | size_t dev_types_len, |
| 10709 | const u8 *ies, size_t ies_len) |
| 10710 | { |
| 10711 | struct i802_bss *bss = priv; |
| 10712 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10713 | struct nl_msg *msg; |
| 10714 | struct nlattr *container; |
| 10715 | int ret; |
| 10716 | |
| 10717 | wpa_printf(MSG_DEBUG, |
| 10718 | "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u", |
| 10719 | freq, period, interval, count); |
| 10720 | |
| 10721 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 10722 | return -1; |
| 10723 | |
| 10724 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10725 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10726 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10727 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START)) |
| 10728 | goto fail; |
| 10729 | |
| 10730 | container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 10731 | if (!container) |
| 10732 | goto fail; |
| 10733 | |
| 10734 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL, |
| 10735 | freq) || |
| 10736 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD, |
| 10737 | period) || |
| 10738 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL, |
| 10739 | interval) || |
| 10740 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT, |
| 10741 | count) || |
| 10742 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES, |
| 10743 | dev_types_len, device_types) || |
| 10744 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE, |
| 10745 | ies_len, ies)) |
| 10746 | goto fail; |
| 10747 | |
| 10748 | nla_nest_end(msg, container); |
| 10749 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10750 | msg = NULL; |
| 10751 | if (ret) { |
| 10752 | wpa_printf(MSG_DEBUG, |
| 10753 | "nl80211: Failed to send P2P Listen offload vendor command"); |
| 10754 | goto fail; |
| 10755 | } |
| 10756 | |
| 10757 | return 0; |
| 10758 | |
| 10759 | fail: |
| 10760 | nlmsg_free(msg); |
| 10761 | return -1; |
| 10762 | } |
| 10763 | |
| 10764 | |
| 10765 | static int nl80211_p2p_lo_stop(void *priv) |
| 10766 | { |
| 10767 | struct i802_bss *bss = priv; |
| 10768 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10769 | struct nl_msg *msg; |
| 10770 | |
| 10771 | wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload"); |
| 10772 | |
| 10773 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 10774 | return -1; |
| 10775 | |
| 10776 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10777 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10778 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10779 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) { |
| 10780 | nlmsg_free(msg); |
| 10781 | return -1; |
| 10782 | } |
| 10783 | |
| 10784 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10785 | } |
| 10786 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 10787 | |
| 10788 | static int nl80211_set_tdls_mode(void *priv, int tdls_external_control) |
| 10789 | { |
| 10790 | struct i802_bss *bss = priv; |
| 10791 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10792 | struct nl_msg *msg; |
| 10793 | struct nlattr *params; |
| 10794 | int ret; |
| 10795 | u32 tdls_mode; |
| 10796 | |
| 10797 | wpa_printf(MSG_DEBUG, |
| 10798 | "nl80211: Set TDKS mode: tdls_external_control=%d", |
| 10799 | tdls_external_control); |
| 10800 | |
| 10801 | if (tdls_external_control == 1) |
| 10802 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT | |
| 10803 | QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL; |
| 10804 | else |
| 10805 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT; |
| 10806 | |
| 10807 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10808 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10809 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10810 | QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS)) |
| 10811 | goto fail; |
| 10812 | |
| 10813 | params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 10814 | if (!params) |
| 10815 | goto fail; |
| 10816 | |
| 10817 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE, |
| 10818 | tdls_mode)) |
| 10819 | goto fail; |
| 10820 | |
| 10821 | nla_nest_end(msg, params); |
| 10822 | |
| 10823 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10824 | msg = NULL; |
| 10825 | if (ret) { |
| 10826 | wpa_printf(MSG_ERROR, |
| 10827 | "nl80211: Set TDLS mode failed: ret=%d (%s)", |
| 10828 | ret, strerror(-ret)); |
| 10829 | goto fail; |
| 10830 | } |
| 10831 | return 0; |
| 10832 | fail: |
| 10833 | nlmsg_free(msg); |
| 10834 | return -1; |
| 10835 | } |
| 10836 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10837 | |
| 10838 | #ifdef CONFIG_MBO |
| 10839 | |
| 10840 | static enum mbo_transition_reject_reason |
| 10841 | nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status) |
| 10842 | { |
| 10843 | switch (status) { |
| 10844 | case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED: |
| 10845 | return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS; |
| 10846 | case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED: |
| 10847 | return MBO_TRANSITION_REJECT_REASON_DELAY; |
| 10848 | case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY: |
| 10849 | return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY; |
| 10850 | case QCA_STATUS_REJECT_LOW_RSSI: |
| 10851 | return MBO_TRANSITION_REJECT_REASON_RSSI; |
| 10852 | case QCA_STATUS_REJECT_HIGH_INTERFERENCE: |
| 10853 | return MBO_TRANSITION_REJECT_REASON_INTERFERENCE; |
| 10854 | case QCA_STATUS_REJECT_UNKNOWN: |
| 10855 | default: |
| 10856 | return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED; |
| 10857 | } |
| 10858 | } |
| 10859 | |
| 10860 | |
| 10861 | static void nl80211_parse_btm_candidate_info(struct candidate_list *candidate, |
| 10862 | struct nlattr *tb[], int num) |
| 10863 | { |
| 10864 | enum qca_wlan_btm_candidate_status status; |
| 10865 | char buf[50]; |
| 10866 | |
| 10867 | os_memcpy(candidate->bssid, |
| 10868 | nla_data(tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID]), |
| 10869 | ETH_ALEN); |
| 10870 | |
| 10871 | status = nla_get_u32( |
| 10872 | tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]); |
| 10873 | candidate->is_accept = status == QCA_STATUS_ACCEPT; |
| 10874 | candidate->reject_reason = nl80211_mbo_reject_reason_mapping(status); |
| 10875 | |
| 10876 | if (candidate->is_accept) |
| 10877 | os_snprintf(buf, sizeof(buf), "Accepted"); |
| 10878 | else |
| 10879 | os_snprintf(buf, sizeof(buf), |
| 10880 | "Rejected, Reject_reason: %d", |
| 10881 | candidate->reject_reason); |
| 10882 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR " %s", |
| 10883 | num, MAC2STR(candidate->bssid), buf); |
| 10884 | } |
| 10885 | |
| 10886 | |
| 10887 | static int |
| 10888 | nl80211_get_bss_transition_status_handler(struct nl_msg *msg, void *arg) |
| 10889 | { |
| 10890 | struct wpa_bss_candidate_info *info = arg; |
| 10891 | struct candidate_list *candidate = info->candidates; |
| 10892 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 10893 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 10894 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1]; |
| 10895 | static struct nla_policy policy[ |
| 10896 | QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1] = { |
| 10897 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] = { |
| 10898 | .minlen = ETH_ALEN |
| 10899 | }, |
| 10900 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS] = { |
| 10901 | .type = NLA_U32, |
| 10902 | }, |
| 10903 | }; |
| 10904 | struct nlattr *attr; |
| 10905 | int rem; |
| 10906 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 10907 | u8 num; |
| 10908 | |
| 10909 | num = info->num; /* number of candidates sent to driver */ |
| 10910 | info->num = 0; |
| 10911 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 10912 | genlmsg_attrlen(gnlh, 0), NULL); |
| 10913 | |
| 10914 | if (!tb_msg[NL80211_ATTR_VENDOR_DATA] || |
| 10915 | nla_parse_nested(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 10916 | tb_msg[NL80211_ATTR_VENDOR_DATA], NULL) || |
| 10917 | !tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO]) |
| 10918 | return NL_SKIP; |
| 10919 | |
| 10920 | wpa_printf(MSG_DEBUG, |
| 10921 | "nl80211: WNM Candidate list received from driver"); |
| 10922 | nla_for_each_nested(attr, |
| 10923 | tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO], |
| 10924 | rem) { |
| 10925 | if (info->num >= num || |
| 10926 | nla_parse_nested( |
| 10927 | tb, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX, |
| 10928 | attr, policy) || |
| 10929 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] || |
| 10930 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]) |
| 10931 | break; |
| 10932 | |
| 10933 | nl80211_parse_btm_candidate_info(candidate, tb, info->num); |
| 10934 | |
| 10935 | candidate++; |
| 10936 | info->num++; |
| 10937 | } |
| 10938 | |
| 10939 | return NL_SKIP; |
| 10940 | } |
| 10941 | |
| 10942 | |
| 10943 | static struct wpa_bss_candidate_info * |
| 10944 | nl80211_get_bss_transition_status(void *priv, struct wpa_bss_trans_info *params) |
| 10945 | { |
| 10946 | struct i802_bss *bss = priv; |
| 10947 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10948 | struct nl_msg *msg; |
| 10949 | struct nlattr *attr, *attr1, *attr2; |
| 10950 | struct wpa_bss_candidate_info *info; |
| 10951 | u8 i; |
| 10952 | int ret; |
| 10953 | u8 *pos; |
| 10954 | |
| 10955 | if (!drv->fetch_bss_trans_status) |
| 10956 | return NULL; |
| 10957 | |
| 10958 | info = os_zalloc(sizeof(*info)); |
| 10959 | if (!info) |
| 10960 | return NULL; |
| 10961 | /* Allocate memory for number of candidates sent to driver */ |
| 10962 | info->candidates = os_calloc(params->n_candidates, |
| 10963 | sizeof(*info->candidates)); |
| 10964 | if (!info->candidates) { |
| 10965 | os_free(info); |
| 10966 | return NULL; |
| 10967 | } |
| 10968 | |
| 10969 | /* Copy the number of candidates being sent to driver. This is used in |
| 10970 | * nl80211_get_bss_transition_status_handler() to limit the number of |
| 10971 | * candidates that can be populated in info->candidates and will be |
| 10972 | * later overwritten with the actual number of candidates received from |
| 10973 | * the driver. |
| 10974 | */ |
| 10975 | info->num = params->n_candidates; |
| 10976 | |
| 10977 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10978 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10979 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10980 | QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS)) |
| 10981 | goto fail; |
| 10982 | |
| 10983 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 10984 | if (!attr) |
| 10985 | goto fail; |
| 10986 | |
| 10987 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON, |
| 10988 | params->mbo_transition_reason)) |
| 10989 | goto fail; |
| 10990 | |
| 10991 | attr1 = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO); |
| 10992 | if (!attr1) |
| 10993 | goto fail; |
| 10994 | |
| 10995 | wpa_printf(MSG_DEBUG, |
| 10996 | "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d", |
| 10997 | params->mbo_transition_reason, params->n_candidates); |
| 10998 | pos = params->bssid; |
| 10999 | for (i = 0; i < params->n_candidates; i++) { |
| 11000 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR, i, |
| 11001 | MAC2STR(pos)); |
| 11002 | attr2 = nla_nest_start(msg, i); |
| 11003 | if (!attr2 || |
| 11004 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID, |
| 11005 | ETH_ALEN, pos)) |
| 11006 | goto fail; |
| 11007 | pos += ETH_ALEN; |
| 11008 | nla_nest_end(msg, attr2); |
| 11009 | } |
| 11010 | |
| 11011 | nla_nest_end(msg, attr1); |
| 11012 | nla_nest_end(msg, attr); |
| 11013 | |
| 11014 | ret = send_and_recv_msgs(drv, msg, |
| 11015 | nl80211_get_bss_transition_status_handler, |
| 11016 | info); |
| 11017 | msg = NULL; |
| 11018 | if (ret) { |
| 11019 | wpa_printf(MSG_ERROR, |
| 11020 | "nl80211: WNM Get BSS transition status failed: ret=%d (%s)", |
| 11021 | ret, strerror(-ret)); |
| 11022 | goto fail; |
| 11023 | } |
| 11024 | return info; |
| 11025 | |
| 11026 | fail: |
| 11027 | nlmsg_free(msg); |
| 11028 | os_free(info->candidates); |
| 11029 | os_free(info); |
| 11030 | return NULL; |
| 11031 | } |
| 11032 | |
| 11033 | |
| 11034 | /** |
| 11035 | * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow |
| 11036 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() |
| 11037 | * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore |
| 11038 | * Returns: 0 on success, -1 on failure |
| 11039 | */ |
| 11040 | static int nl80211_ignore_assoc_disallow(void *priv, int ignore_disallow) |
| 11041 | { |
| 11042 | struct i802_bss *bss = priv; |
| 11043 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11044 | struct nl_msg *msg; |
| 11045 | struct nlattr *attr; |
| 11046 | int ret = -1; |
| 11047 | |
| 11048 | if (!drv->set_wifi_conf_vendor_cmd_avail) |
| 11049 | return -1; |
| 11050 | |
| 11051 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 11052 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 11053 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 11054 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) |
| 11055 | goto fail; |
| 11056 | |
| 11057 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 11058 | if (!attr) |
| 11059 | goto fail; |
| 11060 | |
| 11061 | wpa_printf(MSG_DEBUG, "nl80211: Set ignore_assoc_disallow %d", |
| 11062 | ignore_disallow); |
| 11063 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED, |
| 11064 | ignore_disallow)) |
| 11065 | goto fail; |
| 11066 | |
| 11067 | nla_nest_end(msg, attr); |
| 11068 | |
| 11069 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 11070 | msg = NULL; |
| 11071 | if (ret) { |
| 11072 | wpa_printf(MSG_ERROR, |
| 11073 | "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)", |
| 11074 | ret, strerror(-ret)); |
| 11075 | goto fail; |
| 11076 | } |
| 11077 | |
| 11078 | fail: |
| 11079 | nlmsg_free(msg); |
| 11080 | return ret; |
| 11081 | } |
| 11082 | |
| 11083 | #endif /* CONFIG_MBO */ |
| 11084 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11085 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 11086 | |
| 11087 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11088 | static int nl80211_write_to_file(const char *name, unsigned int val) |
| 11089 | { |
| 11090 | int fd, len; |
| 11091 | char tmp[128]; |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11092 | int ret = 0; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11093 | |
| 11094 | fd = open(name, O_RDWR); |
| 11095 | if (fd < 0) { |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11096 | int level; |
| 11097 | /* |
| 11098 | * Flags may not exist on older kernels, or while we're tearing |
| 11099 | * down a disappearing device. |
| 11100 | */ |
| 11101 | if (errno == ENOENT) { |
| 11102 | ret = 0; |
| 11103 | level = MSG_DEBUG; |
| 11104 | } else { |
| 11105 | ret = -1; |
| 11106 | level = MSG_ERROR; |
| 11107 | } |
| 11108 | wpa_printf(level, "nl80211: Failed to open %s: %s", |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11109 | name, strerror(errno)); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11110 | return ret; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11111 | } |
| 11112 | |
| 11113 | len = os_snprintf(tmp, sizeof(tmp), "%u\n", val); |
| 11114 | len = write(fd, tmp, len); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11115 | if (len < 0) { |
| 11116 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11117 | wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s", |
| 11118 | name, strerror(errno)); |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11119 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11120 | close(fd); |
| 11121 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11122 | return ret; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11123 | } |
| 11124 | |
| 11125 | |
| 11126 | static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags) |
| 11127 | { |
| 11128 | struct i802_bss *bss = priv; |
| 11129 | char path[128]; |
| 11130 | int ret; |
| 11131 | |
| 11132 | wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x", |
| 11133 | filter_flags); |
| 11134 | |
| 11135 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 11136 | ret = os_snprintf(path, sizeof(path), |
| 11137 | "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast", |
| 11138 | bss->ifname); |
| 11139 | if (os_snprintf_error(sizeof(path), ret)) |
| 11140 | return -1; |
| 11141 | |
| 11142 | ret = nl80211_write_to_file(path, |
| 11143 | !!(filter_flags & |
| 11144 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 11145 | if (ret) { |
| 11146 | wpa_printf(MSG_ERROR, |
| 11147 | "nl80211: Failed to set IPv4 unicast in multicast filter"); |
| 11148 | return ret; |
| 11149 | } |
| 11150 | |
| 11151 | os_snprintf(path, sizeof(path), |
| 11152 | "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast", |
| 11153 | bss->ifname); |
| 11154 | ret = nl80211_write_to_file(path, |
| 11155 | !!(filter_flags & |
| 11156 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 11157 | |
| 11158 | if (ret) { |
| 11159 | wpa_printf(MSG_ERROR, |
| 11160 | "nl80211: Failed to set IPv6 unicast in multicast filter"); |
| 11161 | return ret; |
| 11162 | } |
| 11163 | |
| 11164 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 11165 | os_snprintf(path, sizeof(path), |
| 11166 | "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp", |
| 11167 | bss->ifname); |
| 11168 | ret = nl80211_write_to_file(path, |
| 11169 | !!(filter_flags & |
| 11170 | WPA_DATA_FRAME_FILTER_FLAG_ARP)); |
| 11171 | if (ret) { |
| 11172 | wpa_printf(MSG_ERROR, |
| 11173 | "nl80211: Failed set gratuitous ARP filter"); |
| 11174 | return ret; |
| 11175 | } |
| 11176 | |
| 11177 | /* Configure filtering of IPv6 NA frames */ |
| 11178 | os_snprintf(path, sizeof(path), |
| 11179 | "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na", |
| 11180 | bss->ifname); |
| 11181 | ret = nl80211_write_to_file(path, |
| 11182 | !!(filter_flags & |
| 11183 | WPA_DATA_FRAME_FILTER_FLAG_NA)); |
| 11184 | if (ret) { |
| 11185 | wpa_printf(MSG_ERROR, |
| 11186 | "nl80211: Failed to set unsolicited NA filter"); |
| 11187 | return ret; |
| 11188 | } |
| 11189 | |
| 11190 | return 0; |
| 11191 | } |
| 11192 | |
| 11193 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 11194 | static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type, |
| 11195 | const u8 **ext_capa, const u8 **ext_capa_mask, |
| 11196 | unsigned int *ext_capa_len) |
| 11197 | { |
| 11198 | struct i802_bss *bss = priv; |
| 11199 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11200 | enum nl80211_iftype nlmode; |
| 11201 | unsigned int i; |
| 11202 | |
| 11203 | if (!ext_capa || !ext_capa_mask || !ext_capa_len) |
| 11204 | return -1; |
| 11205 | |
| 11206 | nlmode = wpa_driver_nl80211_if_type(type); |
| 11207 | |
| 11208 | /* By default, use the per-radio values */ |
| 11209 | *ext_capa = drv->extended_capa; |
| 11210 | *ext_capa_mask = drv->extended_capa_mask; |
| 11211 | *ext_capa_len = drv->extended_capa_len; |
| 11212 | |
| 11213 | /* Replace the default value if a per-interface type value exists */ |
| 11214 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 11215 | if (nlmode == drv->iface_ext_capa[i].iftype) { |
| 11216 | *ext_capa = drv->iface_ext_capa[i].ext_capa; |
| 11217 | *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask; |
| 11218 | *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len; |
| 11219 | break; |
| 11220 | } |
| 11221 | } |
| 11222 | |
| 11223 | return 0; |
| 11224 | } |
| 11225 | |
| 11226 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11227 | static int nl80211_update_connection_params( |
| 11228 | void *priv, struct wpa_driver_associate_params *params, |
| 11229 | enum wpa_drv_update_connect_params_mask mask) |
| 11230 | { |
| 11231 | struct i802_bss *bss = priv; |
| 11232 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11233 | struct nl_msg *msg; |
| 11234 | int ret = -1; |
| 11235 | enum nl80211_auth_type type; |
| 11236 | |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11237 | /* Update Connection Params is intended for drivers that implement |
| 11238 | * internal SME and expect these updated connection params from |
| 11239 | * wpa_supplicant. Do not send this request for the drivers using |
| 11240 | * SME from wpa_supplicant. |
| 11241 | */ |
| 11242 | if (drv->capa.flags & WPA_DRIVER_FLAGS_SME) |
| 11243 | return 0; |
| 11244 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11245 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS); |
| 11246 | if (!msg) |
| 11247 | goto fail; |
| 11248 | |
| 11249 | wpa_printf(MSG_DEBUG, "nl80211: Update connection params (ifindex=%d)", |
| 11250 | drv->ifindex); |
| 11251 | |
| 11252 | if ((mask & WPA_DRV_UPDATE_ASSOC_IES) && params->wpa_ie) { |
| 11253 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 11254 | params->wpa_ie)) |
| 11255 | goto fail; |
| 11256 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, |
| 11257 | params->wpa_ie_len); |
| 11258 | } |
| 11259 | |
| 11260 | if (mask & WPA_DRV_UPDATE_AUTH_TYPE) { |
| 11261 | type = get_nl_auth_type(params->auth_alg); |
| 11262 | if (type == NL80211_AUTHTYPE_MAX || |
| 11263 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 11264 | goto fail; |
| 11265 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
| 11266 | } |
| 11267 | |
| 11268 | if ((mask & WPA_DRV_UPDATE_FILS_ERP_INFO) && |
| 11269 | nl80211_put_fils_connect_params(drv, params, msg)) |
| 11270 | goto fail; |
| 11271 | |
| 11272 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 11273 | msg = NULL; |
| 11274 | if (ret) |
| 11275 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 11276 | "nl80211: Update connect params command failed: ret=%d (%s)", |
| 11277 | ret, strerror(-ret)); |
| 11278 | |
| 11279 | fail: |
| 11280 | nlmsg_free(msg); |
| 11281 | return ret; |
| 11282 | } |
| 11283 | |
| 11284 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11285 | static int nl80211_send_external_auth_status(void *priv, |
| 11286 | struct external_auth *params) |
| 11287 | { |
| 11288 | struct i802_bss *bss = priv; |
| 11289 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11290 | struct nl_msg *msg = NULL; |
| 11291 | int ret = -1; |
| 11292 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 11293 | /* External auth command/status is intended for drivers that implement |
Ahmed ElArabawy | 0ff61c5 | 2019-12-26 12:38:39 -0800 | [diff] [blame] | 11294 | * internal SME but want to offload authentication processing (e.g., |
| 11295 | * SAE) to hostapd/wpa_supplicant. Do not send the status to drivers |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 11296 | * which do not support AP SME or use wpa_supplicant/hostapd SME. |
| 11297 | */ |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 11298 | if ((is_ap_interface(drv->nlmode) && !bss->drv->device_ap_sme) || |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 11299 | (drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
| 11300 | return -1; |
| 11301 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11302 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 11303 | "nl80211: External auth status: %u", params->status); |
| 11304 | |
| 11305 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_EXTERNAL_AUTH); |
| 11306 | if (!msg || |
| 11307 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, params->status) || |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 11308 | (params->ssid && params->ssid_len && |
| 11309 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || |
| 11310 | (params->pmkid && |
| 11311 | nla_put(msg, NL80211_ATTR_PMKID, PMKID_LEN, params->pmkid)) || |
| 11312 | (params->bssid && |
| 11313 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid))) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11314 | goto fail; |
| 11315 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 11316 | msg = NULL; |
| 11317 | if (ret) { |
| 11318 | wpa_printf(MSG_DEBUG, |
| 11319 | "nl80211: External Auth status update failed: ret=%d (%s)", |
| 11320 | ret, strerror(-ret)); |
| 11321 | goto fail; |
| 11322 | } |
| 11323 | fail: |
| 11324 | nlmsg_free(msg); |
| 11325 | return ret; |
| 11326 | } |
| 11327 | |
| 11328 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 11329 | static int nl80211_set_4addr_mode(void *priv, const char *bridge_ifname, |
| 11330 | int val) |
| 11331 | { |
| 11332 | struct i802_bss *bss = priv; |
| 11333 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 11334 | struct nl_msg *msg; |
| 11335 | int ret = -ENOBUFS; |
| 11336 | |
| 11337 | wpa_printf(MSG_DEBUG, "nl80211: %s 4addr mode (bridge_ifname: %s)", |
| 11338 | val ? "Enable" : "Disable", bridge_ifname); |
| 11339 | |
| 11340 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 11341 | if (!msg || nla_put_u8(msg, NL80211_ATTR_4ADDR, val)) |
| 11342 | goto fail; |
| 11343 | |
| 11344 | if (bridge_ifname[0] && bss->added_if_into_bridge && !val) { |
| 11345 | if (linux_br_del_if(drv->global->ioctl_sock, |
| 11346 | bridge_ifname, bss->ifname)) { |
| 11347 | wpa_printf(MSG_ERROR, |
| 11348 | "nl80211: Failed to remove interface %s from bridge %s", |
| 11349 | bss->ifname, bridge_ifname); |
| 11350 | return -1; |
| 11351 | } |
| 11352 | bss->added_if_into_bridge = 0; |
| 11353 | } |
| 11354 | |
| 11355 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 11356 | msg = NULL; |
| 11357 | if (!ret) { |
| 11358 | if (bridge_ifname[0] && val && |
| 11359 | i802_check_bridge(drv, bss, bridge_ifname, bss->ifname) < 0) |
| 11360 | return -1; |
| 11361 | return 0; |
| 11362 | } |
| 11363 | |
| 11364 | fail: |
| 11365 | nlmsg_free(msg); |
| 11366 | wpa_printf(MSG_ERROR, "nl80211: Failed to enable/disable 4addr"); |
| 11367 | |
| 11368 | return ret; |
| 11369 | } |
| 11370 | |
| 11371 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11372 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 11373 | .name = "nl80211", |
| 11374 | .desc = "Linux nl80211/cfg80211", |
| 11375 | .get_bssid = wpa_driver_nl80211_get_bssid, |
| 11376 | .get_ssid = wpa_driver_nl80211_get_ssid, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11377 | .set_key = driver_nl80211_set_key, |
| 11378 | .scan2 = driver_nl80211_scan2, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11379 | .sched_scan = wpa_driver_nl80211_sched_scan, |
| 11380 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11381 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 11382 | .abort_scan = wpa_driver_nl80211_abort_scan, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11383 | .deauthenticate = driver_nl80211_deauthenticate, |
| 11384 | .authenticate = driver_nl80211_authenticate, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11385 | .associate = wpa_driver_nl80211_associate, |
| 11386 | .global_init = nl80211_global_init, |
| 11387 | .global_deinit = nl80211_global_deinit, |
| 11388 | .init2 = wpa_driver_nl80211_init, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11389 | .deinit = driver_nl80211_deinit, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11390 | .get_capa = wpa_driver_nl80211_get_capa, |
| 11391 | .set_operstate = wpa_driver_nl80211_set_operstate, |
| 11392 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
| 11393 | .set_country = wpa_driver_nl80211_set_country, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 11394 | .get_country = wpa_driver_nl80211_get_country, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11395 | .set_ap = wpa_driver_nl80211_set_ap, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 11396 | .set_acl = wpa_driver_nl80211_set_acl, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11397 | .if_add = wpa_driver_nl80211_if_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11398 | .if_remove = driver_nl80211_if_remove, |
| 11399 | .send_mlme = driver_nl80211_send_mlme, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11400 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11401 | .sta_add = wpa_driver_nl80211_sta_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11402 | .sta_remove = driver_nl80211_sta_remove, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 11403 | .tx_control_port = nl80211_tx_control_port, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11404 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
| 11405 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 11406 | .sta_set_airtime_weight = driver_nl80211_sta_set_airtime_weight, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11407 | .hapd_init = i802_init, |
| 11408 | .hapd_deinit = i802_deinit, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 11409 | .set_wds_sta = i802_set_wds_sta, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11410 | .get_seqnum = i802_get_seqnum, |
| 11411 | .flush = i802_flush, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11412 | .get_inact_sec = i802_get_inact_sec, |
| 11413 | .sta_clear_stats = i802_sta_clear_stats, |
| 11414 | .set_rts = i802_set_rts, |
| 11415 | .set_frag = i802_set_frag, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11416 | .set_tx_queue_params = i802_set_tx_queue_params, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11417 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11418 | .sta_deauth = i802_sta_deauth, |
| 11419 | .sta_disassoc = i802_sta_disassoc, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11420 | .read_sta_data = driver_nl80211_read_sta_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11421 | .set_freq = i802_set_freq, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11422 | .send_action = driver_nl80211_send_action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11423 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
| 11424 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
| 11425 | .cancel_remain_on_channel = |
| 11426 | wpa_driver_nl80211_cancel_remain_on_channel, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11427 | .probe_req_report = driver_nl80211_probe_req_report, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11428 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 11429 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11430 | .resume = wpa_driver_nl80211_resume, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11431 | .signal_monitor = nl80211_signal_monitor, |
| 11432 | .signal_poll = nl80211_signal_poll, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 11433 | .channel_info = nl80211_channel_info, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11434 | .set_param = nl80211_set_param, |
| 11435 | .get_radio_name = nl80211_get_radio_name, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 11436 | .add_pmkid = nl80211_add_pmkid, |
| 11437 | .remove_pmkid = nl80211_remove_pmkid, |
| 11438 | .flush_pmkid = nl80211_flush_pmkid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11439 | .set_rekey_info = nl80211_set_rekey_info, |
| 11440 | .poll_client = nl80211_poll_client, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11441 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 11442 | .start_dfs_cac = nl80211_start_radar_detection, |
| 11443 | .stop_ap = wpa_driver_nl80211_stop_ap, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11444 | #ifdef CONFIG_TDLS |
| 11445 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, |
| 11446 | .tdls_oper = nl80211_tdls_oper, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11447 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
| 11448 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11449 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 11450 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 11451 | .update_dh_ie = nl80211_update_dh_ie, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 11452 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 11453 | .get_survey = wpa_driver_nl80211_get_survey, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11454 | .status = wpa_driver_nl80211_status, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11455 | .switch_channel = nl80211_switch_channel, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11456 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 11457 | .set_noa = wpa_driver_set_p2p_noa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11458 | .get_noa = wpa_driver_get_p2p_noa, |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 11459 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 11460 | #endif /* ANDROID_P2P */ |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 11461 | #ifdef ANDROID |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 11462 | #ifndef ANDROID_LIB_STUB |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 11463 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 11464 | #endif /* !ANDROID_LIB_STUB */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 11465 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 11466 | .vendor_cmd = nl80211_vendor_cmd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11467 | .set_qos_map = nl80211_set_qos_map, |
Hai Shalom | fdcde76 | 2020-04-02 11:19:20 -0700 | [diff] [blame^] | 11468 | .get_wowlan = nl80211_get_wowlan, |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 11469 | .set_wowlan = nl80211_set_wowlan, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11470 | .set_mac_addr = nl80211_set_mac_addr, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11471 | #ifdef CONFIG_MESH |
| 11472 | .init_mesh = wpa_driver_nl80211_init_mesh, |
| 11473 | .join_mesh = wpa_driver_nl80211_join_mesh, |
| 11474 | .leave_mesh = wpa_driver_nl80211_leave_mesh, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame] | 11475 | .probe_mesh_link = nl80211_probe_mesh_link, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11476 | #endif /* CONFIG_MESH */ |
| 11477 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
| 11478 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, |
| 11479 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
| 11480 | .br_set_net_param = wpa_driver_br_set_net_param, |
| 11481 | .add_tx_ts = nl80211_add_ts, |
| 11482 | .del_tx_ts = nl80211_del_ts, |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 11483 | .get_ifindex = nl80211_get_ifindex, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11484 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 11485 | .roaming = nl80211_roaming, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11486 | .disable_fils = nl80211_disable_fils, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11487 | .do_acs = wpa_driver_do_acs, |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11488 | .set_band = nl80211_set_band, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11489 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
| 11490 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 11491 | .p2p_lo_start = nl80211_p2p_lo_start, |
| 11492 | .p2p_lo_stop = nl80211_p2p_lo_stop, |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 11493 | .set_default_scan_ies = nl80211_set_default_scan_ies, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 11494 | .set_tdls_mode = nl80211_set_tdls_mode, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11495 | #ifdef CONFIG_MBO |
| 11496 | .get_bss_transition_status = nl80211_get_bss_transition_status, |
| 11497 | .ignore_assoc_disallow = nl80211_ignore_assoc_disallow, |
| 11498 | #endif /* CONFIG_MBO */ |
| 11499 | .set_bssid_blacklist = nl80211_set_bssid_blacklist, |
Hai Shalom | c356592 | 2019-10-28 11:58:20 -0700 | [diff] [blame] | 11500 | .add_sta_node = nl80211_add_sta_node, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11501 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11502 | .configure_data_frame_filters = nl80211_configure_data_frame_filters, |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 11503 | .get_ext_capab = nl80211_get_ext_capab, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11504 | .update_connect_params = nl80211_update_connection_params, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11505 | .send_external_auth_status = nl80211_send_external_auth_status, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 11506 | .set_4addr_mode = nl80211_set_4addr_mode, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11507 | }; |