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 | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 69 | #ifndef CONFIG_LIBNL20 |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 70 | /* |
| 71 | * libnl 1.1 has a bug, it tries to allocate socket numbers densely |
| 72 | * but when you free a socket again it will mess up its bitmap and |
| 73 | * and use the wrong number the next time it needs a socket ID. |
| 74 | * Therefore, we wrap the handle alloc/destroy and add our own pid |
| 75 | * accounting. |
| 76 | */ |
| 77 | static uint32_t port_bitmap[32] = { 0 }; |
| 78 | |
| 79 | static struct nl_handle *nl80211_handle_alloc(void *cb) |
| 80 | { |
| 81 | struct nl_handle *handle; |
| 82 | uint32_t pid = getpid() & 0x3FFFFF; |
| 83 | int i; |
| 84 | |
| 85 | handle = nl_handle_alloc_cb(cb); |
| 86 | |
| 87 | for (i = 0; i < 1024; i++) { |
| 88 | if (port_bitmap[i / 32] & (1 << (i % 32))) |
| 89 | continue; |
| 90 | port_bitmap[i / 32] |= 1 << (i % 32); |
| 91 | pid += i << 22; |
| 92 | break; |
| 93 | } |
| 94 | |
| 95 | nl_socket_set_local_port(handle, pid); |
| 96 | |
| 97 | return handle; |
| 98 | } |
| 99 | |
| 100 | static void nl80211_handle_destroy(struct nl_handle *handle) |
| 101 | { |
| 102 | uint32_t port = nl_socket_get_local_port(handle); |
| 103 | |
| 104 | port >>= 22; |
| 105 | port_bitmap[port / 32] &= ~(1 << (port % 32)); |
| 106 | |
| 107 | nl_handle_destroy(handle); |
| 108 | } |
| 109 | #endif /* CONFIG_LIBNL20 */ |
| 110 | |
| 111 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 112 | #ifdef ANDROID |
| 113 | /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */ |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 114 | #undef nl_socket_set_nonblocking |
| 115 | #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 116 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 117 | #endif /* ANDROID */ |
| 118 | |
| 119 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 120 | static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg) |
| 121 | { |
| 122 | struct nl_handle *handle; |
| 123 | |
| 124 | handle = nl80211_handle_alloc(cb); |
| 125 | if (handle == NULL) { |
| 126 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 127 | "callbacks (%s)", dbg); |
| 128 | return NULL; |
| 129 | } |
| 130 | |
| 131 | if (genl_connect(handle)) { |
| 132 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " |
| 133 | "netlink (%s)", dbg); |
| 134 | nl80211_handle_destroy(handle); |
| 135 | return NULL; |
| 136 | } |
| 137 | |
| 138 | return handle; |
| 139 | } |
| 140 | |
| 141 | |
| 142 | static void nl_destroy_handles(struct nl_handle **handle) |
| 143 | { |
| 144 | if (*handle == NULL) |
| 145 | return; |
| 146 | nl80211_handle_destroy(*handle); |
| 147 | *handle = NULL; |
| 148 | } |
| 149 | |
| 150 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 151 | #if __WORDSIZE == 64 |
| 152 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL |
| 153 | #else |
| 154 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL |
| 155 | #endif |
| 156 | |
| 157 | static void nl80211_register_eloop_read(struct nl_handle **handle, |
| 158 | eloop_sock_handler handler, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 159 | void *eloop_data, int persist) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 160 | { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 161 | #ifdef CONFIG_LIBNL20 |
| 162 | /* |
| 163 | * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB) |
| 164 | * by default. It is possible to hit that limit in some cases where |
| 165 | * operations are blocked, e.g., with a burst of Deauthentication frames |
| 166 | * to hostapd and STA entry deletion. Try to increase the buffer to make |
| 167 | * this less likely to occur. |
| 168 | */ |
| 169 | if (nl_socket_set_buffer_size(*handle, 262144, 0) < 0) { |
| 170 | wpa_printf(MSG_DEBUG, |
| 171 | "nl80211: Could not set nl_socket RX buffer size: %s", |
| 172 | strerror(errno)); |
| 173 | /* continue anyway with the default (smaller) buffer */ |
| 174 | } |
| 175 | #endif /* CONFIG_LIBNL20 */ |
| 176 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 177 | nl_socket_set_nonblocking(*handle); |
| 178 | eloop_register_read_sock(nl_socket_get_fd(*handle), handler, |
| 179 | eloop_data, *handle); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 180 | if (!persist) |
| 181 | *handle = (void *) (((intptr_t) *handle) ^ |
| 182 | ELOOP_SOCKET_INVALID); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 186 | static void nl80211_destroy_eloop_handle(struct nl_handle **handle, int persist) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 187 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 188 | if (!persist) |
| 189 | *handle = (void *) (((intptr_t) *handle) ^ |
| 190 | ELOOP_SOCKET_INVALID); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 191 | eloop_unregister_read_sock(nl_socket_get_fd(*handle)); |
| 192 | nl_destroy_handles(handle); |
| 193 | } |
| 194 | |
| 195 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 196 | static void nl80211_global_deinit(void *priv); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 197 | static void nl80211_check_global(struct nl80211_global *global); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 198 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 199 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 200 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 201 | struct hostapd_freq_params *freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 202 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 203 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 204 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 205 | const u8 *set_addr, int first, |
| 206 | const char *driver_params); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 207 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 208 | unsigned int freq, unsigned int wait, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 209 | const u8 *buf, size_t buf_len, u64 *cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 210 | int no_cck, int no_ack, int offchanok, |
| 211 | const u16 *csa_offs, size_t csa_offs_len); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 212 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, |
| 213 | int report); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 214 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 215 | #define IFIDX_ANY -1 |
| 216 | |
| 217 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 218 | int ifidx_reason); |
| 219 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 220 | int ifidx_reason); |
| 221 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 222 | int ifidx_reason); |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 223 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 224 | static int nl80211_set_channel(struct i802_bss *bss, |
| 225 | struct hostapd_freq_params *freq, int set_chan); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 226 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 227 | int ifindex, int disabled); |
| 228 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 229 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 230 | int reset_mode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 231 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 232 | static int i802_set_iface_flags(struct i802_bss *bss, int up); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 233 | static int nl80211_set_param(void *priv, const char *param); |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 234 | #ifdef CONFIG_MESH |
| 235 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
| 236 | struct wpa_driver_mesh_bss_params *params); |
| 237 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 238 | 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^] | 239 | u16 reason); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 240 | |
| 241 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 242 | /* Converts nl80211_chan_width to a common format */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 243 | enum chan_width convert2width(int width) |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 244 | { |
| 245 | switch (width) { |
| 246 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 247 | return CHAN_WIDTH_20_NOHT; |
| 248 | case NL80211_CHAN_WIDTH_20: |
| 249 | return CHAN_WIDTH_20; |
| 250 | case NL80211_CHAN_WIDTH_40: |
| 251 | return CHAN_WIDTH_40; |
| 252 | case NL80211_CHAN_WIDTH_80: |
| 253 | return CHAN_WIDTH_80; |
| 254 | case NL80211_CHAN_WIDTH_80P80: |
| 255 | return CHAN_WIDTH_80P80; |
| 256 | case NL80211_CHAN_WIDTH_160: |
| 257 | return CHAN_WIDTH_160; |
| 258 | } |
| 259 | return CHAN_WIDTH_UNKNOWN; |
| 260 | } |
| 261 | |
| 262 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 263 | int is_ap_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 264 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 265 | return nlmode == NL80211_IFTYPE_AP || |
| 266 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 270 | int is_sta_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 271 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 272 | return nlmode == NL80211_IFTYPE_STATION || |
| 273 | nlmode == NL80211_IFTYPE_P2P_CLIENT; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 277 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 278 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 279 | return nlmode == NL80211_IFTYPE_P2P_CLIENT || |
| 280 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 281 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 282 | |
| 283 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 284 | struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, |
| 285 | int ifindex) |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 286 | { |
| 287 | struct i802_bss *bss; |
| 288 | |
| 289 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 290 | if (bss->ifindex == ifindex) |
| 291 | return bss; |
| 292 | } |
| 293 | |
| 294 | return NULL; |
| 295 | } |
| 296 | |
| 297 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 298 | static int is_mesh_interface(enum nl80211_iftype nlmode) |
| 299 | { |
| 300 | return nlmode == NL80211_IFTYPE_MESH_POINT; |
| 301 | } |
| 302 | |
| 303 | |
| 304 | void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 305 | { |
| 306 | if (drv->associated) |
| 307 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); |
| 308 | drv->associated = 0; |
| 309 | os_memset(drv->bssid, 0, ETH_ALEN); |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 310 | drv->first_bss->freq = 0; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 314 | /* nl80211 code */ |
| 315 | static int ack_handler(struct nl_msg *msg, void *arg) |
| 316 | { |
| 317 | int *err = arg; |
| 318 | *err = 0; |
| 319 | return NL_STOP; |
| 320 | } |
| 321 | |
| 322 | static int finish_handler(struct nl_msg *msg, void *arg) |
| 323 | { |
| 324 | int *ret = arg; |
| 325 | *ret = 0; |
| 326 | return NL_SKIP; |
| 327 | } |
| 328 | |
| 329 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, |
| 330 | void *arg) |
| 331 | { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 332 | struct nlmsghdr *nlh = (struct nlmsghdr *) err - 1; |
| 333 | int len = nlh->nlmsg_len; |
| 334 | struct nlattr *attrs; |
| 335 | struct nlattr *tb[NLMSGERR_ATTR_MAX + 1]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 336 | int *ret = arg; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 337 | int ack_len = sizeof(*nlh) + sizeof(int) + sizeof(*nlh); |
| 338 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 339 | *ret = err->error; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 340 | |
| 341 | if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS)) |
| 342 | return NL_SKIP; |
| 343 | |
| 344 | if (!(nlh->nlmsg_flags & NLM_F_CAPPED)) |
| 345 | ack_len += err->msg.nlmsg_len - sizeof(*nlh); |
| 346 | |
| 347 | if (len <= ack_len) |
| 348 | return NL_STOP; |
| 349 | |
| 350 | attrs = (void *) ((unsigned char *) nlh + ack_len); |
| 351 | len -= ack_len; |
| 352 | |
| 353 | nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, len, NULL); |
| 354 | if (tb[NLMSGERR_ATTR_MSG]) { |
| 355 | len = strnlen((char *) nla_data(tb[NLMSGERR_ATTR_MSG]), |
| 356 | nla_len(tb[NLMSGERR_ATTR_MSG])); |
| 357 | wpa_printf(MSG_ERROR, "nl80211: kernel reports: %*s", |
| 358 | len, (char *) nla_data(tb[NLMSGERR_ATTR_MSG])); |
| 359 | } |
| 360 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 361 | return NL_SKIP; |
| 362 | } |
| 363 | |
| 364 | |
| 365 | static int no_seq_check(struct nl_msg *msg, void *arg) |
| 366 | { |
| 367 | return NL_OK; |
| 368 | } |
| 369 | |
| 370 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 371 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
| 372 | { |
| 373 | /* |
| 374 | * Clear nlmsg data, e.g., to make sure key material is not left in |
| 375 | * heap memory for unnecessarily long time. |
| 376 | */ |
| 377 | if (msg) { |
| 378 | struct nlmsghdr *hdr = nlmsg_hdr(msg); |
| 379 | void *data = nlmsg_data(hdr); |
| 380 | /* |
| 381 | * This would use nlmsg_datalen() or the older nlmsg_len() if |
| 382 | * only libnl were to maintain a stable API.. Neither will work |
| 383 | * with all released versions, so just calculate the length |
| 384 | * here. |
| 385 | */ |
| 386 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; |
| 387 | |
| 388 | os_memset(data, 0, len); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 393 | static int send_and_recv(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 394 | struct nl_handle *nl_handle, struct nl_msg *msg, |
| 395 | int (*valid_handler)(struct nl_msg *, void *), |
| 396 | void *valid_data) |
| 397 | { |
| 398 | struct nl_cb *cb; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 399 | int err = -ENOMEM, opt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 400 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 401 | if (!msg) |
| 402 | return -ENOMEM; |
| 403 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 404 | cb = nl_cb_clone(global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 405 | if (!cb) |
| 406 | goto out; |
| 407 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 408 | /* try to set NETLINK_EXT_ACK to 1, ignoring errors */ |
| 409 | opt = 1; |
| 410 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, |
| 411 | NETLINK_EXT_ACK, &opt, sizeof(opt)); |
| 412 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 413 | /* try to set NETLINK_CAP_ACK to 1, ignoring errors */ |
| 414 | opt = 1; |
| 415 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, |
| 416 | NETLINK_CAP_ACK, &opt, sizeof(opt)); |
| 417 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 418 | err = nl_send_auto_complete(nl_handle, msg); |
| 419 | if (err < 0) |
| 420 | goto out; |
| 421 | |
| 422 | err = 1; |
| 423 | |
| 424 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); |
| 425 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
| 426 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
| 427 | |
| 428 | if (valid_handler) |
| 429 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 430 | valid_handler, valid_data); |
| 431 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 432 | while (err > 0) { |
| 433 | int res = nl_recvmsgs(nl_handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 434 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 435 | wpa_printf(MSG_INFO, |
| 436 | "nl80211: %s->nl_recvmsgs failed: %d", |
| 437 | __func__, res); |
| 438 | } |
| 439 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 440 | out: |
| 441 | nl_cb_put(cb); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 442 | if (!valid_handler && valid_data == (void *) -1) |
| 443 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 444 | nlmsg_free(msg); |
| 445 | return err; |
| 446 | } |
| 447 | |
| 448 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 449 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
| 450 | struct nl_msg *msg, |
| 451 | int (*valid_handler)(struct nl_msg *, void *), |
| 452 | void *valid_data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 453 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 454 | return send_and_recv(drv->global, drv->global->nl, msg, |
| 455 | valid_handler, valid_data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | |
| 459 | struct family_data { |
| 460 | const char *group; |
| 461 | int id; |
| 462 | }; |
| 463 | |
| 464 | |
| 465 | static int family_handler(struct nl_msg *msg, void *arg) |
| 466 | { |
| 467 | struct family_data *res = arg; |
| 468 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; |
| 469 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 470 | struct nlattr *mcgrp; |
| 471 | int i; |
| 472 | |
| 473 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 474 | genlmsg_attrlen(gnlh, 0), NULL); |
| 475 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) |
| 476 | return NL_SKIP; |
| 477 | |
| 478 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { |
| 479 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; |
| 480 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), |
| 481 | nla_len(mcgrp), NULL); |
| 482 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || |
| 483 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || |
| 484 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), |
| 485 | res->group, |
| 486 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) |
| 487 | continue; |
| 488 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); |
| 489 | break; |
| 490 | }; |
| 491 | |
| 492 | return NL_SKIP; |
| 493 | } |
| 494 | |
| 495 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 496 | static int nl_get_multicast_id(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 497 | const char *family, const char *group) |
| 498 | { |
| 499 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 500 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 501 | struct family_data res = { group, -ENOENT }; |
| 502 | |
| 503 | msg = nlmsg_alloc(); |
| 504 | if (!msg) |
| 505 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 506 | if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
| 507 | 0, 0, CTRL_CMD_GETFAMILY, 0) || |
| 508 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { |
| 509 | nlmsg_free(msg); |
| 510 | return -1; |
| 511 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 512 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 513 | ret = send_and_recv(global, global->nl, msg, family_handler, &res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 514 | if (ret == 0) |
| 515 | ret = res.id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 516 | return ret; |
| 517 | } |
| 518 | |
| 519 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 520 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
| 521 | struct nl_msg *msg, int flags, uint8_t cmd) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 522 | { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 523 | if (TEST_FAIL()) |
| 524 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 525 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
| 526 | 0, flags, cmd, 0); |
| 527 | } |
| 528 | |
| 529 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 530 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
| 531 | { |
| 532 | if (bss->wdev_id_set) |
| 533 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); |
| 534 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 535 | } |
| 536 | |
| 537 | |
| 538 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 539 | { |
| 540 | struct nl_msg *msg; |
| 541 | |
| 542 | msg = nlmsg_alloc(); |
| 543 | if (!msg) |
| 544 | return NULL; |
| 545 | |
| 546 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || |
| 547 | nl80211_set_iface_id(msg, bss) < 0) { |
| 548 | nlmsg_free(msg); |
| 549 | return NULL; |
| 550 | } |
| 551 | |
| 552 | return msg; |
| 553 | } |
| 554 | |
| 555 | |
| 556 | static struct nl_msg * |
| 557 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, |
| 558 | int flags, uint8_t cmd) |
| 559 | { |
| 560 | struct nl_msg *msg; |
| 561 | |
| 562 | msg = nlmsg_alloc(); |
| 563 | if (!msg) |
| 564 | return NULL; |
| 565 | |
| 566 | if (!nl80211_cmd(drv, msg, flags, cmd) || |
| 567 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { |
| 568 | nlmsg_free(msg); |
| 569 | return NULL; |
| 570 | } |
| 571 | |
| 572 | return msg; |
| 573 | } |
| 574 | |
| 575 | |
| 576 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, |
| 577 | uint8_t cmd) |
| 578 | { |
| 579 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); |
| 580 | } |
| 581 | |
| 582 | |
| 583 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 584 | { |
| 585 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); |
| 586 | } |
| 587 | |
| 588 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 589 | struct wiphy_idx_data { |
| 590 | int wiphy_idx; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 591 | enum nl80211_iftype nlmode; |
| 592 | u8 *macaddr; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 593 | }; |
| 594 | |
| 595 | |
| 596 | static int netdev_info_handler(struct nl_msg *msg, void *arg) |
| 597 | { |
| 598 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 599 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 600 | struct wiphy_idx_data *info = arg; |
| 601 | |
| 602 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 603 | genlmsg_attrlen(gnlh, 0), NULL); |
| 604 | |
| 605 | if (tb[NL80211_ATTR_WIPHY]) |
| 606 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 607 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 608 | if (tb[NL80211_ATTR_IFTYPE]) |
| 609 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); |
| 610 | |
| 611 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
| 612 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 613 | ETH_ALEN); |
| 614 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 615 | return NL_SKIP; |
| 616 | } |
| 617 | |
| 618 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 619 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 620 | { |
| 621 | struct nl_msg *msg; |
| 622 | struct wiphy_idx_data data = { |
| 623 | .wiphy_idx = -1, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 624 | .macaddr = NULL, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 625 | }; |
| 626 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 627 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 628 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 629 | |
| 630 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) |
| 631 | return data.wiphy_idx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 632 | return -1; |
| 633 | } |
| 634 | |
| 635 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 636 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
| 637 | { |
| 638 | struct nl_msg *msg; |
| 639 | struct wiphy_idx_data data = { |
| 640 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
| 641 | .macaddr = NULL, |
| 642 | }; |
| 643 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 644 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 645 | return NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 646 | |
| 647 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) |
| 648 | return data.nlmode; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 649 | return NL80211_IFTYPE_UNSPECIFIED; |
| 650 | } |
| 651 | |
| 652 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 653 | static int nl80211_get_macaddr(struct i802_bss *bss) |
| 654 | { |
| 655 | struct nl_msg *msg; |
| 656 | struct wiphy_idx_data data = { |
| 657 | .macaddr = bss->addr, |
| 658 | }; |
| 659 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 660 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 661 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 662 | |
| 663 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 664 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 665 | |
| 666 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 667 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
| 668 | struct nl80211_wiphy_data *w) |
| 669 | { |
| 670 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 671 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 672 | |
| 673 | msg = nlmsg_alloc(); |
| 674 | if (!msg) |
| 675 | return -1; |
| 676 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 677 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
| 678 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { |
| 679 | nlmsg_free(msg); |
| 680 | return -1; |
| 681 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 682 | |
| 683 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 684 | if (ret) { |
| 685 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " |
| 686 | "failed: ret=%d (%s)", |
| 687 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 688 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 689 | return ret; |
| 690 | } |
| 691 | |
| 692 | |
| 693 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) |
| 694 | { |
| 695 | struct nl80211_wiphy_data *w = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 696 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 697 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 698 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 699 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 700 | res = nl_recvmsgs(handle, w->nl_cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 701 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 702 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 703 | __func__, res); |
| 704 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | |
| 708 | static int process_beacon_event(struct nl_msg *msg, void *arg) |
| 709 | { |
| 710 | struct nl80211_wiphy_data *w = arg; |
| 711 | struct wpa_driver_nl80211_data *drv; |
| 712 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 713 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 714 | union wpa_event_data event; |
| 715 | |
| 716 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 717 | genlmsg_attrlen(gnlh, 0), NULL); |
| 718 | |
| 719 | if (gnlh->cmd != NL80211_CMD_FRAME) { |
| 720 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", |
| 721 | gnlh->cmd); |
| 722 | return NL_SKIP; |
| 723 | } |
| 724 | |
| 725 | if (!tb[NL80211_ATTR_FRAME]) |
| 726 | return NL_SKIP; |
| 727 | |
| 728 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, |
| 729 | wiphy_list) { |
| 730 | os_memset(&event, 0, sizeof(event)); |
| 731 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); |
| 732 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); |
| 733 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
| 734 | } |
| 735 | |
| 736 | return NL_SKIP; |
| 737 | } |
| 738 | |
| 739 | |
| 740 | static struct nl80211_wiphy_data * |
| 741 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) |
| 742 | { |
| 743 | static DEFINE_DL_LIST(nl80211_wiphys); |
| 744 | struct nl80211_wiphy_data *w; |
| 745 | int wiphy_idx, found = 0; |
| 746 | struct i802_bss *tmp_bss; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 747 | u8 channel; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 748 | |
| 749 | if (bss->wiphy_data != NULL) |
| 750 | return bss->wiphy_data; |
| 751 | |
| 752 | wiphy_idx = nl80211_get_wiphy_index(bss); |
| 753 | |
| 754 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { |
| 755 | if (w->wiphy_idx == wiphy_idx) |
| 756 | goto add; |
| 757 | } |
| 758 | |
| 759 | /* alloc new one */ |
| 760 | w = os_zalloc(sizeof(*w)); |
| 761 | if (w == NULL) |
| 762 | return NULL; |
| 763 | w->wiphy_idx = wiphy_idx; |
| 764 | dl_list_init(&w->bsss); |
| 765 | dl_list_init(&w->drvs); |
| 766 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 767 | /* Beacon frames not supported in IEEE 802.11ad */ |
| 768 | if (ieee80211_freq_to_chan(bss->freq, &channel) != |
| 769 | HOSTAPD_MODE_IEEE80211AD) { |
| 770 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 771 | if (!w->nl_cb) { |
| 772 | os_free(w); |
| 773 | return NULL; |
| 774 | } |
| 775 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 776 | no_seq_check, NULL); |
| 777 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 778 | process_beacon_event, w); |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 779 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 780 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, |
| 781 | "wiphy beacons"); |
| 782 | if (w->nl_beacons == NULL) { |
| 783 | os_free(w); |
| 784 | return NULL; |
| 785 | } |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 786 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 787 | if (nl80211_register_beacons(bss->drv, w)) { |
| 788 | nl_destroy_handles(&w->nl_beacons); |
| 789 | os_free(w); |
| 790 | return NULL; |
| 791 | } |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 792 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 793 | nl80211_register_eloop_read(&w->nl_beacons, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 794 | nl80211_recv_beacons, w, 0); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 795 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 796 | |
| 797 | dl_list_add(&nl80211_wiphys, &w->list); |
| 798 | |
| 799 | add: |
| 800 | /* drv entry for this bss already there? */ |
| 801 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 802 | if (tmp_bss->drv == bss->drv) { |
| 803 | found = 1; |
| 804 | break; |
| 805 | } |
| 806 | } |
| 807 | /* if not add it */ |
| 808 | if (!found) |
| 809 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); |
| 810 | |
| 811 | dl_list_add(&w->bsss, &bss->wiphy_list); |
| 812 | bss->wiphy_data = w; |
| 813 | return w; |
| 814 | } |
| 815 | |
| 816 | |
| 817 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) |
| 818 | { |
| 819 | struct nl80211_wiphy_data *w = bss->wiphy_data; |
| 820 | struct i802_bss *tmp_bss; |
| 821 | int found = 0; |
| 822 | |
| 823 | if (w == NULL) |
| 824 | return; |
| 825 | bss->wiphy_data = NULL; |
| 826 | dl_list_del(&bss->wiphy_list); |
| 827 | |
| 828 | /* still any for this drv present? */ |
| 829 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 830 | if (tmp_bss->drv == bss->drv) { |
| 831 | found = 1; |
| 832 | break; |
| 833 | } |
| 834 | } |
| 835 | /* if not remove it */ |
| 836 | if (!found) |
| 837 | dl_list_del(&bss->drv->wiphy_list); |
| 838 | |
| 839 | if (!dl_list_empty(&w->bsss)) |
| 840 | return; |
| 841 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 842 | if (w->nl_beacons) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 843 | nl80211_destroy_eloop_handle(&w->nl_beacons, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 844 | |
| 845 | nl_cb_put(w->nl_cb); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 846 | dl_list_del(&w->list); |
| 847 | os_free(w); |
| 848 | } |
| 849 | |
| 850 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 851 | static unsigned int nl80211_get_ifindex(void *priv) |
| 852 | { |
| 853 | struct i802_bss *bss = priv; |
| 854 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 855 | |
| 856 | return drv->ifindex; |
| 857 | } |
| 858 | |
| 859 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 860 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
| 861 | { |
| 862 | struct i802_bss *bss = priv; |
| 863 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 864 | if (!drv->associated) |
| 865 | return -1; |
| 866 | os_memcpy(bssid, drv->bssid, ETH_ALEN); |
| 867 | return 0; |
| 868 | } |
| 869 | |
| 870 | |
| 871 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
| 872 | { |
| 873 | struct i802_bss *bss = priv; |
| 874 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 875 | if (!drv->associated) |
| 876 | return -1; |
| 877 | os_memcpy(ssid, drv->ssid, drv->ssid_len); |
| 878 | return drv->ssid_len; |
| 879 | } |
| 880 | |
| 881 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 882 | static void wpa_driver_nl80211_event_newlink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 883 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 884 | int ifindex, const char *ifname) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 885 | { |
| 886 | union wpa_event_data event; |
| 887 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 888 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 889 | if (if_nametoindex(drv->first_bss->ifname) == 0) { |
| 890 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", |
| 891 | drv->first_bss->ifname); |
| 892 | return; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 893 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 894 | if (!drv->if_removed) |
| 895 | return; |
| 896 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", |
| 897 | drv->first_bss->ifname); |
| 898 | drv->if_removed = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 899 | } |
| 900 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 901 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 902 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 903 | os_strlcpy(event.interface_status.ifname, ifname, |
| 904 | sizeof(event.interface_status.ifname)); |
| 905 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 906 | if (drv) |
| 907 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 908 | else |
| 909 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 910 | &event); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | |
| 914 | static void wpa_driver_nl80211_event_dellink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 915 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 916 | int ifindex, const char *ifname) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 917 | { |
| 918 | union wpa_event_data event; |
| 919 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 920 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 921 | if (drv->if_removed) { |
| 922 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", |
| 923 | ifname); |
| 924 | return; |
| 925 | } |
| 926 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
| 927 | ifname); |
| 928 | drv->if_removed = 1; |
| 929 | } else { |
| 930 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", |
| 931 | ifname); |
| 932 | } |
| 933 | |
| 934 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 935 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 936 | os_strlcpy(event.interface_status.ifname, ifname, |
| 937 | sizeof(event.interface_status.ifname)); |
| 938 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 939 | if (drv) |
| 940 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 941 | else |
| 942 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 943 | &event); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | |
| 947 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
| 948 | u8 *buf, size_t len) |
| 949 | { |
| 950 | int attrlen, rta_len; |
| 951 | struct rtattr *attr; |
| 952 | |
| 953 | attrlen = len; |
| 954 | attr = (struct rtattr *) buf; |
| 955 | |
| 956 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
| 957 | while (RTA_OK(attr, attrlen)) { |
| 958 | if (attr->rta_type == IFLA_IFNAME) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 959 | if (os_strcmp(((char *) attr) + rta_len, |
| 960 | drv->first_bss->ifname) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 961 | return 1; |
| 962 | else |
| 963 | break; |
| 964 | } |
| 965 | attr = RTA_NEXT(attr, attrlen); |
| 966 | } |
| 967 | |
| 968 | return 0; |
| 969 | } |
| 970 | |
| 971 | |
| 972 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, |
| 973 | int ifindex, u8 *buf, size_t len) |
| 974 | { |
| 975 | if (drv->ifindex == ifindex) |
| 976 | return 1; |
| 977 | |
| 978 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 979 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 980 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
| 981 | "interface"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 982 | if (wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL) < 0) |
| 983 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 984 | return 1; |
| 985 | } |
| 986 | |
| 987 | return 0; |
| 988 | } |
| 989 | |
| 990 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 991 | static struct wpa_driver_nl80211_data * |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 992 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len, |
| 993 | int *init_failed) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 994 | { |
| 995 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 996 | int res; |
| 997 | |
| 998 | if (init_failed) |
| 999 | *init_failed = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1000 | dl_list_for_each(drv, &global->interfaces, |
| 1001 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1002 | res = wpa_driver_nl80211_own_ifindex(drv, idx, buf, len); |
| 1003 | if (res < 0) { |
| 1004 | wpa_printf(MSG_DEBUG, |
| 1005 | "nl80211: Found matching own interface, but failed to complete reinitialization"); |
| 1006 | if (init_failed) |
| 1007 | *init_failed = 1; |
| 1008 | return drv; |
| 1009 | } |
| 1010 | if (res > 0 || have_ifidx(drv, idx, IFIDX_ANY)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1011 | return drv; |
| 1012 | } |
| 1013 | return NULL; |
| 1014 | } |
| 1015 | |
| 1016 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1017 | static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1018 | int ifindex, int notify) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1019 | { |
| 1020 | struct i802_bss *bss; |
| 1021 | u8 addr[ETH_ALEN]; |
| 1022 | |
| 1023 | bss = get_bss_ifindex(drv, ifindex); |
| 1024 | if (bss && |
| 1025 | linux_get_ifhwaddr(drv->global->ioctl_sock, |
| 1026 | bss->ifname, addr) < 0) { |
| 1027 | wpa_printf(MSG_DEBUG, |
| 1028 | "nl80211: %s: failed to re-read MAC address", |
| 1029 | bss->ifname); |
| 1030 | } else if (bss && os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { |
| 1031 | wpa_printf(MSG_DEBUG, |
| 1032 | "nl80211: Own MAC address on ifindex %d (%s) changed from " |
| 1033 | MACSTR " to " MACSTR, |
| 1034 | ifindex, bss->ifname, |
| 1035 | MAC2STR(bss->addr), MAC2STR(addr)); |
| 1036 | os_memcpy(bss->addr, addr, ETH_ALEN); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1037 | if (notify) |
| 1038 | wpa_supplicant_event(drv->ctx, |
| 1039 | EVENT_INTERFACE_MAC_CHANGED, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1040 | } |
| 1041 | } |
| 1042 | |
| 1043 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1044 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
| 1045 | struct ifinfomsg *ifi, |
| 1046 | u8 *buf, size_t len) |
| 1047 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1048 | struct nl80211_global *global = ctx; |
| 1049 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1050 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1051 | struct rtattr *attr; |
| 1052 | u32 brid = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1053 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1054 | char ifname[IFNAMSIZ + 1]; |
| 1055 | char extra[100], *pos, *end; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1056 | int init_failed; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1057 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1058 | extra[0] = '\0'; |
| 1059 | pos = extra; |
| 1060 | end = pos + sizeof(extra); |
| 1061 | ifname[0] = '\0'; |
| 1062 | |
| 1063 | attrlen = len; |
| 1064 | attr = (struct rtattr *) buf; |
| 1065 | while (RTA_OK(attr, attrlen)) { |
| 1066 | switch (attr->rta_type) { |
| 1067 | case IFLA_IFNAME: |
| 1068 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) |
| 1069 | break; |
| 1070 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1071 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1072 | break; |
| 1073 | case IFLA_MASTER: |
| 1074 | brid = nla_get_u32((struct nlattr *) attr); |
| 1075 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1076 | break; |
| 1077 | case IFLA_WIRELESS: |
| 1078 | pos += os_snprintf(pos, end - pos, " wext"); |
| 1079 | break; |
| 1080 | case IFLA_OPERSTATE: |
| 1081 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1082 | nla_get_u32((struct nlattr *) attr)); |
| 1083 | break; |
| 1084 | case IFLA_LINKMODE: |
| 1085 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1086 | nla_get_u32((struct nlattr *) attr)); |
| 1087 | break; |
| 1088 | } |
| 1089 | attr = RTA_NEXT(attr, attrlen); |
| 1090 | } |
| 1091 | extra[sizeof(extra) - 1] = '\0'; |
| 1092 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1093 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1094 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1095 | ifi->ifi_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1096 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1097 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1098 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1099 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1100 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1101 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, &init_failed); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1102 | if (!drv) |
| 1103 | goto event_newlink; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1104 | if (init_failed) |
| 1105 | return; /* do not update interface state */ |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1106 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1107 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1108 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1109 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1110 | linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1111 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1112 | "event since interface %s is up", namebuf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1113 | drv->ignore_if_down_event = 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1114 | /* Re-read MAC address as it may have changed */ |
| 1115 | nl80211_refresh_mac(drv, ifi->ifi_index, 1); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1116 | return; |
| 1117 | } |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1118 | wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", |
| 1119 | namebuf, ifname); |
| 1120 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 1121 | wpa_printf(MSG_DEBUG, |
| 1122 | "nl80211: Not the main interface (%s) - do not indicate interface down", |
| 1123 | drv->first_bss->ifname); |
| 1124 | } else if (drv->ignore_if_down_event) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1125 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1126 | "event generated by mode change"); |
| 1127 | drv->ignore_if_down_event = 0; |
| 1128 | } else { |
| 1129 | drv->if_disabled = 1; |
| 1130 | wpa_supplicant_event(drv->ctx, |
| 1131 | EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1132 | |
| 1133 | /* |
| 1134 | * Try to get drv again, since it may be removed as |
| 1135 | * part of the EVENT_INTERFACE_DISABLED handling for |
| 1136 | * dynamic interfaces |
| 1137 | */ |
| 1138 | drv = nl80211_find_drv(global, ifi->ifi_index, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1139 | buf, len, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1140 | if (!drv) |
| 1141 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1142 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 1146 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1147 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1148 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1149 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1150 | "event since interface %s is down", |
| 1151 | namebuf); |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 1152 | return; |
| 1153 | } |
| 1154 | wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)", |
| 1155 | namebuf, ifname); |
| 1156 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 1157 | wpa_printf(MSG_DEBUG, |
| 1158 | "nl80211: Not the main interface (%s) - do not indicate interface up", |
| 1159 | drv->first_bss->ifname); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1160 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1161 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1162 | "event since interface %s does not exist", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1163 | drv->first_bss->ifname); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1164 | } else if (drv->if_removed) { |
| 1165 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1166 | "event since interface %s is marked " |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1167 | "removed", drv->first_bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1168 | } else { |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1169 | /* Re-read MAC address as it may have changed */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1170 | nl80211_refresh_mac(drv, ifi->ifi_index, 0); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1171 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1172 | drv->if_disabled = 0; |
| 1173 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, |
| 1174 | NULL); |
| 1175 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | /* |
| 1179 | * Some drivers send the association event before the operup event--in |
| 1180 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() |
| 1181 | * fails. This will hit us when wpa_supplicant does not need to do |
| 1182 | * IEEE 802.1X authentication |
| 1183 | */ |
| 1184 | if (drv->operstate == 1 && |
| 1185 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1186 | !(ifi->ifi_flags & IFF_RUNNING)) { |
| 1187 | 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] | 1188 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1189 | -1, IF_OPER_UP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1190 | } |
| 1191 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1192 | event_newlink: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1193 | if (ifname[0]) |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1194 | wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index, |
| 1195 | ifname); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1196 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1197 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1198 | struct i802_bss *bss; |
| 1199 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1200 | /* device has been added to bridge */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1201 | if (!if_indextoname(brid, namebuf)) { |
| 1202 | wpa_printf(MSG_DEBUG, |
| 1203 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1204 | brid); |
| 1205 | return; |
| 1206 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1207 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
| 1208 | brid, namebuf); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1209 | add_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1210 | |
| 1211 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 1212 | if (os_strcmp(ifname, bss->ifname) == 0) { |
| 1213 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); |
| 1214 | break; |
| 1215 | } |
| 1216 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1217 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1218 | } |
| 1219 | |
| 1220 | |
| 1221 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
| 1222 | struct ifinfomsg *ifi, |
| 1223 | u8 *buf, size_t len) |
| 1224 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1225 | struct nl80211_global *global = ctx; |
| 1226 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1227 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1228 | struct rtattr *attr; |
| 1229 | u32 brid = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1230 | char ifname[IFNAMSIZ + 1]; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1231 | char extra[100], *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1232 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1233 | extra[0] = '\0'; |
| 1234 | pos = extra; |
| 1235 | end = pos + sizeof(extra); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1236 | ifname[0] = '\0'; |
| 1237 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1238 | attrlen = len; |
| 1239 | attr = (struct rtattr *) buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1240 | while (RTA_OK(attr, attrlen)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1241 | switch (attr->rta_type) { |
| 1242 | case IFLA_IFNAME: |
| 1243 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) |
| 1244 | break; |
| 1245 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1246 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1247 | break; |
| 1248 | case IFLA_MASTER: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1249 | brid = nla_get_u32((struct nlattr *) attr); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1250 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1251 | break; |
| 1252 | case IFLA_OPERSTATE: |
| 1253 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1254 | nla_get_u32((struct nlattr *) attr)); |
| 1255 | break; |
| 1256 | case IFLA_LINKMODE: |
| 1257 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1258 | nla_get_u32((struct nlattr *) attr)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1259 | break; |
| 1260 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1261 | attr = RTA_NEXT(attr, attrlen); |
| 1262 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1263 | extra[sizeof(extra) - 1] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1264 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1265 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1266 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1267 | ifi->ifi_flags, |
| 1268 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1269 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1270 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1271 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1272 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1273 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1274 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1275 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1276 | /* device has been removed from bridge */ |
| 1277 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1278 | |
| 1279 | if (!if_indextoname(brid, namebuf)) { |
| 1280 | wpa_printf(MSG_DEBUG, |
| 1281 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1282 | brid); |
| 1283 | } else { |
| 1284 | wpa_printf(MSG_DEBUG, |
| 1285 | "nl80211: Remove ifindex %u for bridge %s", |
| 1286 | brid, namebuf); |
| 1287 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1288 | del_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1289 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1290 | |
| 1291 | if (ifi->ifi_family != AF_BRIDGE || !brid) |
| 1292 | wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index, |
| 1293 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1297 | struct nl80211_get_assoc_freq_arg { |
| 1298 | struct wpa_driver_nl80211_data *drv; |
| 1299 | unsigned int assoc_freq; |
| 1300 | unsigned int ibss_freq; |
| 1301 | u8 assoc_bssid[ETH_ALEN]; |
| 1302 | u8 assoc_ssid[SSID_MAX_LEN]; |
| 1303 | u8 assoc_ssid_len; |
| 1304 | }; |
| 1305 | |
| 1306 | static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg) |
| 1307 | { |
| 1308 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1309 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1310 | struct nlattr *bss[NL80211_BSS_MAX + 1]; |
| 1311 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { |
| 1312 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, |
| 1313 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, |
| 1314 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, |
| 1315 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
| 1316 | }; |
| 1317 | struct nl80211_get_assoc_freq_arg *ctx = arg; |
| 1318 | enum nl80211_bss_status status; |
| 1319 | |
| 1320 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1321 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1322 | if (!tb[NL80211_ATTR_BSS] || |
| 1323 | nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], |
| 1324 | bss_policy) || |
| 1325 | !bss[NL80211_BSS_STATUS]) |
| 1326 | return NL_SKIP; |
| 1327 | |
| 1328 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); |
| 1329 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1330 | bss[NL80211_BSS_FREQUENCY]) { |
| 1331 | ctx->assoc_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1332 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", |
| 1333 | ctx->assoc_freq); |
| 1334 | } |
| 1335 | if (status == NL80211_BSS_STATUS_IBSS_JOINED && |
| 1336 | bss[NL80211_BSS_FREQUENCY]) { |
| 1337 | ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1338 | wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz", |
| 1339 | ctx->ibss_freq); |
| 1340 | } |
| 1341 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1342 | bss[NL80211_BSS_BSSID]) { |
| 1343 | os_memcpy(ctx->assoc_bssid, |
| 1344 | nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN); |
| 1345 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " |
| 1346 | MACSTR, MAC2STR(ctx->assoc_bssid)); |
| 1347 | } |
| 1348 | |
| 1349 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1350 | bss[NL80211_BSS_INFORMATION_ELEMENTS]) { |
| 1351 | const u8 *ie, *ssid; |
| 1352 | size_t ie_len; |
| 1353 | |
| 1354 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1355 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1356 | ssid = get_ie(ie, ie_len, WLAN_EID_SSID); |
| 1357 | if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) { |
| 1358 | ctx->assoc_ssid_len = ssid[1]; |
| 1359 | os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]); |
| 1360 | } |
| 1361 | } |
| 1362 | |
| 1363 | return NL_SKIP; |
| 1364 | } |
| 1365 | |
| 1366 | |
| 1367 | 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] | 1368 | { |
| 1369 | struct nl_msg *msg; |
| 1370 | int ret; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1371 | struct nl80211_get_assoc_freq_arg arg; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1372 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1373 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1374 | os_memset(&arg, 0, sizeof(arg)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1375 | arg.drv = drv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1376 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
| 1377 | &arg); |
| 1378 | if (ret == 0) { |
| 1379 | os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len); |
| 1380 | return arg.assoc_ssid_len; |
| 1381 | } |
| 1382 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)", |
| 1383 | ret, strerror(-ret)); |
| 1384 | return ret; |
| 1385 | } |
| 1386 | |
| 1387 | |
| 1388 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
| 1389 | { |
| 1390 | struct nl_msg *msg; |
| 1391 | int ret; |
| 1392 | struct nl80211_get_assoc_freq_arg arg; |
| 1393 | |
| 1394 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
| 1395 | os_memset(&arg, 0, sizeof(arg)); |
| 1396 | arg.drv = drv; |
| 1397 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
| 1398 | &arg); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1399 | if (ret == 0) { |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1400 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
| 1401 | arg.ibss_freq : arg.assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1402 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1403 | "associated BSS from scan results: %u MHz", freq); |
| 1404 | if (freq) |
| 1405 | drv->assoc_freq = freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1406 | return drv->assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1407 | } |
| 1408 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
| 1409 | "(%s)", ret, strerror(-ret)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1410 | return drv->assoc_freq; |
| 1411 | } |
| 1412 | |
| 1413 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1414 | static int get_link_signal(struct nl_msg *msg, void *arg) |
| 1415 | { |
| 1416 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1417 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1418 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; |
| 1419 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { |
| 1420 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1421 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1422 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1423 | }; |
| 1424 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
| 1425 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 1426 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 1427 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 1428 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, |
| 1429 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 1430 | }; |
| 1431 | struct wpa_signal_info *sig_change = arg; |
| 1432 | |
| 1433 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1434 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1435 | if (!tb[NL80211_ATTR_STA_INFO] || |
| 1436 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, |
| 1437 | tb[NL80211_ATTR_STA_INFO], policy)) |
| 1438 | return NL_SKIP; |
| 1439 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) |
| 1440 | return NL_SKIP; |
| 1441 | |
| 1442 | sig_change->current_signal = |
| 1443 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); |
| 1444 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1445 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
| 1446 | sig_change->avg_signal = |
| 1447 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); |
| 1448 | else |
| 1449 | sig_change->avg_signal = 0; |
| 1450 | |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1451 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
| 1452 | sig_change->avg_beacon_signal = |
| 1453 | (s8) |
| 1454 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); |
| 1455 | else |
| 1456 | sig_change->avg_beacon_signal = 0; |
| 1457 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1458 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
| 1459 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, |
| 1460 | sinfo[NL80211_STA_INFO_TX_BITRATE], |
| 1461 | rate_policy)) { |
| 1462 | sig_change->current_txrate = 0; |
| 1463 | } else { |
| 1464 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { |
| 1465 | sig_change->current_txrate = |
| 1466 | nla_get_u16(rinfo[ |
| 1467 | NL80211_RATE_INFO_BITRATE]) * 100; |
| 1468 | } |
| 1469 | } |
| 1470 | } |
| 1471 | |
| 1472 | return NL_SKIP; |
| 1473 | } |
| 1474 | |
| 1475 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1476 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
| 1477 | struct wpa_signal_info *sig) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1478 | { |
| 1479 | struct nl_msg *msg; |
| 1480 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1481 | sig->current_signal = -WPA_INVALID_NOISE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1482 | sig->current_txrate = 0; |
| 1483 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1484 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
| 1485 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) { |
| 1486 | nlmsg_free(msg); |
| 1487 | return -ENOBUFS; |
| 1488 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1489 | |
| 1490 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | |
| 1494 | static int get_link_noise(struct nl_msg *msg, void *arg) |
| 1495 | { |
| 1496 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1497 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1498 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 1499 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 1500 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 1501 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 1502 | }; |
| 1503 | struct wpa_signal_info *sig_change = arg; |
| 1504 | |
| 1505 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1506 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1507 | |
| 1508 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 1509 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); |
| 1510 | return NL_SKIP; |
| 1511 | } |
| 1512 | |
| 1513 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 1514 | tb[NL80211_ATTR_SURVEY_INFO], |
| 1515 | survey_policy)) { |
| 1516 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " |
| 1517 | "attributes!"); |
| 1518 | return NL_SKIP; |
| 1519 | } |
| 1520 | |
| 1521 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 1522 | return NL_SKIP; |
| 1523 | |
| 1524 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 1525 | sig_change->frequency) |
| 1526 | return NL_SKIP; |
| 1527 | |
| 1528 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 1529 | return NL_SKIP; |
| 1530 | |
| 1531 | sig_change->current_noise = |
| 1532 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 1533 | |
| 1534 | return NL_SKIP; |
| 1535 | } |
| 1536 | |
| 1537 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1538 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
| 1539 | struct wpa_signal_info *sig_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1540 | { |
| 1541 | struct nl_msg *msg; |
| 1542 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1543 | sig_change->current_noise = WPA_INVALID_NOISE; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1544 | sig_change->frequency = drv->assoc_freq; |
| 1545 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1546 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1547 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 1551 | static int get_channel_info(struct nl_msg *msg, void *arg) |
| 1552 | { |
| 1553 | struct nlattr *tb[NL80211_ATTR_MAX + 1] = { 0 }; |
| 1554 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1555 | struct wpa_channel_info *chan_info = arg; |
| 1556 | |
| 1557 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1558 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1559 | |
| 1560 | os_memset(chan_info, 0, sizeof(struct wpa_channel_info)); |
| 1561 | chan_info->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 1562 | |
| 1563 | if (tb[NL80211_ATTR_WIPHY_FREQ]) |
| 1564 | chan_info->frequency = |
| 1565 | nla_get_u32(tb[NL80211_ATTR_WIPHY_FREQ]); |
| 1566 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) |
| 1567 | chan_info->chanwidth = convert2width( |
| 1568 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 1569 | if (tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]) { |
| 1570 | enum nl80211_channel_type ct = |
| 1571 | nla_get_u32(tb[NL80211_ATTR_WIPHY_CHANNEL_TYPE]); |
| 1572 | |
| 1573 | switch (ct) { |
| 1574 | case NL80211_CHAN_HT40MINUS: |
| 1575 | chan_info->sec_channel = -1; |
| 1576 | break; |
| 1577 | case NL80211_CHAN_HT40PLUS: |
| 1578 | chan_info->sec_channel = 1; |
| 1579 | break; |
| 1580 | default: |
| 1581 | chan_info->sec_channel = 0; |
| 1582 | break; |
| 1583 | } |
| 1584 | } |
| 1585 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 1586 | chan_info->center_frq1 = |
| 1587 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 1588 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 1589 | chan_info->center_frq2 = |
| 1590 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 1591 | |
| 1592 | if (chan_info->center_frq2) { |
| 1593 | u8 seg1_idx = 0; |
| 1594 | |
| 1595 | if (ieee80211_freq_to_chan(chan_info->center_frq2, &seg1_idx) != |
| 1596 | NUM_HOSTAPD_MODES) |
| 1597 | chan_info->seg1_idx = seg1_idx; |
| 1598 | } |
| 1599 | |
| 1600 | return NL_SKIP; |
| 1601 | } |
| 1602 | |
| 1603 | |
| 1604 | static int nl80211_channel_info(void *priv, struct wpa_channel_info *ci) |
| 1605 | { |
| 1606 | struct i802_bss *bss = priv; |
| 1607 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1608 | struct nl_msg *msg; |
| 1609 | |
| 1610 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
| 1611 | return send_and_recv_msgs(drv, msg, get_channel_info, ci); |
| 1612 | } |
| 1613 | |
| 1614 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1615 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
| 1616 | void *handle) |
| 1617 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1618 | struct nl_cb *cb = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1619 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1620 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1621 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1622 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1623 | res = nl_recvmsgs(handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 1624 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1625 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 1626 | __func__, res); |
| 1627 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1628 | } |
| 1629 | |
| 1630 | |
| 1631 | /** |
| 1632 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain |
| 1633 | * @priv: driver_nl80211 private data |
| 1634 | * @alpha2_arg: country to which to switch to |
| 1635 | * Returns: 0 on success, -1 on failure |
| 1636 | * |
| 1637 | * This asks nl80211 to set the regulatory domain for given |
| 1638 | * country ISO / IEC alpha2. |
| 1639 | */ |
| 1640 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) |
| 1641 | { |
| 1642 | struct i802_bss *bss = priv; |
| 1643 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1644 | char alpha2[3]; |
| 1645 | struct nl_msg *msg; |
| 1646 | |
| 1647 | msg = nlmsg_alloc(); |
| 1648 | if (!msg) |
| 1649 | return -ENOMEM; |
| 1650 | |
| 1651 | alpha2[0] = alpha2_arg[0]; |
| 1652 | alpha2[1] = alpha2_arg[1]; |
| 1653 | alpha2[2] = '\0'; |
| 1654 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1655 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
| 1656 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { |
| 1657 | nlmsg_free(msg); |
| 1658 | return -EINVAL; |
| 1659 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1660 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) |
| 1661 | return -EINVAL; |
| 1662 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1666 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
| 1667 | { |
| 1668 | char *alpha2 = arg; |
| 1669 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 1670 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1671 | |
| 1672 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1673 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1674 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { |
| 1675 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); |
| 1676 | return NL_SKIP; |
| 1677 | } |
| 1678 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); |
| 1679 | return NL_SKIP; |
| 1680 | } |
| 1681 | |
| 1682 | |
| 1683 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) |
| 1684 | { |
| 1685 | struct i802_bss *bss = priv; |
| 1686 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1687 | struct nl_msg *msg; |
| 1688 | int ret; |
| 1689 | |
| 1690 | msg = nlmsg_alloc(); |
| 1691 | if (!msg) |
| 1692 | return -ENOMEM; |
| 1693 | |
| 1694 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
| 1695 | alpha2[0] = '\0'; |
| 1696 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2); |
| 1697 | if (!alpha2[0]) |
| 1698 | ret = -1; |
| 1699 | |
| 1700 | return ret; |
| 1701 | } |
| 1702 | |
| 1703 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1704 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1705 | { |
| 1706 | int ret; |
| 1707 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1708 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1709 | if (global->nl_cb == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1710 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 1711 | "callbacks"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1712 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1713 | } |
| 1714 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1715 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
| 1716 | if (global->nl == NULL) |
| 1717 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1718 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1719 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
| 1720 | if (global->nl80211_id < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1721 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
| 1722 | "found"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1723 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1724 | } |
| 1725 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1726 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
| 1727 | if (global->nl_event == NULL) |
| 1728 | goto err; |
| 1729 | |
| 1730 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1731 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1732 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1733 | if (ret < 0) { |
| 1734 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1735 | "membership for scan events: %d (%s)", |
| 1736 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1737 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1738 | } |
| 1739 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1740 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1741 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1742 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1743 | if (ret < 0) { |
| 1744 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1745 | "membership for mlme events: %d (%s)", |
| 1746 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1747 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1748 | } |
| 1749 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1750 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1751 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1752 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1753 | if (ret < 0) { |
| 1754 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1755 | "membership for regulatory events: %d (%s)", |
| 1756 | ret, strerror(-ret)); |
| 1757 | /* Continue without regulatory events */ |
| 1758 | } |
| 1759 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1760 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
| 1761 | if (ret >= 0) |
| 1762 | ret = nl_socket_add_membership(global->nl_event, ret); |
| 1763 | if (ret < 0) { |
| 1764 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1765 | "membership for vendor events: %d (%s)", |
| 1766 | ret, strerror(-ret)); |
| 1767 | /* Continue without vendor events */ |
| 1768 | } |
| 1769 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1770 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1771 | no_seq_check, NULL); |
| 1772 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1773 | process_global_event, global); |
| 1774 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1775 | nl80211_register_eloop_read(&global->nl_event, |
| 1776 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1777 | global->nl_cb, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1778 | |
| 1779 | return 0; |
| 1780 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1781 | err: |
| 1782 | nl_destroy_handles(&global->nl_event); |
| 1783 | nl_destroy_handles(&global->nl); |
| 1784 | nl_cb_put(global->nl_cb); |
| 1785 | global->nl_cb = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1786 | return -1; |
| 1787 | } |
| 1788 | |
| 1789 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1790 | static void nl80211_check_global(struct nl80211_global *global) |
| 1791 | { |
| 1792 | struct nl_handle *handle; |
| 1793 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; |
| 1794 | int ret; |
| 1795 | unsigned int i; |
| 1796 | |
| 1797 | /* |
| 1798 | * Try to re-add memberships to handle case of cfg80211 getting reloaded |
| 1799 | * and all registration having been cleared. |
| 1800 | */ |
| 1801 | handle = (void *) (((intptr_t) global->nl_event) ^ |
| 1802 | ELOOP_SOCKET_INVALID); |
| 1803 | |
| 1804 | for (i = 0; groups[i]; i++) { |
| 1805 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); |
| 1806 | if (ret >= 0) |
| 1807 | ret = nl_socket_add_membership(handle, ret); |
| 1808 | if (ret < 0) { |
| 1809 | wpa_printf(MSG_INFO, |
| 1810 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", |
| 1811 | groups[i], ret, strerror(-ret)); |
| 1812 | } |
| 1813 | } |
| 1814 | } |
| 1815 | |
| 1816 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1817 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
| 1818 | { |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1819 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1820 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1821 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1822 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1823 | /* |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1824 | * rtnetlink ifdown handler will report interfaces other than the P2P |
| 1825 | * Device interface as disabled. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1826 | */ |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1827 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 1828 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1829 | } |
| 1830 | |
| 1831 | |
| 1832 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) |
| 1833 | { |
| 1834 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1835 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1836 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1837 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
| 1838 | "after rfkill unblock"); |
| 1839 | return; |
| 1840 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1841 | |
| 1842 | if (is_p2p_net_interface(drv->nlmode)) |
| 1843 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
| 1844 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1845 | /* |
| 1846 | * rtnetlink ifup handler will report interfaces other than the P2P |
| 1847 | * Device interface as enabled. |
| 1848 | */ |
| 1849 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 1850 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1851 | } |
| 1852 | |
| 1853 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1854 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
| 1855 | void *eloop_ctx, |
| 1856 | void *handle) |
| 1857 | { |
| 1858 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 1859 | u8 data[2048]; |
| 1860 | struct msghdr msg; |
| 1861 | struct iovec entry; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1862 | u8 control[512]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1863 | struct cmsghdr *cmsg; |
| 1864 | int res, found_ee = 0, found_wifi = 0, acked = 0; |
| 1865 | union wpa_event_data event; |
| 1866 | |
| 1867 | memset(&msg, 0, sizeof(msg)); |
| 1868 | msg.msg_iov = &entry; |
| 1869 | msg.msg_iovlen = 1; |
| 1870 | entry.iov_base = data; |
| 1871 | entry.iov_len = sizeof(data); |
| 1872 | msg.msg_control = &control; |
| 1873 | msg.msg_controllen = sizeof(control); |
| 1874 | |
| 1875 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); |
| 1876 | /* if error or not fitting 802.3 header, return */ |
| 1877 | if (res < 14) |
| 1878 | return; |
| 1879 | |
| 1880 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
| 1881 | { |
| 1882 | if (cmsg->cmsg_level == SOL_SOCKET && |
| 1883 | cmsg->cmsg_type == SCM_WIFI_STATUS) { |
| 1884 | int *ack; |
| 1885 | |
| 1886 | found_wifi = 1; |
| 1887 | ack = (void *)CMSG_DATA(cmsg); |
| 1888 | acked = *ack; |
| 1889 | } |
| 1890 | |
| 1891 | if (cmsg->cmsg_level == SOL_PACKET && |
| 1892 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { |
| 1893 | struct sock_extended_err *err = |
| 1894 | (struct sock_extended_err *)CMSG_DATA(cmsg); |
| 1895 | |
| 1896 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) |
| 1897 | found_ee = 1; |
| 1898 | } |
| 1899 | } |
| 1900 | |
| 1901 | if (!found_ee || !found_wifi) |
| 1902 | return; |
| 1903 | |
| 1904 | memset(&event, 0, sizeof(event)); |
| 1905 | event.eapol_tx_status.dst = data; |
| 1906 | event.eapol_tx_status.data = data + 14; |
| 1907 | event.eapol_tx_status.data_len = res - 14; |
| 1908 | event.eapol_tx_status.ack = acked; |
| 1909 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); |
| 1910 | } |
| 1911 | |
| 1912 | |
| 1913 | static int nl80211_init_bss(struct i802_bss *bss) |
| 1914 | { |
| 1915 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1916 | if (!bss->nl_cb) |
| 1917 | return -1; |
| 1918 | |
| 1919 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1920 | no_seq_check, NULL); |
| 1921 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1922 | process_bss_event, bss); |
| 1923 | |
| 1924 | return 0; |
| 1925 | } |
| 1926 | |
| 1927 | |
| 1928 | static void nl80211_destroy_bss(struct i802_bss *bss) |
| 1929 | { |
| 1930 | nl_cb_put(bss->nl_cb); |
| 1931 | bss->nl_cb = NULL; |
| 1932 | } |
| 1933 | |
| 1934 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1935 | static void |
| 1936 | wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv) |
| 1937 | { |
| 1938 | struct rfkill_config *rcfg; |
| 1939 | |
| 1940 | if (drv->rfkill) |
| 1941 | return; |
| 1942 | |
| 1943 | rcfg = os_zalloc(sizeof(*rcfg)); |
| 1944 | if (!rcfg) |
| 1945 | return; |
| 1946 | |
| 1947 | rcfg->ctx = drv; |
| 1948 | |
| 1949 | /* rfkill uses netdev sysfs for initialization. However, P2P Device is |
| 1950 | * not associated with a netdev, so use the name of some other interface |
| 1951 | * sharing the same wiphy as the P2P Device interface. |
| 1952 | * |
| 1953 | * Note: This is valid, as a P2P Device interface is always dynamically |
| 1954 | * created and is created only once another wpa_s interface was added. |
| 1955 | */ |
| 1956 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 1957 | struct nl80211_global *global = drv->global; |
| 1958 | struct wpa_driver_nl80211_data *tmp1; |
| 1959 | |
| 1960 | dl_list_for_each(tmp1, &global->interfaces, |
| 1961 | struct wpa_driver_nl80211_data, list) { |
| 1962 | if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx || |
| 1963 | !tmp1->rfkill) |
| 1964 | continue; |
| 1965 | |
| 1966 | wpa_printf(MSG_DEBUG, |
| 1967 | "nl80211: Use (%s) to initialize P2P Device rfkill", |
| 1968 | tmp1->first_bss->ifname); |
| 1969 | os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname, |
| 1970 | sizeof(rcfg->ifname)); |
| 1971 | break; |
| 1972 | } |
| 1973 | } else { |
| 1974 | os_strlcpy(rcfg->ifname, drv->first_bss->ifname, |
| 1975 | sizeof(rcfg->ifname)); |
| 1976 | } |
| 1977 | |
| 1978 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; |
| 1979 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; |
| 1980 | drv->rfkill = rfkill_init(rcfg); |
| 1981 | if (!drv->rfkill) { |
| 1982 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
| 1983 | os_free(rcfg); |
| 1984 | } |
| 1985 | } |
| 1986 | |
| 1987 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1988 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
| 1989 | void *global_priv, int hostapd, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1990 | const u8 *set_addr, |
| 1991 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1992 | { |
| 1993 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1994 | struct i802_bss *bss; |
| 1995 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1996 | if (global_priv == NULL) |
| 1997 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1998 | drv = os_zalloc(sizeof(*drv)); |
| 1999 | if (drv == NULL) |
| 2000 | return NULL; |
| 2001 | drv->global = global_priv; |
| 2002 | drv->ctx = ctx; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2003 | drv->hostapd = !!hostapd; |
| 2004 | drv->eapol_sock = -1; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 2005 | |
| 2006 | /* |
| 2007 | * There is no driver capability flag for this, so assume it is |
| 2008 | * supported and disable this on first attempt to use if the driver |
| 2009 | * rejects the command due to missing support. |
| 2010 | */ |
| 2011 | drv->set_rekey_offload = 1; |
| 2012 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 2013 | drv->num_if_indices = ARRAY_SIZE(drv->default_if_indices); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2014 | drv->if_indices = drv->default_if_indices; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2015 | |
| 2016 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); |
| 2017 | if (!drv->first_bss) { |
| 2018 | os_free(drv); |
| 2019 | return NULL; |
| 2020 | } |
| 2021 | bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2022 | bss->drv = drv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2023 | bss->ctx = ctx; |
| 2024 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2025 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
| 2026 | drv->monitor_ifidx = -1; |
| 2027 | drv->monitor_sock = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2028 | drv->eapol_tx_sock = -1; |
| 2029 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2030 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2031 | if (nl80211_init_bss(bss)) |
| 2032 | goto failed; |
| 2033 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2034 | 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] | 2035 | goto failed; |
| 2036 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2037 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
| 2038 | if (drv->eapol_tx_sock < 0) |
| 2039 | goto failed; |
| 2040 | |
| 2041 | if (drv->data_tx_status) { |
| 2042 | int enabled = 1; |
| 2043 | |
| 2044 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, |
| 2045 | &enabled, sizeof(enabled)) < 0) { |
| 2046 | wpa_printf(MSG_DEBUG, |
| 2047 | "nl80211: wifi status sockopt failed\n"); |
| 2048 | drv->data_tx_status = 0; |
| 2049 | if (!drv->use_monitor) |
| 2050 | drv->capa.flags &= |
| 2051 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
| 2052 | } else { |
| 2053 | eloop_register_read_sock(drv->eapol_tx_sock, |
| 2054 | wpa_driver_nl80211_handle_eapol_tx_status, |
| 2055 | drv, NULL); |
| 2056 | } |
| 2057 | } |
| 2058 | |
| 2059 | if (drv->global) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2060 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2061 | dl_list_add(&drv->global->interfaces, &drv->list); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2062 | drv->in_interface_list = 1; |
| 2063 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2064 | |
| 2065 | return bss; |
| 2066 | |
| 2067 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2068 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2069 | return NULL; |
| 2070 | } |
| 2071 | |
| 2072 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2073 | /** |
| 2074 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface |
| 2075 | * @ctx: context to be used when calling wpa_supplicant functions, |
| 2076 | * e.g., wpa_supplicant_event() |
| 2077 | * @ifname: interface name, e.g., wlan0 |
| 2078 | * @global_priv: private driver global data from global_init() |
| 2079 | * Returns: Pointer to private data, %NULL on failure |
| 2080 | */ |
| 2081 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
| 2082 | void *global_priv) |
| 2083 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2084 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
| 2085 | NULL); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2086 | } |
| 2087 | |
| 2088 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2089 | static int nl80211_register_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2090 | struct nl_handle *nl_handle, |
| 2091 | u16 type, const u8 *match, size_t match_len) |
| 2092 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2093 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2094 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2095 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2096 | char buf[30]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2097 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2098 | buf[0] = '\0'; |
| 2099 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 2100 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s", |
| 2101 | type, fc2str(type), nl_handle, buf); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2102 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2103 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) || |
| 2104 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
| 2105 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { |
| 2106 | nlmsg_free(msg); |
| 2107 | return -1; |
| 2108 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2109 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2110 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2111 | if (ret) { |
| 2112 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
| 2113 | "failed (type=%u): ret=%d (%s)", |
| 2114 | type, ret, strerror(-ret)); |
| 2115 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", |
| 2116 | match, match_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2117 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2118 | return ret; |
| 2119 | } |
| 2120 | |
| 2121 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2122 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
| 2123 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2124 | if (bss->nl_mgmt) { |
| 2125 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
| 2126 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
| 2127 | return -1; |
| 2128 | } |
| 2129 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2130 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2131 | if (bss->nl_mgmt == NULL) |
| 2132 | return -1; |
| 2133 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2134 | return 0; |
| 2135 | } |
| 2136 | |
| 2137 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2138 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
| 2139 | { |
| 2140 | nl80211_register_eloop_read(&bss->nl_mgmt, |
| 2141 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2142 | bss->nl_cb, 0); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2146 | static int nl80211_register_action_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2147 | const u8 *match, size_t match_len) |
| 2148 | { |
| 2149 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2150 | return nl80211_register_frame(bss, bss->nl_mgmt, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2151 | type, match, match_len); |
| 2152 | } |
| 2153 | |
| 2154 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2155 | static int nl80211_init_connect_handle(struct i802_bss *bss) |
| 2156 | { |
| 2157 | if (bss->nl_connect) { |
| 2158 | wpa_printf(MSG_DEBUG, |
| 2159 | "nl80211: Connect handle already created (nl_connect=%p)", |
| 2160 | bss->nl_connect); |
| 2161 | return -1; |
| 2162 | } |
| 2163 | |
| 2164 | bss->nl_connect = nl_create_handle(bss->nl_cb, "connect"); |
| 2165 | if (!bss->nl_connect) |
| 2166 | return -1; |
| 2167 | nl80211_register_eloop_read(&bss->nl_connect, |
| 2168 | wpa_driver_nl80211_event_receive, |
| 2169 | bss->nl_cb, 1); |
| 2170 | return 0; |
| 2171 | } |
| 2172 | |
| 2173 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2174 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2175 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2176 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2177 | int ret = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2178 | |
| 2179 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2180 | return -1; |
| 2181 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
| 2182 | "handle %p", bss->nl_mgmt); |
| 2183 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2184 | if (drv->nlmode == NL80211_IFTYPE_ADHOC || |
| 2185 | ((drv->capa.flags & WPA_DRIVER_FLAGS_SAE) && |
| 2186 | !(drv->capa.flags & WPA_DRIVER_FLAGS_SME))) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2187 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
| 2188 | |
| 2189 | /* register for any AUTH message */ |
| 2190 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); |
| 2191 | } |
| 2192 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2193 | #ifdef CONFIG_INTERWORKING |
| 2194 | /* QoS Map Configure */ |
| 2195 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2196 | ret = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2197 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2198 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2199 | /* GAS Initial Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2200 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2201 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2202 | /* GAS Initial Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2203 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2204 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2205 | /* GAS Comeback Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2206 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2207 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2208 | /* GAS Comeback Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2209 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2210 | ret = -1; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2211 | /* Protected GAS Initial Request */ |
| 2212 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) |
| 2213 | ret = -1; |
| 2214 | /* Protected GAS Initial Response */ |
| 2215 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) |
| 2216 | ret = -1; |
| 2217 | /* Protected GAS Comeback Request */ |
| 2218 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) |
| 2219 | ret = -1; |
| 2220 | /* Protected GAS Comeback Response */ |
| 2221 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) |
| 2222 | ret = -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2223 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2224 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2225 | /* P2P Public Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2226 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2227 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
| 2228 | 6) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2229 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2230 | /* P2P Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2231 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2232 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
| 2233 | 5) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2234 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2235 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2236 | #ifdef CONFIG_DPP |
| 2237 | /* DPP Public Action */ |
| 2238 | if (nl80211_register_action_frame(bss, |
| 2239 | (u8 *) "\x04\x09\x50\x6f\x9a\x1a", |
| 2240 | 6) < 0) |
| 2241 | ret = -1; |
| 2242 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2243 | #ifdef CONFIG_IEEE80211W |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 2244 | #ifdef CONFIG_OCV |
| 2245 | /* SA Query Request */ |
| 2246 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x00", 2) < 0) |
| 2247 | ret = -1; |
| 2248 | #endif /* CONFIG_OCV */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2249 | /* SA Query Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2250 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2251 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2252 | #endif /* CONFIG_IEEE80211W */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2253 | #ifdef CONFIG_TDLS |
| 2254 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { |
| 2255 | /* TDLS Discovery Response */ |
| 2256 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
| 2257 | 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2258 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2259 | } |
| 2260 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2261 | #ifdef CONFIG_FST |
| 2262 | /* FST Action frames */ |
| 2263 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2264 | ret = -1; |
| 2265 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2266 | |
| 2267 | /* FT Action frames */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2268 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2269 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2270 | else |
| 2271 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | |
| 2272 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; |
| 2273 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2274 | /* WNM - BSS Transition Management Request */ |
| 2275 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2276 | ret = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2277 | /* WNM-Sleep Mode Response */ |
| 2278 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2279 | ret = -1; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 2280 | #ifdef CONFIG_WNM |
| 2281 | /* WNM - Collocated Interference Request */ |
| 2282 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x0b", 2) < 0) |
| 2283 | ret = -1; |
| 2284 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2285 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2286 | #ifdef CONFIG_HS20 |
| 2287 | /* WNM-Notification */ |
| 2288 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2289 | ret = -1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2290 | #endif /* CONFIG_HS20 */ |
| 2291 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2292 | /* WMM-AC ADDTS Response */ |
| 2293 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) |
| 2294 | ret = -1; |
| 2295 | |
| 2296 | /* WMM-AC DELTS */ |
| 2297 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) |
| 2298 | ret = -1; |
| 2299 | |
| 2300 | /* Radio Measurement - Neighbor Report Response */ |
| 2301 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) |
| 2302 | ret = -1; |
| 2303 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2304 | /* Radio Measurement - Radio Measurement Request */ |
| 2305 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0) |
| 2306 | ret = -1; |
| 2307 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2308 | /* Radio Measurement - Link Measurement Request */ |
| 2309 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && |
| 2310 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) |
| 2311 | ret = -1; |
| 2312 | |
| 2313 | nl80211_mgmt_handle_register_eloop(bss); |
| 2314 | |
| 2315 | return ret; |
| 2316 | } |
| 2317 | |
| 2318 | |
| 2319 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
| 2320 | { |
| 2321 | int ret = 0; |
| 2322 | |
| 2323 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2324 | return -1; |
| 2325 | |
| 2326 | wpa_printf(MSG_DEBUG, |
| 2327 | "nl80211: Subscribe to mgmt frames with mesh handle %p", |
| 2328 | bss->nl_mgmt); |
| 2329 | |
| 2330 | /* Auth frames for mesh SAE */ |
| 2331 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2332 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2333 | (WLAN_FC_STYPE_AUTH << 4), |
| 2334 | NULL, 0) < 0) |
| 2335 | ret = -1; |
| 2336 | |
| 2337 | /* Mesh peering open */ |
| 2338 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) |
| 2339 | ret = -1; |
| 2340 | /* Mesh peering confirm */ |
| 2341 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) |
| 2342 | ret = -1; |
| 2343 | /* Mesh peering close */ |
| 2344 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) |
| 2345 | ret = -1; |
| 2346 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2347 | nl80211_mgmt_handle_register_eloop(bss); |
| 2348 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2349 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2350 | } |
| 2351 | |
| 2352 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2353 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
| 2354 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2355 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2356 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2357 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2358 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
| 2359 | 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] | 2360 | if (ret) { |
| 2361 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " |
| 2362 | "failed: ret=%d (%s)", |
| 2363 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2364 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2365 | return ret; |
| 2366 | } |
| 2367 | |
| 2368 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2369 | static int nl80211_action_subscribe_ap(struct i802_bss *bss) |
| 2370 | { |
| 2371 | int ret = 0; |
| 2372 | |
| 2373 | /* Public Action frames */ |
| 2374 | if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0) |
| 2375 | ret = -1; |
| 2376 | /* RRM Measurement Report */ |
| 2377 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0) |
| 2378 | ret = -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2379 | /* RRM Link Measurement Report */ |
| 2380 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0) |
| 2381 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2382 | /* RRM Neighbor Report Request */ |
| 2383 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0) |
| 2384 | ret = -1; |
| 2385 | /* FT Action frames */ |
| 2386 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
| 2387 | ret = -1; |
| 2388 | #ifdef CONFIG_IEEE80211W |
| 2389 | /* SA Query */ |
| 2390 | if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0) |
| 2391 | ret = -1; |
| 2392 | #endif /* CONFIG_IEEE80211W */ |
| 2393 | /* Protected Dual of Public Action */ |
| 2394 | if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0) |
| 2395 | ret = -1; |
| 2396 | /* WNM */ |
| 2397 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0) |
| 2398 | ret = -1; |
| 2399 | /* WMM */ |
| 2400 | if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0) |
| 2401 | ret = -1; |
| 2402 | #ifdef CONFIG_FST |
| 2403 | /* FST Action frames */ |
| 2404 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2405 | ret = -1; |
| 2406 | #endif /* CONFIG_FST */ |
| 2407 | /* Vendor-specific */ |
| 2408 | if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0) |
| 2409 | ret = -1; |
| 2410 | |
| 2411 | return ret; |
| 2412 | } |
| 2413 | |
| 2414 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2415 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
| 2416 | { |
| 2417 | static const int stypes[] = { |
| 2418 | WLAN_FC_STYPE_AUTH, |
| 2419 | WLAN_FC_STYPE_ASSOC_REQ, |
| 2420 | WLAN_FC_STYPE_REASSOC_REQ, |
| 2421 | WLAN_FC_STYPE_DISASSOC, |
| 2422 | WLAN_FC_STYPE_DEAUTH, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2423 | WLAN_FC_STYPE_PROBE_REQ, |
| 2424 | /* Beacon doesn't work as mac80211 doesn't currently allow |
| 2425 | * it, but it wouldn't really be the right thing anyway as |
| 2426 | * it isn't per interface ... maybe just dump the scan |
| 2427 | * results periodically for OLBC? |
| 2428 | */ |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2429 | /* WLAN_FC_STYPE_BEACON, */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2430 | }; |
| 2431 | unsigned int i; |
| 2432 | |
| 2433 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2434 | return -1; |
| 2435 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2436 | "handle %p", bss->nl_mgmt); |
| 2437 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2438 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2439 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2440 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2441 | (stypes[i] << 4), |
| 2442 | NULL, 0) < 0) { |
| 2443 | goto out_err; |
| 2444 | } |
| 2445 | } |
| 2446 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2447 | if (nl80211_action_subscribe_ap(bss)) |
| 2448 | goto out_err; |
| 2449 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2450 | if (nl80211_register_spurious_class3(bss)) |
| 2451 | goto out_err; |
| 2452 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2453 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2454 | return 0; |
| 2455 | |
| 2456 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2457 | nl_destroy_handles(&bss->nl_mgmt); |
| 2458 | return -1; |
| 2459 | } |
| 2460 | |
| 2461 | |
| 2462 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
| 2463 | { |
| 2464 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2465 | return -1; |
| 2466 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2467 | "handle %p (device SME)", bss->nl_mgmt); |
| 2468 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2469 | if (nl80211_action_subscribe_ap(bss)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2470 | goto out_err; |
| 2471 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 2472 | if (bss->drv->device_ap_sme) { |
| 2473 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
| 2474 | |
| 2475 | /* Register for all Authentication frames */ |
| 2476 | if (nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0) |
| 2477 | < 0) |
| 2478 | wpa_printf(MSG_DEBUG, |
| 2479 | "nl80211: Failed to subscribe to handle Authentication frames - SAE offload may not work"); |
| 2480 | } |
| 2481 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2482 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2483 | return 0; |
| 2484 | |
| 2485 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2486 | nl_destroy_handles(&bss->nl_mgmt); |
| 2487 | return -1; |
| 2488 | } |
| 2489 | |
| 2490 | |
| 2491 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
| 2492 | { |
| 2493 | if (bss->nl_mgmt == NULL) |
| 2494 | return; |
| 2495 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
| 2496 | "(%s)", bss->nl_mgmt, reason); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2497 | nl80211_destroy_eloop_handle(&bss->nl_mgmt, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2498 | |
| 2499 | nl80211_put_wiphy_data_ap(bss); |
| 2500 | } |
| 2501 | |
| 2502 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2503 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
| 2504 | { |
| 2505 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); |
| 2506 | } |
| 2507 | |
| 2508 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2509 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
| 2510 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2511 | struct nl_msg *msg; |
| 2512 | int ret; |
| 2513 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2514 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
| 2515 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2516 | |
| 2517 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", |
| 2518 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2519 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2520 | } |
| 2521 | |
| 2522 | |
| 2523 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
| 2524 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2525 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2526 | int ret; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2527 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2528 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
| 2529 | NL80211_CMD_STOP_P2P_DEVICE); |
| 2530 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2531 | |
| 2532 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
| 2533 | start ? "Start" : "Stop", |
| 2534 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2535 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2536 | return ret; |
| 2537 | } |
| 2538 | |
| 2539 | |
| 2540 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
| 2541 | { |
| 2542 | enum nl80211_iftype nlmode; |
| 2543 | |
| 2544 | nlmode = nl80211_get_ifmode(bss); |
| 2545 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2546 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, |
| 2547 | bss->ifname, up); |
| 2548 | } |
| 2549 | |
| 2550 | /* P2P Device has start/stop which is equivalent */ |
| 2551 | return nl80211_set_p2pdev(bss, up); |
| 2552 | } |
| 2553 | |
| 2554 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2555 | #ifdef CONFIG_TESTING_OPTIONS |
| 2556 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) |
| 2557 | { |
| 2558 | /* struct wpa_driver_nl80211_data *drv = arg; */ |
| 2559 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 2560 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2561 | |
| 2562 | |
| 2563 | wpa_printf(MSG_DEBUG, |
| 2564 | "nl80211: QCA vendor test command response received"); |
| 2565 | |
| 2566 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2567 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2568 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { |
| 2569 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); |
| 2570 | return NL_SKIP; |
| 2571 | } |
| 2572 | |
| 2573 | wpa_hexdump(MSG_DEBUG, |
| 2574 | "nl80211: Received QCA vendor test command response", |
| 2575 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), |
| 2576 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); |
| 2577 | |
| 2578 | return NL_SKIP; |
| 2579 | } |
| 2580 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2581 | |
| 2582 | |
| 2583 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) |
| 2584 | { |
| 2585 | #ifdef CONFIG_TESTING_OPTIONS |
| 2586 | struct nl_msg *msg; |
| 2587 | struct nlattr *params; |
| 2588 | int ret; |
| 2589 | |
| 2590 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2591 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2592 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2593 | QCA_NL80211_VENDOR_SUBCMD_TEST) || |
| 2594 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 2595 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { |
| 2596 | nlmsg_free(msg); |
| 2597 | return; |
| 2598 | } |
| 2599 | nla_nest_end(msg, params); |
| 2600 | |
| 2601 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv); |
| 2602 | wpa_printf(MSG_DEBUG, |
| 2603 | "nl80211: QCA vendor test command returned %d (%s)", |
| 2604 | ret, strerror(-ret)); |
| 2605 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2606 | } |
| 2607 | |
| 2608 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2609 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2610 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2611 | const u8 *set_addr, int first, |
| 2612 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2613 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2614 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2615 | int send_rfkill_event = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2616 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2617 | |
| 2618 | drv->ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2619 | bss->ifindex = drv->ifindex; |
| 2620 | bss->wdev_id = drv->global->if_add_wdevid; |
| 2621 | bss->wdev_id_set = drv->global->if_add_wdevid_set; |
| 2622 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2623 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
| 2624 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2625 | drv->global->if_add_wdevid_set = 0; |
| 2626 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2627 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2628 | bss->static_ap = 1; |
| 2629 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 2630 | if (first && |
| 2631 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && |
| 2632 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) |
| 2633 | drv->start_iface_up = 1; |
| 2634 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2635 | if (wpa_driver_nl80211_capa(drv)) |
| 2636 | return -1; |
| 2637 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2638 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
| 2639 | return -1; |
| 2640 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2641 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
| 2642 | bss->ifname, drv->phyname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2643 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2644 | if (set_addr && |
| 2645 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || |
| 2646 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2647 | set_addr))) |
| 2648 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2649 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2650 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2651 | drv->start_mode_ap = 1; |
| 2652 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2653 | if (drv->hostapd || bss->static_ap) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2654 | nlmode = NL80211_IFTYPE_AP; |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 2655 | else if (bss->if_dynamic || |
| 2656 | nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2657 | nlmode = nl80211_get_ifmode(bss); |
| 2658 | else |
| 2659 | nlmode = NL80211_IFTYPE_STATION; |
| 2660 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2661 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2662 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2663 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2664 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2665 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2666 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2667 | nl80211_get_macaddr(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2668 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2669 | wpa_driver_nl80211_drv_init_rfkill(drv); |
| 2670 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2671 | if (!rfkill_is_blocked(drv->rfkill)) { |
| 2672 | int ret = i802_set_iface_flags(bss, 1); |
| 2673 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2674 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
| 2675 | "interface '%s' UP", bss->ifname); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2676 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2677 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2678 | |
| 2679 | if (is_p2p_net_interface(nlmode)) |
| 2680 | nl80211_disable_11b_rates(bss->drv, |
| 2681 | bss->drv->ifindex, 1); |
| 2682 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2683 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2684 | return ret; |
| 2685 | } else { |
| 2686 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " |
| 2687 | "interface '%s' due to rfkill", bss->ifname); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2688 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 2689 | drv->if_disabled = 1; |
| 2690 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2691 | send_rfkill_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2692 | } |
| 2693 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2694 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2695 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
| 2696 | 1, IF_OPER_DORMANT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2697 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2698 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2699 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2700 | bss->addr)) |
| 2701 | return -1; |
| 2702 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); |
| 2703 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2704 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2705 | if (send_rfkill_event) { |
| 2706 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, |
| 2707 | drv, drv->ctx); |
| 2708 | } |
| 2709 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2710 | if (drv->vendor_cmd_test_avail) |
| 2711 | qca_vendor_test(drv); |
| 2712 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2713 | nl80211_init_connect_handle(bss); |
| 2714 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2715 | return 0; |
| 2716 | } |
| 2717 | |
| 2718 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2719 | static int wpa_driver_nl80211_del_beacon(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2720 | { |
| 2721 | struct nl_msg *msg; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2722 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2723 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2724 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
| 2725 | drv->ifindex); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2726 | nl80211_put_wiphy_data_ap(bss); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2727 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2728 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2729 | } |
| 2730 | |
| 2731 | |
| 2732 | /** |
| 2733 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2734 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2735 | * |
| 2736 | * Shut down driver interface and processing of driver events. Free |
| 2737 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). |
| 2738 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2739 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2740 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2741 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2742 | unsigned int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2743 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2744 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
| 2745 | bss->ifname, drv->disabled_11b_rates); |
| 2746 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2747 | bss->in_deinit = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2748 | if (drv->data_tx_status) |
| 2749 | eloop_unregister_read_sock(drv->eapol_tx_sock); |
| 2750 | if (drv->eapol_tx_sock >= 0) |
| 2751 | close(drv->eapol_tx_sock); |
| 2752 | |
| 2753 | if (bss->nl_preq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2754 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 2755 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2756 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 2757 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2758 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2759 | "interface %s from bridge %s: %s", |
| 2760 | bss->ifname, bss->brname, strerror(errno)); |
| 2761 | } |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 2762 | |
| 2763 | if (drv->rtnl_sk) |
| 2764 | nl80211_handle_destroy(drv->rtnl_sk); |
| 2765 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2766 | if (bss->added_bridge) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2767 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
| 2768 | 0) < 0) |
| 2769 | wpa_printf(MSG_INFO, |
| 2770 | "nl80211: Could not set bridge %s down", |
| 2771 | bss->brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2772 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2773 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2774 | "bridge %s: %s", |
| 2775 | bss->brname, strerror(errno)); |
| 2776 | } |
| 2777 | |
| 2778 | nl80211_remove_monitor_interface(drv); |
| 2779 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2780 | if (is_ap_interface(drv->nlmode)) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2781 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2782 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2783 | if (drv->eapol_sock >= 0) { |
| 2784 | eloop_unregister_read_sock(drv->eapol_sock); |
| 2785 | close(drv->eapol_sock); |
| 2786 | } |
| 2787 | |
| 2788 | if (drv->if_indices != drv->default_if_indices) |
| 2789 | os_free(drv->if_indices); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2790 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2791 | if (drv->disabled_11b_rates) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2792 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 2793 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2794 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
| 2795 | IF_OPER_UP); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 2796 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2797 | rfkill_deinit(drv->rfkill); |
| 2798 | |
| 2799 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 2800 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2801 | if (!drv->start_iface_up) |
| 2802 | (void) i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2803 | |
| 2804 | if (drv->addr_changed) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2805 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 2806 | 0) < 0) { |
| 2807 | wpa_printf(MSG_DEBUG, |
| 2808 | "nl80211: Could not set interface down to restore permanent MAC address"); |
| 2809 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2810 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2811 | drv->perm_addr) < 0) { |
| 2812 | wpa_printf(MSG_DEBUG, |
| 2813 | "nl80211: Could not restore permanent MAC address"); |
| 2814 | } |
| 2815 | } |
| 2816 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2817 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2818 | if (!drv->hostapd || !drv->start_mode_ap) |
| 2819 | wpa_driver_nl80211_set_mode(bss, |
| 2820 | NL80211_IFTYPE_STATION); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2821 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2822 | } else { |
| 2823 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
| 2824 | nl80211_del_p2pdev(bss); |
| 2825 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2826 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2827 | if (bss->nl_connect) |
| 2828 | nl80211_destroy_eloop_handle(&bss->nl_connect, 1); |
| 2829 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2830 | nl80211_destroy_bss(drv->first_bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2831 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2832 | os_free(drv->filter_ssids); |
| 2833 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2834 | os_free(drv->auth_ie); |
| 2835 | |
| 2836 | if (drv->in_interface_list) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2837 | dl_list_del(&drv->list); |
| 2838 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2839 | os_free(drv->extended_capa); |
| 2840 | os_free(drv->extended_capa_mask); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2841 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 2842 | os_free(drv->iface_ext_capa[i].ext_capa); |
| 2843 | os_free(drv->iface_ext_capa[i].ext_capa_mask); |
| 2844 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2845 | os_free(drv->first_bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2846 | os_free(drv); |
| 2847 | } |
| 2848 | |
| 2849 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2850 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
| 2851 | { |
| 2852 | switch (alg) { |
| 2853 | case WPA_ALG_WEP: |
| 2854 | if (key_len == 5) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2855 | return RSN_CIPHER_SUITE_WEP40; |
| 2856 | return RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2857 | case WPA_ALG_TKIP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2858 | return RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2859 | case WPA_ALG_CCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2860 | return RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2861 | case WPA_ALG_GCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2862 | return RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2863 | case WPA_ALG_CCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2864 | return RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2865 | case WPA_ALG_GCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2866 | return RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2867 | case WPA_ALG_IGTK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2868 | return RSN_CIPHER_SUITE_AES_128_CMAC; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2869 | case WPA_ALG_BIP_GMAC_128: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2870 | return RSN_CIPHER_SUITE_BIP_GMAC_128; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2871 | case WPA_ALG_BIP_GMAC_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2872 | return RSN_CIPHER_SUITE_BIP_GMAC_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2873 | case WPA_ALG_BIP_CMAC_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2874 | return RSN_CIPHER_SUITE_BIP_CMAC_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2875 | case WPA_ALG_SMS4: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2876 | return RSN_CIPHER_SUITE_SMS4; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2877 | case WPA_ALG_KRK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2878 | return RSN_CIPHER_SUITE_KRK; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2879 | case WPA_ALG_NONE: |
| 2880 | case WPA_ALG_PMK: |
| 2881 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", |
| 2882 | alg); |
| 2883 | return 0; |
| 2884 | } |
| 2885 | |
| 2886 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", |
| 2887 | alg); |
| 2888 | return 0; |
| 2889 | } |
| 2890 | |
| 2891 | |
| 2892 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) |
| 2893 | { |
| 2894 | switch (cipher) { |
| 2895 | case WPA_CIPHER_CCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2896 | return RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2897 | case WPA_CIPHER_GCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2898 | return RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2899 | case WPA_CIPHER_CCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2900 | return RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2901 | case WPA_CIPHER_GCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2902 | return RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2903 | case WPA_CIPHER_TKIP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2904 | return RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2905 | case WPA_CIPHER_WEP104: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2906 | return RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2907 | case WPA_CIPHER_WEP40: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2908 | return RSN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2909 | case WPA_CIPHER_GTK_NOT_USED: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2910 | return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2911 | } |
| 2912 | |
| 2913 | return 0; |
| 2914 | } |
| 2915 | |
| 2916 | |
| 2917 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], |
| 2918 | int max_suites) |
| 2919 | { |
| 2920 | int num_suites = 0; |
| 2921 | |
| 2922 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2923 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2924 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2925 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2926 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2927 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2928 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2929 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2930 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2931 | suites[num_suites++] = RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2932 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2933 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2934 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2935 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2936 | |
| 2937 | return num_suites; |
| 2938 | } |
| 2939 | |
| 2940 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2941 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2942 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 2943 | const u8 *key, size_t key_len) |
| 2944 | { |
| 2945 | struct nl_msg *msg; |
| 2946 | int ret; |
| 2947 | |
| 2948 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
| 2949 | return 0; |
| 2950 | |
| 2951 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2952 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2953 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2954 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || |
| 2955 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { |
| 2956 | nl80211_nlmsg_clear(msg); |
| 2957 | nlmsg_free(msg); |
| 2958 | return -1; |
| 2959 | } |
| 2960 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 2961 | if (ret) { |
| 2962 | wpa_printf(MSG_DEBUG, |
| 2963 | "nl80211: Key management set key failed: ret=%d (%s)", |
| 2964 | ret, strerror(-ret)); |
| 2965 | } |
| 2966 | |
| 2967 | return ret; |
| 2968 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2969 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2970 | |
| 2971 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2972 | static int nl80211_set_pmk(struct wpa_driver_nl80211_data *drv, |
| 2973 | const u8 *key, size_t key_len, |
| 2974 | const u8 *addr) |
| 2975 | { |
| 2976 | struct nl_msg *msg = NULL; |
| 2977 | int ret; |
| 2978 | |
| 2979 | /* |
| 2980 | * If the authenticator address is not set, assume it is |
| 2981 | * the current BSSID. |
| 2982 | */ |
| 2983 | if (!addr && drv->associated) |
| 2984 | addr = drv->bssid; |
| 2985 | else if (!addr) |
| 2986 | return -1; |
| 2987 | |
| 2988 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK to the driver for " MACSTR, |
| 2989 | MAC2STR(addr)); |
| 2990 | wpa_hexdump_key(MSG_DEBUG, "nl80211: PMK", key, key_len); |
| 2991 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_PMK); |
| 2992 | if (!msg || |
| 2993 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 2994 | nla_put(msg, NL80211_ATTR_PMK, key_len, key)) { |
| 2995 | nl80211_nlmsg_clear(msg); |
| 2996 | nlmsg_free(msg); |
| 2997 | return -ENOBUFS; |
| 2998 | } |
| 2999 | |
| 3000 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 3001 | if (ret) { |
| 3002 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK failed: ret=%d (%s)", |
| 3003 | ret, strerror(-ret)); |
| 3004 | } |
| 3005 | |
| 3006 | return ret; |
| 3007 | } |
| 3008 | |
| 3009 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3010 | static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3011 | enum wpa_alg alg, const u8 *addr, |
| 3012 | int key_idx, int set_tx, |
| 3013 | const u8 *seq, size_t seq_len, |
| 3014 | const u8 *key, size_t key_len) |
| 3015 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3016 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3017 | int ifindex; |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3018 | struct nl_msg *msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3019 | int ret; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 3020 | int tdls = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3021 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3022 | /* Ignore for P2P Device */ |
| 3023 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 3024 | return 0; |
| 3025 | |
| 3026 | ifindex = if_nametoindex(ifname); |
| 3027 | wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3028 | "set_tx=%d seq_len=%lu key_len=%lu", |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3029 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3030 | (unsigned long) seq_len, (unsigned long) key_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3031 | #ifdef CONFIG_TDLS |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 3032 | if (key_idx == -1) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3033 | key_idx = 0; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 3034 | tdls = 1; |
| 3035 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3036 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3037 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3038 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3039 | if (alg == WPA_ALG_PMK && |
| 3040 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { |
| 3041 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
| 3042 | __func__); |
| 3043 | ret = issue_key_mgmt_set_key(drv, key, key_len); |
| 3044 | return ret; |
| 3045 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3046 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3047 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3048 | if (alg == WPA_ALG_PMK && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3049 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3050 | return nl80211_set_pmk(drv, key, key_len, addr); |
| 3051 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3052 | if (alg == WPA_ALG_NONE) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3053 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
| 3054 | if (!msg) |
| 3055 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3056 | } else { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3057 | u32 suite; |
| 3058 | |
| 3059 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 3060 | if (!suite) |
| 3061 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3062 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
| 3063 | if (!msg || |
| 3064 | nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3065 | nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, suite)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3066 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3067 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3068 | } |
| 3069 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3070 | if (seq && seq_len) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3071 | if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq)) |
| 3072 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3073 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
| 3074 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3075 | |
| 3076 | if (addr && !is_broadcast_ether_addr(addr)) { |
| 3077 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3078 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 3079 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3080 | |
| 3081 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { |
| 3082 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3083 | if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, |
| 3084 | NL80211_KEYTYPE_GROUP)) |
| 3085 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3086 | } |
| 3087 | } else if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3088 | struct nlattr *types; |
| 3089 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3090 | wpa_printf(MSG_DEBUG, " broadcast key"); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3091 | |
| 3092 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3093 | if (!types || |
| 3094 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 3095 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3096 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3097 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3098 | if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 3099 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3100 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3101 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3102 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
| 3103 | ret = 0; |
| 3104 | if (ret) |
| 3105 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", |
| 3106 | ret, strerror(-ret)); |
| 3107 | |
| 3108 | /* |
| 3109 | * If we failed or don't need to set the default TX key (below), |
| 3110 | * we're done here. |
| 3111 | */ |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 3112 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3113 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3114 | if (is_ap_interface(drv->nlmode) && addr && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3115 | !is_broadcast_ether_addr(addr)) |
| 3116 | return ret; |
| 3117 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3118 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
| 3119 | if (!msg || |
| 3120 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 3121 | nla_put_flag(msg, (alg == WPA_ALG_IGTK || |
| 3122 | alg == WPA_ALG_BIP_GMAC_128 || |
| 3123 | alg == WPA_ALG_BIP_GMAC_256 || |
| 3124 | alg == WPA_ALG_BIP_CMAC_256) ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3125 | NL80211_ATTR_KEY_DEFAULT_MGMT : |
| 3126 | NL80211_ATTR_KEY_DEFAULT)) |
| 3127 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3128 | if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3129 | struct nlattr *types; |
| 3130 | |
| 3131 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3132 | if (!types || |
| 3133 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 3134 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3135 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3136 | } else if (addr) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3137 | struct nlattr *types; |
| 3138 | |
| 3139 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3140 | if (!types || |
| 3141 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) |
| 3142 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3143 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3144 | } |
| 3145 | |
| 3146 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3147 | if (ret == -ENOENT) |
| 3148 | ret = 0; |
| 3149 | if (ret) |
| 3150 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " |
| 3151 | "err=%d %s)", ret, strerror(-ret)); |
| 3152 | return ret; |
| 3153 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3154 | fail: |
| 3155 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3156 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3157 | return -ENOBUFS; |
| 3158 | } |
| 3159 | |
| 3160 | |
| 3161 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
| 3162 | int key_idx, int defkey, |
| 3163 | const u8 *seq, size_t seq_len, |
| 3164 | const u8 *key, size_t key_len) |
| 3165 | { |
| 3166 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3167 | u32 suite; |
| 3168 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3169 | if (!key_attr) |
| 3170 | return -1; |
| 3171 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3172 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 3173 | if (!suite) |
| 3174 | return -1; |
| 3175 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3176 | if (defkey && alg == WPA_ALG_IGTK) { |
| 3177 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) |
| 3178 | return -1; |
| 3179 | } else if (defkey) { |
| 3180 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) |
| 3181 | return -1; |
| 3182 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3183 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3184 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3185 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3186 | (seq && seq_len && |
| 3187 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || |
| 3188 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) |
| 3189 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3190 | |
| 3191 | nla_nest_end(msg, key_attr); |
| 3192 | |
| 3193 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3194 | } |
| 3195 | |
| 3196 | |
| 3197 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
| 3198 | struct nl_msg *msg) |
| 3199 | { |
| 3200 | int i, privacy = 0; |
| 3201 | struct nlattr *nl_keys, *nl_key; |
| 3202 | |
| 3203 | for (i = 0; i < 4; i++) { |
| 3204 | if (!params->wep_key[i]) |
| 3205 | continue; |
| 3206 | privacy = 1; |
| 3207 | break; |
| 3208 | } |
| 3209 | if (params->wps == WPS_MODE_PRIVACY) |
| 3210 | privacy = 1; |
| 3211 | if (params->pairwise_suite && |
| 3212 | params->pairwise_suite != WPA_CIPHER_NONE) |
| 3213 | privacy = 1; |
| 3214 | |
| 3215 | if (!privacy) |
| 3216 | return 0; |
| 3217 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3218 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 3219 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3220 | |
| 3221 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); |
| 3222 | if (!nl_keys) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3223 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3224 | |
| 3225 | for (i = 0; i < 4; i++) { |
| 3226 | if (!params->wep_key[i]) |
| 3227 | continue; |
| 3228 | |
| 3229 | nl_key = nla_nest_start(msg, i); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3230 | if (!nl_key || |
| 3231 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], |
| 3232 | params->wep_key[i]) || |
| 3233 | nla_put_u32(msg, NL80211_KEY_CIPHER, |
| 3234 | params->wep_key_len[i] == 5 ? |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3235 | RSN_CIPHER_SUITE_WEP40 : |
| 3236 | RSN_CIPHER_SUITE_WEP104) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3237 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
| 3238 | (i == params->wep_tx_keyidx && |
| 3239 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) |
| 3240 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3241 | |
| 3242 | nla_nest_end(msg, nl_key); |
| 3243 | } |
| 3244 | nla_nest_end(msg, nl_keys); |
| 3245 | |
| 3246 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3247 | } |
| 3248 | |
| 3249 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3250 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 3251 | const u8 *addr, int cmd, u16 reason_code, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3252 | int local_state_change, |
| 3253 | struct nl_handle *nl_connect) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3254 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3255 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3256 | struct nl_msg *msg; |
| 3257 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3258 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
| 3259 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
| 3260 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 3261 | (local_state_change && |
| 3262 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { |
| 3263 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3264 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3265 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3266 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3267 | if (nl_connect) |
| 3268 | ret = send_and_recv(drv->global, nl_connect, msg, NULL, NULL); |
| 3269 | else |
| 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) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3272 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 3273 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", |
| 3274 | reason_code, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3275 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3276 | return ret; |
| 3277 | } |
| 3278 | |
| 3279 | |
| 3280 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 3281 | u16 reason_code, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3282 | struct nl_handle *nl_connect) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3283 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3284 | int ret; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3285 | int drv_associated = drv->associated; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3286 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3287 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3288 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3289 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3290 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3291 | reason_code, 0, nl_connect); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3292 | /* |
| 3293 | * For locally generated disconnect, supplicant already generates a |
| 3294 | * DEAUTH event, so ignore the event from NL80211. |
| 3295 | */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3296 | drv->ignore_next_local_disconnect = drv_associated && (ret == 0); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3297 | |
| 3298 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3299 | } |
| 3300 | |
| 3301 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3302 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 3303 | const u8 *addr, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3304 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3305 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3306 | int ret; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3307 | int drv_associated = drv->associated; |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3308 | |
| 3309 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3310 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3311 | return nl80211_leave_ibss(drv, 1); |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3312 | } |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3313 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
| 3314 | struct nl_handle *nl_connect = NULL; |
| 3315 | |
| 3316 | if (bss->use_nl_connect) |
| 3317 | nl_connect = bss->nl_connect; |
| 3318 | return wpa_driver_nl80211_disconnect(drv, reason_code, |
| 3319 | nl_connect); |
| 3320 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3321 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
| 3322 | __func__, MAC2STR(addr), reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3323 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3324 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3325 | reason_code, 0, NULL); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3326 | /* |
| 3327 | * For locally generated deauthenticate, supplicant already generates a |
| 3328 | * DEAUTH event, so ignore the event from NL80211. |
| 3329 | */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3330 | drv->ignore_next_local_deauth = drv_associated && (ret == 0); |
| 3331 | |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3332 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3333 | } |
| 3334 | |
| 3335 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3336 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
| 3337 | struct wpa_driver_auth_params *params) |
| 3338 | { |
| 3339 | int i; |
| 3340 | |
| 3341 | drv->auth_freq = params->freq; |
| 3342 | drv->auth_alg = params->auth_alg; |
| 3343 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; |
| 3344 | drv->auth_local_state_change = params->local_state_change; |
| 3345 | drv->auth_p2p = params->p2p; |
| 3346 | |
| 3347 | if (params->bssid) |
| 3348 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); |
| 3349 | else |
| 3350 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); |
| 3351 | |
| 3352 | if (params->ssid) { |
| 3353 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); |
| 3354 | drv->auth_ssid_len = params->ssid_len; |
| 3355 | } else |
| 3356 | drv->auth_ssid_len = 0; |
| 3357 | |
| 3358 | |
| 3359 | os_free(drv->auth_ie); |
| 3360 | drv->auth_ie = NULL; |
| 3361 | drv->auth_ie_len = 0; |
| 3362 | if (params->ie) { |
| 3363 | drv->auth_ie = os_malloc(params->ie_len); |
| 3364 | if (drv->auth_ie) { |
| 3365 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); |
| 3366 | drv->auth_ie_len = params->ie_len; |
| 3367 | } |
| 3368 | } |
| 3369 | |
| 3370 | for (i = 0; i < 4; i++) { |
| 3371 | if (params->wep_key[i] && params->wep_key_len[i] && |
| 3372 | params->wep_key_len[i] <= 16) { |
| 3373 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], |
| 3374 | params->wep_key_len[i]); |
| 3375 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; |
| 3376 | } else |
| 3377 | drv->auth_wep_key_len[i] = 0; |
| 3378 | } |
| 3379 | } |
| 3380 | |
| 3381 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3382 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
| 3383 | { |
| 3384 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3385 | |
| 3386 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) |
| 3387 | return; |
| 3388 | |
| 3389 | /* |
| 3390 | * Looks like we failed to unmask 11b rates previously. This could |
| 3391 | * happen, e.g., if the interface was down at the point in time when a |
| 3392 | * P2P group was terminated. |
| 3393 | */ |
| 3394 | wpa_printf(MSG_DEBUG, |
| 3395 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", |
| 3396 | bss->ifname); |
| 3397 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 3398 | } |
| 3399 | |
| 3400 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3401 | static enum nl80211_auth_type get_nl_auth_type(int wpa_auth_alg) |
| 3402 | { |
| 3403 | if (wpa_auth_alg & WPA_AUTH_ALG_OPEN) |
| 3404 | return NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 3405 | if (wpa_auth_alg & WPA_AUTH_ALG_SHARED) |
| 3406 | return NL80211_AUTHTYPE_SHARED_KEY; |
| 3407 | if (wpa_auth_alg & WPA_AUTH_ALG_LEAP) |
| 3408 | return NL80211_AUTHTYPE_NETWORK_EAP; |
| 3409 | if (wpa_auth_alg & WPA_AUTH_ALG_FT) |
| 3410 | return NL80211_AUTHTYPE_FT; |
| 3411 | if (wpa_auth_alg & WPA_AUTH_ALG_SAE) |
| 3412 | return NL80211_AUTHTYPE_SAE; |
| 3413 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS) |
| 3414 | return NL80211_AUTHTYPE_FILS_SK; |
| 3415 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS_SK_PFS) |
| 3416 | return NL80211_AUTHTYPE_FILS_SK_PFS; |
| 3417 | |
| 3418 | return NL80211_AUTHTYPE_MAX; |
| 3419 | } |
| 3420 | |
| 3421 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3422 | static int wpa_driver_nl80211_authenticate( |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3423 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3424 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3425 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3426 | int ret = -1, i; |
| 3427 | struct nl_msg *msg; |
| 3428 | enum nl80211_auth_type type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3429 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3430 | int count = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3431 | int is_retry; |
| 3432 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3433 | nl80211_unmask_11b_rates(bss); |
| 3434 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3435 | is_retry = drv->retry_auth; |
| 3436 | drv->retry_auth = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3437 | drv->ignore_deauth_event = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3438 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3439 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3440 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3441 | if (params->bssid) |
| 3442 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 3443 | else |
| 3444 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3445 | /* FIX: IBSS mode */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3446 | nlmode = params->p2p ? |
| 3447 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 3448 | if (drv->nlmode != nlmode && |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3449 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3450 | return -1; |
| 3451 | |
| 3452 | retry: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3453 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
| 3454 | drv->ifindex); |
| 3455 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3456 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
| 3457 | if (!msg) |
| 3458 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3459 | |
| 3460 | for (i = 0; i < 4; i++) { |
| 3461 | if (!params->wep_key[i]) |
| 3462 | continue; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3463 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3464 | NULL, i, |
| 3465 | i == params->wep_tx_keyidx, NULL, 0, |
| 3466 | params->wep_key[i], |
| 3467 | params->wep_key_len[i]); |
| 3468 | if (params->wep_tx_keyidx != i) |
| 3469 | continue; |
| 3470 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3471 | params->wep_key[i], params->wep_key_len[i])) |
| 3472 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3473 | } |
| 3474 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3475 | if (params->bssid) { |
| 3476 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 3477 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3478 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 3479 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3480 | } |
| 3481 | if (params->freq) { |
| 3482 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3483 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
| 3484 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3485 | } |
| 3486 | if (params->ssid) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 3487 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
| 3488 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3489 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 3490 | params->ssid)) |
| 3491 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3492 | } |
| 3493 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3494 | if (params->ie && |
| 3495 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) |
| 3496 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3497 | if (params->auth_data) { |
| 3498 | wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data, |
| 3499 | params->auth_data_len); |
| 3500 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len, |
| 3501 | params->auth_data)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3502 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3503 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3504 | type = get_nl_auth_type(params->auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3505 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3506 | if (type == NL80211_AUTHTYPE_MAX || |
| 3507 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3508 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3509 | if (params->local_state_change) { |
| 3510 | wpa_printf(MSG_DEBUG, " * Local state change only"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3511 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
| 3512 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3516 | msg = NULL; |
| 3517 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3518 | wpa_dbg(drv->ctx, MSG_DEBUG, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3519 | "nl80211: MLME command failed (auth): count=%d ret=%d (%s)", |
| 3520 | count, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3521 | count++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3522 | if ((ret == -EALREADY || ret == -EEXIST) && count == 1 && |
| 3523 | params->bssid && !params->local_state_change) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3524 | /* |
| 3525 | * mac80211 does not currently accept new |
| 3526 | * authentication if we are already authenticated. As a |
| 3527 | * workaround, force deauthentication and try again. |
| 3528 | */ |
| 3529 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " |
| 3530 | "after forced deauthentication"); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3531 | drv->ignore_deauth_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3532 | wpa_driver_nl80211_deauthenticate( |
| 3533 | bss, params->bssid, |
| 3534 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 3535 | nlmsg_free(msg); |
| 3536 | goto retry; |
| 3537 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3538 | |
| 3539 | if (ret == -ENOENT && params->freq && !is_retry) { |
| 3540 | /* |
| 3541 | * cfg80211 has likely expired the BSS entry even |
| 3542 | * though it was previously available in our internal |
| 3543 | * BSS table. To recover quickly, start a single |
| 3544 | * channel scan on the specified channel. |
| 3545 | */ |
| 3546 | struct wpa_driver_scan_params scan; |
| 3547 | int freqs[2]; |
| 3548 | |
| 3549 | os_memset(&scan, 0, sizeof(scan)); |
| 3550 | scan.num_ssids = 1; |
| 3551 | if (params->ssid) { |
| 3552 | scan.ssids[0].ssid = params->ssid; |
| 3553 | scan.ssids[0].ssid_len = params->ssid_len; |
| 3554 | } |
| 3555 | freqs[0] = params->freq; |
| 3556 | freqs[1] = 0; |
| 3557 | scan.freqs = freqs; |
| 3558 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " |
| 3559 | "channel scan to refresh cfg80211 BSS " |
| 3560 | "entry"); |
| 3561 | ret = wpa_driver_nl80211_scan(bss, &scan); |
| 3562 | if (ret == 0) { |
| 3563 | nl80211_copy_auth_params(drv, params); |
| 3564 | drv->scan_for_auth = 1; |
| 3565 | } |
| 3566 | } else if (is_retry) { |
| 3567 | /* |
| 3568 | * Need to indicate this with an event since the return |
| 3569 | * value from the retry is not delivered to core code. |
| 3570 | */ |
| 3571 | union wpa_event_data event; |
| 3572 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " |
| 3573 | "failed"); |
| 3574 | os_memset(&event, 0, sizeof(event)); |
| 3575 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, |
| 3576 | ETH_ALEN); |
| 3577 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, |
| 3578 | &event); |
| 3579 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3580 | } else { |
| 3581 | wpa_printf(MSG_DEBUG, |
| 3582 | "nl80211: Authentication request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3583 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3584 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3585 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3586 | nlmsg_free(msg); |
| 3587 | return ret; |
| 3588 | } |
| 3589 | |
| 3590 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3591 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3592 | { |
| 3593 | struct wpa_driver_auth_params params; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3594 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3595 | int i; |
| 3596 | |
| 3597 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); |
| 3598 | |
| 3599 | os_memset(¶ms, 0, sizeof(params)); |
| 3600 | params.freq = drv->auth_freq; |
| 3601 | params.auth_alg = drv->auth_alg; |
| 3602 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; |
| 3603 | params.local_state_change = drv->auth_local_state_change; |
| 3604 | params.p2p = drv->auth_p2p; |
| 3605 | |
| 3606 | if (!is_zero_ether_addr(drv->auth_bssid_)) |
| 3607 | params.bssid = drv->auth_bssid_; |
| 3608 | |
| 3609 | if (drv->auth_ssid_len) { |
| 3610 | params.ssid = drv->auth_ssid; |
| 3611 | params.ssid_len = drv->auth_ssid_len; |
| 3612 | } |
| 3613 | |
| 3614 | params.ie = drv->auth_ie; |
| 3615 | params.ie_len = drv->auth_ie_len; |
| 3616 | |
| 3617 | for (i = 0; i < 4; i++) { |
| 3618 | if (drv->auth_wep_key_len[i]) { |
| 3619 | params.wep_key[i] = drv->auth_wep_key[i]; |
| 3620 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; |
| 3621 | } |
| 3622 | } |
| 3623 | |
| 3624 | drv->retry_auth = 1; |
| 3625 | return wpa_driver_nl80211_authenticate(bss, ¶ms); |
| 3626 | } |
| 3627 | |
| 3628 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3629 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
| 3630 | const void *data, size_t len, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3631 | int encrypt, int noack, |
| 3632 | unsigned int freq, int no_cck, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3633 | int offchanok, unsigned int wait_time, |
| 3634 | const u16 *csa_offs, |
| 3635 | size_t csa_offs_len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3636 | { |
| 3637 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3638 | u64 cookie; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3639 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3640 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 3641 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3642 | freq = nl80211_get_assoc_freq(drv); |
| 3643 | wpa_printf(MSG_DEBUG, |
| 3644 | "nl80211: send_frame - Use assoc_freq=%u for IBSS", |
| 3645 | freq); |
| 3646 | } |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3647 | if (freq == 0) { |
| 3648 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", |
| 3649 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3650 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3651 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3652 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3653 | if (drv->use_monitor) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3654 | wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3655 | freq, bss->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3656 | return nl80211_send_monitor(drv, data, len, encrypt, noack); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3657 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3658 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3659 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3660 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3661 | &cookie, no_cck, noack, offchanok, |
| 3662 | csa_offs, csa_offs_len); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3663 | if (res == 0 && !noack) { |
| 3664 | const struct ieee80211_mgmt *mgmt; |
| 3665 | u16 fc; |
| 3666 | |
| 3667 | mgmt = (const struct ieee80211_mgmt *) data; |
| 3668 | fc = le_to_host16(mgmt->frame_control); |
| 3669 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3670 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { |
| 3671 | wpa_printf(MSG_MSGDUMP, |
| 3672 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", |
| 3673 | (long long unsigned int) |
| 3674 | drv->send_action_cookie, |
| 3675 | (long long unsigned int) cookie); |
| 3676 | drv->send_action_cookie = cookie; |
| 3677 | } |
| 3678 | } |
| 3679 | |
| 3680 | return res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3681 | } |
| 3682 | |
| 3683 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3684 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
| 3685 | size_t data_len, int noack, |
| 3686 | unsigned int freq, int no_cck, |
| 3687 | int offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3688 | unsigned int wait_time, |
| 3689 | const u16 *csa_offs, |
| 3690 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3691 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3692 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3693 | struct ieee80211_mgmt *mgmt; |
| 3694 | int encrypt = 1; |
| 3695 | u16 fc; |
| 3696 | |
| 3697 | mgmt = (struct ieee80211_mgmt *) data; |
| 3698 | fc = le_to_host16(mgmt->frame_control); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 3699 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR |
| 3700 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d", |
| 3701 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, |
| 3702 | fc, fc2str(fc), drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3703 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3704 | if ((is_sta_interface(drv->nlmode) || |
| 3705 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3706 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3707 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { |
| 3708 | /* |
| 3709 | * The use of last_mgmt_freq is a bit of a hack, |
| 3710 | * but it works due to the single-threaded nature |
| 3711 | * of wpa_supplicant. |
| 3712 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3713 | if (freq == 0) { |
| 3714 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", |
| 3715 | drv->last_mgmt_freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3716 | freq = drv->last_mgmt_freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3717 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3718 | return nl80211_send_frame_cmd(bss, freq, 0, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3719 | data, data_len, NULL, 1, noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3720 | 1, csa_offs, csa_offs_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3721 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3722 | |
| 3723 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3724 | if (freq == 0) { |
| 3725 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", |
| 3726 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3727 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3728 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3729 | return nl80211_send_frame_cmd(bss, freq, |
| 3730 | (int) freq == bss->freq ? 0 : |
| 3731 | wait_time, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3732 | data, data_len, |
| 3733 | &drv->send_action_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3734 | no_cck, noack, offchanok, |
| 3735 | csa_offs, csa_offs_len); |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 3736 | } |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 3737 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3738 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3739 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 3740 | /* |
| 3741 | * Only one of the authentication frame types is encrypted. |
| 3742 | * In order for static WEP encryption to work properly (i.e., |
| 3743 | * to not encrypt the frame), we need to tell mac80211 about |
| 3744 | * the frames that must not be encrypted. |
| 3745 | */ |
| 3746 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 3747 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); |
| 3748 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
| 3749 | encrypt = 0; |
| 3750 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3751 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3752 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3753 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3754 | noack, freq, no_cck, offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3755 | wait_time, csa_offs, |
| 3756 | csa_offs_len); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3757 | } |
| 3758 | |
| 3759 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3760 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
| 3761 | { |
| 3762 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 3763 | u8 rates_len = 0; |
| 3764 | int i; |
| 3765 | |
| 3766 | if (!basic_rates) |
| 3767 | return 0; |
| 3768 | |
| 3769 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) |
| 3770 | rates[rates_len++] = basic_rates[i] / 5; |
| 3771 | |
| 3772 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); |
| 3773 | } |
| 3774 | |
| 3775 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3776 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
| 3777 | int slot, int ht_opmode, int ap_isolate, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3778 | const int *basic_rates) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3779 | { |
| 3780 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3781 | struct nl_msg *msg; |
| 3782 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3783 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
| 3784 | (cts >= 0 && |
| 3785 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || |
| 3786 | (preamble >= 0 && |
| 3787 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || |
| 3788 | (slot >= 0 && |
| 3789 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || |
| 3790 | (ht_opmode >= 0 && |
| 3791 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || |
| 3792 | (ap_isolate >= 0 && |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3793 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
| 3794 | nl80211_put_basic_rates(msg, basic_rates)) { |
| 3795 | nlmsg_free(msg); |
| 3796 | return -ENOBUFS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3797 | } |
| 3798 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3799 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3800 | } |
| 3801 | |
| 3802 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3803 | static int wpa_driver_nl80211_set_acl(void *priv, |
| 3804 | struct hostapd_acl_params *params) |
| 3805 | { |
| 3806 | struct i802_bss *bss = priv; |
| 3807 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3808 | struct nl_msg *msg; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3809 | struct nl_msg *acl; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3810 | unsigned int i; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3811 | int ret; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3812 | |
| 3813 | if (!(drv->capa.max_acl_mac_addrs)) |
| 3814 | return -ENOTSUP; |
| 3815 | |
| 3816 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) |
| 3817 | return -ENOTSUP; |
| 3818 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3819 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
| 3820 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); |
| 3821 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3822 | acl = nlmsg_alloc(); |
| 3823 | if (!acl) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3824 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3825 | for (i = 0; i < params->num_mac_acl; i++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3826 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { |
| 3827 | nlmsg_free(acl); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3828 | return -ENOMEM; |
| 3829 | } |
| 3830 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3831 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3832 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
| 3833 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
| 3834 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : |
| 3835 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || |
| 3836 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
| 3837 | nlmsg_free(msg); |
| 3838 | nlmsg_free(acl); |
| 3839 | return -ENOMEM; |
| 3840 | } |
| 3841 | nlmsg_free(acl); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3842 | |
| 3843 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3844 | if (ret) { |
| 3845 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", |
| 3846 | ret, strerror(-ret)); |
| 3847 | } |
| 3848 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3849 | return ret; |
| 3850 | } |
| 3851 | |
| 3852 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3853 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
| 3854 | { |
| 3855 | if (beacon_int > 0) { |
| 3856 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); |
| 3857 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 3858 | beacon_int); |
| 3859 | } |
| 3860 | |
| 3861 | return 0; |
| 3862 | } |
| 3863 | |
| 3864 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3865 | static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period) |
| 3866 | { |
| 3867 | if (dtim_period > 0) { |
| 3868 | wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period); |
| 3869 | return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); |
| 3870 | } |
| 3871 | |
| 3872 | return 0; |
| 3873 | } |
| 3874 | |
| 3875 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3876 | #ifdef CONFIG_MESH |
| 3877 | static int nl80211_set_mesh_config(void *priv, |
| 3878 | struct wpa_driver_mesh_bss_params *params) |
| 3879 | { |
| 3880 | struct i802_bss *bss = priv; |
| 3881 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3882 | struct nl_msg *msg; |
| 3883 | int ret; |
| 3884 | |
| 3885 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG); |
| 3886 | if (!msg) |
| 3887 | return -1; |
| 3888 | |
| 3889 | ret = nl80211_put_mesh_config(msg, params); |
| 3890 | if (ret < 0) { |
| 3891 | nlmsg_free(msg); |
| 3892 | return ret; |
| 3893 | } |
| 3894 | |
| 3895 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3896 | if (ret) { |
| 3897 | wpa_printf(MSG_ERROR, |
| 3898 | "nl80211: Mesh config set failed: %d (%s)", |
| 3899 | ret, strerror(-ret)); |
| 3900 | return ret; |
| 3901 | } |
| 3902 | return 0; |
| 3903 | } |
| 3904 | #endif /* CONFIG_MESH */ |
| 3905 | |
| 3906 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3907 | static int nl80211_put_beacon_rate(struct nl_msg *msg, const u64 flags, |
| 3908 | struct wpa_driver_ap_params *params) |
| 3909 | { |
| 3910 | struct nlattr *bands, *band; |
| 3911 | struct nl80211_txrate_vht vht_rate; |
| 3912 | |
| 3913 | if (!params->freq || |
| 3914 | (params->beacon_rate == 0 && |
| 3915 | params->rate_type == BEACON_RATE_LEGACY)) |
| 3916 | return 0; |
| 3917 | |
| 3918 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 3919 | if (!bands) |
| 3920 | return -1; |
| 3921 | |
| 3922 | switch (params->freq->mode) { |
| 3923 | case HOSTAPD_MODE_IEEE80211B: |
| 3924 | case HOSTAPD_MODE_IEEE80211G: |
| 3925 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
| 3926 | break; |
| 3927 | case HOSTAPD_MODE_IEEE80211A: |
| 3928 | band = nla_nest_start(msg, NL80211_BAND_5GHZ); |
| 3929 | break; |
| 3930 | case HOSTAPD_MODE_IEEE80211AD: |
| 3931 | band = nla_nest_start(msg, NL80211_BAND_60GHZ); |
| 3932 | break; |
| 3933 | default: |
| 3934 | return 0; |
| 3935 | } |
| 3936 | |
| 3937 | if (!band) |
| 3938 | return -1; |
| 3939 | |
| 3940 | os_memset(&vht_rate, 0, sizeof(vht_rate)); |
| 3941 | |
| 3942 | switch (params->rate_type) { |
| 3943 | case BEACON_RATE_LEGACY: |
| 3944 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) { |
| 3945 | wpa_printf(MSG_INFO, |
| 3946 | "nl80211: Driver does not support setting Beacon frame rate (legacy)"); |
| 3947 | return -1; |
| 3948 | } |
| 3949 | |
| 3950 | if (nla_put_u8(msg, NL80211_TXRATE_LEGACY, |
| 3951 | (u8) params->beacon_rate / 5) || |
| 3952 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || |
| 3953 | (params->freq->vht_enabled && |
| 3954 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 3955 | &vht_rate))) |
| 3956 | return -1; |
| 3957 | |
| 3958 | wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)", |
| 3959 | params->beacon_rate); |
| 3960 | break; |
| 3961 | case BEACON_RATE_HT: |
| 3962 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) { |
| 3963 | wpa_printf(MSG_INFO, |
| 3964 | "nl80211: Driver does not support setting Beacon frame rate (HT)"); |
| 3965 | return -1; |
| 3966 | } |
| 3967 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || |
| 3968 | nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) || |
| 3969 | (params->freq->vht_enabled && |
| 3970 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 3971 | &vht_rate))) |
| 3972 | return -1; |
| 3973 | wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u", |
| 3974 | params->beacon_rate); |
| 3975 | break; |
| 3976 | case BEACON_RATE_VHT: |
| 3977 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) { |
| 3978 | wpa_printf(MSG_INFO, |
| 3979 | "nl80211: Driver does not support setting Beacon frame rate (VHT)"); |
| 3980 | return -1; |
| 3981 | } |
| 3982 | vht_rate.mcs[0] = BIT(params->beacon_rate); |
| 3983 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL)) |
| 3984 | return -1; |
| 3985 | if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL)) |
| 3986 | return -1; |
| 3987 | if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 3988 | &vht_rate)) |
| 3989 | return -1; |
| 3990 | wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u", |
| 3991 | params->beacon_rate); |
| 3992 | break; |
| 3993 | } |
| 3994 | |
| 3995 | nla_nest_end(msg, band); |
| 3996 | nla_nest_end(msg, bands); |
| 3997 | |
| 3998 | return 0; |
| 3999 | } |
| 4000 | |
| 4001 | |
| 4002 | static int nl80211_set_multicast_to_unicast(struct i802_bss *bss, |
| 4003 | int multicast_to_unicast) |
| 4004 | { |
| 4005 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4006 | struct nl_msg *msg; |
| 4007 | int ret; |
| 4008 | |
| 4009 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST); |
| 4010 | if (!msg || |
| 4011 | (multicast_to_unicast && |
| 4012 | nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) { |
| 4013 | wpa_printf(MSG_ERROR, |
| 4014 | "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s", |
| 4015 | bss->ifname); |
| 4016 | nlmsg_free(msg); |
| 4017 | return -ENOBUFS; |
| 4018 | } |
| 4019 | |
| 4020 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4021 | |
| 4022 | switch (ret) { |
| 4023 | case 0: |
| 4024 | wpa_printf(MSG_DEBUG, |
| 4025 | "nl80211: multicast to unicast %s on interface %s", |
| 4026 | multicast_to_unicast ? "enabled" : "disabled", |
| 4027 | bss->ifname); |
| 4028 | break; |
| 4029 | case -EOPNOTSUPP: |
| 4030 | if (!multicast_to_unicast) |
| 4031 | break; |
| 4032 | wpa_printf(MSG_INFO, |
| 4033 | "nl80211: multicast to unicast not supported on interface %s", |
| 4034 | bss->ifname); |
| 4035 | break; |
| 4036 | default: |
| 4037 | wpa_printf(MSG_ERROR, |
| 4038 | "nl80211: %s multicast to unicast failed with %d (%s) on interface %s", |
| 4039 | multicast_to_unicast ? "enabling" : "disabling", |
| 4040 | ret, strerror(-ret), bss->ifname); |
| 4041 | break; |
| 4042 | } |
| 4043 | |
| 4044 | return ret; |
| 4045 | } |
| 4046 | |
| 4047 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4048 | static int wpa_driver_nl80211_set_ap(void *priv, |
| 4049 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4050 | { |
| 4051 | struct i802_bss *bss = priv; |
| 4052 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4053 | struct nl_msg *msg; |
| 4054 | u8 cmd = NL80211_CMD_NEW_BEACON; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4055 | int ret = -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4056 | int beacon_set; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4057 | int num_suites; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4058 | int smps_mode; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4059 | u32 suites[10], suite; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4060 | u32 ver; |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4061 | #ifdef CONFIG_MESH |
| 4062 | struct wpa_driver_mesh_bss_params mesh_params; |
| 4063 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4064 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4065 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4066 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4067 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
| 4068 | beacon_set); |
| 4069 | if (beacon_set) |
| 4070 | cmd = NL80211_CMD_SET_BEACON; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4071 | else if (!drv->device_ap_sme && !drv->use_monitor && |
| 4072 | !nl80211_get_wiphy_data_ap(bss)) |
| 4073 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4074 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4075 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
| 4076 | params->head, params->head_len); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4077 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
| 4078 | params->tail, params->tail_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4079 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4080 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4081 | wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate); |
| 4082 | wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4083 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4084 | wpa_printf(MSG_DEBUG, "nl80211: ssid=%s", |
| 4085 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4086 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 4087 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
| 4088 | params->head) || |
| 4089 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, |
| 4090 | params->tail) || |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4091 | nl80211_put_beacon_int(msg, params->beacon_int) || |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4092 | nl80211_put_beacon_rate(msg, drv->capa.flags, params) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4093 | nl80211_put_dtim_period(msg, params->dtim_period) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4094 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 4095 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4096 | if (params->proberesp && params->proberesp_len) { |
| 4097 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", |
| 4098 | params->proberesp, params->proberesp_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4099 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
| 4100 | params->proberesp)) |
| 4101 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4102 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4103 | switch (params->hide_ssid) { |
| 4104 | case NO_SSID_HIDING: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4105 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4106 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 4107 | NL80211_HIDDEN_SSID_NOT_IN_USE)) |
| 4108 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4109 | break; |
| 4110 | case HIDDEN_SSID_ZERO_LEN: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4111 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4112 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 4113 | NL80211_HIDDEN_SSID_ZERO_LEN)) |
| 4114 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4115 | break; |
| 4116 | case HIDDEN_SSID_ZERO_CONTENTS: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4117 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4118 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 4119 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) |
| 4120 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4121 | break; |
| 4122 | } |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4123 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4124 | if (params->privacy && |
| 4125 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 4126 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4127 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4128 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
| 4129 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { |
| 4130 | /* Leave out the attribute */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4131 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
| 4132 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 4133 | NL80211_AUTHTYPE_SHARED_KEY)) |
| 4134 | goto fail; |
| 4135 | } else { |
| 4136 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 4137 | NL80211_AUTHTYPE_OPEN_SYSTEM)) |
| 4138 | goto fail; |
| 4139 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4140 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4141 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4142 | ver = 0; |
| 4143 | if (params->wpa_version & WPA_PROTO_WPA) |
| 4144 | ver |= NL80211_WPA_VERSION_1; |
| 4145 | if (params->wpa_version & WPA_PROTO_RSN) |
| 4146 | ver |= NL80211_WPA_VERSION_2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4147 | if (ver && |
| 4148 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 4149 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4150 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4151 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
| 4152 | params->key_mgmt_suites); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4153 | num_suites = 0; |
| 4154 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4155 | suites[num_suites++] = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4156 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4157 | suites[num_suites++] = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4158 | if (num_suites && |
| 4159 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), |
| 4160 | suites)) |
| 4161 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4162 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4163 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4164 | (!params->pairwise_ciphers || |
| 4165 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) && |
| 4166 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 4167 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4168 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4169 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 4170 | if (drv->device_ap_sme && |
| 4171 | (params->key_mgmt_suites & WPA_KEY_MGMT_SAE) && |
| 4172 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) |
| 4173 | goto fail; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 4174 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4175 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
| 4176 | params->pairwise_ciphers); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4177 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
| 4178 | suites, ARRAY_SIZE(suites)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4179 | if (num_suites && |
| 4180 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 4181 | num_suites * sizeof(u32), suites)) |
| 4182 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4183 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4184 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
| 4185 | params->group_cipher); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4186 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4187 | if (suite && |
| 4188 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) |
| 4189 | goto fail; |
| 4190 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 4191 | if (params->ht_opmode != -1) { |
| 4192 | switch (params->smps_mode) { |
| 4193 | case HT_CAP_INFO_SMPS_DYNAMIC: |
| 4194 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic"); |
| 4195 | smps_mode = NL80211_SMPS_DYNAMIC; |
| 4196 | break; |
| 4197 | case HT_CAP_INFO_SMPS_STATIC: |
| 4198 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static"); |
| 4199 | smps_mode = NL80211_SMPS_STATIC; |
| 4200 | break; |
| 4201 | default: |
| 4202 | /* invalid - fallback to smps off */ |
| 4203 | case HT_CAP_INFO_SMPS_DISABLED: |
| 4204 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off"); |
| 4205 | smps_mode = NL80211_SMPS_OFF; |
| 4206 | break; |
| 4207 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4208 | if (nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, smps_mode)) |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 4209 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4210 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4211 | |
| 4212 | if (params->beacon_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4213 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
| 4214 | params->beacon_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4215 | if (nla_put(msg, NL80211_ATTR_IE, |
| 4216 | wpabuf_len(params->beacon_ies), |
| 4217 | wpabuf_head(params->beacon_ies))) |
| 4218 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4219 | } |
| 4220 | if (params->proberesp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4221 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
| 4222 | params->proberesp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4223 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 4224 | wpabuf_len(params->proberesp_ies), |
| 4225 | wpabuf_head(params->proberesp_ies))) |
| 4226 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4227 | } |
| 4228 | if (params->assocresp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4229 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
| 4230 | params->assocresp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4231 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 4232 | wpabuf_len(params->assocresp_ies), |
| 4233 | wpabuf_head(params->assocresp_ies))) |
| 4234 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4235 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4236 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4237 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4238 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
| 4239 | params->ap_max_inactivity); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4240 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
| 4241 | params->ap_max_inactivity)) |
| 4242 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4243 | } |
| 4244 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4245 | #ifdef CONFIG_P2P |
| 4246 | if (params->p2p_go_ctwindow > 0) { |
| 4247 | if (drv->p2p_go_ctwindow_supported) { |
| 4248 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", |
| 4249 | params->p2p_go_ctwindow); |
| 4250 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, |
| 4251 | params->p2p_go_ctwindow)) |
| 4252 | goto fail; |
| 4253 | } else { |
| 4254 | wpa_printf(MSG_INFO, |
| 4255 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); |
| 4256 | } |
| 4257 | } |
| 4258 | #endif /* CONFIG_P2P */ |
| 4259 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4260 | if (params->pbss) { |
| 4261 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); |
| 4262 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 4263 | goto fail; |
| 4264 | } |
| 4265 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4266 | if (params->ftm_responder) { |
| 4267 | struct nlattr *ftm; |
| 4268 | |
| 4269 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_FTM_RESPONDER)) { |
| 4270 | ret = -ENOTSUP; |
| 4271 | goto fail; |
| 4272 | } |
| 4273 | |
| 4274 | ftm = nla_nest_start(msg, NL80211_ATTR_FTM_RESPONDER); |
| 4275 | if (!ftm || |
| 4276 | nla_put_flag(msg, NL80211_FTM_RESP_ATTR_ENABLED) || |
| 4277 | (params->lci && |
| 4278 | nla_put(msg, NL80211_FTM_RESP_ATTR_LCI, |
| 4279 | wpabuf_len(params->lci), |
| 4280 | wpabuf_head(params->lci))) || |
| 4281 | (params->civic && |
| 4282 | nla_put(msg, NL80211_FTM_RESP_ATTR_CIVICLOC, |
| 4283 | wpabuf_len(params->civic), |
| 4284 | wpabuf_head(params->civic)))) |
| 4285 | goto fail; |
| 4286 | nla_nest_end(msg, ftm); |
| 4287 | } |
| 4288 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4289 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4290 | if (ret) { |
| 4291 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", |
| 4292 | ret, strerror(-ret)); |
| 4293 | } else { |
| 4294 | bss->beacon_set = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4295 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
| 4296 | params->short_slot_time, params->ht_opmode, |
| 4297 | params->isolate, params->basic_rates); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4298 | nl80211_set_multicast_to_unicast(bss, |
| 4299 | params->multicast_to_unicast); |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4300 | if (beacon_set && params->freq && |
| 4301 | params->freq->bandwidth != bss->bandwidth) { |
| 4302 | wpa_printf(MSG_DEBUG, |
| 4303 | "nl80211: Update BSS %s bandwidth: %d -> %d", |
| 4304 | bss->ifname, bss->bandwidth, |
| 4305 | params->freq->bandwidth); |
| 4306 | ret = nl80211_set_channel(bss, params->freq, 1); |
| 4307 | if (ret) { |
| 4308 | wpa_printf(MSG_DEBUG, |
| 4309 | "nl80211: Frequency set failed: %d (%s)", |
| 4310 | ret, strerror(-ret)); |
| 4311 | } else { |
| 4312 | wpa_printf(MSG_DEBUG, |
| 4313 | "nl80211: Frequency set succeeded for ht2040 coex"); |
| 4314 | bss->bandwidth = params->freq->bandwidth; |
| 4315 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4316 | } else if (!beacon_set && params->freq) { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4317 | /* |
| 4318 | * cfg80211 updates the driver on frequence change in AP |
| 4319 | * mode only at the point when beaconing is started, so |
| 4320 | * set the initial value here. |
| 4321 | */ |
| 4322 | bss->bandwidth = params->freq->bandwidth; |
| 4323 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4324 | } |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4325 | |
| 4326 | #ifdef CONFIG_MESH |
| 4327 | if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) { |
| 4328 | os_memset(&mesh_params, 0, sizeof(mesh_params)); |
| 4329 | mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE; |
| 4330 | mesh_params.ht_opmode = params->ht_opmode; |
| 4331 | ret = nl80211_set_mesh_config(priv, &mesh_params); |
| 4332 | if (ret < 0) |
| 4333 | return ret; |
| 4334 | } |
| 4335 | #endif /* CONFIG_MESH */ |
| 4336 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4337 | return ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4338 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4339 | nlmsg_free(msg); |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 4340 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4341 | } |
| 4342 | |
| 4343 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4344 | static int nl80211_put_freq_params(struct nl_msg *msg, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4345 | const struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4346 | { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4347 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4348 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
| 4349 | return -ENOBUFS; |
| 4350 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 4351 | wpa_printf(MSG_DEBUG, " * he_enabled=%d", freq->he_enabled); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4352 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
| 4353 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); |
| 4354 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 4355 | if (freq->vht_enabled || freq->he_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4356 | enum nl80211_chan_width cw; |
| 4357 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4358 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4359 | switch (freq->bandwidth) { |
| 4360 | case 20: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4361 | cw = NL80211_CHAN_WIDTH_20; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4362 | break; |
| 4363 | case 40: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4364 | cw = NL80211_CHAN_WIDTH_40; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4365 | break; |
| 4366 | case 80: |
| 4367 | if (freq->center_freq2) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4368 | cw = NL80211_CHAN_WIDTH_80P80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4369 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4370 | cw = NL80211_CHAN_WIDTH_80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4371 | break; |
| 4372 | case 160: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4373 | cw = NL80211_CHAN_WIDTH_160; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4374 | break; |
| 4375 | default: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4376 | return -EINVAL; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4377 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4378 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4379 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
| 4380 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", |
| 4381 | freq->center_freq1); |
| 4382 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", |
| 4383 | freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4384 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
| 4385 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, |
| 4386 | freq->center_freq1) || |
| 4387 | (freq->center_freq2 && |
| 4388 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 4389 | freq->center_freq2))) |
| 4390 | return -ENOBUFS; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4391 | } else if (freq->ht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4392 | enum nl80211_channel_type ct; |
| 4393 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4394 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
| 4395 | freq->sec_channel_offset); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4396 | switch (freq->sec_channel_offset) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4397 | case -1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4398 | ct = NL80211_CHAN_HT40MINUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4399 | break; |
| 4400 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4401 | ct = NL80211_CHAN_HT40PLUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4402 | break; |
| 4403 | default: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4404 | ct = NL80211_CHAN_HT20; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4405 | break; |
| 4406 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4407 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4408 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4409 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
| 4410 | return -ENOBUFS; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4411 | } else { |
| 4412 | wpa_printf(MSG_DEBUG, " * channel_type=%d", |
| 4413 | NL80211_CHAN_NO_HT); |
| 4414 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 4415 | NL80211_CHAN_NO_HT)) |
| 4416 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4417 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4418 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4419 | } |
| 4420 | |
| 4421 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4422 | static int nl80211_set_channel(struct i802_bss *bss, |
| 4423 | struct hostapd_freq_params *freq, int set_chan) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4424 | { |
| 4425 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4426 | struct nl_msg *msg; |
| 4427 | int ret; |
| 4428 | |
| 4429 | wpa_printf(MSG_DEBUG, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 4430 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, he_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
| 4431 | freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4432 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4433 | |
| 4434 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
| 4435 | NL80211_CMD_SET_WIPHY); |
| 4436 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { |
| 4437 | nlmsg_free(msg); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4438 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4439 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4440 | |
| 4441 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4442 | if (ret == 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4443 | bss->freq = freq->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4444 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4445 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4446 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4447 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4448 | return -1; |
| 4449 | } |
| 4450 | |
| 4451 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4452 | static u32 sta_flags_nl80211(int flags) |
| 4453 | { |
| 4454 | u32 f = 0; |
| 4455 | |
| 4456 | if (flags & WPA_STA_AUTHORIZED) |
| 4457 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 4458 | if (flags & WPA_STA_WMM) |
| 4459 | f |= BIT(NL80211_STA_FLAG_WME); |
| 4460 | if (flags & WPA_STA_SHORT_PREAMBLE) |
| 4461 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
| 4462 | if (flags & WPA_STA_MFP) |
| 4463 | f |= BIT(NL80211_STA_FLAG_MFP); |
| 4464 | if (flags & WPA_STA_TDLS_PEER) |
| 4465 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4466 | if (flags & WPA_STA_AUTHENTICATED) |
| 4467 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4468 | if (flags & WPA_STA_ASSOCIATED) |
| 4469 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4470 | |
| 4471 | return f; |
| 4472 | } |
| 4473 | |
| 4474 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4475 | #ifdef CONFIG_MESH |
| 4476 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) |
| 4477 | { |
| 4478 | switch (state) { |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4479 | case PLINK_IDLE: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4480 | return NL80211_PLINK_LISTEN; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4481 | case PLINK_OPN_SNT: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4482 | return NL80211_PLINK_OPN_SNT; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4483 | case PLINK_OPN_RCVD: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4484 | return NL80211_PLINK_OPN_RCVD; |
| 4485 | case PLINK_CNF_RCVD: |
| 4486 | return NL80211_PLINK_CNF_RCVD; |
| 4487 | case PLINK_ESTAB: |
| 4488 | return NL80211_PLINK_ESTAB; |
| 4489 | case PLINK_HOLDING: |
| 4490 | return NL80211_PLINK_HOLDING; |
| 4491 | case PLINK_BLOCKED: |
| 4492 | return NL80211_PLINK_BLOCKED; |
| 4493 | default: |
| 4494 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", |
| 4495 | state); |
| 4496 | } |
| 4497 | return -1; |
| 4498 | } |
| 4499 | #endif /* CONFIG_MESH */ |
| 4500 | |
| 4501 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4502 | static int wpa_driver_nl80211_sta_add(void *priv, |
| 4503 | struct hostapd_sta_add_params *params) |
| 4504 | { |
| 4505 | struct i802_bss *bss = priv; |
| 4506 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4507 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4508 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4509 | int ret = -ENOBUFS; |
| 4510 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4511 | if ((params->flags & WPA_STA_TDLS_PEER) && |
| 4512 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 4513 | return -EOPNOTSUPP; |
| 4514 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4515 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
| 4516 | params->set ? "Set" : "Add", MAC2STR(params->addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4517 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
| 4518 | NL80211_CMD_NEW_STATION); |
| 4519 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) |
| 4520 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4521 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4522 | /* |
| 4523 | * Set the below properties only in one of the following cases: |
| 4524 | * 1. New station is added, already associated. |
| 4525 | * 2. Set WPA_STA_TDLS_PEER station. |
| 4526 | * 3. Set an already added unassociated station, if driver supports |
| 4527 | * full AP client state. (Set these properties after station became |
| 4528 | * associated will be rejected by the driver). |
| 4529 | */ |
| 4530 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
| 4531 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 4532 | (params->flags & WPA_STA_ASSOCIATED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4533 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
| 4534 | params->supp_rates, params->supp_rates_len); |
| 4535 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
| 4536 | params->capability); |
| 4537 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, |
| 4538 | params->supp_rates_len, params->supp_rates) || |
| 4539 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, |
| 4540 | params->capability)) |
| 4541 | goto fail; |
| 4542 | |
| 4543 | if (params->ht_capabilities) { |
| 4544 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
| 4545 | (u8 *) params->ht_capabilities, |
| 4546 | sizeof(*params->ht_capabilities)); |
| 4547 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
| 4548 | sizeof(*params->ht_capabilities), |
| 4549 | params->ht_capabilities)) |
| 4550 | goto fail; |
| 4551 | } |
| 4552 | |
| 4553 | if (params->vht_capabilities) { |
| 4554 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
| 4555 | (u8 *) params->vht_capabilities, |
| 4556 | sizeof(*params->vht_capabilities)); |
| 4557 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
| 4558 | sizeof(*params->vht_capabilities), |
| 4559 | params->vht_capabilities)) |
| 4560 | goto fail; |
| 4561 | } |
| 4562 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 4563 | if (params->he_capab) { |
| 4564 | wpa_hexdump(MSG_DEBUG, " * he_capab", |
| 4565 | params->he_capab, params->he_capab_len); |
| 4566 | if (nla_put(msg, NL80211_ATTR_HE_CAPABILITY, |
| 4567 | params->he_capab_len, params->he_capab)) |
| 4568 | goto fail; |
| 4569 | } |
| 4570 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4571 | if (params->ext_capab) { |
| 4572 | wpa_hexdump(MSG_DEBUG, " * ext_capab", |
| 4573 | params->ext_capab, params->ext_capab_len); |
| 4574 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
| 4575 | params->ext_capab_len, params->ext_capab)) |
| 4576 | goto fail; |
| 4577 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4578 | |
| 4579 | if (is_ap_interface(drv->nlmode) && |
| 4580 | nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS, |
| 4581 | params->support_p2p_ps ? |
| 4582 | NL80211_P2P_PS_SUPPORTED : |
| 4583 | NL80211_P2P_PS_UNSUPPORTED)) |
| 4584 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4585 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4586 | if (!params->set) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4587 | if (params->aid) { |
| 4588 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4589 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
| 4590 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4591 | } else { |
| 4592 | /* |
| 4593 | * cfg80211 validates that AID is non-zero, so we have |
| 4594 | * to make this a non-zero value for the TDLS case where |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4595 | * a dummy STA entry is used for now and for a station |
| 4596 | * that is still not associated. |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4597 | */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4598 | wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)", |
| 4599 | (params->flags & WPA_STA_TDLS_PEER) ? |
| 4600 | "TDLS" : "UNASSOC_STA"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4601 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
| 4602 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4603 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4604 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 4605 | params->listen_interval); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4606 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 4607 | params->listen_interval)) |
| 4608 | goto fail; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4609 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
| 4610 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4611 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
| 4612 | goto fail; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4613 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 4614 | (params->flags & WPA_STA_ASSOCIATED)) { |
| 4615 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
| 4616 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 4617 | params->listen_interval); |
| 4618 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || |
| 4619 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 4620 | params->listen_interval)) |
| 4621 | goto fail; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4622 | } |
| 4623 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 4624 | if (params->vht_opmode_enabled) { |
| 4625 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4626 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
| 4627 | params->vht_opmode)) |
| 4628 | goto fail; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4629 | } |
| 4630 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4631 | if (params->supp_channels) { |
| 4632 | wpa_hexdump(MSG_DEBUG, " * supported channels", |
| 4633 | params->supp_channels, params->supp_channels_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4634 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
| 4635 | params->supp_channels_len, params->supp_channels)) |
| 4636 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4637 | } |
| 4638 | |
| 4639 | if (params->supp_oper_classes) { |
| 4640 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", |
| 4641 | params->supp_oper_classes, |
| 4642 | params->supp_oper_classes_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4643 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
| 4644 | params->supp_oper_classes_len, |
| 4645 | params->supp_oper_classes)) |
| 4646 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4647 | } |
| 4648 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4649 | os_memset(&upd, 0, sizeof(upd)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4650 | upd.set = sta_flags_nl80211(params->flags); |
| 4651 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4652 | |
| 4653 | /* |
| 4654 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH |
| 4655 | * flags, as nl80211 driver moves a new station, by default, into |
| 4656 | * associated state. |
| 4657 | * |
| 4658 | * On the other hand, if the driver supports that feature and the |
| 4659 | * station is added in unauthenticated state, set the |
| 4660 | * authenticated/associated bits in the mask to prevent moving this |
| 4661 | * station to associated state before it is actually associated. |
| 4662 | * |
| 4663 | * This is irrelevant for mesh mode where the station is added to the |
| 4664 | * driver as authenticated already, and ASSOCIATED isn't part of the |
| 4665 | * nl80211 API. |
| 4666 | */ |
| 4667 | if (!is_mesh_interface(drv->nlmode)) { |
| 4668 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { |
| 4669 | wpa_printf(MSG_DEBUG, |
| 4670 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); |
| 4671 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4672 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); |
| 4673 | } else if (!params->set && |
| 4674 | !(params->flags & WPA_STA_TDLS_PEER)) { |
| 4675 | if (!(params->flags & WPA_STA_AUTHENTICATED)) |
| 4676 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
| 4677 | if (!(params->flags & WPA_STA_ASSOCIATED)) |
| 4678 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 4679 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4680 | #ifdef CONFIG_MESH |
| 4681 | } else { |
| 4682 | if (params->plink_state == PLINK_ESTAB && params->peer_aid) { |
| 4683 | ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID, |
| 4684 | params->peer_aid); |
| 4685 | if (ret) |
| 4686 | goto fail; |
| 4687 | } |
| 4688 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4689 | } |
| 4690 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4691 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
| 4692 | upd.set, upd.mask); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4693 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 4694 | goto fail; |
| 4695 | |
| 4696 | #ifdef CONFIG_MESH |
| 4697 | if (params->plink_state && |
| 4698 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, |
| 4699 | sta_plink_state_nl80211(params->plink_state))) |
| 4700 | goto fail; |
| 4701 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4702 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 4703 | if ((!params->set || FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) && |
| 4704 | (params->flags & WPA_STA_WMM)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4705 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 4706 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4707 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4708 | if (!wme || |
| 4709 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 4710 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || |
| 4711 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, |
| 4712 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
| 4713 | WMM_QOSINFO_STA_SP_MASK)) |
| 4714 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4715 | nla_nest_end(msg, wme); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4716 | } |
| 4717 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4718 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4719 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4720 | if (ret) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4721 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
| 4722 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, |
| 4723 | strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4724 | if (ret == -EEXIST) |
| 4725 | ret = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4726 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4727 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4728 | return ret; |
| 4729 | } |
| 4730 | |
| 4731 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4732 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
| 4733 | { |
| 4734 | #ifdef CONFIG_LIBNL3_ROUTE |
| 4735 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4736 | struct rtnl_neigh *rn; |
| 4737 | struct nl_addr *nl_addr; |
| 4738 | int err; |
| 4739 | |
| 4740 | rn = rtnl_neigh_alloc(); |
| 4741 | if (!rn) |
| 4742 | return; |
| 4743 | |
| 4744 | rtnl_neigh_set_family(rn, AF_BRIDGE); |
| 4745 | rtnl_neigh_set_ifindex(rn, bss->ifindex); |
| 4746 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); |
| 4747 | if (!nl_addr) { |
| 4748 | rtnl_neigh_put(rn); |
| 4749 | return; |
| 4750 | } |
| 4751 | rtnl_neigh_set_lladdr(rn, nl_addr); |
| 4752 | |
| 4753 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 4754 | if (err < 0) { |
| 4755 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " |
| 4756 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), |
| 4757 | bss->ifindex, nl_geterror(err)); |
| 4758 | } else { |
| 4759 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " |
| 4760 | MACSTR, MAC2STR(addr)); |
| 4761 | } |
| 4762 | |
| 4763 | nl_addr_put(nl_addr); |
| 4764 | rtnl_neigh_put(rn); |
| 4765 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 4766 | } |
| 4767 | |
| 4768 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4769 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
| 4770 | int deauth, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4771 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4772 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4773 | struct nl_msg *msg; |
| 4774 | int ret; |
| 4775 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4776 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
| 4777 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 4778 | (deauth == 0 && |
| 4779 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 4780 | WLAN_FC_STYPE_DISASSOC)) || |
| 4781 | (deauth == 1 && |
| 4782 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 4783 | WLAN_FC_STYPE_DEAUTH)) || |
| 4784 | (reason_code && |
| 4785 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { |
| 4786 | nlmsg_free(msg); |
| 4787 | return -ENOBUFS; |
| 4788 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4789 | |
| 4790 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 4791 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
| 4792 | " --> %d (%s)", |
| 4793 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4794 | |
| 4795 | if (drv->rtnl_sk) |
| 4796 | rtnl_neigh_delete_fdb_entry(bss, addr); |
| 4797 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4798 | if (ret == -ENOENT) |
| 4799 | return 0; |
| 4800 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4801 | } |
| 4802 | |
| 4803 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4804 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4805 | { |
| 4806 | struct nl_msg *msg; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4807 | struct wpa_driver_nl80211_data *drv2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4808 | |
| 4809 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
| 4810 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4811 | /* stop listening for EAPOL on this interface */ |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4812 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 4813 | struct wpa_driver_nl80211_data, list) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4814 | { |
| 4815 | del_ifidx(drv2, ifidx, IFIDX_ANY); |
| 4816 | /* Remove all bridges learned for this iface */ |
| 4817 | del_ifidx(drv2, IFIDX_ANY, ifidx); |
| 4818 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4819 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4820 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4821 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 4822 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4823 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
| 4824 | } |
| 4825 | |
| 4826 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 4827 | const char * nl80211_iftype_str(enum nl80211_iftype mode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4828 | { |
| 4829 | switch (mode) { |
| 4830 | case NL80211_IFTYPE_ADHOC: |
| 4831 | return "ADHOC"; |
| 4832 | case NL80211_IFTYPE_STATION: |
| 4833 | return "STATION"; |
| 4834 | case NL80211_IFTYPE_AP: |
| 4835 | return "AP"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 4836 | case NL80211_IFTYPE_AP_VLAN: |
| 4837 | return "AP_VLAN"; |
| 4838 | case NL80211_IFTYPE_WDS: |
| 4839 | return "WDS"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4840 | case NL80211_IFTYPE_MONITOR: |
| 4841 | return "MONITOR"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 4842 | case NL80211_IFTYPE_MESH_POINT: |
| 4843 | return "MESH_POINT"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4844 | case NL80211_IFTYPE_P2P_CLIENT: |
| 4845 | return "P2P_CLIENT"; |
| 4846 | case NL80211_IFTYPE_P2P_GO: |
| 4847 | return "P2P_GO"; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4848 | case NL80211_IFTYPE_P2P_DEVICE: |
| 4849 | return "P2P_DEVICE"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4850 | default: |
| 4851 | return "unknown"; |
| 4852 | } |
| 4853 | } |
| 4854 | |
| 4855 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4856 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
| 4857 | const char *ifname, |
| 4858 | enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4859 | const u8 *addr, int wds, |
| 4860 | int (*handler)(struct nl_msg *, void *), |
| 4861 | void *arg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4862 | { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4863 | struct nl_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4864 | int ifidx; |
| 4865 | int ret = -ENOBUFS; |
| 4866 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4867 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
| 4868 | iftype, nl80211_iftype_str(iftype)); |
| 4869 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4870 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
| 4871 | if (!msg || |
| 4872 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
| 4873 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) |
| 4874 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4875 | |
| 4876 | if (iftype == NL80211_IFTYPE_MONITOR) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4877 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4878 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4879 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4880 | if (!flags || |
| 4881 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) |
| 4882 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4883 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4884 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4885 | } else if (wds) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4886 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
| 4887 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4888 | } |
| 4889 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4890 | /* |
| 4891 | * Tell cfg80211 that the interface belongs to the socket that created |
| 4892 | * it, and the interface should be deleted when the socket is closed. |
| 4893 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4894 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 4895 | goto fail; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4896 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4897 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4898 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4899 | if (ret) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4900 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4901 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4902 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
| 4903 | ifname, ret, strerror(-ret)); |
| 4904 | return ret; |
| 4905 | } |
| 4906 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4907 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
| 4908 | return 0; |
| 4909 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4910 | ifidx = if_nametoindex(ifname); |
| 4911 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
| 4912 | ifname, ifidx); |
| 4913 | |
| 4914 | if (ifidx <= 0) |
| 4915 | return -1; |
| 4916 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4917 | /* |
| 4918 | * Some virtual interfaces need to process EAPOL packets and events on |
| 4919 | * the parent interface. This is used mainly with hostapd. |
| 4920 | */ |
| 4921 | if (drv->hostapd || |
| 4922 | iftype == NL80211_IFTYPE_AP_VLAN || |
| 4923 | iftype == NL80211_IFTYPE_WDS || |
| 4924 | iftype == NL80211_IFTYPE_MONITOR) { |
| 4925 | /* start listening for EAPOL on this interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4926 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4927 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4928 | |
| 4929 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4930 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4931 | nl80211_remove_iface(drv, ifidx); |
| 4932 | return -1; |
| 4933 | } |
| 4934 | |
| 4935 | return ifidx; |
| 4936 | } |
| 4937 | |
| 4938 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4939 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
| 4940 | const char *ifname, enum nl80211_iftype iftype, |
| 4941 | const u8 *addr, int wds, |
| 4942 | int (*handler)(struct nl_msg *, void *), |
| 4943 | void *arg, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4944 | { |
| 4945 | int ret; |
| 4946 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4947 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
| 4948 | arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4949 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4950 | /* if error occurred and interface exists already */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4951 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4952 | if (use_existing) { |
| 4953 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", |
| 4954 | ifname); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 4955 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
| 4956 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4957 | addr) < 0 && |
| 4958 | (linux_set_iface_flags(drv->global->ioctl_sock, |
| 4959 | ifname, 0) < 0 || |
| 4960 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4961 | addr) < 0 || |
| 4962 | linux_set_iface_flags(drv->global->ioctl_sock, |
| 4963 | ifname, 1) < 0)) |
| 4964 | return -1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4965 | return -ENFILE; |
| 4966 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4967 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
| 4968 | |
| 4969 | /* Try to remove the interface that was already there. */ |
| 4970 | nl80211_remove_iface(drv, if_nametoindex(ifname)); |
| 4971 | |
| 4972 | /* Try to create the interface again */ |
| 4973 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4974 | wds, handler, arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4975 | } |
| 4976 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4977 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
| 4978 | wpa_printf(MSG_DEBUG, |
| 4979 | "nl80211: Interface %s created for P2P - disable 11b rates", |
| 4980 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4981 | nl80211_disable_11b_rates(drv, ret, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4982 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4983 | |
| 4984 | return ret; |
| 4985 | } |
| 4986 | |
| 4987 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4988 | static int nl80211_setup_ap(struct i802_bss *bss) |
| 4989 | { |
| 4990 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4991 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4992 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 4993 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4994 | |
| 4995 | /* |
| 4996 | * Disable Probe Request reporting unless we need it in this way for |
| 4997 | * devices that include the AP SME, in the other case (unless using |
| 4998 | * monitor iface) we'll get it through the nl_mgmt socket instead. |
| 4999 | */ |
| 5000 | if (!drv->device_ap_sme) |
| 5001 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 5002 | |
| 5003 | if (!drv->device_ap_sme && !drv->use_monitor) |
| 5004 | if (nl80211_mgmt_subscribe_ap(bss)) |
| 5005 | return -1; |
| 5006 | |
| 5007 | if (drv->device_ap_sme && !drv->use_monitor) |
| 5008 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5009 | wpa_printf(MSG_DEBUG, |
| 5010 | "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] | 5011 | |
| 5012 | if (!drv->device_ap_sme && drv->use_monitor && |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 5013 | nl80211_create_monitor_interface(drv) && |
| 5014 | !drv->device_ap_sme) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5015 | return -1; |
| 5016 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5017 | if (drv->device_ap_sme && |
| 5018 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { |
| 5019 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " |
| 5020 | "Probe Request frame reporting in AP mode"); |
| 5021 | /* Try to survive without this */ |
| 5022 | } |
| 5023 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5024 | return 0; |
| 5025 | } |
| 5026 | |
| 5027 | |
| 5028 | static void nl80211_teardown_ap(struct i802_bss *bss) |
| 5029 | { |
| 5030 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5031 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5032 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 5033 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5034 | if (drv->device_ap_sme) { |
| 5035 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 5036 | if (!drv->use_monitor) |
| 5037 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); |
| 5038 | } else if (drv->use_monitor) |
| 5039 | nl80211_remove_monitor_interface(drv); |
| 5040 | else |
| 5041 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
| 5042 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5043 | nl80211_put_wiphy_data_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5044 | bss->beacon_set = 0; |
| 5045 | } |
| 5046 | |
| 5047 | |
| 5048 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
| 5049 | const u8 *addr, const u8 *data, |
| 5050 | size_t data_len) |
| 5051 | { |
| 5052 | struct sockaddr_ll ll; |
| 5053 | int ret; |
| 5054 | |
| 5055 | if (bss->drv->eapol_tx_sock < 0) { |
| 5056 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); |
| 5057 | return -1; |
| 5058 | } |
| 5059 | |
| 5060 | os_memset(&ll, 0, sizeof(ll)); |
| 5061 | ll.sll_family = AF_PACKET; |
| 5062 | ll.sll_ifindex = bss->ifindex; |
| 5063 | ll.sll_protocol = htons(ETH_P_PAE); |
| 5064 | ll.sll_halen = ETH_ALEN; |
| 5065 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); |
| 5066 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, |
| 5067 | (struct sockaddr *) &ll, sizeof(ll)); |
| 5068 | if (ret < 0) |
| 5069 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", |
| 5070 | strerror(errno)); |
| 5071 | |
| 5072 | return ret; |
| 5073 | } |
| 5074 | |
| 5075 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5076 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 5077 | |
| 5078 | static int wpa_driver_nl80211_hapd_send_eapol( |
| 5079 | void *priv, const u8 *addr, const u8 *data, |
| 5080 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
| 5081 | { |
| 5082 | struct i802_bss *bss = priv; |
| 5083 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5084 | struct ieee80211_hdr *hdr; |
| 5085 | size_t len; |
| 5086 | u8 *pos; |
| 5087 | int res; |
| 5088 | int qos = flags & WPA_STA_WMM; |
Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 5089 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5090 | if (drv->device_ap_sme || !drv->use_monitor) |
| 5091 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
| 5092 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5093 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
| 5094 | data_len; |
| 5095 | hdr = os_zalloc(len); |
| 5096 | if (hdr == NULL) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 5097 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
| 5098 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5099 | return -1; |
| 5100 | } |
| 5101 | |
| 5102 | hdr->frame_control = |
| 5103 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); |
| 5104 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 5105 | if (encrypt) |
| 5106 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); |
| 5107 | if (qos) { |
| 5108 | hdr->frame_control |= |
| 5109 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); |
| 5110 | } |
| 5111 | |
| 5112 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 5113 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 5114 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 5115 | pos = (u8 *) (hdr + 1); |
| 5116 | |
| 5117 | if (qos) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 5118 | /* Set highest priority in QoS header */ |
| 5119 | pos[0] = 7; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5120 | pos[1] = 0; |
| 5121 | pos += 2; |
| 5122 | } |
| 5123 | |
| 5124 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); |
| 5125 | pos += sizeof(rfc1042_header); |
| 5126 | WPA_PUT_BE16(pos, ETH_P_PAE); |
| 5127 | pos += 2; |
| 5128 | memcpy(pos, data, data_len); |
| 5129 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5130 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5131 | 0, 0, 0, 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5132 | if (res < 0) { |
| 5133 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " |
| 5134 | "failed: %d (%s)", |
| 5135 | (unsigned long) len, errno, strerror(errno)); |
| 5136 | } |
| 5137 | os_free(hdr); |
| 5138 | |
| 5139 | return res; |
| 5140 | } |
| 5141 | |
| 5142 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5143 | 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] | 5144 | unsigned int total_flags, |
| 5145 | unsigned int flags_or, |
| 5146 | unsigned int flags_and) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5147 | { |
| 5148 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5149 | struct nl_msg *msg; |
| 5150 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5151 | struct nl80211_sta_flag_update upd; |
| 5152 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5153 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
| 5154 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", |
| 5155 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, |
| 5156 | !!(total_flags & WPA_STA_AUTHORIZED)); |
| 5157 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5158 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5159 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 5160 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5161 | |
| 5162 | /* |
| 5163 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This |
| 5164 | * can be removed eventually. |
| 5165 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5166 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5167 | if (!flags || |
| 5168 | ((total_flags & WPA_STA_AUTHORIZED) && |
| 5169 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || |
| 5170 | ((total_flags & WPA_STA_WMM) && |
| 5171 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || |
| 5172 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && |
| 5173 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || |
| 5174 | ((total_flags & WPA_STA_MFP) && |
| 5175 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || |
| 5176 | ((total_flags & WPA_STA_TDLS_PEER) && |
| 5177 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) |
| 5178 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5179 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5180 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5181 | |
| 5182 | os_memset(&upd, 0, sizeof(upd)); |
| 5183 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); |
| 5184 | upd.set = sta_flags_nl80211(flags_or); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5185 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 5186 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5187 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5188 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 5189 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5190 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5191 | return -ENOBUFS; |
| 5192 | } |
| 5193 | |
| 5194 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 5195 | static int driver_nl80211_sta_set_airtime_weight(void *priv, const u8 *addr, |
| 5196 | unsigned int weight) |
| 5197 | { |
| 5198 | struct i802_bss *bss = priv; |
| 5199 | struct nl_msg *msg; |
| 5200 | |
| 5201 | wpa_printf(MSG_DEBUG, |
| 5202 | "nl80211: Set STA airtime weight - ifname=%s addr=" MACSTR |
| 5203 | " weight=%u", bss->ifname, MAC2STR(addr), weight); |
| 5204 | |
| 5205 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5206 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 5207 | nla_put_u16(msg, NL80211_ATTR_AIRTIME_WEIGHT, weight)) |
| 5208 | goto fail; |
| 5209 | |
| 5210 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 5211 | fail: |
| 5212 | nlmsg_free(msg); |
| 5213 | return -ENOBUFS; |
| 5214 | } |
| 5215 | |
| 5216 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5217 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
| 5218 | struct wpa_driver_associate_params *params) |
| 5219 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5220 | enum nl80211_iftype nlmode, old_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5221 | |
| 5222 | if (params->p2p) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5223 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
| 5224 | "group (GO)"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5225 | nlmode = NL80211_IFTYPE_P2P_GO; |
| 5226 | } else |
| 5227 | nlmode = NL80211_IFTYPE_AP; |
| 5228 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5229 | old_mode = drv->nlmode; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5230 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5231 | nl80211_remove_monitor_interface(drv); |
| 5232 | return -1; |
| 5233 | } |
| 5234 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5235 | if (params->freq.freq && |
| 5236 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5237 | if (old_mode != nlmode) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5238 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5239 | nl80211_remove_monitor_interface(drv); |
| 5240 | return -1; |
| 5241 | } |
| 5242 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5243 | return 0; |
| 5244 | } |
| 5245 | |
| 5246 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5247 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 5248 | int reset_mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5249 | { |
| 5250 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5251 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5252 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5253 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5254 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5255 | if (ret) { |
| 5256 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " |
| 5257 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5258 | } else { |
| 5259 | wpa_printf(MSG_DEBUG, |
| 5260 | "nl80211: Leave IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5261 | } |
| 5262 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5263 | if (reset_mode && |
| 5264 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 5265 | NL80211_IFTYPE_STATION)) { |
| 5266 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 5267 | "station mode"); |
| 5268 | } |
| 5269 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5270 | return ret; |
| 5271 | } |
| 5272 | |
| 5273 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5274 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
| 5275 | struct wpa_driver_associate_params *params) |
| 5276 | { |
| 5277 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) |
| 5278 | return -1; |
| 5279 | |
| 5280 | if (params->htcaps && params->htcaps_mask) { |
| 5281 | int sz = sizeof(struct ieee80211_ht_capabilities); |
| 5282 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); |
| 5283 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", |
| 5284 | params->htcaps_mask, sz); |
| 5285 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, |
| 5286 | params->htcaps) || |
| 5287 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 5288 | params->htcaps_mask)) |
| 5289 | return -1; |
| 5290 | } |
| 5291 | |
| 5292 | #ifdef CONFIG_VHT_OVERRIDES |
| 5293 | if (params->disable_vht) { |
| 5294 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
| 5295 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) |
| 5296 | return -1; |
| 5297 | } |
| 5298 | |
| 5299 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 5300 | int sz = sizeof(struct ieee80211_vht_capabilities); |
| 5301 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); |
| 5302 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", |
| 5303 | params->vhtcaps_mask, sz); |
| 5304 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, |
| 5305 | params->vhtcaps) || |
| 5306 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 5307 | params->vhtcaps_mask)) |
| 5308 | return -1; |
| 5309 | } |
| 5310 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 5311 | |
| 5312 | return 0; |
| 5313 | } |
| 5314 | |
| 5315 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5316 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
| 5317 | struct wpa_driver_associate_params *params) |
| 5318 | { |
| 5319 | struct nl_msg *msg; |
| 5320 | int ret = -1; |
| 5321 | int count = 0; |
| 5322 | |
| 5323 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); |
| 5324 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5325 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5326 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 5327 | "IBSS mode"); |
| 5328 | return -1; |
| 5329 | } |
| 5330 | |
| 5331 | retry: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5332 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
| 5333 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
| 5334 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5335 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5336 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
| 5337 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5338 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 5339 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5340 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 5341 | drv->ssid_len = params->ssid_len; |
| 5342 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5343 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
| 5344 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5345 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5346 | |
| 5347 | ret = nl80211_set_conn_keys(params, msg); |
| 5348 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5349 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5350 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5351 | if (params->bssid && params->fixed_bssid) { |
| 5352 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, |
| 5353 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5354 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 5355 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5356 | } |
| 5357 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5358 | if (params->fixed_freq) { |
| 5359 | wpa_printf(MSG_DEBUG, " * fixed_freq"); |
| 5360 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) |
| 5361 | goto fail; |
| 5362 | } |
| 5363 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5364 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 5365 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 5366 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
| 5367 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5368 | wpa_printf(MSG_DEBUG, " * control port"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5369 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 5370 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5371 | } |
| 5372 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5373 | if (params->wpa_ie) { |
| 5374 | wpa_hexdump(MSG_DEBUG, |
| 5375 | " * Extra IEs for Beacon/Probe Response frames", |
| 5376 | params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5377 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 5378 | params->wpa_ie)) |
| 5379 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5380 | } |
| 5381 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 5382 | ret = nl80211_ht_vht_overrides(msg, params); |
| 5383 | if (ret < 0) |
| 5384 | goto fail; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5385 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5386 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5387 | msg = NULL; |
| 5388 | if (ret) { |
| 5389 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", |
| 5390 | ret, strerror(-ret)); |
| 5391 | count++; |
| 5392 | if (ret == -EALREADY && count == 1) { |
| 5393 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " |
| 5394 | "forced leave"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5395 | nl80211_leave_ibss(drv, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5396 | nlmsg_free(msg); |
| 5397 | goto retry; |
| 5398 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5399 | } else { |
| 5400 | wpa_printf(MSG_DEBUG, |
| 5401 | "nl80211: Join IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5402 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5403 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5404 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5405 | nlmsg_free(msg); |
| 5406 | return ret; |
| 5407 | } |
| 5408 | |
| 5409 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5410 | static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data *drv, |
| 5411 | struct wpa_driver_associate_params *params, |
| 5412 | struct nl_msg *msg) |
| 5413 | { |
| 5414 | if (params->fils_erp_username_len) { |
| 5415 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP EMSKname/username", |
| 5416 | params->fils_erp_username, |
| 5417 | params->fils_erp_username_len); |
| 5418 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_USERNAME, |
| 5419 | params->fils_erp_username_len, |
| 5420 | params->fils_erp_username)) |
| 5421 | return -1; |
| 5422 | } |
| 5423 | |
| 5424 | if (params->fils_erp_realm_len) { |
| 5425 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP Realm", |
| 5426 | params->fils_erp_realm, |
| 5427 | params->fils_erp_realm_len); |
| 5428 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_REALM, |
| 5429 | params->fils_erp_realm_len, params->fils_erp_realm)) |
| 5430 | return -1; |
| 5431 | } |
| 5432 | |
| 5433 | wpa_printf(MSG_DEBUG, " * FILS ERP next seq %u", |
| 5434 | params->fils_erp_next_seq_num); |
| 5435 | if (nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 5436 | params->fils_erp_next_seq_num)) |
| 5437 | return -1; |
| 5438 | |
| 5439 | if (params->fils_erp_rrk_len) { |
| 5440 | wpa_printf(MSG_DEBUG, " * FILS ERP rRK (len=%lu)", |
| 5441 | (unsigned long) params->fils_erp_rrk_len); |
| 5442 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_RRK, |
| 5443 | params->fils_erp_rrk_len, params->fils_erp_rrk)) |
| 5444 | return -1; |
| 5445 | } |
| 5446 | |
| 5447 | return 0; |
| 5448 | } |
| 5449 | |
| 5450 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5451 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
| 5452 | struct wpa_driver_associate_params *params, |
| 5453 | struct nl_msg *msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5454 | { |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5455 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 5456 | return -1; |
| 5457 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5458 | if (params->bssid) { |
| 5459 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 5460 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5461 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 5462 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5463 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5464 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5465 | if (params->bssid_hint) { |
| 5466 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, |
| 5467 | MAC2STR(params->bssid_hint)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5468 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
| 5469 | params->bssid_hint)) |
| 5470 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5471 | } |
| 5472 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5473 | if (params->freq.freq) { |
| 5474 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5475 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 5476 | params->freq.freq)) |
| 5477 | return -1; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5478 | drv->assoc_freq = params->freq.freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5479 | } else |
| 5480 | drv->assoc_freq = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5481 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5482 | if (params->freq_hint) { |
| 5483 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5484 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
| 5485 | params->freq_hint)) |
| 5486 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5487 | } |
| 5488 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5489 | if (params->bg_scan_period >= 0) { |
| 5490 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 5491 | params->bg_scan_period); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5492 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 5493 | params->bg_scan_period)) |
| 5494 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5495 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5496 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5497 | if (params->ssid) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5498 | wpa_printf(MSG_DEBUG, " * SSID=%s", |
| 5499 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5500 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 5501 | params->ssid)) |
| 5502 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5503 | if (params->ssid_len > sizeof(drv->ssid)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5504 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5505 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 5506 | drv->ssid_len = params->ssid_len; |
| 5507 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5508 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5509 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5510 | if (params->wpa_ie && |
| 5511 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) |
| 5512 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5513 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5514 | if (params->wpa_proto) { |
| 5515 | enum nl80211_wpa_versions ver = 0; |
| 5516 | |
| 5517 | if (params->wpa_proto & WPA_PROTO_WPA) |
| 5518 | ver |= NL80211_WPA_VERSION_1; |
| 5519 | if (params->wpa_proto & WPA_PROTO_RSN) |
| 5520 | ver |= NL80211_WPA_VERSION_2; |
| 5521 | |
| 5522 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5523 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 5524 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5525 | } |
| 5526 | |
| 5527 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
| 5528 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
| 5529 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5530 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 5531 | cipher)) |
| 5532 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5533 | } |
| 5534 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 5535 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
| 5536 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { |
| 5537 | /* |
| 5538 | * This is likely to work even though many drivers do not |
| 5539 | * advertise support for operations without GTK. |
| 5540 | */ |
| 5541 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); |
| 5542 | } else if (params->group_suite != WPA_CIPHER_NONE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5543 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
| 5544 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5545 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
| 5546 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5547 | } |
| 5548 | |
| 5549 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 5550 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 5551 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || |
| 5552 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5553 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5554 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
| 5555 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5556 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 5557 | params->key_mgmt_suite == WPA_KEY_MGMT_SAE || |
| 5558 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_SAE || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5559 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5560 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 5561 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X_SHA384 || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5562 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA256 || |
| 5563 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA384 || |
| 5564 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA256 || |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5565 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA384 || |
| 5566 | params->key_mgmt_suite == WPA_KEY_MGMT_OWE || |
| 5567 | params->key_mgmt_suite == WPA_KEY_MGMT_DPP) { |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5568 | int mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5569 | |
| 5570 | switch (params->key_mgmt_suite) { |
| 5571 | case WPA_KEY_MGMT_CCKM: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5572 | mgmt = RSN_AUTH_KEY_MGMT_CCKM; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5573 | break; |
| 5574 | case WPA_KEY_MGMT_IEEE8021X: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5575 | mgmt = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5576 | break; |
| 5577 | case WPA_KEY_MGMT_FT_IEEE8021X: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5578 | mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5579 | break; |
| 5580 | case WPA_KEY_MGMT_FT_PSK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5581 | mgmt = RSN_AUTH_KEY_MGMT_FT_PSK; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5582 | break; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5583 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5584 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SHA256; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5585 | break; |
| 5586 | case WPA_KEY_MGMT_PSK_SHA256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5587 | mgmt = RSN_AUTH_KEY_MGMT_PSK_SHA256; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5588 | break; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5589 | case WPA_KEY_MGMT_OSEN: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5590 | mgmt = RSN_AUTH_KEY_MGMT_OSEN; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5591 | break; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 5592 | case WPA_KEY_MGMT_SAE: |
| 5593 | mgmt = RSN_AUTH_KEY_MGMT_SAE; |
| 5594 | break; |
| 5595 | case WPA_KEY_MGMT_FT_SAE: |
| 5596 | mgmt = RSN_AUTH_KEY_MGMT_FT_SAE; |
| 5597 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5598 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5599 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5600 | break; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5601 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5602 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5603 | break; |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 5604 | case WPA_KEY_MGMT_FT_IEEE8021X_SHA384: |
| 5605 | mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X_SHA384; |
| 5606 | break; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5607 | case WPA_KEY_MGMT_FILS_SHA256: |
| 5608 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA256; |
| 5609 | break; |
| 5610 | case WPA_KEY_MGMT_FILS_SHA384: |
| 5611 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA384; |
| 5612 | break; |
| 5613 | case WPA_KEY_MGMT_FT_FILS_SHA256: |
| 5614 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256; |
| 5615 | break; |
| 5616 | case WPA_KEY_MGMT_FT_FILS_SHA384: |
| 5617 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384; |
| 5618 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5619 | case WPA_KEY_MGMT_OWE: |
| 5620 | mgmt = RSN_AUTH_KEY_MGMT_OWE; |
| 5621 | break; |
| 5622 | case WPA_KEY_MGMT_DPP: |
| 5623 | mgmt = RSN_AUTH_KEY_MGMT_DPP; |
| 5624 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5625 | case WPA_KEY_MGMT_PSK: |
| 5626 | default: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5627 | mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5628 | break; |
| 5629 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5630 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5631 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
| 5632 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5633 | } |
| 5634 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5635 | if (params->req_key_mgmt_offload && |
| 5636 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_8021X)) { |
| 5637 | wpa_printf(MSG_DEBUG, " * WANT_1X_4WAY_HS"); |
| 5638 | if (nla_put_flag(msg, NL80211_ATTR_WANT_1X_4WAY_HS)) |
| 5639 | return -1; |
| 5640 | } |
| 5641 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5642 | /* Add PSK in case of 4-way handshake offload */ |
| 5643 | if (params->psk && |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5644 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE_PSK)) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5645 | wpa_hexdump_key(MSG_DEBUG, " * PSK", params->psk, 32); |
| 5646 | if (nla_put(msg, NL80211_ATTR_PMK, 32, params->psk)) |
| 5647 | return -1; |
| 5648 | } |
| 5649 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5650 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 5651 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5652 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 5653 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 5654 | (params->pairwise_suite == WPA_CIPHER_NONE || |
| 5655 | params->pairwise_suite == WPA_CIPHER_WEP104 || |
| 5656 | params->pairwise_suite == WPA_CIPHER_WEP40) && |
| 5657 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 5658 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
| 5659 | return -1; |
| 5660 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5661 | if (params->rrm_used) { |
| 5662 | u32 drv_rrm_flags = drv->capa.rrm_flags; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5663 | if ((!((drv_rrm_flags & |
| 5664 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && |
| 5665 | (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && |
| 5666 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5667 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
| 5668 | return -1; |
| 5669 | } |
| 5670 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5671 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5672 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5673 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5674 | if (params->p2p) |
| 5675 | wpa_printf(MSG_DEBUG, " * P2P group"); |
| 5676 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5677 | if (params->pbss) { |
| 5678 | wpa_printf(MSG_DEBUG, " * PBSS"); |
| 5679 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 5680 | return -1; |
| 5681 | } |
| 5682 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 5683 | drv->connect_reassoc = 0; |
| 5684 | if (params->prev_bssid) { |
| 5685 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, |
| 5686 | MAC2STR(params->prev_bssid)); |
| 5687 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
| 5688 | params->prev_bssid)) |
| 5689 | return -1; |
| 5690 | drv->connect_reassoc = 1; |
| 5691 | } |
| 5692 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5693 | if ((params->auth_alg & WPA_AUTH_ALG_FILS) && |
| 5694 | nl80211_put_fils_connect_params(drv, params, msg) != 0) |
| 5695 | return -1; |
| 5696 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5697 | if ((params->auth_alg & WPA_AUTH_ALG_SAE) && |
| 5698 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) && |
| 5699 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) |
| 5700 | return -1; |
| 5701 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5702 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5703 | } |
| 5704 | |
| 5705 | |
| 5706 | static int wpa_driver_nl80211_try_connect( |
| 5707 | struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5708 | struct wpa_driver_associate_params *params, |
| 5709 | struct nl_handle *nl_connect) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5710 | { |
| 5711 | struct nl_msg *msg; |
| 5712 | enum nl80211_auth_type type; |
| 5713 | int ret; |
| 5714 | int algs; |
| 5715 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5716 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5717 | if (params->req_key_mgmt_offload && params->psk && |
| 5718 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 5719 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
| 5720 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { |
| 5721 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); |
| 5722 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); |
| 5723 | if (ret) |
| 5724 | return ret; |
| 5725 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5726 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5727 | |
| 5728 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
| 5729 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5730 | if (!msg) |
| 5731 | return -1; |
| 5732 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5733 | ret = nl80211_connect_common(drv, params, msg); |
| 5734 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5735 | goto fail; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5736 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5737 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 5738 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 5739 | goto fail; |
| 5740 | |
| 5741 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_OPTIONAL && |
| 5742 | (drv->capa.flags & WPA_DRIVER_FLAGS_MFP_OPTIONAL) && |
| 5743 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_OPTIONAL)) |
| 5744 | goto fail; |
| 5745 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5746 | algs = 0; |
| 5747 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 5748 | algs++; |
| 5749 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 5750 | algs++; |
| 5751 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 5752 | algs++; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5753 | if (params->auth_alg & WPA_AUTH_ALG_FILS) |
| 5754 | algs++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5755 | if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 5756 | algs++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5757 | if (algs > 1) { |
| 5758 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " |
| 5759 | "selection"); |
| 5760 | goto skip_auth_type; |
| 5761 | } |
| 5762 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5763 | type = get_nl_auth_type(params->auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5764 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5765 | if (type == NL80211_AUTHTYPE_MAX || |
| 5766 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5767 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5768 | |
| 5769 | skip_auth_type: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5770 | ret = nl80211_set_conn_keys(params, msg); |
| 5771 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5772 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5773 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5774 | if (nl_connect) |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5775 | ret = send_and_recv(drv->global, nl_connect, msg, |
| 5776 | NULL, (void *) -1); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5777 | else |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5778 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5779 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5780 | msg = NULL; |
| 5781 | if (ret) { |
| 5782 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " |
| 5783 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5784 | } else { |
| 5785 | wpa_printf(MSG_DEBUG, |
| 5786 | "nl80211: Connect request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5787 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5788 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5789 | fail: |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5790 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5791 | nlmsg_free(msg); |
| 5792 | return ret; |
| 5793 | |
| 5794 | } |
| 5795 | |
| 5796 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5797 | static int wpa_driver_nl80211_connect( |
| 5798 | struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5799 | struct wpa_driver_associate_params *params, |
| 5800 | struct nl_handle *nl_connect) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5801 | { |
Jithu Jance | a7c60b4 | 2014-12-03 18:54:40 +0530 | [diff] [blame] | 5802 | int ret; |
| 5803 | |
| 5804 | /* Store the connection attempted bssid for future use */ |
| 5805 | if (params->bssid) |
| 5806 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 5807 | else |
| 5808 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
| 5809 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5810 | ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5811 | if (ret == -EALREADY) { |
| 5812 | /* |
| 5813 | * cfg80211 does not currently accept new connections if |
| 5814 | * we are already connected. As a workaround, force |
| 5815 | * disconnection and try again. |
| 5816 | */ |
| 5817 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " |
| 5818 | "disconnecting before reassociation " |
| 5819 | "attempt"); |
| 5820 | if (wpa_driver_nl80211_disconnect( |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5821 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID, nl_connect)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5822 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5823 | ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5824 | } |
| 5825 | return ret; |
| 5826 | } |
| 5827 | |
| 5828 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5829 | static int wpa_driver_nl80211_associate( |
| 5830 | void *priv, struct wpa_driver_associate_params *params) |
| 5831 | { |
| 5832 | struct i802_bss *bss = priv; |
| 5833 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5834 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5835 | struct nl_msg *msg; |
| 5836 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5837 | nl80211_unmask_11b_rates(bss); |
| 5838 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5839 | if (params->mode == IEEE80211_MODE_AP) |
| 5840 | return wpa_driver_nl80211_ap(drv, params); |
| 5841 | |
| 5842 | if (params->mode == IEEE80211_MODE_IBSS) |
| 5843 | return wpa_driver_nl80211_ibss(drv, params); |
| 5844 | |
| 5845 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5846 | enum nl80211_iftype nlmode = params->p2p ? |
| 5847 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5848 | struct nl_handle *nl_connect = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5849 | |
| 5850 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5851 | return -1; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5852 | if (params->auth_alg & WPA_AUTH_ALG_SAE) { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5853 | nl_connect = bss->nl_connect; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 5854 | bss->use_nl_connect = 1; |
| 5855 | } else { |
| 5856 | bss->use_nl_connect = 0; |
| 5857 | } |
| 5858 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5859 | return wpa_driver_nl80211_connect(drv, params, nl_connect); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5860 | } |
| 5861 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5862 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5863 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5864 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
| 5865 | drv->ifindex); |
| 5866 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5867 | if (!msg) |
| 5868 | return -1; |
| 5869 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5870 | ret = nl80211_connect_common(drv, params, msg); |
| 5871 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5872 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5873 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5874 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 5875 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 5876 | goto fail; |
| 5877 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5878 | if (params->fils_kek) { |
| 5879 | wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)", |
| 5880 | (unsigned int) params->fils_kek_len); |
| 5881 | if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len, |
| 5882 | params->fils_kek)) |
| 5883 | goto fail; |
| 5884 | } |
| 5885 | if (params->fils_nonces) { |
| 5886 | wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)", |
| 5887 | params->fils_nonces, |
| 5888 | params->fils_nonces_len); |
| 5889 | if (nla_put(msg, NL80211_ATTR_FILS_NONCES, |
| 5890 | params->fils_nonces_len, params->fils_nonces)) |
| 5891 | goto fail; |
| 5892 | } |
| 5893 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5894 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5895 | msg = NULL; |
| 5896 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5897 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 5898 | "nl80211: MLME command failed (assoc): ret=%d (%s)", |
| 5899 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5900 | nl80211_dump_scan(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5901 | } else { |
| 5902 | wpa_printf(MSG_DEBUG, |
| 5903 | "nl80211: Association request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5904 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5905 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5906 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5907 | nlmsg_free(msg); |
| 5908 | return ret; |
| 5909 | } |
| 5910 | |
| 5911 | |
| 5912 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5913 | int ifindex, enum nl80211_iftype mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5914 | { |
| 5915 | struct nl_msg *msg; |
| 5916 | int ret = -ENOBUFS; |
| 5917 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5918 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
| 5919 | ifindex, mode, nl80211_iftype_str(mode)); |
| 5920 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5921 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 5922 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) |
| 5923 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5924 | |
| 5925 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5926 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5927 | if (!ret) |
| 5928 | return 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5929 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5930 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5931 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
| 5932 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); |
| 5933 | return ret; |
| 5934 | } |
| 5935 | |
| 5936 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5937 | static int wpa_driver_nl80211_set_mode_impl( |
| 5938 | struct i802_bss *bss, |
| 5939 | enum nl80211_iftype nlmode, |
| 5940 | struct hostapd_freq_params *desired_freq_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5941 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5942 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5943 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5944 | int i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5945 | int was_ap = is_ap_interface(drv->nlmode); |
| 5946 | int res; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5947 | int mode_switch_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5948 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5949 | if (TEST_FAIL()) |
| 5950 | return -1; |
| 5951 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5952 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 5953 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) |
| 5954 | mode_switch_res = 0; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5955 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5956 | if (mode_switch_res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5957 | drv->nlmode = nlmode; |
| 5958 | ret = 0; |
| 5959 | goto done; |
| 5960 | } |
| 5961 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5962 | if (mode_switch_res == -ENODEV) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5963 | return -1; |
| 5964 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5965 | if (nlmode == drv->nlmode) { |
| 5966 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
| 5967 | "requested mode - ignore error"); |
| 5968 | ret = 0; |
| 5969 | goto done; /* Already in the requested mode */ |
| 5970 | } |
| 5971 | |
| 5972 | /* mac80211 doesn't allow mode changes while the device is up, so |
| 5973 | * take the device down, try to set the mode again, and bring the |
| 5974 | * device back up. |
| 5975 | */ |
| 5976 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
| 5977 | "interface down"); |
| 5978 | for (i = 0; i < 10; i++) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5979 | res = i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5980 | if (res == -EACCES || res == -ENODEV) |
| 5981 | break; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5982 | if (res != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5983 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
| 5984 | "interface down"); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5985 | os_sleep(0, 100000); |
| 5986 | continue; |
| 5987 | } |
| 5988 | |
| 5989 | /* |
| 5990 | * Setting the mode will fail for some drivers if the phy is |
| 5991 | * on a frequency that the mode is disallowed in. |
| 5992 | */ |
| 5993 | if (desired_freq_params) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5994 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5995 | if (res) { |
| 5996 | wpa_printf(MSG_DEBUG, |
| 5997 | "nl80211: Failed to set frequency on interface"); |
| 5998 | } |
| 5999 | } |
| 6000 | |
| 6001 | /* Try to set the mode again while the interface is down */ |
| 6002 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 6003 | if (mode_switch_res == -EBUSY) { |
| 6004 | wpa_printf(MSG_DEBUG, |
| 6005 | "nl80211: Delaying mode set while interface going down"); |
| 6006 | os_sleep(0, 100000); |
| 6007 | continue; |
| 6008 | } |
| 6009 | ret = mode_switch_res; |
| 6010 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6011 | } |
| 6012 | |
| 6013 | if (!ret) { |
| 6014 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " |
| 6015 | "interface is down"); |
| 6016 | drv->nlmode = nlmode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6017 | drv->ignore_if_down_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6018 | } |
| 6019 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6020 | /* Bring the interface back up */ |
| 6021 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); |
| 6022 | if (res != 0) { |
| 6023 | wpa_printf(MSG_DEBUG, |
| 6024 | "nl80211: Failed to set interface up after switching mode"); |
| 6025 | ret = -1; |
| 6026 | } |
| 6027 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6028 | done: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6029 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6030 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " |
| 6031 | "from %d failed", nlmode, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6032 | return ret; |
| 6033 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6034 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6035 | if (is_p2p_net_interface(nlmode)) { |
| 6036 | wpa_printf(MSG_DEBUG, |
| 6037 | "nl80211: Interface %s mode change to P2P - disable 11b rates", |
| 6038 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6039 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6040 | } else if (drv->disabled_11b_rates) { |
| 6041 | wpa_printf(MSG_DEBUG, |
| 6042 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", |
| 6043 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6044 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6045 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6046 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6047 | if (is_ap_interface(nlmode)) { |
| 6048 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
| 6049 | /* Setup additional AP mode functionality if needed */ |
| 6050 | if (nl80211_setup_ap(bss)) |
| 6051 | return -1; |
| 6052 | } else if (was_ap) { |
| 6053 | /* Remove additional AP mode functionality */ |
| 6054 | nl80211_teardown_ap(bss); |
| 6055 | } else { |
| 6056 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
| 6057 | } |
| 6058 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6059 | if (is_mesh_interface(nlmode) && |
| 6060 | nl80211_mgmt_subscribe_mesh(bss)) |
| 6061 | return -1; |
| 6062 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6063 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6064 | !is_mesh_interface(nlmode) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6065 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 6066 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " |
| 6067 | "frame processing - ignore for now"); |
| 6068 | |
| 6069 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6070 | } |
| 6071 | |
| 6072 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6073 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 6074 | enum nl80211_iftype nlmode) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6075 | { |
| 6076 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); |
| 6077 | } |
| 6078 | |
| 6079 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6080 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 6081 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6082 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6083 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 6084 | freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 6085 | } |
| 6086 | |
| 6087 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6088 | static int wpa_driver_nl80211_get_capa(void *priv, |
| 6089 | struct wpa_driver_capa *capa) |
| 6090 | { |
| 6091 | struct i802_bss *bss = priv; |
| 6092 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 6093 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6094 | if (!drv->has_capability) |
| 6095 | return -1; |
| 6096 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 6097 | if (drv->extended_capa && drv->extended_capa_mask) { |
| 6098 | capa->extended_capa = drv->extended_capa; |
| 6099 | capa->extended_capa_mask = drv->extended_capa_mask; |
| 6100 | capa->extended_capa_len = drv->extended_capa_len; |
| 6101 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6102 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6103 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6104 | } |
| 6105 | |
| 6106 | |
| 6107 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) |
| 6108 | { |
| 6109 | struct i802_bss *bss = priv; |
| 6110 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6111 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6112 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
| 6113 | bss->ifname, drv->operstate, state, |
| 6114 | state ? "UP" : "DORMANT"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6115 | drv->operstate = state; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6116 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6117 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
| 6118 | } |
| 6119 | |
| 6120 | |
| 6121 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) |
| 6122 | { |
| 6123 | struct i802_bss *bss = priv; |
| 6124 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6125 | struct nl_msg *msg; |
| 6126 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6127 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6128 | |
| 6129 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { |
| 6130 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); |
| 6131 | return 0; |
| 6132 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6133 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 6134 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
| 6135 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); |
| 6136 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6137 | os_memset(&upd, 0, sizeof(upd)); |
| 6138 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 6139 | if (authorized) |
| 6140 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6141 | |
| 6142 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 6143 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
| 6144 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { |
| 6145 | nlmsg_free(msg); |
| 6146 | return -ENOBUFS; |
| 6147 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6148 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6149 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6150 | if (!ret) |
| 6151 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 6152 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
| 6153 | ret, strerror(-ret)); |
| 6154 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6155 | } |
| 6156 | |
| 6157 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6158 | /* Set kernel driver on given frequency (MHz) */ |
| 6159 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6160 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6161 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 6162 | return nl80211_set_channel(bss, freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6163 | } |
| 6164 | |
| 6165 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6166 | static inline int min_int(int a, int b) |
| 6167 | { |
| 6168 | if (a < b) |
| 6169 | return a; |
| 6170 | return b; |
| 6171 | } |
| 6172 | |
| 6173 | |
| 6174 | static int get_key_handler(struct nl_msg *msg, void *arg) |
| 6175 | { |
| 6176 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6177 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6178 | |
| 6179 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6180 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6181 | |
| 6182 | /* |
| 6183 | * TODO: validate the key index and mac address! |
| 6184 | * Otherwise, there's a race condition as soon as |
| 6185 | * the kernel starts sending key notifications. |
| 6186 | */ |
| 6187 | |
| 6188 | if (tb[NL80211_ATTR_KEY_SEQ]) |
| 6189 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 6190 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6191 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6192 | return NL_SKIP; |
| 6193 | } |
| 6194 | |
| 6195 | |
| 6196 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, |
| 6197 | int idx, u8 *seq) |
| 6198 | { |
| 6199 | struct i802_bss *bss = priv; |
| 6200 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6201 | struct nl_msg *msg; |
| 6202 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6203 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
| 6204 | NL80211_CMD_GET_KEY); |
| 6205 | if (!msg || |
| 6206 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 6207 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
| 6208 | nlmsg_free(msg); |
| 6209 | return -ENOBUFS; |
| 6210 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6211 | |
| 6212 | memset(seq, 0, 6); |
| 6213 | |
| 6214 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6215 | } |
| 6216 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6217 | |
| 6218 | static int i802_set_rts(void *priv, int rts) |
| 6219 | { |
| 6220 | struct i802_bss *bss = priv; |
| 6221 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6222 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6223 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6224 | u32 val; |
| 6225 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6226 | if (rts >= 2347 || rts == -1) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6227 | val = (u32) -1; |
| 6228 | else |
| 6229 | val = rts; |
| 6230 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6231 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 6232 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
| 6233 | nlmsg_free(msg); |
| 6234 | return -ENOBUFS; |
| 6235 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6236 | |
| 6237 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6238 | if (!ret) |
| 6239 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6240 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
| 6241 | "%d (%s)", rts, ret, strerror(-ret)); |
| 6242 | return ret; |
| 6243 | } |
| 6244 | |
| 6245 | |
| 6246 | static int i802_set_frag(void *priv, int frag) |
| 6247 | { |
| 6248 | struct i802_bss *bss = priv; |
| 6249 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6250 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6251 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6252 | u32 val; |
| 6253 | |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 6254 | if (frag >= 2346 || frag == -1) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6255 | val = (u32) -1; |
| 6256 | else |
| 6257 | val = frag; |
| 6258 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6259 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 6260 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
| 6261 | nlmsg_free(msg); |
| 6262 | return -ENOBUFS; |
| 6263 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6264 | |
| 6265 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6266 | if (!ret) |
| 6267 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6268 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
| 6269 | "%d: %d (%s)", frag, ret, strerror(-ret)); |
| 6270 | return ret; |
| 6271 | } |
| 6272 | |
| 6273 | |
| 6274 | static int i802_flush(void *priv) |
| 6275 | { |
| 6276 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6277 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6278 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6279 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6280 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
| 6281 | bss->ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6282 | |
| 6283 | /* |
| 6284 | * XXX: FIX! this needs to flush all VLANs too |
| 6285 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6286 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
| 6287 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6288 | if (res) { |
| 6289 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " |
| 6290 | "(%s)", res, strerror(-res)); |
| 6291 | } |
| 6292 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6293 | } |
| 6294 | |
| 6295 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 6296 | static void get_sta_tid_stats(struct hostap_sta_driver_data *data, |
| 6297 | struct nlattr *attr) |
| 6298 | { |
| 6299 | struct nlattr *tid_stats[NL80211_TID_STATS_MAX + 1], *tidattr; |
| 6300 | struct nlattr *txq_stats[NL80211_TXQ_STATS_MAX + 1]; |
| 6301 | static struct nla_policy txq_stats_policy[NL80211_TXQ_STATS_MAX + 1] = { |
| 6302 | [NL80211_TXQ_STATS_BACKLOG_BYTES] = { .type = NLA_U32 }, |
| 6303 | [NL80211_TXQ_STATS_BACKLOG_PACKETS] = { .type = NLA_U32 }, |
| 6304 | }; |
| 6305 | int rem; |
| 6306 | |
| 6307 | nla_for_each_nested(tidattr, attr, rem) { |
| 6308 | if (nla_parse_nested(tid_stats, NL80211_TID_STATS_MAX, |
| 6309 | tidattr, NULL) != 0 || |
| 6310 | !tid_stats[NL80211_TID_STATS_TXQ_STATS] || |
| 6311 | nla_parse_nested(txq_stats, NL80211_TXQ_STATS_MAX, |
| 6312 | tid_stats[NL80211_TID_STATS_TXQ_STATS], |
| 6313 | txq_stats_policy) != 0) |
| 6314 | continue; |
| 6315 | /* sum the backlogs over all TIDs for station */ |
| 6316 | if (txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]) |
| 6317 | data->backlog_bytes += nla_get_u32( |
| 6318 | txq_stats[NL80211_TXQ_STATS_BACKLOG_BYTES]); |
| 6319 | if (txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]) |
| 6320 | data->backlog_bytes += nla_get_u32( |
| 6321 | txq_stats[NL80211_TXQ_STATS_BACKLOG_PACKETS]); |
| 6322 | } |
| 6323 | } |
| 6324 | |
| 6325 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6326 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
| 6327 | { |
| 6328 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6329 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6330 | struct hostap_sta_driver_data *data = arg; |
| 6331 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; |
| 6332 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
| 6333 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, |
| 6334 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, |
| 6335 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, |
| 6336 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
| 6337 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 6338 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6339 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
| 6340 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6341 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6342 | [NL80211_STA_INFO_ACK_SIGNAL] = { .type = NLA_U8 }, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 6343 | [NL80211_STA_INFO_RX_DURATION] = { .type = NLA_U64 }, |
| 6344 | [NL80211_STA_INFO_TX_DURATION] = { .type = NLA_U64 }, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6345 | }; |
| 6346 | struct nlattr *rate[NL80211_RATE_INFO_MAX + 1]; |
| 6347 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 6348 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 6349 | [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 }, |
| 6350 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 6351 | [NL80211_RATE_INFO_VHT_MCS] = { .type = NLA_U8 }, |
| 6352 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 6353 | [NL80211_RATE_INFO_VHT_NSS] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6354 | }; |
| 6355 | |
| 6356 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6357 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6358 | |
| 6359 | /* |
| 6360 | * TODO: validate the interface and mac address! |
| 6361 | * Otherwise, there's a race condition as soon as |
| 6362 | * the kernel starts sending station notifications. |
| 6363 | */ |
| 6364 | |
| 6365 | if (!tb[NL80211_ATTR_STA_INFO]) { |
| 6366 | wpa_printf(MSG_DEBUG, "sta stats missing!"); |
| 6367 | return NL_SKIP; |
| 6368 | } |
| 6369 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, |
| 6370 | tb[NL80211_ATTR_STA_INFO], |
| 6371 | stats_policy)) { |
| 6372 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); |
| 6373 | return NL_SKIP; |
| 6374 | } |
| 6375 | |
| 6376 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) |
| 6377 | data->inactive_msec = |
| 6378 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6379 | /* For backwards compatibility, fetch the 32-bit counters first. */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6380 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
| 6381 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); |
| 6382 | if (stats[NL80211_STA_INFO_TX_BYTES]) |
| 6383 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6384 | if (stats[NL80211_STA_INFO_RX_BYTES64] && |
| 6385 | stats[NL80211_STA_INFO_TX_BYTES64]) { |
| 6386 | /* |
| 6387 | * The driver supports 64-bit counters, so use them to override |
| 6388 | * the 32-bit values. |
| 6389 | */ |
| 6390 | data->rx_bytes = |
| 6391 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); |
| 6392 | data->tx_bytes = |
| 6393 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); |
| 6394 | data->bytes_64bit = 1; |
| 6395 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6396 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
| 6397 | data->rx_packets = |
| 6398 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); |
| 6399 | if (stats[NL80211_STA_INFO_TX_PACKETS]) |
| 6400 | data->tx_packets = |
| 6401 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 6402 | if (stats[NL80211_STA_INFO_RX_DURATION]) |
| 6403 | data->rx_airtime = |
| 6404 | nla_get_u64(stats[NL80211_STA_INFO_RX_DURATION]); |
| 6405 | if (stats[NL80211_STA_INFO_TX_DURATION]) |
| 6406 | data->tx_airtime = |
| 6407 | nla_get_u64(stats[NL80211_STA_INFO_TX_DURATION]); |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 6408 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
| 6409 | data->tx_retry_failed = |
| 6410 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6411 | if (stats[NL80211_STA_INFO_SIGNAL]) |
| 6412 | data->signal = nla_get_u8(stats[NL80211_STA_INFO_SIGNAL]); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6413 | if (stats[NL80211_STA_INFO_ACK_SIGNAL]) { |
| 6414 | data->last_ack_rssi = |
| 6415 | nla_get_u8(stats[NL80211_STA_INFO_ACK_SIGNAL]); |
| 6416 | data->flags |= STA_DRV_DATA_LAST_ACK_RSSI; |
| 6417 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6418 | |
| 6419 | if (stats[NL80211_STA_INFO_TX_BITRATE] && |
| 6420 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, |
| 6421 | stats[NL80211_STA_INFO_TX_BITRATE], |
| 6422 | rate_policy) == 0) { |
| 6423 | if (rate[NL80211_RATE_INFO_BITRATE32]) |
| 6424 | data->current_tx_rate = |
| 6425 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); |
| 6426 | else if (rate[NL80211_RATE_INFO_BITRATE]) |
| 6427 | data->current_tx_rate = |
| 6428 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); |
| 6429 | |
| 6430 | if (rate[NL80211_RATE_INFO_MCS]) { |
| 6431 | data->tx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]); |
| 6432 | data->flags |= STA_DRV_DATA_TX_MCS; |
| 6433 | } |
| 6434 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { |
| 6435 | data->tx_vhtmcs = |
| 6436 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); |
| 6437 | data->flags |= STA_DRV_DATA_TX_VHT_MCS; |
| 6438 | } |
| 6439 | if (rate[NL80211_RATE_INFO_SHORT_GI]) |
| 6440 | data->flags |= STA_DRV_DATA_TX_SHORT_GI; |
| 6441 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { |
| 6442 | data->tx_vht_nss = |
| 6443 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); |
| 6444 | data->flags |= STA_DRV_DATA_TX_VHT_NSS; |
| 6445 | } |
| 6446 | } |
| 6447 | |
| 6448 | if (stats[NL80211_STA_INFO_RX_BITRATE] && |
| 6449 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, |
| 6450 | stats[NL80211_STA_INFO_RX_BITRATE], |
| 6451 | rate_policy) == 0) { |
| 6452 | if (rate[NL80211_RATE_INFO_BITRATE32]) |
| 6453 | data->current_rx_rate = |
| 6454 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); |
| 6455 | else if (rate[NL80211_RATE_INFO_BITRATE]) |
| 6456 | data->current_rx_rate = |
| 6457 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); |
| 6458 | |
| 6459 | if (rate[NL80211_RATE_INFO_MCS]) { |
| 6460 | data->rx_mcs = |
| 6461 | nla_get_u8(rate[NL80211_RATE_INFO_MCS]); |
| 6462 | data->flags |= STA_DRV_DATA_RX_MCS; |
| 6463 | } |
| 6464 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { |
| 6465 | data->rx_vhtmcs = |
| 6466 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); |
| 6467 | data->flags |= STA_DRV_DATA_RX_VHT_MCS; |
| 6468 | } |
| 6469 | if (rate[NL80211_RATE_INFO_SHORT_GI]) |
| 6470 | data->flags |= STA_DRV_DATA_RX_SHORT_GI; |
| 6471 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { |
| 6472 | data->rx_vht_nss = |
| 6473 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); |
| 6474 | data->flags |= STA_DRV_DATA_RX_VHT_NSS; |
| 6475 | } |
| 6476 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6477 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 6478 | if (stats[NL80211_STA_INFO_TID_STATS]) |
| 6479 | get_sta_tid_stats(data, stats[NL80211_STA_INFO_TID_STATS]); |
| 6480 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6481 | return NL_SKIP; |
| 6482 | } |
| 6483 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6484 | static int i802_read_sta_data(struct i802_bss *bss, |
| 6485 | struct hostap_sta_driver_data *data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6486 | const u8 *addr) |
| 6487 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6488 | struct nl_msg *msg; |
| 6489 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6490 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
| 6491 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 6492 | nlmsg_free(msg); |
| 6493 | return -ENOBUFS; |
| 6494 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6495 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6496 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6497 | } |
| 6498 | |
| 6499 | |
| 6500 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
| 6501 | int cw_min, int cw_max, int burst_time) |
| 6502 | { |
| 6503 | struct i802_bss *bss = priv; |
| 6504 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6505 | struct nl_msg *msg; |
| 6506 | struct nlattr *txq, *params; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6507 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6508 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6509 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6510 | if (!msg) |
| 6511 | return -1; |
| 6512 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6513 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
| 6514 | if (!txq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6515 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6516 | |
| 6517 | /* We are only sending parameters for a single TXQ at a time */ |
| 6518 | params = nla_nest_start(msg, 1); |
| 6519 | if (!params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6520 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6521 | |
| 6522 | switch (queue) { |
| 6523 | case 0: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6524 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
| 6525 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6526 | break; |
| 6527 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6528 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
| 6529 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6530 | break; |
| 6531 | case 2: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6532 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
| 6533 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6534 | break; |
| 6535 | case 3: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6536 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
| 6537 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6538 | break; |
| 6539 | } |
| 6540 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
| 6541 | * 32 usec, so need to convert the value here. */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6542 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
| 6543 | (burst_time * 100 + 16) / 32) || |
| 6544 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || |
| 6545 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || |
| 6546 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) |
| 6547 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6548 | |
| 6549 | nla_nest_end(msg, params); |
| 6550 | |
| 6551 | nla_nest_end(msg, txq); |
| 6552 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6553 | res = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6554 | wpa_printf(MSG_DEBUG, |
| 6555 | "nl80211: TX queue param set: queue=%d aifs=%d cw_min=%d cw_max=%d burst_time=%d --> res=%d", |
| 6556 | queue, aifs, cw_min, cw_max, burst_time, res); |
| 6557 | if (res == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6558 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6559 | msg = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6560 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6561 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6562 | return -1; |
| 6563 | } |
| 6564 | |
| 6565 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6566 | 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] | 6567 | const char *ifname, int vlan_id) |
| 6568 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6569 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6570 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6571 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6572 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6573 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
| 6574 | ", ifname=%s[%d], vlan_id=%d)", |
| 6575 | bss->ifname, if_nametoindex(bss->ifname), |
| 6576 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6577 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 6578 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 6579 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { |
| 6580 | nlmsg_free(msg); |
| 6581 | return -ENOBUFS; |
| 6582 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6583 | |
| 6584 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6585 | if (ret < 0) { |
| 6586 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" |
| 6587 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", |
| 6588 | MAC2STR(addr), ifname, vlan_id, ret, |
| 6589 | strerror(-ret)); |
| 6590 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6591 | return ret; |
| 6592 | } |
| 6593 | |
| 6594 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6595 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
| 6596 | { |
| 6597 | struct hostap_sta_driver_data data; |
| 6598 | int ret; |
| 6599 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 6600 | os_memset(&data, 0, sizeof(data)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6601 | data.inactive_msec = (unsigned long) -1; |
| 6602 | ret = i802_read_sta_data(priv, &data, addr); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6603 | if (ret == -ENOENT) |
| 6604 | return -ENOENT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6605 | if (ret || data.inactive_msec == (unsigned long) -1) |
| 6606 | return -1; |
| 6607 | return data.inactive_msec / 1000; |
| 6608 | } |
| 6609 | |
| 6610 | |
| 6611 | static int i802_sta_clear_stats(void *priv, const u8 *addr) |
| 6612 | { |
| 6613 | #if 0 |
| 6614 | /* TODO */ |
| 6615 | #endif |
| 6616 | return 0; |
| 6617 | } |
| 6618 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6619 | |
| 6620 | 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^] | 6621 | u16 reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6622 | { |
| 6623 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6624 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6625 | struct ieee80211_mgmt mgmt; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 6626 | u8 channel; |
| 6627 | |
| 6628 | if (ieee80211_freq_to_chan(bss->freq, &channel) == |
| 6629 | HOSTAPD_MODE_IEEE80211AD) { |
| 6630 | /* Deauthentication is not used in DMG/IEEE 802.11ad; |
| 6631 | * disassociate the STA instead. */ |
| 6632 | return i802_sta_disassoc(priv, own_addr, addr, reason); |
| 6633 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6634 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6635 | if (is_mesh_interface(drv->nlmode)) |
| 6636 | return -1; |
| 6637 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6638 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6639 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6640 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6641 | memset(&mgmt, 0, sizeof(mgmt)); |
| 6642 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 6643 | WLAN_FC_STYPE_DEAUTH); |
| 6644 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 6645 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 6646 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 6647 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
| 6648 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 6649 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6650 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6651 | 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6652 | } |
| 6653 | |
| 6654 | |
| 6655 | 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^] | 6656 | u16 reason) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6657 | { |
| 6658 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6659 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6660 | struct ieee80211_mgmt mgmt; |
| 6661 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6662 | if (is_mesh_interface(drv->nlmode)) |
| 6663 | return -1; |
| 6664 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6665 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6666 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6667 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6668 | memset(&mgmt, 0, sizeof(mgmt)); |
| 6669 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 6670 | WLAN_FC_STYPE_DISASSOC); |
| 6671 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 6672 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 6673 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 6674 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
| 6675 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 6676 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6677 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6678 | 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6679 | } |
| 6680 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6681 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6682 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
| 6683 | { |
| 6684 | char buf[200], *pos, *end; |
| 6685 | int i, res; |
| 6686 | |
| 6687 | pos = buf; |
| 6688 | end = pos + sizeof(buf); |
| 6689 | |
| 6690 | for (i = 0; i < drv->num_if_indices; i++) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 6691 | if (!drv->if_indices[i].ifindex) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6692 | continue; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6693 | res = os_snprintf(pos, end - pos, " %d(%d)", |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 6694 | drv->if_indices[i].ifindex, |
| 6695 | drv->if_indices[i].reason); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6696 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6697 | break; |
| 6698 | pos += res; |
| 6699 | } |
| 6700 | *pos = '\0'; |
| 6701 | |
| 6702 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", |
| 6703 | drv->num_if_indices, buf); |
| 6704 | } |
| 6705 | |
| 6706 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6707 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 6708 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6709 | { |
| 6710 | int i; |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 6711 | struct drv_nl80211_if_info *old; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6712 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6713 | wpa_printf(MSG_DEBUG, |
| 6714 | "nl80211: Add own interface ifindex %d (ifidx_reason %d)", |
| 6715 | ifidx, ifidx_reason); |
| 6716 | if (have_ifidx(drv, ifidx, ifidx_reason)) { |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6717 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
| 6718 | ifidx); |
| 6719 | return; |
| 6720 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6721 | for (i = 0; i < drv->num_if_indices; i++) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 6722 | if (drv->if_indices[i].ifindex == 0) { |
| 6723 | drv->if_indices[i].ifindex = ifidx; |
| 6724 | drv->if_indices[i].reason = ifidx_reason; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6725 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6726 | return; |
| 6727 | } |
| 6728 | } |
| 6729 | |
| 6730 | if (drv->if_indices != drv->default_if_indices) |
| 6731 | old = drv->if_indices; |
| 6732 | else |
| 6733 | old = NULL; |
| 6734 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6735 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 6736 | sizeof(*old)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6737 | if (!drv->if_indices) { |
| 6738 | if (!old) |
| 6739 | drv->if_indices = drv->default_if_indices; |
| 6740 | else |
| 6741 | drv->if_indices = old; |
| 6742 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
| 6743 | "interfaces"); |
| 6744 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); |
| 6745 | return; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6746 | } |
| 6747 | if (!old) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6748 | os_memcpy(drv->if_indices, drv->default_if_indices, |
| 6749 | sizeof(drv->default_if_indices)); |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 6750 | drv->if_indices[drv->num_if_indices].ifindex = ifidx; |
| 6751 | drv->if_indices[drv->num_if_indices].reason = ifidx_reason; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6752 | drv->num_if_indices++; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6753 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6754 | } |
| 6755 | |
| 6756 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6757 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 6758 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6759 | { |
| 6760 | int i; |
| 6761 | |
| 6762 | for (i = 0; i < drv->num_if_indices; i++) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 6763 | if ((drv->if_indices[i].ifindex == ifidx || |
| 6764 | ifidx == IFIDX_ANY) && |
| 6765 | (drv->if_indices[i].reason == ifidx_reason || |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6766 | ifidx_reason == IFIDX_ANY)) { |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 6767 | drv->if_indices[i].ifindex = 0; |
| 6768 | drv->if_indices[i].reason = 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6769 | break; |
| 6770 | } |
| 6771 | } |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6772 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6773 | } |
| 6774 | |
| 6775 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6776 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 6777 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6778 | { |
| 6779 | int i; |
| 6780 | |
| 6781 | for (i = 0; i < drv->num_if_indices; i++) |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 6782 | if (drv->if_indices[i].ifindex == ifidx && |
| 6783 | (drv->if_indices[i].reason == ifidx_reason || |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6784 | ifidx_reason == IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6785 | return 1; |
| 6786 | |
| 6787 | return 0; |
| 6788 | } |
| 6789 | |
| 6790 | |
| 6791 | 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] | 6792 | const char *bridge_ifname, char *ifname_wds) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6793 | { |
| 6794 | struct i802_bss *bss = priv; |
| 6795 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6796 | char name[IFNAMSIZ + 1]; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6797 | union wpa_event_data event; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 6798 | int ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6799 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame] | 6800 | ret = os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
| 6801 | if (ret >= (int) sizeof(name)) |
| 6802 | wpa_printf(MSG_WARNING, |
| 6803 | "nl80211: WDS interface name was truncated"); |
| 6804 | else if (ret < 0) |
| 6805 | return ret; |
| 6806 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6807 | if (ifname_wds) |
| 6808 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); |
| 6809 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6810 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
| 6811 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); |
| 6812 | if (val) { |
| 6813 | if (!if_nametoindex(name)) { |
| 6814 | if (nl80211_create_iface(drv, name, |
| 6815 | NL80211_IFTYPE_AP_VLAN, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6816 | bss->addr, 1, NULL, NULL, 0) < |
| 6817 | 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6818 | return -1; |
| 6819 | if (bridge_ifname && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6820 | linux_br_add_if(drv->global->ioctl_sock, |
| 6821 | bridge_ifname, name) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6822 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6823 | |
| 6824 | os_memset(&event, 0, sizeof(event)); |
| 6825 | event.wds_sta_interface.sta_addr = addr; |
| 6826 | event.wds_sta_interface.ifname = name; |
| 6827 | event.wds_sta_interface.istatus = INTERFACE_ADDED; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 6828 | wpa_supplicant_event(bss->ctx, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6829 | EVENT_WDS_STA_INTERFACE_STATUS, |
| 6830 | &event); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6831 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6832 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
| 6833 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " |
| 6834 | "interface %s up", name); |
| 6835 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6836 | return i802_set_sta_vlan(priv, addr, name, 0); |
| 6837 | } else { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 6838 | if (bridge_ifname && |
| 6839 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, |
| 6840 | name) < 0) |
| 6841 | wpa_printf(MSG_INFO, |
| 6842 | "nl80211: Failed to remove interface %s from bridge %s: %s", |
| 6843 | name, bridge_ifname, strerror(errno)); |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6844 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6845 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 6846 | nl80211_remove_iface(drv, if_nametoindex(name)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6847 | os_memset(&event, 0, sizeof(event)); |
| 6848 | event.wds_sta_interface.sta_addr = addr; |
| 6849 | event.wds_sta_interface.ifname = name; |
| 6850 | event.wds_sta_interface.istatus = INTERFACE_REMOVED; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 6851 | wpa_supplicant_event(bss->ctx, EVENT_WDS_STA_INTERFACE_STATUS, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6852 | &event); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 6853 | return 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6854 | } |
| 6855 | } |
| 6856 | |
| 6857 | |
| 6858 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
| 6859 | { |
| 6860 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 6861 | struct sockaddr_ll lladdr; |
| 6862 | unsigned char buf[3000]; |
| 6863 | int len; |
| 6864 | socklen_t fromlen = sizeof(lladdr); |
| 6865 | |
| 6866 | len = recvfrom(sock, buf, sizeof(buf), 0, |
| 6867 | (struct sockaddr *)&lladdr, &fromlen); |
| 6868 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6869 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
| 6870 | strerror(errno)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6871 | return; |
| 6872 | } |
| 6873 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6874 | if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6875 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
| 6876 | } |
| 6877 | |
| 6878 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6879 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
| 6880 | struct i802_bss *bss, |
| 6881 | const char *brname, const char *ifname) |
| 6882 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6883 | int br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6884 | char in_br[IFNAMSIZ]; |
| 6885 | |
| 6886 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6887 | br_ifindex = if_nametoindex(brname); |
| 6888 | if (br_ifindex == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6889 | /* |
| 6890 | * Bridge was configured, but the bridge device does |
| 6891 | * not exist. Try to add it now. |
| 6892 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6893 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6894 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
| 6895 | "bridge interface %s: %s", |
| 6896 | brname, strerror(errno)); |
| 6897 | return -1; |
| 6898 | } |
| 6899 | bss->added_bridge = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6900 | br_ifindex = if_nametoindex(brname); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6901 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6902 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6903 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6904 | |
| 6905 | if (linux_br_get(in_br, ifname) == 0) { |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 6906 | if (os_strcmp(in_br, brname) == 0) { |
| 6907 | bss->already_in_bridge = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6908 | return 0; /* already in the bridge */ |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 6909 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6910 | |
| 6911 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " |
| 6912 | "bridge %s", ifname, in_br); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6913 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
| 6914 | 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6915 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
| 6916 | "remove interface %s from bridge " |
| 6917 | "%s: %s", |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6918 | ifname, in_br, strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6919 | return -1; |
| 6920 | } |
| 6921 | } |
| 6922 | |
| 6923 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", |
| 6924 | ifname, brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6925 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6926 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
| 6927 | "into bridge %s: %s", |
| 6928 | ifname, brname, strerror(errno)); |
| 6929 | return -1; |
| 6930 | } |
| 6931 | bss->added_if_into_bridge = 1; |
| 6932 | |
| 6933 | return 0; |
| 6934 | } |
| 6935 | |
| 6936 | |
| 6937 | static void *i802_init(struct hostapd_data *hapd, |
| 6938 | struct wpa_init_params *params) |
| 6939 | { |
| 6940 | struct wpa_driver_nl80211_data *drv; |
| 6941 | struct i802_bss *bss; |
| 6942 | size_t i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6943 | char master_ifname[IFNAMSIZ]; |
| 6944 | int ifindex, br_ifindex = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6945 | int br_added = 0; |
| 6946 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 6947 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
| 6948 | params->global_priv, 1, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6949 | params->bssid, params->driver_params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6950 | if (bss == NULL) |
| 6951 | return NULL; |
| 6952 | |
| 6953 | drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6954 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6955 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6956 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6957 | params->ifname, master_ifname); |
| 6958 | br_ifindex = if_nametoindex(master_ifname); |
| 6959 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 6960 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && |
| 6961 | linux_master_get(master_ifname, params->ifname) == 0) { |
| 6962 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", |
| 6963 | params->ifname, master_ifname); |
| 6964 | /* start listening for EAPOL on the master interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6965 | add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6966 | |
| 6967 | /* check if master itself is under bridge */ |
| 6968 | if (linux_br_get(master_ifname, master_ifname) == 0) { |
| 6969 | wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s", |
| 6970 | master_ifname); |
| 6971 | br_ifindex = if_nametoindex(master_ifname); |
| 6972 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 6973 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6974 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6975 | master_ifname[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6976 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6977 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6978 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6979 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6980 | for (i = 0; i < params->num_bridge; i++) { |
| 6981 | if (params->bridge[i]) { |
| 6982 | ifindex = if_nametoindex(params->bridge[i]); |
| 6983 | if (ifindex) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6984 | add_ifidx(drv, ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6985 | if (ifindex == br_ifindex) |
| 6986 | br_added = 1; |
| 6987 | } |
| 6988 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6989 | |
| 6990 | /* start listening for EAPOL on the default AP interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6991 | add_ifidx(drv, drv->ifindex, IFIDX_ANY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6992 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6993 | if (params->num_bridge && params->bridge[0]) { |
| 6994 | if (i802_check_bridge(drv, bss, params->bridge[0], |
| 6995 | params->ifname) < 0) |
| 6996 | goto failed; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6997 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6998 | br_added = 1; |
| 6999 | } |
| 7000 | |
| 7001 | if (!br_added && br_ifindex && |
| 7002 | (params->num_bridge == 0 || !params->bridge[0])) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7003 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7004 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7005 | #ifdef CONFIG_LIBNL3_ROUTE |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 7006 | if (bss->added_if_into_bridge || bss->already_in_bridge) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7007 | drv->rtnl_sk = nl_socket_alloc(); |
| 7008 | if (drv->rtnl_sk == NULL) { |
| 7009 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); |
| 7010 | goto failed; |
| 7011 | } |
| 7012 | |
| 7013 | if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) { |
| 7014 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", |
| 7015 | strerror(errno)); |
| 7016 | goto failed; |
| 7017 | } |
| 7018 | } |
| 7019 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 7020 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7021 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
| 7022 | if (drv->eapol_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7023 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
| 7024 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7025 | goto failed; |
| 7026 | } |
| 7027 | |
| 7028 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) |
| 7029 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7030 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7031 | goto failed; |
| 7032 | } |
| 7033 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7034 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 7035 | params->own_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7036 | goto failed; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7037 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7038 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7039 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
| 7040 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7041 | return bss; |
| 7042 | |
| 7043 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7044 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7045 | return NULL; |
| 7046 | } |
| 7047 | |
| 7048 | |
| 7049 | static void i802_deinit(void *priv) |
| 7050 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7051 | struct i802_bss *bss = priv; |
| 7052 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7053 | } |
| 7054 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7055 | |
| 7056 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
| 7057 | enum wpa_driver_if_type type) |
| 7058 | { |
| 7059 | switch (type) { |
| 7060 | case WPA_IF_STATION: |
| 7061 | return NL80211_IFTYPE_STATION; |
| 7062 | case WPA_IF_P2P_CLIENT: |
| 7063 | case WPA_IF_P2P_GROUP: |
| 7064 | return NL80211_IFTYPE_P2P_CLIENT; |
| 7065 | case WPA_IF_AP_VLAN: |
| 7066 | return NL80211_IFTYPE_AP_VLAN; |
| 7067 | case WPA_IF_AP_BSS: |
| 7068 | return NL80211_IFTYPE_AP; |
| 7069 | case WPA_IF_P2P_GO: |
| 7070 | return NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7071 | case WPA_IF_P2P_DEVICE: |
| 7072 | return NL80211_IFTYPE_P2P_DEVICE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7073 | case WPA_IF_MESH: |
| 7074 | return NL80211_IFTYPE_MESH_POINT; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7075 | default: |
| 7076 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7077 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7078 | } |
| 7079 | |
| 7080 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7081 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
| 7082 | { |
| 7083 | struct wpa_driver_nl80211_data *drv; |
| 7084 | dl_list_for_each(drv, &global->interfaces, |
| 7085 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7086 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7087 | return 1; |
| 7088 | } |
| 7089 | return 0; |
| 7090 | } |
| 7091 | |
| 7092 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7093 | 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] | 7094 | { |
| 7095 | unsigned int idx; |
| 7096 | |
| 7097 | if (!drv->global) |
| 7098 | return -1; |
| 7099 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7100 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7101 | for (idx = 0; idx < 64; idx++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7102 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7103 | new_addr[0] ^= idx << 2; |
| 7104 | if (!nl80211_addr_in_use(drv->global, new_addr)) |
| 7105 | break; |
| 7106 | } |
| 7107 | if (idx == 64) |
| 7108 | return -1; |
| 7109 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7110 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7111 | MACSTR, MAC2STR(new_addr)); |
| 7112 | |
| 7113 | return 0; |
| 7114 | } |
| 7115 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7116 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7117 | struct wdev_info { |
| 7118 | u64 wdev_id; |
| 7119 | int wdev_id_set; |
| 7120 | u8 macaddr[ETH_ALEN]; |
| 7121 | }; |
| 7122 | |
| 7123 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) |
| 7124 | { |
| 7125 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7126 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7127 | struct wdev_info *wi = arg; |
| 7128 | |
| 7129 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7130 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7131 | if (tb[NL80211_ATTR_WDEV]) { |
| 7132 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 7133 | wi->wdev_id_set = 1; |
| 7134 | } |
| 7135 | |
| 7136 | if (tb[NL80211_ATTR_MAC]) |
| 7137 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 7138 | ETH_ALEN); |
| 7139 | |
| 7140 | return NL_SKIP; |
| 7141 | } |
| 7142 | |
| 7143 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7144 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
| 7145 | const char *ifname, const u8 *addr, |
| 7146 | void *bss_ctx, void **drv_priv, |
| 7147 | char *force_ifname, u8 *if_addr, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7148 | const char *bridge, int use_existing, |
| 7149 | int setup_ap) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7150 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7151 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7152 | struct i802_bss *bss = priv; |
| 7153 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7154 | int ifidx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7155 | int added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7156 | |
| 7157 | if (addr) |
| 7158 | os_memcpy(if_addr, addr, ETH_ALEN); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7159 | nlmode = wpa_driver_nl80211_if_type(type); |
| 7160 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 7161 | struct wdev_info p2pdev_info; |
| 7162 | |
| 7163 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); |
| 7164 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
| 7165 | 0, nl80211_wdev_handler, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7166 | &p2pdev_info, use_existing); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7167 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
| 7168 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
| 7169 | ifname); |
| 7170 | return -1; |
| 7171 | } |
| 7172 | |
| 7173 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; |
| 7174 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; |
| 7175 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) |
| 7176 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); |
| 7177 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", |
| 7178 | ifname, |
| 7179 | (long long unsigned int) p2pdev_info.wdev_id); |
| 7180 | } else { |
| 7181 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7182 | 0, NULL, NULL, use_existing); |
| 7183 | if (use_existing && ifidx == -ENFILE) { |
| 7184 | added = 0; |
| 7185 | ifidx = if_nametoindex(ifname); |
| 7186 | } else if (ifidx < 0) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7187 | return -1; |
| 7188 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7189 | } |
| 7190 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7191 | if (!addr) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 7192 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7193 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
| 7194 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 7195 | ifname, if_addr) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7196 | if (added) |
| 7197 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7198 | return -1; |
| 7199 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7200 | } |
| 7201 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7202 | if (!addr && |
| 7203 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 7204 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
| 7205 | type == WPA_IF_STATION)) { |
| 7206 | /* Enforce unique address */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7207 | u8 new_addr[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7208 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7209 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7210 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 7211 | if (added) |
| 7212 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7213 | return -1; |
| 7214 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7215 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7216 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 7217 | "for interface %s type %d", ifname, type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7218 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 7219 | if (added) |
| 7220 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7221 | return -1; |
| 7222 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7223 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7224 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 7225 | if (added) |
| 7226 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7227 | return -1; |
| 7228 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7229 | } |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 7230 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7231 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7232 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7233 | if (type == WPA_IF_AP_BSS && setup_ap) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7234 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
| 7235 | if (new_bss == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7236 | if (added) |
| 7237 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7238 | return -1; |
| 7239 | } |
| 7240 | |
| 7241 | if (bridge && |
| 7242 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { |
| 7243 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " |
| 7244 | "interface %s to a bridge %s", |
| 7245 | ifname, bridge); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7246 | if (added) |
| 7247 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7248 | os_free(new_bss); |
| 7249 | return -1; |
| 7250 | } |
| 7251 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7252 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
| 7253 | { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 7254 | if (added) |
| 7255 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7256 | os_free(new_bss); |
| 7257 | return -1; |
| 7258 | } |
| 7259 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7260 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7261 | new_bss->ifindex = ifidx; |
| 7262 | new_bss->drv = drv; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7263 | new_bss->next = drv->first_bss->next; |
| 7264 | new_bss->freq = drv->first_bss->freq; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7265 | new_bss->ctx = bss_ctx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7266 | new_bss->added_if = added; |
| 7267 | drv->first_bss->next = new_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7268 | if (drv_priv) |
| 7269 | *drv_priv = new_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7270 | nl80211_init_bss(new_bss); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7271 | |
| 7272 | /* Subscribe management frames for this WPA_IF_AP_BSS */ |
| 7273 | if (nl80211_setup_ap(new_bss)) |
| 7274 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7275 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7276 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7277 | if (drv->global) |
| 7278 | drv->global->if_add_ifindex = ifidx; |
| 7279 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7280 | /* |
| 7281 | * Some virtual interfaces need to process EAPOL packets and events on |
| 7282 | * the parent interface. This is used mainly with hostapd. |
| 7283 | */ |
| 7284 | if (ifidx > 0 && |
| 7285 | (drv->hostapd || |
| 7286 | nlmode == NL80211_IFTYPE_AP_VLAN || |
| 7287 | nlmode == NL80211_IFTYPE_WDS || |
| 7288 | nlmode == NL80211_IFTYPE_MONITOR)) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7289 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7290 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7291 | return 0; |
| 7292 | } |
| 7293 | |
| 7294 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7295 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7296 | enum wpa_driver_if_type type, |
| 7297 | const char *ifname) |
| 7298 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7299 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7300 | int ifindex = if_nametoindex(ifname); |
| 7301 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7302 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
| 7303 | __func__, type, ifname, ifindex, bss->added_if); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 7304 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7305 | nl80211_remove_iface(drv, ifindex); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 7306 | else if (ifindex > 0 && !bss->added_if) { |
| 7307 | struct wpa_driver_nl80211_data *drv2; |
| 7308 | dl_list_for_each(drv2, &drv->global->interfaces, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7309 | struct wpa_driver_nl80211_data, list) { |
| 7310 | del_ifidx(drv2, ifindex, IFIDX_ANY); |
| 7311 | del_ifidx(drv2, IFIDX_ANY, ifindex); |
| 7312 | } |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 7313 | } |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7314 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7315 | if (type != WPA_IF_AP_BSS) |
| 7316 | return 0; |
| 7317 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7318 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7319 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 7320 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7321 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 7322 | "interface %s from bridge %s: %s", |
| 7323 | bss->ifname, bss->brname, strerror(errno)); |
| 7324 | } |
| 7325 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7326 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7327 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 7328 | "bridge %s: %s", |
| 7329 | bss->brname, strerror(errno)); |
| 7330 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7331 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7332 | if (bss != drv->first_bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7333 | struct i802_bss *tbss; |
| 7334 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7335 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
| 7336 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7337 | if (tbss->next == bss) { |
| 7338 | tbss->next = bss->next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7339 | /* Unsubscribe management frames */ |
| 7340 | nl80211_teardown_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7341 | nl80211_destroy_bss(bss); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7342 | if (!bss->added_if) |
| 7343 | i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7344 | os_free(bss); |
| 7345 | bss = NULL; |
| 7346 | break; |
| 7347 | } |
| 7348 | } |
| 7349 | if (bss) |
| 7350 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " |
| 7351 | "BSS %p in the list", __func__, bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7352 | } else { |
| 7353 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
| 7354 | nl80211_teardown_ap(bss); |
| 7355 | if (!bss->added_if && !drv->first_bss->next) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 7356 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7357 | nl80211_destroy_bss(bss); |
| 7358 | if (!bss->added_if) |
| 7359 | i802_set_iface_flags(bss, 0); |
| 7360 | if (drv->first_bss->next) { |
| 7361 | drv->first_bss = drv->first_bss->next; |
| 7362 | drv->ctx = drv->first_bss->ctx; |
| 7363 | os_free(bss); |
| 7364 | } else { |
| 7365 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); |
| 7366 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7367 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7368 | |
| 7369 | return 0; |
| 7370 | } |
| 7371 | |
| 7372 | |
| 7373 | static int cookie_handler(struct nl_msg *msg, void *arg) |
| 7374 | { |
| 7375 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7376 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7377 | u64 *cookie = arg; |
| 7378 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7379 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7380 | if (tb[NL80211_ATTR_COOKIE]) |
| 7381 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 7382 | return NL_SKIP; |
| 7383 | } |
| 7384 | |
| 7385 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7386 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7387 | unsigned int freq, unsigned int wait, |
| 7388 | const u8 *buf, size_t buf_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7389 | u64 *cookie_out, int no_cck, int no_ack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7390 | int offchanok, const u16 *csa_offs, |
| 7391 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7392 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7393 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7394 | struct nl_msg *msg; |
| 7395 | u64 cookie; |
| 7396 | int ret = -1; |
| 7397 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7398 | 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] | 7399 | "no_ack=%d offchanok=%d", |
| 7400 | freq, wait, no_cck, no_ack, offchanok); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7401 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7402 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7403 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
| 7404 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 7405 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || |
| 7406 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 7407 | drv->test_use_roc_tx) && |
| 7408 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || |
| 7409 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || |
| 7410 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7411 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
| 7412 | csa_offs_len * sizeof(u16), csa_offs)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7413 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
| 7414 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7415 | |
| 7416 | cookie = 0; |
| 7417 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 7418 | msg = NULL; |
| 7419 | if (ret) { |
| 7420 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 7421 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
| 7422 | freq, wait); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7423 | } else { |
| 7424 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " |
| 7425 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
| 7426 | (long long unsigned int) cookie); |
| 7427 | |
| 7428 | if (cookie_out) |
| 7429 | *cookie_out = no_ack ? (u64) -1 : cookie; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7430 | |
| 7431 | if (drv->num_send_action_cookies == MAX_SEND_ACTION_COOKIES) { |
| 7432 | wpa_printf(MSG_DEBUG, |
| 7433 | "nl80211: Drop oldest pending send action cookie 0x%llx", |
| 7434 | (long long unsigned int) |
| 7435 | drv->send_action_cookies[0]); |
| 7436 | os_memmove(&drv->send_action_cookies[0], |
| 7437 | &drv->send_action_cookies[1], |
| 7438 | (MAX_SEND_ACTION_COOKIES - 1) * |
| 7439 | sizeof(u64)); |
| 7440 | drv->num_send_action_cookies--; |
| 7441 | } |
| 7442 | drv->send_action_cookies[drv->num_send_action_cookies] = cookie; |
| 7443 | drv->num_send_action_cookies++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7444 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7445 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7446 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7447 | nlmsg_free(msg); |
| 7448 | return ret; |
| 7449 | } |
| 7450 | |
| 7451 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7452 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
| 7453 | unsigned int freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7454 | unsigned int wait_time, |
| 7455 | const u8 *dst, const u8 *src, |
| 7456 | const u8 *bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7457 | const u8 *data, size_t data_len, |
| 7458 | int no_cck) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7459 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7460 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7461 | int ret = -1; |
| 7462 | u8 *buf; |
| 7463 | struct ieee80211_hdr *hdr; |
| 7464 | |
| 7465 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7466 | "freq=%u MHz wait=%d ms no_cck=%d)", |
| 7467 | drv->ifindex, freq, wait_time, no_cck); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7468 | |
| 7469 | buf = os_zalloc(24 + data_len); |
| 7470 | if (buf == NULL) |
| 7471 | return ret; |
| 7472 | os_memcpy(buf + 24, data, data_len); |
| 7473 | hdr = (struct ieee80211_hdr *) buf; |
| 7474 | hdr->frame_control = |
| 7475 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); |
| 7476 | os_memcpy(hdr->addr1, dst, ETH_ALEN); |
| 7477 | os_memcpy(hdr->addr2, src, ETH_ALEN); |
| 7478 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); |
| 7479 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 7480 | if (os_memcmp(bss->addr, src, ETH_ALEN) != 0) { |
| 7481 | wpa_printf(MSG_DEBUG, "nl80211: Use random TA " MACSTR, |
| 7482 | MAC2STR(src)); |
| 7483 | os_memcpy(bss->rand_addr, src, ETH_ALEN); |
| 7484 | } else { |
| 7485 | os_memset(bss->rand_addr, 0, ETH_ALEN); |
| 7486 | } |
| 7487 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7488 | if (is_ap_interface(drv->nlmode) && |
| 7489 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 7490 | (int) freq == bss->freq || drv->device_ap_sme || |
| 7491 | !drv->use_monitor)) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7492 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
| 7493 | 0, freq, no_cck, 1, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7494 | wait_time, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7495 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7496 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7497 | 24 + data_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7498 | &drv->send_action_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7499 | no_cck, 0, 1, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7500 | |
| 7501 | os_free(buf); |
| 7502 | return ret; |
| 7503 | } |
| 7504 | |
| 7505 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7506 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7507 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7508 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7509 | struct nl_msg *msg; |
| 7510 | int ret; |
| 7511 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 7512 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7513 | (long long unsigned int) cookie); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7514 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7515 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7516 | nlmsg_free(msg); |
| 7517 | return; |
| 7518 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7519 | |
| 7520 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7521 | if (ret) |
| 7522 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " |
| 7523 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7524 | } |
| 7525 | |
| 7526 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7527 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
| 7528 | { |
| 7529 | struct i802_bss *bss = priv; |
| 7530 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7531 | unsigned int i; |
| 7532 | u64 cookie; |
| 7533 | |
| 7534 | /* Cancel the last pending TX cookie */ |
| 7535 | nl80211_frame_wait_cancel(bss, drv->send_action_cookie); |
| 7536 | |
| 7537 | /* |
| 7538 | * Cancel the other pending TX cookies, if any. This is needed since |
| 7539 | * the driver may keep a list of all pending offchannel TX operations |
| 7540 | * and free up the radio only once they have expired or cancelled. |
| 7541 | */ |
| 7542 | for (i = drv->num_send_action_cookies; i > 0; i--) { |
| 7543 | cookie = drv->send_action_cookies[i - 1]; |
| 7544 | if (cookie != drv->send_action_cookie) |
| 7545 | nl80211_frame_wait_cancel(bss, cookie); |
| 7546 | } |
| 7547 | drv->num_send_action_cookies = 0; |
| 7548 | } |
| 7549 | |
| 7550 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7551 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
| 7552 | unsigned int duration) |
| 7553 | { |
| 7554 | struct i802_bss *bss = priv; |
| 7555 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7556 | struct nl_msg *msg; |
| 7557 | int ret; |
| 7558 | u64 cookie; |
| 7559 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7560 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
| 7561 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 7562 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { |
| 7563 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7564 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7565 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7566 | |
| 7567 | cookie = 0; |
| 7568 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 7569 | if (ret == 0) { |
| 7570 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " |
| 7571 | "0x%llx for freq=%u MHz duration=%u", |
| 7572 | (long long unsigned int) cookie, freq, duration); |
| 7573 | drv->remain_on_chan_cookie = cookie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7574 | drv->pending_remain_on_chan = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7575 | return 0; |
| 7576 | } |
| 7577 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " |
| 7578 | "(freq=%d duration=%u): %d (%s)", |
| 7579 | freq, duration, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7580 | return -1; |
| 7581 | } |
| 7582 | |
| 7583 | |
| 7584 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) |
| 7585 | { |
| 7586 | struct i802_bss *bss = priv; |
| 7587 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7588 | struct nl_msg *msg; |
| 7589 | int ret; |
| 7590 | |
| 7591 | if (!drv->pending_remain_on_chan) { |
| 7592 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " |
| 7593 | "to cancel"); |
| 7594 | return -1; |
| 7595 | } |
| 7596 | |
| 7597 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " |
| 7598 | "0x%llx", |
| 7599 | (long long unsigned int) drv->remain_on_chan_cookie); |
| 7600 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7601 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
| 7602 | if (!msg || |
| 7603 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
| 7604 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7605 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7606 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7607 | |
| 7608 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7609 | if (ret == 0) |
| 7610 | return 0; |
| 7611 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " |
| 7612 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7613 | return -1; |
| 7614 | } |
| 7615 | |
| 7616 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7617 | 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] | 7618 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7619 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 7620 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7621 | if (!report) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7622 | if (bss->nl_preq && drv->device_ap_sme && |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 7623 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
| 7624 | !bss->static_ap) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7625 | /* |
| 7626 | * Do not disable Probe Request reporting that was |
| 7627 | * enabled in nl80211_setup_ap(). |
| 7628 | */ |
| 7629 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " |
| 7630 | "Probe Request reporting nl_preq=%p while " |
| 7631 | "in AP mode", bss->nl_preq); |
| 7632 | } else if (bss->nl_preq) { |
| 7633 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
| 7634 | "reporting nl_preq=%p", bss->nl_preq); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7635 | nl80211_destroy_eloop_handle(&bss->nl_preq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7636 | } |
| 7637 | return 0; |
| 7638 | } |
| 7639 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7640 | if (bss->nl_preq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7641 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7642 | "already on! nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7643 | return 0; |
| 7644 | } |
| 7645 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7646 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
| 7647 | if (bss->nl_preq == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7648 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7649 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
| 7650 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7651 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7652 | if (nl80211_register_frame(bss, bss->nl_preq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7653 | (WLAN_FC_TYPE_MGMT << 2) | |
| 7654 | (WLAN_FC_STYPE_PROBE_REQ << 4), |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7655 | NULL, 0) < 0) |
| 7656 | goto out_err; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 7657 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7658 | nl80211_register_eloop_read(&bss->nl_preq, |
| 7659 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7660 | bss->nl_cb, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7661 | |
| 7662 | return 0; |
| 7663 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7664 | out_err: |
| 7665 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7666 | return -1; |
| 7667 | } |
| 7668 | |
| 7669 | |
| 7670 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 7671 | int ifindex, int disabled) |
| 7672 | { |
| 7673 | struct nl_msg *msg; |
| 7674 | struct nlattr *bands, *band; |
| 7675 | int ret; |
| 7676 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7677 | wpa_printf(MSG_DEBUG, |
| 7678 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", |
| 7679 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : |
| 7680 | "no NL80211_TXRATE_LEGACY constraint"); |
| 7681 | |
| 7682 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
| 7683 | NL80211_CMD_SET_TX_BITRATE_MASK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7684 | if (!msg) |
| 7685 | return -1; |
| 7686 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7687 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 7688 | if (!bands) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7689 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7690 | |
| 7691 | /* |
| 7692 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything |
| 7693 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS |
| 7694 | * rates. All 5 GHz rates are left enabled. |
| 7695 | */ |
| 7696 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7697 | if (!band || |
| 7698 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, |
| 7699 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) |
| 7700 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7701 | nla_nest_end(msg, band); |
| 7702 | |
| 7703 | nla_nest_end(msg, bands); |
| 7704 | |
| 7705 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7706 | if (ret) { |
| 7707 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " |
| 7708 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7709 | } else |
| 7710 | drv->disabled_11b_rates = disabled; |
| 7711 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7712 | return ret; |
| 7713 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7714 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7715 | nlmsg_free(msg); |
| 7716 | return -1; |
| 7717 | } |
| 7718 | |
| 7719 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7720 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
| 7721 | { |
| 7722 | struct i802_bss *bss = priv; |
| 7723 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7724 | if (!is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7725 | return -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 7726 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7727 | bss->beacon_set = 0; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7728 | |
| 7729 | /* |
| 7730 | * If the P2P GO interface was dynamically added, then it is |
| 7731 | * possible that the interface change to station is not possible. |
| 7732 | */ |
| 7733 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) |
| 7734 | return 0; |
| 7735 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7736 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7737 | } |
| 7738 | |
| 7739 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7740 | static int wpa_driver_nl80211_stop_ap(void *priv) |
| 7741 | { |
| 7742 | struct i802_bss *bss = priv; |
| 7743 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7744 | if (!is_ap_interface(drv->nlmode)) |
| 7745 | return -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 7746 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7747 | bss->beacon_set = 0; |
| 7748 | return 0; |
| 7749 | } |
| 7750 | |
| 7751 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7752 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
| 7753 | { |
| 7754 | struct i802_bss *bss = priv; |
| 7755 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7756 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) |
| 7757 | return -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7758 | |
| 7759 | /* |
| 7760 | * If the P2P Client interface was dynamically added, then it is |
| 7761 | * possible that the interface change to station is not possible. |
| 7762 | */ |
| 7763 | if (bss->if_dynamic) |
| 7764 | return 0; |
| 7765 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7766 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
| 7767 | } |
| 7768 | |
| 7769 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7770 | static void wpa_driver_nl80211_resume(void *priv) |
| 7771 | { |
| 7772 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7773 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7774 | |
| 7775 | if (i802_set_iface_flags(bss, 1)) |
| 7776 | 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] | 7777 | |
| 7778 | if (is_p2p_net_interface(nlmode)) |
| 7779 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7780 | } |
| 7781 | |
| 7782 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7783 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
| 7784 | { |
| 7785 | struct i802_bss *bss = priv; |
| 7786 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7787 | struct nl_msg *msg; |
| 7788 | struct nlattr *cqm; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7789 | |
| 7790 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " |
| 7791 | "hysteresis=%d", threshold, hysteresis); |
| 7792 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7793 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
| 7794 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
| 7795 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || |
| 7796 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { |
| 7797 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7798 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7799 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7800 | nla_nest_end(msg, cqm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7801 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7802 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7803 | } |
| 7804 | |
| 7805 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7806 | static int get_channel_width(struct nl_msg *msg, void *arg) |
| 7807 | { |
| 7808 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7809 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7810 | struct wpa_signal_info *sig_change = arg; |
| 7811 | |
| 7812 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7813 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7814 | |
| 7815 | sig_change->center_frq1 = -1; |
| 7816 | sig_change->center_frq2 = -1; |
| 7817 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 7818 | |
| 7819 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 7820 | sig_change->chanwidth = convert2width( |
| 7821 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 7822 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 7823 | sig_change->center_frq1 = |
| 7824 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 7825 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 7826 | sig_change->center_frq2 = |
| 7827 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 7828 | } |
| 7829 | |
| 7830 | return NL_SKIP; |
| 7831 | } |
| 7832 | |
| 7833 | |
| 7834 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, |
| 7835 | struct wpa_signal_info *sig) |
| 7836 | { |
| 7837 | struct nl_msg *msg; |
| 7838 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7839 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7840 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7841 | } |
| 7842 | |
| 7843 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7844 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
| 7845 | { |
| 7846 | struct i802_bss *bss = priv; |
| 7847 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7848 | int res; |
| 7849 | |
| 7850 | os_memset(si, 0, sizeof(*si)); |
| 7851 | res = nl80211_get_link_signal(drv, si); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7852 | if (res) { |
| 7853 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && |
| 7854 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
| 7855 | return res; |
| 7856 | si->current_signal = 0; |
| 7857 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7858 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7859 | res = nl80211_get_channel_width(drv, si); |
| 7860 | if (res != 0) |
| 7861 | return res; |
| 7862 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7863 | return nl80211_get_link_noise(drv, si); |
| 7864 | } |
| 7865 | |
| 7866 | |
| 7867 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
| 7868 | int encrypt) |
| 7869 | { |
| 7870 | struct i802_bss *bss = priv; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7871 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7872 | 0, 0, 0, 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7873 | } |
| 7874 | |
| 7875 | |
| 7876 | static int nl80211_set_param(void *priv, const char *param) |
| 7877 | { |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 7878 | struct i802_bss *bss = priv; |
| 7879 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7880 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7881 | if (param == NULL) |
| 7882 | return 0; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7883 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7884 | |
| 7885 | #ifdef CONFIG_P2P |
| 7886 | if (os_strstr(param, "use_p2p_group_interface=1")) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7887 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 7888 | "interface"); |
| 7889 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 7890 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 7891 | } |
| 7892 | #endif /* CONFIG_P2P */ |
| 7893 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 7894 | if (os_strstr(param, "use_monitor=1")) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7895 | drv->use_monitor = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7896 | |
| 7897 | if (os_strstr(param, "force_connect_cmd=1")) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7898 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7899 | drv->force_connect_cmd = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7900 | } |
| 7901 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 7902 | if (os_strstr(param, "force_bss_selection=1")) |
| 7903 | drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
| 7904 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 7905 | if (os_strstr(param, "no_offchannel_tx=1")) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 7906 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 7907 | drv->test_use_roc_tx = 1; |
| 7908 | } |
| 7909 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7910 | return 0; |
| 7911 | } |
| 7912 | |
| 7913 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7914 | static void * nl80211_global_init(void *ctx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7915 | { |
| 7916 | struct nl80211_global *global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7917 | struct netlink_config *cfg; |
| 7918 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7919 | global = os_zalloc(sizeof(*global)); |
| 7920 | if (global == NULL) |
| 7921 | return NULL; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7922 | global->ctx = ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7923 | global->ioctl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7924 | dl_list_init(&global->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7925 | global->if_add_ifindex = -1; |
| 7926 | |
| 7927 | cfg = os_zalloc(sizeof(*cfg)); |
| 7928 | if (cfg == NULL) |
| 7929 | goto err; |
| 7930 | |
| 7931 | cfg->ctx = global; |
| 7932 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; |
| 7933 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; |
| 7934 | global->netlink = netlink_init(cfg); |
| 7935 | if (global->netlink == NULL) { |
| 7936 | os_free(cfg); |
| 7937 | goto err; |
| 7938 | } |
| 7939 | |
| 7940 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
| 7941 | goto err; |
| 7942 | |
| 7943 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 7944 | if (global->ioctl_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7945 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
| 7946 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7947 | goto err; |
| 7948 | } |
| 7949 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7950 | return global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7951 | |
| 7952 | err: |
| 7953 | nl80211_global_deinit(global); |
| 7954 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7955 | } |
| 7956 | |
| 7957 | |
| 7958 | static void nl80211_global_deinit(void *priv) |
| 7959 | { |
| 7960 | struct nl80211_global *global = priv; |
| 7961 | if (global == NULL) |
| 7962 | return; |
| 7963 | if (!dl_list_empty(&global->interfaces)) { |
| 7964 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " |
| 7965 | "nl80211_global_deinit", |
| 7966 | dl_list_len(&global->interfaces)); |
| 7967 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7968 | |
| 7969 | if (global->netlink) |
| 7970 | netlink_deinit(global->netlink); |
| 7971 | |
| 7972 | nl_destroy_handles(&global->nl); |
| 7973 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7974 | if (global->nl_event) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7975 | nl80211_destroy_eloop_handle(&global->nl_event, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7976 | |
| 7977 | nl_cb_put(global->nl_cb); |
| 7978 | |
| 7979 | if (global->ioctl_sock >= 0) |
| 7980 | close(global->ioctl_sock); |
| 7981 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7982 | os_free(global); |
| 7983 | } |
| 7984 | |
| 7985 | |
| 7986 | static const char * nl80211_get_radio_name(void *priv) |
| 7987 | { |
| 7988 | struct i802_bss *bss = priv; |
| 7989 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7990 | return drv->phyname; |
| 7991 | } |
| 7992 | |
| 7993 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7994 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, |
| 7995 | struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7996 | { |
| 7997 | struct nl_msg *msg; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7998 | const size_t PMK_MAX_LEN = 48; /* current cfg80211 limit */ |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7999 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8000 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8001 | (params->pmkid && |
| 8002 | nla_put(msg, NL80211_ATTR_PMKID, 16, params->pmkid)) || |
| 8003 | (params->bssid && |
| 8004 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) || |
| 8005 | (params->ssid_len && |
| 8006 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || |
| 8007 | (params->fils_cache_id && |
| 8008 | nla_put(msg, NL80211_ATTR_FILS_CACHE_ID, 2, |
| 8009 | params->fils_cache_id)) || |
Hai Shalom | 021b0b5 | 2019-04-10 11:17:58 -0700 | [diff] [blame] | 8010 | (cmd != NL80211_CMD_DEL_PMKSA && |
| 8011 | params->pmk_len && params->pmk_len <= PMK_MAX_LEN && |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8012 | nla_put(msg, NL80211_ATTR_PMK, params->pmk_len, params->pmk))) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8013 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8014 | nlmsg_free(msg); |
| 8015 | return -ENOBUFS; |
| 8016 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8017 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8018 | return send_and_recv_msgs(bss->drv, msg, NULL, (void *) -1); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8019 | } |
| 8020 | |
| 8021 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8022 | static int nl80211_add_pmkid(void *priv, struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8023 | { |
| 8024 | struct i802_bss *bss = priv; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8025 | int ret; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8026 | |
| 8027 | if (params->bssid) |
| 8028 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, |
| 8029 | MAC2STR(params->bssid)); |
| 8030 | else if (params->fils_cache_id && params->ssid_len) { |
| 8031 | wpa_printf(MSG_DEBUG, |
| 8032 | "nl80211: Add PMKSA for cache id %02x%02x SSID %s", |
| 8033 | params->fils_cache_id[0], params->fils_cache_id[1], |
| 8034 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
| 8035 | } |
| 8036 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8037 | ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params); |
| 8038 | if (ret < 0) { |
| 8039 | wpa_printf(MSG_DEBUG, |
| 8040 | "nl80211: NL80211_CMD_SET_PMKSA failed: %d (%s)", |
| 8041 | ret, strerror(-ret)); |
| 8042 | } |
| 8043 | |
| 8044 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8045 | } |
| 8046 | |
| 8047 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8048 | static int nl80211_remove_pmkid(void *priv, struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8049 | { |
| 8050 | struct i802_bss *bss = priv; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8051 | int ret; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8052 | |
| 8053 | if (params->bssid) |
| 8054 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, |
| 8055 | MAC2STR(params->bssid)); |
| 8056 | else if (params->fils_cache_id && params->ssid_len) { |
| 8057 | wpa_printf(MSG_DEBUG, |
| 8058 | "nl80211: Delete PMKSA for cache id %02x%02x SSID %s", |
| 8059 | params->fils_cache_id[0], params->fils_cache_id[1], |
| 8060 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
| 8061 | } |
| 8062 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8063 | ret = nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, params); |
| 8064 | if (ret < 0) { |
| 8065 | wpa_printf(MSG_DEBUG, |
| 8066 | "nl80211: NL80211_CMD_DEL_PMKSA failed: %d (%s)", |
| 8067 | ret, strerror(-ret)); |
| 8068 | } |
| 8069 | |
| 8070 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8071 | } |
| 8072 | |
| 8073 | |
| 8074 | static int nl80211_flush_pmkid(void *priv) |
| 8075 | { |
| 8076 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8077 | struct nl_msg *msg; |
| 8078 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8079 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8080 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_FLUSH_PMKSA); |
| 8081 | if (!msg) |
| 8082 | return -ENOBUFS; |
| 8083 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 8084 | } |
| 8085 | |
| 8086 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8087 | static void clean_survey_results(struct survey_results *survey_results) |
| 8088 | { |
| 8089 | struct freq_survey *survey, *tmp; |
| 8090 | |
| 8091 | if (dl_list_empty(&survey_results->survey_list)) |
| 8092 | return; |
| 8093 | |
| 8094 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 8095 | struct freq_survey, list) { |
| 8096 | dl_list_del(&survey->list); |
| 8097 | os_free(survey); |
| 8098 | } |
| 8099 | } |
| 8100 | |
| 8101 | |
| 8102 | static void add_survey(struct nlattr **sinfo, u32 ifidx, |
| 8103 | struct dl_list *survey_list) |
| 8104 | { |
| 8105 | struct freq_survey *survey; |
| 8106 | |
| 8107 | survey = os_zalloc(sizeof(struct freq_survey)); |
| 8108 | if (!survey) |
| 8109 | return; |
| 8110 | |
| 8111 | survey->ifidx = ifidx; |
| 8112 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 8113 | survey->filled = 0; |
| 8114 | |
| 8115 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { |
| 8116 | survey->nf = (int8_t) |
| 8117 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 8118 | survey->filled |= SURVEY_HAS_NF; |
| 8119 | } |
| 8120 | |
| 8121 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { |
| 8122 | survey->channel_time = |
| 8123 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); |
| 8124 | survey->filled |= SURVEY_HAS_CHAN_TIME; |
| 8125 | } |
| 8126 | |
| 8127 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { |
| 8128 | survey->channel_time_busy = |
| 8129 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); |
| 8130 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; |
| 8131 | } |
| 8132 | |
| 8133 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { |
| 8134 | survey->channel_time_rx = |
| 8135 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); |
| 8136 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; |
| 8137 | } |
| 8138 | |
| 8139 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { |
| 8140 | survey->channel_time_tx = |
| 8141 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); |
| 8142 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; |
| 8143 | } |
| 8144 | |
| 8145 | 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)", |
| 8146 | survey->freq, |
| 8147 | survey->nf, |
| 8148 | (unsigned long int) survey->channel_time, |
| 8149 | (unsigned long int) survey->channel_time_busy, |
| 8150 | (unsigned long int) survey->channel_time_tx, |
| 8151 | (unsigned long int) survey->channel_time_rx, |
| 8152 | survey->filled); |
| 8153 | |
| 8154 | dl_list_add_tail(survey_list, &survey->list); |
| 8155 | } |
| 8156 | |
| 8157 | |
| 8158 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, |
| 8159 | unsigned int freq_filter) |
| 8160 | { |
| 8161 | if (!freq_filter) |
| 8162 | return 1; |
| 8163 | |
| 8164 | return freq_filter == surveyed_freq; |
| 8165 | } |
| 8166 | |
| 8167 | |
| 8168 | static int survey_handler(struct nl_msg *msg, void *arg) |
| 8169 | { |
| 8170 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8171 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8172 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 8173 | struct survey_results *survey_results; |
| 8174 | u32 surveyed_freq = 0; |
| 8175 | u32 ifidx; |
| 8176 | |
| 8177 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 8178 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 8179 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 8180 | }; |
| 8181 | |
| 8182 | survey_results = (struct survey_results *) arg; |
| 8183 | |
| 8184 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8185 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8186 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 8187 | if (!tb[NL80211_ATTR_IFINDEX]) |
| 8188 | return NL_SKIP; |
| 8189 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8190 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 8191 | |
| 8192 | if (!tb[NL80211_ATTR_SURVEY_INFO]) |
| 8193 | return NL_SKIP; |
| 8194 | |
| 8195 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 8196 | tb[NL80211_ATTR_SURVEY_INFO], |
| 8197 | survey_policy)) |
| 8198 | return NL_SKIP; |
| 8199 | |
| 8200 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { |
| 8201 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); |
| 8202 | return NL_SKIP; |
| 8203 | } |
| 8204 | |
| 8205 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 8206 | |
| 8207 | if (!check_survey_ok(sinfo, surveyed_freq, |
| 8208 | survey_results->freq_filter)) |
| 8209 | return NL_SKIP; |
| 8210 | |
| 8211 | if (survey_results->freq_filter && |
| 8212 | survey_results->freq_filter != surveyed_freq) { |
| 8213 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", |
| 8214 | surveyed_freq); |
| 8215 | return NL_SKIP; |
| 8216 | } |
| 8217 | |
| 8218 | add_survey(sinfo, ifidx, &survey_results->survey_list); |
| 8219 | |
| 8220 | return NL_SKIP; |
| 8221 | } |
| 8222 | |
| 8223 | |
| 8224 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) |
| 8225 | { |
| 8226 | struct i802_bss *bss = priv; |
| 8227 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8228 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8229 | int err; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8230 | union wpa_event_data data; |
| 8231 | struct survey_results *survey_results; |
| 8232 | |
| 8233 | os_memset(&data, 0, sizeof(data)); |
| 8234 | survey_results = &data.survey_results; |
| 8235 | |
| 8236 | dl_list_init(&survey_results->survey_list); |
| 8237 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8238 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8239 | if (!msg) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8240 | return -ENOBUFS; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8241 | |
| 8242 | if (freq) |
| 8243 | data.survey_results.freq_filter = freq; |
| 8244 | |
| 8245 | do { |
| 8246 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); |
| 8247 | err = send_and_recv_msgs(drv, msg, survey_handler, |
| 8248 | survey_results); |
| 8249 | } while (err > 0); |
| 8250 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8251 | if (err) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8252 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8253 | else |
| 8254 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8255 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8256 | clean_survey_results(survey_results); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8257 | return err; |
| 8258 | } |
| 8259 | |
| 8260 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 8261 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
| 8262 | const u8 *kck, size_t kck_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8263 | const u8 *replay_ctr) |
| 8264 | { |
| 8265 | struct i802_bss *bss = priv; |
| 8266 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8267 | struct nlattr *replay_nested; |
| 8268 | struct nl_msg *msg; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8269 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8270 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8271 | if (!drv->set_rekey_offload) |
| 8272 | return; |
| 8273 | |
| 8274 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8275 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
| 8276 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 8277 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8278 | (kck_len && nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8279 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
| 8280 | replay_ctr)) { |
| 8281 | nl80211_nlmsg_clear(msg); |
| 8282 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8283 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8284 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8285 | |
| 8286 | nla_nest_end(msg, replay_nested); |
| 8287 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8288 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 8289 | if (ret == -EOPNOTSUPP) { |
| 8290 | wpa_printf(MSG_DEBUG, |
| 8291 | "nl80211: Driver does not support rekey offload"); |
| 8292 | drv->set_rekey_offload = 0; |
| 8293 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8294 | } |
| 8295 | |
| 8296 | |
| 8297 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
| 8298 | const u8 *addr, int qos) |
| 8299 | { |
| 8300 | /* send data frame to poll STA and check whether |
| 8301 | * this frame is ACKed */ |
| 8302 | struct { |
| 8303 | struct ieee80211_hdr hdr; |
| 8304 | u16 qos_ctl; |
| 8305 | } STRUCT_PACKED nulldata; |
| 8306 | size_t size; |
| 8307 | |
| 8308 | /* Send data frame to poll STA and check whether this frame is ACKed */ |
| 8309 | |
| 8310 | os_memset(&nulldata, 0, sizeof(nulldata)); |
| 8311 | |
| 8312 | if (qos) { |
| 8313 | nulldata.hdr.frame_control = |
| 8314 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 8315 | WLAN_FC_STYPE_QOS_NULL); |
| 8316 | size = sizeof(nulldata); |
| 8317 | } else { |
| 8318 | nulldata.hdr.frame_control = |
| 8319 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 8320 | WLAN_FC_STYPE_NULLFUNC); |
| 8321 | size = sizeof(struct ieee80211_hdr); |
| 8322 | } |
| 8323 | |
| 8324 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 8325 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 8326 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 8327 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 8328 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8329 | if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8330 | 0, 0, NULL, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8331 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
| 8332 | "send poll frame"); |
| 8333 | } |
| 8334 | |
| 8335 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
| 8336 | int qos) |
| 8337 | { |
| 8338 | struct i802_bss *bss = priv; |
| 8339 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8340 | struct nl_msg *msg; |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 8341 | u64 cookie; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8342 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8343 | |
| 8344 | if (!drv->poll_command_supported) { |
| 8345 | nl80211_send_null_frame(bss, own_addr, addr, qos); |
| 8346 | return; |
| 8347 | } |
| 8348 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8349 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
| 8350 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 8351 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8352 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8353 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8354 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 8355 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8356 | if (ret < 0) { |
| 8357 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " |
| 8358 | MACSTR " failed: ret=%d (%s)", |
| 8359 | MAC2STR(addr), ret, strerror(-ret)); |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 8360 | } else { |
| 8361 | wpa_printf(MSG_DEBUG, |
| 8362 | "nl80211: Client probe request addr=" MACSTR |
| 8363 | " cookie=%llu", MAC2STR(addr), |
| 8364 | (long long unsigned int) cookie); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8365 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8366 | } |
| 8367 | |
| 8368 | |
| 8369 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
| 8370 | { |
| 8371 | struct nl_msg *msg; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8372 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8373 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8374 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
| 8375 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
| 8376 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { |
| 8377 | nlmsg_free(msg); |
| 8378 | return -ENOBUFS; |
| 8379 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8380 | |
| 8381 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 8382 | if (ret < 0) { |
| 8383 | wpa_printf(MSG_DEBUG, |
| 8384 | "nl80211: Setting PS state %s failed: %d (%s)", |
| 8385 | enabled ? "enabled" : "disabled", |
| 8386 | ret, strerror(-ret)); |
| 8387 | } |
| 8388 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8389 | } |
| 8390 | |
| 8391 | |
| 8392 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, |
| 8393 | int ctwindow) |
| 8394 | { |
| 8395 | struct i802_bss *bss = priv; |
| 8396 | |
| 8397 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " |
| 8398 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); |
| 8399 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8400 | if (opp_ps != -1 || ctwindow != -1) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8401 | #ifdef ANDROID_P2P |
| 8402 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8403 | #else /* ANDROID_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8404 | return -1; /* Not yet supported */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8405 | #endif /* ANDROID_P2P */ |
| 8406 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8407 | |
| 8408 | if (legacy_ps == -1) |
| 8409 | return 0; |
| 8410 | if (legacy_ps != 0 && legacy_ps != 1) |
| 8411 | return -1; /* Not yet supported */ |
| 8412 | |
| 8413 | return nl80211_set_power_save(bss, legacy_ps); |
| 8414 | } |
| 8415 | |
| 8416 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8417 | static int nl80211_start_radar_detection(void *priv, |
| 8418 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8419 | { |
| 8420 | struct i802_bss *bss = priv; |
| 8421 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8422 | struct nl_msg *msg; |
| 8423 | int ret; |
| 8424 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 8425 | 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)", |
| 8426 | freq->freq, freq->ht_enabled, freq->vht_enabled, freq->he_enabled, |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8427 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 8428 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8429 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
| 8430 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " |
| 8431 | "detection"); |
| 8432 | return -1; |
| 8433 | } |
| 8434 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8435 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
| 8436 | nl80211_put_freq_params(msg, freq) < 0) { |
| 8437 | nlmsg_free(msg); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8438 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8439 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8440 | |
| 8441 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8442 | if (ret == 0) |
| 8443 | return 0; |
| 8444 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " |
| 8445 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8446 | return -1; |
| 8447 | } |
| 8448 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8449 | #ifdef CONFIG_TDLS |
| 8450 | |
| 8451 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, |
| 8452 | u8 dialog_token, u16 status_code, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 8453 | u32 peer_capab, int initiator, const u8 *buf, |
| 8454 | size_t len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8455 | { |
| 8456 | struct i802_bss *bss = priv; |
| 8457 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8458 | struct nl_msg *msg; |
| 8459 | |
| 8460 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 8461 | return -EOPNOTSUPP; |
| 8462 | |
| 8463 | if (!dst) |
| 8464 | return -EINVAL; |
| 8465 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8466 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
| 8467 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 8468 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || |
| 8469 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || |
| 8470 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) |
| 8471 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8472 | if (peer_capab) { |
| 8473 | /* |
| 8474 | * The internal enum tdls_peer_capability definition is |
| 8475 | * currently identical with the nl80211 enum |
| 8476 | * nl80211_tdls_peer_capability, so no conversion is needed |
| 8477 | * here. |
| 8478 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8479 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
| 8480 | peer_capab)) |
| 8481 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8482 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8483 | if ((initiator && |
| 8484 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || |
| 8485 | nla_put(msg, NL80211_ATTR_IE, len, buf)) |
| 8486 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8487 | |
| 8488 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8489 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8490 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8491 | nlmsg_free(msg); |
| 8492 | return -ENOBUFS; |
| 8493 | } |
| 8494 | |
| 8495 | |
| 8496 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) |
| 8497 | { |
| 8498 | struct i802_bss *bss = priv; |
| 8499 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8500 | struct nl_msg *msg; |
| 8501 | enum nl80211_tdls_operation nl80211_oper; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8502 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8503 | |
| 8504 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 8505 | return -EOPNOTSUPP; |
| 8506 | |
| 8507 | switch (oper) { |
| 8508 | case TDLS_DISCOVERY_REQ: |
| 8509 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; |
| 8510 | break; |
| 8511 | case TDLS_SETUP: |
| 8512 | nl80211_oper = NL80211_TDLS_SETUP; |
| 8513 | break; |
| 8514 | case TDLS_TEARDOWN: |
| 8515 | nl80211_oper = NL80211_TDLS_TEARDOWN; |
| 8516 | break; |
| 8517 | case TDLS_ENABLE_LINK: |
| 8518 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; |
| 8519 | break; |
| 8520 | case TDLS_DISABLE_LINK: |
| 8521 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; |
| 8522 | break; |
| 8523 | case TDLS_ENABLE: |
| 8524 | return 0; |
| 8525 | case TDLS_DISABLE: |
| 8526 | return 0; |
| 8527 | default: |
| 8528 | return -EINVAL; |
| 8529 | } |
| 8530 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8531 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
| 8532 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
| 8533 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
| 8534 | nlmsg_free(msg); |
| 8535 | return -ENOBUFS; |
| 8536 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8537 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8538 | res = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8539 | wpa_printf(MSG_DEBUG, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR |
| 8540 | " --> res=%d (%s)", nl80211_oper, MAC2STR(peer), res, |
| 8541 | strerror(-res)); |
| 8542 | return res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8543 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8544 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8545 | |
| 8546 | static int |
| 8547 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, |
| 8548 | const struct hostapd_freq_params *params) |
| 8549 | { |
| 8550 | struct i802_bss *bss = priv; |
| 8551 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8552 | struct nl_msg *msg; |
| 8553 | int ret = -ENOBUFS; |
| 8554 | |
| 8555 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 8556 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 8557 | return -EOPNOTSUPP; |
| 8558 | |
| 8559 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR |
| 8560 | " oper_class=%u freq=%u", |
| 8561 | MAC2STR(addr), oper_class, params->freq); |
| 8562 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); |
| 8563 | if (!msg || |
| 8564 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 8565 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || |
| 8566 | (ret = nl80211_put_freq_params(msg, params))) { |
| 8567 | nlmsg_free(msg); |
| 8568 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); |
| 8569 | return ret; |
| 8570 | } |
| 8571 | |
| 8572 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8573 | } |
| 8574 | |
| 8575 | |
| 8576 | static int |
| 8577 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) |
| 8578 | { |
| 8579 | struct i802_bss *bss = priv; |
| 8580 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8581 | struct nl_msg *msg; |
| 8582 | |
| 8583 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 8584 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 8585 | return -EOPNOTSUPP; |
| 8586 | |
| 8587 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, |
| 8588 | MAC2STR(addr)); |
| 8589 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); |
| 8590 | if (!msg || |
| 8591 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 8592 | nlmsg_free(msg); |
| 8593 | wpa_printf(MSG_DEBUG, |
| 8594 | "nl80211: Could not build TDLS cancel chan switch"); |
| 8595 | return -ENOBUFS; |
| 8596 | } |
| 8597 | |
| 8598 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8599 | } |
| 8600 | |
| 8601 | #endif /* CONFIG TDLS */ |
| 8602 | |
| 8603 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8604 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
| 8605 | enum wpa_alg alg, const u8 *addr, |
| 8606 | int key_idx, int set_tx, |
| 8607 | const u8 *seq, size_t seq_len, |
| 8608 | const u8 *key, size_t key_len) |
| 8609 | { |
| 8610 | struct i802_bss *bss = priv; |
| 8611 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, |
| 8612 | set_tx, seq, seq_len, key, key_len); |
| 8613 | } |
| 8614 | |
| 8615 | |
| 8616 | static int driver_nl80211_scan2(void *priv, |
| 8617 | struct wpa_driver_scan_params *params) |
| 8618 | { |
| 8619 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8620 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 8621 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8622 | |
| 8623 | /* |
| 8624 | * Do a vendor specific scan if possible. If only_new_results is |
| 8625 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush |
| 8626 | * cannot be achieved through a vendor scan. The below condition may |
| 8627 | * need to be modified if new scan flags are added in the future whose |
| 8628 | * functionality can only be achieved through a normal scan. |
| 8629 | */ |
| 8630 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) |
| 8631 | return wpa_driver_nl80211_vendor_scan(bss, params); |
| 8632 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8633 | return wpa_driver_nl80211_scan(bss, params); |
| 8634 | } |
| 8635 | |
| 8636 | |
| 8637 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 8638 | u16 reason_code) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8639 | { |
| 8640 | struct i802_bss *bss = priv; |
| 8641 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); |
| 8642 | } |
| 8643 | |
| 8644 | |
| 8645 | static int driver_nl80211_authenticate(void *priv, |
| 8646 | struct wpa_driver_auth_params *params) |
| 8647 | { |
| 8648 | struct i802_bss *bss = priv; |
| 8649 | return wpa_driver_nl80211_authenticate(bss, params); |
| 8650 | } |
| 8651 | |
| 8652 | |
| 8653 | static void driver_nl80211_deinit(void *priv) |
| 8654 | { |
| 8655 | struct i802_bss *bss = priv; |
| 8656 | wpa_driver_nl80211_deinit(bss); |
| 8657 | } |
| 8658 | |
| 8659 | |
| 8660 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, |
| 8661 | const char *ifname) |
| 8662 | { |
| 8663 | struct i802_bss *bss = priv; |
| 8664 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 8665 | } |
| 8666 | |
| 8667 | |
| 8668 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8669 | size_t data_len, int noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8670 | unsigned int freq, |
| 8671 | const u16 *csa_offs, size_t csa_offs_len) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8672 | { |
| 8673 | struct i802_bss *bss = priv; |
| 8674 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8675 | freq, 0, 0, 0, csa_offs, |
| 8676 | csa_offs_len); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8677 | } |
| 8678 | |
| 8679 | |
| 8680 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) |
| 8681 | { |
| 8682 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8683 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8684 | } |
| 8685 | |
| 8686 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8687 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
| 8688 | const char *ifname, int vlan_id) |
| 8689 | { |
| 8690 | struct i802_bss *bss = priv; |
| 8691 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); |
| 8692 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8693 | |
| 8694 | |
| 8695 | static int driver_nl80211_read_sta_data(void *priv, |
| 8696 | struct hostap_sta_driver_data *data, |
| 8697 | const u8 *addr) |
| 8698 | { |
| 8699 | struct i802_bss *bss = priv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 8700 | |
| 8701 | os_memset(data, 0, sizeof(*data)); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8702 | return i802_read_sta_data(bss, data, addr); |
| 8703 | } |
| 8704 | |
| 8705 | |
| 8706 | static int driver_nl80211_send_action(void *priv, unsigned int freq, |
| 8707 | unsigned int wait_time, |
| 8708 | const u8 *dst, const u8 *src, |
| 8709 | const u8 *bssid, |
| 8710 | const u8 *data, size_t data_len, |
| 8711 | int no_cck) |
| 8712 | { |
| 8713 | struct i802_bss *bss = priv; |
| 8714 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, |
| 8715 | bssid, data, data_len, no_cck); |
| 8716 | } |
| 8717 | |
| 8718 | |
| 8719 | static int driver_nl80211_probe_req_report(void *priv, int report) |
| 8720 | { |
| 8721 | struct i802_bss *bss = priv; |
| 8722 | return wpa_driver_nl80211_probe_req_report(bss, report); |
| 8723 | } |
| 8724 | |
| 8725 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8726 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
| 8727 | const u8 *ies, size_t ies_len) |
| 8728 | { |
| 8729 | int ret; |
| 8730 | struct nl_msg *msg; |
| 8731 | struct i802_bss *bss = priv; |
| 8732 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8733 | u16 mdid = WPA_GET_LE16(md); |
| 8734 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8735 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8736 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
| 8737 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
| 8738 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { |
| 8739 | nlmsg_free(msg); |
| 8740 | return -ENOBUFS; |
| 8741 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8742 | |
| 8743 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8744 | if (ret) { |
| 8745 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " |
| 8746 | "err=%d (%s)", ret, strerror(-ret)); |
| 8747 | } |
| 8748 | |
| 8749 | return ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8750 | } |
| 8751 | |
| 8752 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 8753 | static int nl80211_update_dh_ie(void *priv, const u8 *peer_mac, |
| 8754 | u16 reason_code, const u8 *ie, size_t ie_len) |
| 8755 | { |
| 8756 | int ret; |
| 8757 | struct nl_msg *msg; |
| 8758 | struct i802_bss *bss = priv; |
| 8759 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8760 | |
| 8761 | wpa_printf(MSG_DEBUG, "nl80211: Updating DH IE peer: " MACSTR |
| 8762 | " reason %u", MAC2STR(peer_mac), reason_code); |
| 8763 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UPDATE_OWE_INFO)) || |
| 8764 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer_mac) || |
| 8765 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, reason_code) || |
| 8766 | (ie && nla_put(msg, NL80211_ATTR_IE, ie_len, ie))) { |
| 8767 | nlmsg_free(msg); |
| 8768 | return -ENOBUFS; |
| 8769 | } |
| 8770 | |
| 8771 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8772 | if (ret) { |
| 8773 | wpa_printf(MSG_DEBUG, |
| 8774 | "nl80211: update_dh_ie failed err=%d (%s)", |
| 8775 | ret, strerror(-ret)); |
| 8776 | } |
| 8777 | |
| 8778 | return ret; |
| 8779 | } |
| 8780 | |
| 8781 | |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 8782 | static const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8783 | { |
| 8784 | struct i802_bss *bss = priv; |
| 8785 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8786 | |
| 8787 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 8788 | return NULL; |
| 8789 | |
| 8790 | return bss->addr; |
| 8791 | } |
| 8792 | |
| 8793 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8794 | static const char * scan_state_str(enum scan_states scan_state) |
| 8795 | { |
| 8796 | switch (scan_state) { |
| 8797 | case NO_SCAN: |
| 8798 | return "NO_SCAN"; |
| 8799 | case SCAN_REQUESTED: |
| 8800 | return "SCAN_REQUESTED"; |
| 8801 | case SCAN_STARTED: |
| 8802 | return "SCAN_STARTED"; |
| 8803 | case SCAN_COMPLETED: |
| 8804 | return "SCAN_COMPLETED"; |
| 8805 | case SCAN_ABORTED: |
| 8806 | return "SCAN_ABORTED"; |
| 8807 | case SCHED_SCAN_STARTED: |
| 8808 | return "SCHED_SCAN_STARTED"; |
| 8809 | case SCHED_SCAN_STOPPED: |
| 8810 | return "SCHED_SCAN_STOPPED"; |
| 8811 | case SCHED_SCAN_RESULTS: |
| 8812 | return "SCHED_SCAN_RESULTS"; |
| 8813 | } |
| 8814 | |
| 8815 | return "??"; |
| 8816 | } |
| 8817 | |
| 8818 | |
| 8819 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) |
| 8820 | { |
| 8821 | struct i802_bss *bss = priv; |
| 8822 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8823 | int res; |
| 8824 | char *pos, *end; |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8825 | struct nl_msg *msg; |
| 8826 | char alpha2[3] = { 0, 0, 0 }; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8827 | |
| 8828 | pos = buf; |
| 8829 | end = buf + buflen; |
| 8830 | |
| 8831 | res = os_snprintf(pos, end - pos, |
| 8832 | "ifindex=%d\n" |
| 8833 | "ifname=%s\n" |
| 8834 | "brname=%s\n" |
| 8835 | "addr=" MACSTR "\n" |
| 8836 | "freq=%d\n" |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 8837 | "%s%s%s%s%s%s", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8838 | bss->ifindex, |
| 8839 | bss->ifname, |
| 8840 | bss->brname, |
| 8841 | MAC2STR(bss->addr), |
| 8842 | bss->freq, |
| 8843 | bss->beacon_set ? "beacon_set=1\n" : "", |
| 8844 | bss->added_if_into_bridge ? |
| 8845 | "added_if_into_bridge=1\n" : "", |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 8846 | bss->already_in_bridge ? "already_in_bridge=1\n" : "", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8847 | bss->added_bridge ? "added_bridge=1\n" : "", |
| 8848 | bss->in_deinit ? "in_deinit=1\n" : "", |
| 8849 | bss->if_dynamic ? "if_dynamic=1\n" : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8850 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8851 | return pos - buf; |
| 8852 | pos += res; |
| 8853 | |
| 8854 | if (bss->wdev_id_set) { |
| 8855 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", |
| 8856 | (unsigned long long) bss->wdev_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8857 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8858 | return pos - buf; |
| 8859 | pos += res; |
| 8860 | } |
| 8861 | |
| 8862 | res = os_snprintf(pos, end - pos, |
| 8863 | "phyname=%s\n" |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8864 | "perm_addr=" MACSTR "\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8865 | "drv_ifindex=%d\n" |
| 8866 | "operstate=%d\n" |
| 8867 | "scan_state=%s\n" |
| 8868 | "auth_bssid=" MACSTR "\n" |
| 8869 | "auth_attempt_bssid=" MACSTR "\n" |
| 8870 | "bssid=" MACSTR "\n" |
| 8871 | "prev_bssid=" MACSTR "\n" |
| 8872 | "associated=%d\n" |
| 8873 | "assoc_freq=%u\n" |
| 8874 | "monitor_sock=%d\n" |
| 8875 | "monitor_ifidx=%d\n" |
| 8876 | "monitor_refcount=%d\n" |
| 8877 | "last_mgmt_freq=%u\n" |
| 8878 | "eapol_tx_sock=%d\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8879 | "%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] | 8880 | drv->phyname, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8881 | MAC2STR(drv->perm_addr), |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8882 | drv->ifindex, |
| 8883 | drv->operstate, |
| 8884 | scan_state_str(drv->scan_state), |
| 8885 | MAC2STR(drv->auth_bssid), |
| 8886 | MAC2STR(drv->auth_attempt_bssid), |
| 8887 | MAC2STR(drv->bssid), |
| 8888 | MAC2STR(drv->prev_bssid), |
| 8889 | drv->associated, |
| 8890 | drv->assoc_freq, |
| 8891 | drv->monitor_sock, |
| 8892 | drv->monitor_ifidx, |
| 8893 | drv->monitor_refcount, |
| 8894 | drv->last_mgmt_freq, |
| 8895 | drv->eapol_tx_sock, |
| 8896 | drv->ignore_if_down_event ? |
| 8897 | "ignore_if_down_event=1\n" : "", |
| 8898 | drv->scan_complete_events ? |
| 8899 | "scan_complete_events=1\n" : "", |
| 8900 | drv->disabled_11b_rates ? |
| 8901 | "disabled_11b_rates=1\n" : "", |
| 8902 | drv->pending_remain_on_chan ? |
| 8903 | "pending_remain_on_chan=1\n" : "", |
| 8904 | drv->in_interface_list ? "in_interface_list=1\n" : "", |
| 8905 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", |
| 8906 | drv->poll_command_supported ? |
| 8907 | "poll_command_supported=1\n" : "", |
| 8908 | drv->data_tx_status ? "data_tx_status=1\n" : "", |
| 8909 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", |
| 8910 | drv->retry_auth ? "retry_auth=1\n" : "", |
| 8911 | drv->use_monitor ? "use_monitor=1\n" : "", |
| 8912 | drv->ignore_next_local_disconnect ? |
| 8913 | "ignore_next_local_disconnect=1\n" : "", |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 8914 | drv->ignore_next_local_deauth ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8915 | "ignore_next_local_deauth=1\n" : ""); |
| 8916 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8917 | return pos - buf; |
| 8918 | pos += res; |
| 8919 | |
| 8920 | if (drv->has_capability) { |
| 8921 | res = os_snprintf(pos, end - pos, |
| 8922 | "capa.key_mgmt=0x%x\n" |
| 8923 | "capa.enc=0x%x\n" |
| 8924 | "capa.auth=0x%x\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8925 | "capa.flags=0x%llx\n" |
| 8926 | "capa.rrm_flags=0x%x\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8927 | "capa.max_scan_ssids=%d\n" |
| 8928 | "capa.max_sched_scan_ssids=%d\n" |
| 8929 | "capa.sched_scan_supported=%d\n" |
| 8930 | "capa.max_match_sets=%d\n" |
| 8931 | "capa.max_remain_on_chan=%u\n" |
| 8932 | "capa.max_stations=%u\n" |
| 8933 | "capa.probe_resp_offloads=0x%x\n" |
| 8934 | "capa.max_acl_mac_addrs=%u\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8935 | "capa.num_multichan_concurrent=%u\n" |
| 8936 | "capa.mac_addr_rand_sched_scan_supported=%d\n" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8937 | "capa.mac_addr_rand_scan_supported=%d\n" |
| 8938 | "capa.conc_capab=%u\n" |
| 8939 | "capa.max_conc_chan_2_4=%u\n" |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8940 | "capa.max_conc_chan_5_0=%u\n" |
| 8941 | "capa.max_sched_scan_plans=%u\n" |
| 8942 | "capa.max_sched_scan_plan_interval=%u\n" |
| 8943 | "capa.max_sched_scan_plan_iterations=%u\n", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8944 | drv->capa.key_mgmt, |
| 8945 | drv->capa.enc, |
| 8946 | drv->capa.auth, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8947 | (unsigned long long) drv->capa.flags, |
| 8948 | drv->capa.rrm_flags, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8949 | drv->capa.max_scan_ssids, |
| 8950 | drv->capa.max_sched_scan_ssids, |
| 8951 | drv->capa.sched_scan_supported, |
| 8952 | drv->capa.max_match_sets, |
| 8953 | drv->capa.max_remain_on_chan, |
| 8954 | drv->capa.max_stations, |
| 8955 | drv->capa.probe_resp_offloads, |
| 8956 | drv->capa.max_acl_mac_addrs, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8957 | drv->capa.num_multichan_concurrent, |
| 8958 | drv->capa.mac_addr_rand_sched_scan_supported, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8959 | drv->capa.mac_addr_rand_scan_supported, |
| 8960 | drv->capa.conc_capab, |
| 8961 | drv->capa.max_conc_chan_2_4, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8962 | drv->capa.max_conc_chan_5_0, |
| 8963 | drv->capa.max_sched_scan_plans, |
| 8964 | drv->capa.max_sched_scan_plan_interval, |
| 8965 | drv->capa.max_sched_scan_plan_iterations); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8966 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8967 | return pos - buf; |
| 8968 | pos += res; |
| 8969 | } |
| 8970 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 8971 | msg = nlmsg_alloc(); |
| 8972 | if (msg && |
| 8973 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG) && |
| 8974 | nla_put_u32(msg, NL80211_ATTR_WIPHY, drv->wiphy_idx) == 0) { |
| 8975 | if (send_and_recv_msgs(drv, msg, nl80211_get_country, |
| 8976 | alpha2) == 0 && |
| 8977 | alpha2[0]) { |
| 8978 | res = os_snprintf(pos, end - pos, "country=%s\n", |
| 8979 | alpha2); |
| 8980 | if (os_snprintf_error(end - pos, res)) |
| 8981 | return pos - buf; |
| 8982 | pos += res; |
| 8983 | } |
| 8984 | } else { |
| 8985 | nlmsg_free(msg); |
| 8986 | } |
| 8987 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8988 | return pos - buf; |
| 8989 | } |
| 8990 | |
| 8991 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8992 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
| 8993 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8994 | if ((settings->head && |
| 8995 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, |
| 8996 | settings->head_len, settings->head)) || |
| 8997 | (settings->tail && |
| 8998 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, |
| 8999 | settings->tail_len, settings->tail)) || |
| 9000 | (settings->beacon_ies && |
| 9001 | nla_put(msg, NL80211_ATTR_IE, |
| 9002 | settings->beacon_ies_len, settings->beacon_ies)) || |
| 9003 | (settings->proberesp_ies && |
| 9004 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 9005 | settings->proberesp_ies_len, settings->proberesp_ies)) || |
| 9006 | (settings->assocresp_ies && |
| 9007 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 9008 | settings->assocresp_ies_len, settings->assocresp_ies)) || |
| 9009 | (settings->probe_resp && |
| 9010 | nla_put(msg, NL80211_ATTR_PROBE_RESP, |
| 9011 | settings->probe_resp_len, settings->probe_resp))) |
| 9012 | return -ENOBUFS; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9013 | |
| 9014 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9015 | } |
| 9016 | |
| 9017 | |
| 9018 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) |
| 9019 | { |
| 9020 | struct nl_msg *msg; |
| 9021 | struct i802_bss *bss = priv; |
| 9022 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9023 | struct nlattr *beacon_csa; |
| 9024 | int ret = -ENOBUFS; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9025 | int csa_off_len = 0; |
| 9026 | int i; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9027 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 9028 | 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] | 9029 | settings->cs_count, settings->block_tx, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 9030 | settings->freq_params.freq, settings->freq_params.bandwidth, |
| 9031 | settings->freq_params.center_freq1, |
| 9032 | settings->freq_params.center_freq2); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9033 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9034 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9035 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
| 9036 | return -EOPNOTSUPP; |
| 9037 | } |
| 9038 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9039 | if (drv->nlmode != NL80211_IFTYPE_AP && |
| 9040 | drv->nlmode != NL80211_IFTYPE_P2P_GO && |
| 9041 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9042 | return -EOPNOTSUPP; |
| 9043 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9044 | /* |
| 9045 | * Remove empty counters, assuming Probe Response and Beacon frame |
| 9046 | * counters match. This implementation assumes that there are only two |
| 9047 | * counters. |
| 9048 | */ |
| 9049 | if (settings->counter_offset_beacon[0] && |
| 9050 | !settings->counter_offset_beacon[1]) { |
| 9051 | csa_off_len = 1; |
| 9052 | } else if (settings->counter_offset_beacon[1] && |
| 9053 | !settings->counter_offset_beacon[0]) { |
| 9054 | csa_off_len = 1; |
| 9055 | settings->counter_offset_beacon[0] = |
| 9056 | settings->counter_offset_beacon[1]; |
| 9057 | settings->counter_offset_presp[0] = |
| 9058 | settings->counter_offset_presp[1]; |
| 9059 | } else if (settings->counter_offset_beacon[1] && |
| 9060 | settings->counter_offset_beacon[0]) { |
| 9061 | csa_off_len = 2; |
| 9062 | } else { |
| 9063 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); |
| 9064 | return -EINVAL; |
| 9065 | } |
| 9066 | |
| 9067 | /* Check CSA counters validity */ |
| 9068 | if (drv->capa.max_csa_counters && |
| 9069 | csa_off_len > drv->capa.max_csa_counters) { |
| 9070 | wpa_printf(MSG_ERROR, |
| 9071 | "nl80211: Too many CSA counters provided"); |
| 9072 | return -EINVAL; |
| 9073 | } |
| 9074 | |
| 9075 | if (!settings->beacon_csa.tail) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9076 | return -EINVAL; |
| 9077 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9078 | for (i = 0; i < csa_off_len; i++) { |
| 9079 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; |
| 9080 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; |
| 9081 | |
| 9082 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || |
| 9083 | (settings->beacon_csa.tail[csa_c_off_bcn] != |
| 9084 | settings->cs_count)) |
| 9085 | return -EINVAL; |
| 9086 | |
| 9087 | if (settings->beacon_csa.probe_resp && |
| 9088 | ((settings->beacon_csa.probe_resp_len <= |
| 9089 | csa_c_off_presp) || |
| 9090 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != |
| 9091 | settings->cs_count))) |
| 9092 | return -EINVAL; |
| 9093 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9094 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9095 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
| 9096 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
| 9097 | settings->cs_count) || |
| 9098 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || |
| 9099 | (settings->block_tx && |
| 9100 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9101 | goto error; |
| 9102 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9103 | /* beacon_after params */ |
| 9104 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 9105 | if (ret) |
| 9106 | goto error; |
| 9107 | |
| 9108 | /* beacon_csa params */ |
| 9109 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); |
| 9110 | if (!beacon_csa) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9111 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9112 | |
| 9113 | ret = set_beacon_data(msg, &settings->beacon_csa); |
| 9114 | if (ret) |
| 9115 | goto error; |
| 9116 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9117 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
| 9118 | csa_off_len * sizeof(u16), |
| 9119 | settings->counter_offset_beacon) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9120 | (settings->beacon_csa.probe_resp && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9121 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
| 9122 | csa_off_len * sizeof(u16), |
| 9123 | settings->counter_offset_presp))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9124 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9125 | |
| 9126 | nla_nest_end(msg, beacon_csa); |
| 9127 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9128 | if (ret) { |
| 9129 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", |
| 9130 | ret, strerror(-ret)); |
| 9131 | } |
| 9132 | return ret; |
| 9133 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9134 | fail: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9135 | ret = -ENOBUFS; |
| 9136 | error: |
| 9137 | nlmsg_free(msg); |
| 9138 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); |
| 9139 | return ret; |
| 9140 | } |
| 9141 | |
| 9142 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9143 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
| 9144 | u8 user_priority, u16 admitted_time) |
| 9145 | { |
| 9146 | struct i802_bss *bss = priv; |
| 9147 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9148 | struct nl_msg *msg; |
| 9149 | int ret; |
| 9150 | |
| 9151 | wpa_printf(MSG_DEBUG, |
| 9152 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", |
| 9153 | tsid, admitted_time, user_priority); |
| 9154 | |
| 9155 | if (!is_sta_interface(drv->nlmode)) |
| 9156 | return -ENOTSUP; |
| 9157 | |
| 9158 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
| 9159 | if (!msg || |
| 9160 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 9161 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 9162 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || |
| 9163 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { |
| 9164 | nlmsg_free(msg); |
| 9165 | return -ENOBUFS; |
| 9166 | } |
| 9167 | |
| 9168 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9169 | if (ret) |
| 9170 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", |
| 9171 | ret, strerror(-ret)); |
| 9172 | return ret; |
| 9173 | } |
| 9174 | |
| 9175 | |
| 9176 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) |
| 9177 | { |
| 9178 | struct i802_bss *bss = priv; |
| 9179 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9180 | struct nl_msg *msg; |
| 9181 | int ret; |
| 9182 | |
| 9183 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); |
| 9184 | |
| 9185 | if (!is_sta_interface(drv->nlmode)) |
| 9186 | return -ENOTSUP; |
| 9187 | |
| 9188 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
| 9189 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 9190 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 9191 | nlmsg_free(msg); |
| 9192 | return -ENOBUFS; |
| 9193 | } |
| 9194 | |
| 9195 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9196 | if (ret) |
| 9197 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", |
| 9198 | ret, strerror(-ret)); |
| 9199 | return ret; |
| 9200 | } |
| 9201 | |
| 9202 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9203 | #ifdef CONFIG_TESTING_OPTIONS |
| 9204 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) |
| 9205 | { |
| 9206 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9207 | struct wpabuf *buf = arg; |
| 9208 | |
| 9209 | if (!buf) |
| 9210 | return NL_SKIP; |
| 9211 | |
| 9212 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { |
| 9213 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); |
| 9214 | return NL_SKIP; |
| 9215 | } |
| 9216 | |
| 9217 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), |
| 9218 | genlmsg_attrlen(gnlh, 0)); |
| 9219 | |
| 9220 | return NL_SKIP; |
| 9221 | } |
| 9222 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 9223 | |
| 9224 | |
| 9225 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
| 9226 | { |
| 9227 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9228 | struct nlattr *nl_vendor_reply, *nl; |
| 9229 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9230 | struct wpabuf *buf = arg; |
| 9231 | int rem; |
| 9232 | |
| 9233 | if (!buf) |
| 9234 | return NL_SKIP; |
| 9235 | |
| 9236 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9237 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9238 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; |
| 9239 | |
| 9240 | if (!nl_vendor_reply) |
| 9241 | return NL_SKIP; |
| 9242 | |
| 9243 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { |
| 9244 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); |
| 9245 | return NL_SKIP; |
| 9246 | } |
| 9247 | |
| 9248 | nla_for_each_nested(nl, nl_vendor_reply, rem) { |
| 9249 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); |
| 9250 | } |
| 9251 | |
| 9252 | return NL_SKIP; |
| 9253 | } |
| 9254 | |
| 9255 | |
| 9256 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, |
| 9257 | unsigned int subcmd, const u8 *data, |
| 9258 | size_t data_len, struct wpabuf *buf) |
| 9259 | { |
| 9260 | struct i802_bss *bss = priv; |
| 9261 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9262 | struct nl_msg *msg; |
| 9263 | int ret; |
| 9264 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9265 | #ifdef CONFIG_TESTING_OPTIONS |
| 9266 | if (vendor_id == 0xffffffff) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9267 | msg = nlmsg_alloc(); |
| 9268 | if (!msg) |
| 9269 | return -ENOMEM; |
| 9270 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9271 | nl80211_cmd(drv, msg, 0, subcmd); |
| 9272 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < |
| 9273 | 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9274 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9275 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
| 9276 | if (ret) |
| 9277 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", |
| 9278 | ret); |
| 9279 | return ret; |
| 9280 | } |
| 9281 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 9282 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9283 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 9284 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
| 9285 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || |
| 9286 | (data && |
| 9287 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) |
| 9288 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9289 | |
| 9290 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); |
| 9291 | if (ret) |
| 9292 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", |
| 9293 | ret); |
| 9294 | return ret; |
| 9295 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9296 | fail: |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9297 | nlmsg_free(msg); |
| 9298 | return -ENOBUFS; |
| 9299 | } |
| 9300 | |
| 9301 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9302 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
| 9303 | u8 qos_map_set_len) |
| 9304 | { |
| 9305 | struct i802_bss *bss = priv; |
| 9306 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9307 | struct nl_msg *msg; |
| 9308 | int ret; |
| 9309 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9310 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
| 9311 | qos_map_set, qos_map_set_len); |
| 9312 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9313 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
| 9314 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
| 9315 | nlmsg_free(msg); |
| 9316 | return -ENOBUFS; |
| 9317 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9318 | |
| 9319 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9320 | if (ret) |
| 9321 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); |
| 9322 | |
| 9323 | return ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9324 | } |
| 9325 | |
| 9326 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9327 | static int nl80211_set_wowlan(void *priv, |
| 9328 | const struct wowlan_triggers *triggers) |
| 9329 | { |
| 9330 | struct i802_bss *bss = priv; |
| 9331 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9332 | struct nl_msg *msg; |
| 9333 | struct nlattr *wowlan_triggers; |
| 9334 | int ret; |
| 9335 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9336 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
| 9337 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 9338 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9339 | !(wowlan_triggers = nla_nest_start(msg, |
| 9340 | NL80211_ATTR_WOWLAN_TRIGGERS)) || |
| 9341 | (triggers->any && |
| 9342 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 9343 | (triggers->disconnect && |
| 9344 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 9345 | (triggers->magic_pkt && |
| 9346 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 9347 | (triggers->gtk_rekey_failure && |
| 9348 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 9349 | (triggers->eap_identity_req && |
| 9350 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 9351 | (triggers->four_way_handshake && |
| 9352 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 9353 | (triggers->rfkill_release && |
| 9354 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { |
| 9355 | nlmsg_free(msg); |
| 9356 | return -ENOBUFS; |
| 9357 | } |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9358 | |
| 9359 | nla_nest_end(msg, wowlan_triggers); |
| 9360 | |
| 9361 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9362 | if (ret) |
| 9363 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); |
| 9364 | |
| 9365 | return ret; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9366 | } |
| 9367 | |
| 9368 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9369 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9370 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
| 9371 | { |
| 9372 | struct i802_bss *bss = priv; |
| 9373 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9374 | struct nl_msg *msg; |
| 9375 | struct nlattr *params; |
| 9376 | |
| 9377 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); |
| 9378 | |
| 9379 | if (!drv->roaming_vendor_cmd_avail) { |
| 9380 | wpa_printf(MSG_DEBUG, |
| 9381 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); |
| 9382 | return -1; |
| 9383 | } |
| 9384 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9385 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9386 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9387 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9388 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || |
| 9389 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9390 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, |
| 9391 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : |
| 9392 | QCA_ROAMING_NOT_ALLOWED) || |
| 9393 | (bssid && |
| 9394 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { |
| 9395 | nlmsg_free(msg); |
| 9396 | return -1; |
| 9397 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9398 | nla_nest_end(msg, params); |
| 9399 | |
| 9400 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9401 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9402 | |
| 9403 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9404 | static int nl80211_disable_fils(void *priv, int disable) |
| 9405 | { |
| 9406 | struct i802_bss *bss = priv; |
| 9407 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9408 | struct nl_msg *msg; |
| 9409 | struct nlattr *params; |
| 9410 | |
| 9411 | wpa_printf(MSG_DEBUG, "nl80211: Disable FILS=%d", disable); |
| 9412 | |
| 9413 | if (!drv->set_wifi_conf_vendor_cmd_avail) |
| 9414 | return -1; |
| 9415 | |
| 9416 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9417 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9418 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9419 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) || |
| 9420 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9421 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS, |
| 9422 | disable)) { |
| 9423 | nlmsg_free(msg); |
| 9424 | return -1; |
| 9425 | } |
| 9426 | nla_nest_end(msg, params); |
| 9427 | |
| 9428 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9429 | } |
| 9430 | |
| 9431 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9432 | /* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */ |
| 9433 | #define WPA_SUPPLICANT_CLIENT_ID 1 |
| 9434 | |
| 9435 | static int nl80211_set_bssid_blacklist(void *priv, unsigned int num_bssid, |
| 9436 | const u8 *bssid) |
| 9437 | { |
| 9438 | struct i802_bss *bss = priv; |
| 9439 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9440 | struct nl_msg *msg; |
| 9441 | struct nlattr *params, *nlbssids, *attr; |
| 9442 | unsigned int i; |
| 9443 | |
| 9444 | wpa_printf(MSG_DEBUG, "nl80211: Set blacklist BSSID (num=%u)", |
| 9445 | num_bssid); |
| 9446 | |
| 9447 | if (!drv->roam_vendor_cmd_avail) |
| 9448 | return -1; |
| 9449 | |
| 9450 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9451 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9452 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9453 | QCA_NL80211_VENDOR_SUBCMD_ROAM) || |
| 9454 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9455 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD, |
| 9456 | QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_SET_BLACKLIST_BSSID) || |
| 9457 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID, |
| 9458 | WPA_SUPPLICANT_CLIENT_ID) || |
| 9459 | nla_put_u32(msg, |
| 9460 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID, |
| 9461 | num_bssid)) |
| 9462 | goto fail; |
| 9463 | |
| 9464 | nlbssids = nla_nest_start( |
| 9465 | msg, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS); |
| 9466 | if (!nlbssids) |
| 9467 | goto fail; |
| 9468 | |
| 9469 | for (i = 0; i < num_bssid; i++) { |
| 9470 | attr = nla_nest_start(msg, i); |
| 9471 | if (!attr) |
| 9472 | goto fail; |
| 9473 | if (nla_put(msg, |
| 9474 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID, |
| 9475 | ETH_ALEN, &bssid[i * ETH_ALEN])) |
| 9476 | goto fail; |
| 9477 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%u]: " MACSTR, i, |
| 9478 | MAC2STR(&bssid[i * ETH_ALEN])); |
| 9479 | nla_nest_end(msg, attr); |
| 9480 | } |
| 9481 | nla_nest_end(msg, nlbssids); |
| 9482 | nla_nest_end(msg, params); |
| 9483 | |
| 9484 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9485 | |
| 9486 | fail: |
| 9487 | nlmsg_free(msg); |
| 9488 | return -1; |
| 9489 | } |
| 9490 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9491 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9492 | |
| 9493 | |
| 9494 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
| 9495 | { |
| 9496 | struct i802_bss *bss = priv; |
| 9497 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9498 | int new_addr = addr != NULL; |
| 9499 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9500 | if (TEST_FAIL()) |
| 9501 | return -1; |
| 9502 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9503 | if (!addr) |
| 9504 | addr = drv->perm_addr; |
| 9505 | |
| 9506 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) |
| 9507 | return -1; |
| 9508 | |
| 9509 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) |
| 9510 | { |
| 9511 | wpa_printf(MSG_DEBUG, |
| 9512 | "nl80211: failed to set_mac_addr for %s to " MACSTR, |
| 9513 | bss->ifname, MAC2STR(addr)); |
| 9514 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 9515 | 1) < 0) { |
| 9516 | wpa_printf(MSG_DEBUG, |
| 9517 | "nl80211: Could not restore interface UP after failed set_mac_addr"); |
| 9518 | } |
| 9519 | return -1; |
| 9520 | } |
| 9521 | |
| 9522 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, |
| 9523 | bss->ifname, MAC2STR(addr)); |
| 9524 | drv->addr_changed = new_addr; |
| 9525 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 9526 | |
| 9527 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) |
| 9528 | { |
| 9529 | wpa_printf(MSG_DEBUG, |
| 9530 | "nl80211: Could not restore interface UP after set_mac_addr"); |
| 9531 | } |
| 9532 | |
| 9533 | return 0; |
| 9534 | } |
| 9535 | |
| 9536 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9537 | #ifdef CONFIG_MESH |
| 9538 | |
| 9539 | static int wpa_driver_nl80211_init_mesh(void *priv) |
| 9540 | { |
| 9541 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { |
| 9542 | wpa_printf(MSG_INFO, |
| 9543 | "nl80211: Failed to set interface into mesh mode"); |
| 9544 | return -1; |
| 9545 | } |
| 9546 | return 0; |
| 9547 | } |
| 9548 | |
| 9549 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9550 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
| 9551 | size_t mesh_id_len) |
| 9552 | { |
| 9553 | if (mesh_id) { |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 9554 | wpa_printf(MSG_DEBUG, " * Mesh ID (SSID)=%s", |
| 9555 | wpa_ssid_txt(mesh_id, mesh_id_len)); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9556 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); |
| 9557 | } |
| 9558 | |
| 9559 | return 0; |
| 9560 | } |
| 9561 | |
| 9562 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9563 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
| 9564 | struct wpa_driver_mesh_bss_params *params) |
| 9565 | { |
| 9566 | struct nlattr *container; |
| 9567 | |
| 9568 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
| 9569 | if (!container) |
| 9570 | return -1; |
| 9571 | |
| 9572 | if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9573 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 9574 | params->auto_plinks)) || |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9575 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) && |
| 9576 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9577 | params->max_peer_links)) || |
| 9578 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD) && |
| 9579 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 9580 | params->rssi_threshold))) |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9581 | return -1; |
| 9582 | |
| 9583 | /* |
| 9584 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because |
| 9585 | * the timer could disconnect stations even in that case. |
| 9586 | */ |
| 9587 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) && |
| 9588 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 9589 | params->peer_link_timeout)) { |
| 9590 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); |
| 9591 | return -1; |
| 9592 | } |
| 9593 | |
| 9594 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) && |
| 9595 | nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) { |
| 9596 | wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE"); |
| 9597 | return -1; |
| 9598 | } |
| 9599 | |
| 9600 | nla_nest_end(msg, container); |
| 9601 | |
| 9602 | return 0; |
| 9603 | } |
| 9604 | |
| 9605 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9606 | static int nl80211_join_mesh(struct i802_bss *bss, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9607 | struct wpa_driver_mesh_join_params *params) |
| 9608 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9609 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9610 | struct nl_msg *msg; |
| 9611 | struct nlattr *container; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 9612 | int ret = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9613 | |
| 9614 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
| 9615 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9616 | if (!msg || |
| 9617 | nl80211_put_freq_params(msg, ¶ms->freq) || |
| 9618 | nl80211_put_basic_rates(msg, params->basic_rates) || |
| 9619 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 9620 | nl80211_put_beacon_int(msg, params->beacon_int) || |
| 9621 | nl80211_put_dtim_period(msg, params->dtim_period)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9622 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9623 | |
| 9624 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
| 9625 | |
| 9626 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); |
| 9627 | if (!container) |
| 9628 | goto fail; |
| 9629 | |
| 9630 | if (params->ies) { |
| 9631 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); |
| 9632 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
| 9633 | params->ies)) |
| 9634 | goto fail; |
| 9635 | } |
| 9636 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ |
| 9637 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { |
| 9638 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
| 9639 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) |
| 9640 | goto fail; |
| 9641 | } |
| 9642 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
| 9643 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) |
| 9644 | goto fail; |
| 9645 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && |
| 9646 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) |
| 9647 | goto fail; |
| 9648 | nla_nest_end(msg, container); |
| 9649 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9650 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS; |
| 9651 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT; |
| 9652 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS; |
| 9653 | if (nl80211_put_mesh_config(msg, ¶ms->conf) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9654 | goto fail; |
| 9655 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9656 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9657 | msg = NULL; |
| 9658 | if (ret) { |
| 9659 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", |
| 9660 | ret, strerror(-ret)); |
| 9661 | goto fail; |
| 9662 | } |
| 9663 | ret = 0; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 9664 | drv->assoc_freq = bss->freq = params->freq.freq; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9665 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
| 9666 | |
| 9667 | fail: |
| 9668 | nlmsg_free(msg); |
| 9669 | return ret; |
| 9670 | } |
| 9671 | |
| 9672 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9673 | static int |
| 9674 | wpa_driver_nl80211_join_mesh(void *priv, |
| 9675 | struct wpa_driver_mesh_join_params *params) |
| 9676 | { |
| 9677 | struct i802_bss *bss = priv; |
| 9678 | int ret, timeout; |
| 9679 | |
| 9680 | timeout = params->conf.peer_link_timeout; |
| 9681 | |
| 9682 | /* Disable kernel inactivity timer */ |
| 9683 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) |
| 9684 | params->conf.peer_link_timeout = 0; |
| 9685 | |
| 9686 | ret = nl80211_join_mesh(bss, params); |
| 9687 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { |
| 9688 | wpa_printf(MSG_DEBUG, |
| 9689 | "nl80211: Mesh join retry for peer_link_timeout"); |
| 9690 | /* |
| 9691 | * Old kernel does not support setting |
| 9692 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds |
| 9693 | * into future from peer_link_timeout. |
| 9694 | */ |
| 9695 | params->conf.peer_link_timeout = timeout + 60; |
| 9696 | ret = nl80211_join_mesh(priv, params); |
| 9697 | } |
| 9698 | |
| 9699 | params->conf.peer_link_timeout = timeout; |
| 9700 | return ret; |
| 9701 | } |
| 9702 | |
| 9703 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9704 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
| 9705 | { |
| 9706 | struct i802_bss *bss = priv; |
| 9707 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9708 | struct nl_msg *msg; |
| 9709 | int ret; |
| 9710 | |
| 9711 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); |
| 9712 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
| 9713 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9714 | if (ret) { |
| 9715 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", |
| 9716 | ret, strerror(-ret)); |
| 9717 | } else { |
| 9718 | wpa_printf(MSG_DEBUG, |
| 9719 | "nl80211: mesh leave request send successfully"); |
| 9720 | } |
| 9721 | |
| 9722 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
| 9723 | NL80211_IFTYPE_STATION)) { |
| 9724 | wpa_printf(MSG_INFO, |
| 9725 | "nl80211: Failed to set interface into station mode"); |
| 9726 | } |
| 9727 | return ret; |
| 9728 | } |
| 9729 | |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 9730 | |
| 9731 | static int nl80211_probe_mesh_link(void *priv, const u8 *addr, const u8 *eth, |
| 9732 | size_t len) |
| 9733 | { |
| 9734 | struct i802_bss *bss = priv; |
| 9735 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9736 | struct nl_msg *msg; |
| 9737 | int ret; |
| 9738 | |
| 9739 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_PROBE_MESH_LINK); |
| 9740 | if (!msg || |
| 9741 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 9742 | nla_put(msg, NL80211_ATTR_FRAME, len, eth)) { |
| 9743 | nlmsg_free(msg); |
| 9744 | return -ENOBUFS; |
| 9745 | } |
| 9746 | |
| 9747 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9748 | if (ret) { |
| 9749 | wpa_printf(MSG_DEBUG, "nl80211: mesh link probe to " MACSTR |
| 9750 | " failed: ret=%d (%s)", |
| 9751 | MAC2STR(addr), ret, strerror(-ret)); |
| 9752 | } else { |
| 9753 | wpa_printf(MSG_DEBUG, "nl80211: Mesh link to " MACSTR |
| 9754 | " probed successfully", MAC2STR(addr)); |
| 9755 | } |
| 9756 | |
| 9757 | return ret; |
| 9758 | } |
| 9759 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9760 | #endif /* CONFIG_MESH */ |
| 9761 | |
| 9762 | |
| 9763 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
| 9764 | const u8 *ipaddr, int prefixlen, |
| 9765 | const u8 *addr) |
| 9766 | { |
| 9767 | #ifdef CONFIG_LIBNL3_ROUTE |
| 9768 | struct i802_bss *bss = priv; |
| 9769 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9770 | struct rtnl_neigh *rn; |
| 9771 | struct nl_addr *nl_ipaddr = NULL; |
| 9772 | struct nl_addr *nl_lladdr = NULL; |
| 9773 | int family, addrsize; |
| 9774 | int res; |
| 9775 | |
| 9776 | if (!ipaddr || prefixlen == 0 || !addr) |
| 9777 | return -EINVAL; |
| 9778 | |
| 9779 | if (bss->br_ifindex == 0) { |
| 9780 | wpa_printf(MSG_DEBUG, |
| 9781 | "nl80211: bridge must be set before adding an ip neigh to it"); |
| 9782 | return -1; |
| 9783 | } |
| 9784 | |
| 9785 | if (!drv->rtnl_sk) { |
| 9786 | wpa_printf(MSG_DEBUG, |
| 9787 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 9788 | return -1; |
| 9789 | } |
| 9790 | |
| 9791 | if (version == 4) { |
| 9792 | family = AF_INET; |
| 9793 | addrsize = 4; |
| 9794 | } else if (version == 6) { |
| 9795 | family = AF_INET6; |
| 9796 | addrsize = 16; |
| 9797 | } else { |
| 9798 | return -EINVAL; |
| 9799 | } |
| 9800 | |
| 9801 | rn = rtnl_neigh_alloc(); |
| 9802 | if (rn == NULL) |
| 9803 | return -ENOMEM; |
| 9804 | |
| 9805 | /* set the destination ip address for neigh */ |
| 9806 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 9807 | if (nl_ipaddr == NULL) { |
| 9808 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 9809 | res = -ENOMEM; |
| 9810 | goto errout; |
| 9811 | } |
| 9812 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); |
| 9813 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 9814 | if (res) { |
| 9815 | wpa_printf(MSG_DEBUG, |
| 9816 | "nl80211: neigh set destination addr failed"); |
| 9817 | goto errout; |
| 9818 | } |
| 9819 | |
| 9820 | /* set the corresponding lladdr for neigh */ |
| 9821 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); |
| 9822 | if (nl_lladdr == NULL) { |
| 9823 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); |
| 9824 | res = -ENOMEM; |
| 9825 | goto errout; |
| 9826 | } |
| 9827 | rtnl_neigh_set_lladdr(rn, nl_lladdr); |
| 9828 | |
| 9829 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 9830 | rtnl_neigh_set_state(rn, NUD_PERMANENT); |
| 9831 | |
| 9832 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); |
| 9833 | if (res) { |
| 9834 | wpa_printf(MSG_DEBUG, |
| 9835 | "nl80211: Adding bridge ip neigh failed: %s", |
| 9836 | strerror(errno)); |
| 9837 | } |
| 9838 | errout: |
| 9839 | if (nl_lladdr) |
| 9840 | nl_addr_put(nl_lladdr); |
| 9841 | if (nl_ipaddr) |
| 9842 | nl_addr_put(nl_ipaddr); |
| 9843 | if (rn) |
| 9844 | rtnl_neigh_put(rn); |
| 9845 | return res; |
| 9846 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 9847 | return -1; |
| 9848 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 9849 | } |
| 9850 | |
| 9851 | |
| 9852 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
| 9853 | const u8 *ipaddr) |
| 9854 | { |
| 9855 | #ifdef CONFIG_LIBNL3_ROUTE |
| 9856 | struct i802_bss *bss = priv; |
| 9857 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9858 | struct rtnl_neigh *rn; |
| 9859 | struct nl_addr *nl_ipaddr; |
| 9860 | int family, addrsize; |
| 9861 | int res; |
| 9862 | |
| 9863 | if (!ipaddr) |
| 9864 | return -EINVAL; |
| 9865 | |
| 9866 | if (version == 4) { |
| 9867 | family = AF_INET; |
| 9868 | addrsize = 4; |
| 9869 | } else if (version == 6) { |
| 9870 | family = AF_INET6; |
| 9871 | addrsize = 16; |
| 9872 | } else { |
| 9873 | return -EINVAL; |
| 9874 | } |
| 9875 | |
| 9876 | if (bss->br_ifindex == 0) { |
| 9877 | wpa_printf(MSG_DEBUG, |
| 9878 | "nl80211: bridge must be set to delete an ip neigh"); |
| 9879 | return -1; |
| 9880 | } |
| 9881 | |
| 9882 | if (!drv->rtnl_sk) { |
| 9883 | wpa_printf(MSG_DEBUG, |
| 9884 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 9885 | return -1; |
| 9886 | } |
| 9887 | |
| 9888 | rn = rtnl_neigh_alloc(); |
| 9889 | if (rn == NULL) |
| 9890 | return -ENOMEM; |
| 9891 | |
| 9892 | /* set the destination ip address for neigh */ |
| 9893 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 9894 | if (nl_ipaddr == NULL) { |
| 9895 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 9896 | res = -ENOMEM; |
| 9897 | goto errout; |
| 9898 | } |
| 9899 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 9900 | if (res) { |
| 9901 | wpa_printf(MSG_DEBUG, |
| 9902 | "nl80211: neigh set destination addr failed"); |
| 9903 | goto errout; |
| 9904 | } |
| 9905 | |
| 9906 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 9907 | |
| 9908 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 9909 | if (res) { |
| 9910 | wpa_printf(MSG_DEBUG, |
| 9911 | "nl80211: Deleting bridge ip neigh failed: %s", |
| 9912 | strerror(errno)); |
| 9913 | } |
| 9914 | errout: |
| 9915 | if (nl_ipaddr) |
| 9916 | nl_addr_put(nl_ipaddr); |
| 9917 | if (rn) |
| 9918 | rtnl_neigh_put(rn); |
| 9919 | return res; |
| 9920 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 9921 | return -1; |
| 9922 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 9923 | } |
| 9924 | |
| 9925 | |
| 9926 | static int linux_write_system_file(const char *path, unsigned int val) |
| 9927 | { |
| 9928 | char buf[50]; |
| 9929 | int fd, len; |
| 9930 | |
| 9931 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); |
| 9932 | if (os_snprintf_error(sizeof(buf), len)) |
| 9933 | return -1; |
| 9934 | |
| 9935 | fd = open(path, O_WRONLY); |
| 9936 | if (fd < 0) |
| 9937 | return -1; |
| 9938 | |
| 9939 | if (write(fd, buf, len) < 0) { |
| 9940 | wpa_printf(MSG_DEBUG, |
| 9941 | "nl80211: Failed to write Linux system file: %s with the value of %d", |
| 9942 | path, val); |
| 9943 | close(fd); |
| 9944 | return -1; |
| 9945 | } |
| 9946 | close(fd); |
| 9947 | |
| 9948 | return 0; |
| 9949 | } |
| 9950 | |
| 9951 | |
| 9952 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) |
| 9953 | { |
| 9954 | switch (attr) { |
| 9955 | case DRV_BR_PORT_ATTR_PROXYARP: |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 9956 | return "proxyarp_wifi"; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9957 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
| 9958 | return "hairpin_mode"; |
| 9959 | } |
| 9960 | |
| 9961 | return NULL; |
| 9962 | } |
| 9963 | |
| 9964 | |
| 9965 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, |
| 9966 | unsigned int val) |
| 9967 | { |
| 9968 | struct i802_bss *bss = priv; |
| 9969 | char path[128]; |
| 9970 | const char *attr_txt; |
| 9971 | |
| 9972 | attr_txt = drv_br_port_attr_str(attr); |
| 9973 | if (attr_txt == NULL) |
| 9974 | return -EINVAL; |
| 9975 | |
| 9976 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", |
| 9977 | bss->ifname, attr_txt); |
| 9978 | |
| 9979 | if (linux_write_system_file(path, val)) |
| 9980 | return -1; |
| 9981 | |
| 9982 | return 0; |
| 9983 | } |
| 9984 | |
| 9985 | |
| 9986 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
| 9987 | { |
| 9988 | switch (param) { |
| 9989 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 9990 | return "arp_accept"; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 9991 | default: |
| 9992 | return NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9993 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9994 | } |
| 9995 | |
| 9996 | |
| 9997 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, |
| 9998 | unsigned int val) |
| 9999 | { |
| 10000 | struct i802_bss *bss = priv; |
| 10001 | char path[128]; |
| 10002 | const char *param_txt; |
| 10003 | int ip_version = 4; |
| 10004 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 10005 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
| 10006 | os_snprintf(path, sizeof(path), |
| 10007 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", |
| 10008 | bss->brname); |
| 10009 | goto set_val; |
| 10010 | } |
| 10011 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10012 | param_txt = drv_br_net_param_str(param); |
| 10013 | if (param_txt == NULL) |
| 10014 | return -EINVAL; |
| 10015 | |
| 10016 | switch (param) { |
| 10017 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 10018 | ip_version = 4; |
| 10019 | break; |
| 10020 | default: |
| 10021 | return -EINVAL; |
| 10022 | } |
| 10023 | |
| 10024 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", |
| 10025 | ip_version, bss->brname, param_txt); |
| 10026 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 10027 | set_val: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10028 | if (linux_write_system_file(path, val)) |
| 10029 | return -1; |
| 10030 | |
| 10031 | return 0; |
| 10032 | } |
| 10033 | |
| 10034 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10035 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 10036 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10037 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
| 10038 | { |
| 10039 | switch (hw_mode) { |
| 10040 | case HOSTAPD_MODE_IEEE80211B: |
| 10041 | return QCA_ACS_MODE_IEEE80211B; |
| 10042 | case HOSTAPD_MODE_IEEE80211G: |
| 10043 | return QCA_ACS_MODE_IEEE80211G; |
| 10044 | case HOSTAPD_MODE_IEEE80211A: |
| 10045 | return QCA_ACS_MODE_IEEE80211A; |
| 10046 | case HOSTAPD_MODE_IEEE80211AD: |
| 10047 | return QCA_ACS_MODE_IEEE80211AD; |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 10048 | case HOSTAPD_MODE_IEEE80211ANY: |
| 10049 | return QCA_ACS_MODE_IEEE80211ANY; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10050 | default: |
| 10051 | return -1; |
| 10052 | } |
| 10053 | } |
| 10054 | |
| 10055 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10056 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
| 10057 | { |
| 10058 | int i, len, ret; |
| 10059 | u32 *freqs; |
| 10060 | |
| 10061 | if (!freq_list) |
| 10062 | return 0; |
| 10063 | len = int_array_len(freq_list); |
| 10064 | freqs = os_malloc(sizeof(u32) * len); |
| 10065 | if (!freqs) |
| 10066 | return -1; |
| 10067 | for (i = 0; i < len; i++) |
| 10068 | freqs[i] = freq_list[i]; |
| 10069 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, |
| 10070 | sizeof(u32) * len, freqs); |
| 10071 | os_free(freqs); |
| 10072 | return ret; |
| 10073 | } |
| 10074 | |
| 10075 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10076 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
| 10077 | { |
| 10078 | struct i802_bss *bss = priv; |
| 10079 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10080 | struct nl_msg *msg; |
| 10081 | struct nlattr *data; |
| 10082 | int ret; |
| 10083 | int mode; |
| 10084 | |
| 10085 | mode = hw_mode_to_qca_acs(params->hw_mode); |
| 10086 | if (mode < 0) |
| 10087 | return -1; |
| 10088 | |
| 10089 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10090 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10091 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10092 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || |
| 10093 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10094 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || |
| 10095 | (params->ht_enabled && |
| 10096 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || |
| 10097 | (params->ht40_enabled && |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 10098 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
| 10099 | (params->vht_enabled && |
| 10100 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || |
| 10101 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, |
| 10102 | params->ch_width) || |
| 10103 | (params->ch_list_len && |
| 10104 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, params->ch_list_len, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10105 | params->ch_list)) || |
| 10106 | add_acs_freq_list(msg, params->freq_list)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10107 | nlmsg_free(msg); |
| 10108 | return -ENOBUFS; |
| 10109 | } |
| 10110 | nla_nest_end(msg, data); |
| 10111 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 10112 | wpa_printf(MSG_DEBUG, |
| 10113 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u", |
| 10114 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
| 10115 | params->vht_enabled, params->ch_width, params->ch_list_len); |
| 10116 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10117 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10118 | if (ret) { |
| 10119 | wpa_printf(MSG_DEBUG, |
| 10120 | "nl80211: Failed to invoke driver ACS function: %s", |
| 10121 | strerror(errno)); |
| 10122 | } |
| 10123 | return ret; |
| 10124 | } |
| 10125 | |
| 10126 | |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 10127 | static int nl80211_set_band(void *priv, enum set_band band) |
| 10128 | { |
| 10129 | struct i802_bss *bss = priv; |
| 10130 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10131 | struct nl_msg *msg; |
| 10132 | struct nlattr *data; |
| 10133 | int ret; |
| 10134 | enum qca_set_band qca_band; |
| 10135 | |
| 10136 | if (!drv->setband_vendor_cmd_avail) |
| 10137 | return -1; |
| 10138 | |
| 10139 | switch (band) { |
| 10140 | case WPA_SETBAND_AUTO: |
| 10141 | qca_band = QCA_SETBAND_AUTO; |
| 10142 | break; |
| 10143 | case WPA_SETBAND_5G: |
| 10144 | qca_band = QCA_SETBAND_5G; |
| 10145 | break; |
| 10146 | case WPA_SETBAND_2G: |
| 10147 | qca_band = QCA_SETBAND_2G; |
| 10148 | break; |
| 10149 | default: |
| 10150 | return -1; |
| 10151 | } |
| 10152 | |
| 10153 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10154 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10155 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10156 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || |
| 10157 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10158 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) { |
| 10159 | nlmsg_free(msg); |
| 10160 | return -ENOBUFS; |
| 10161 | } |
| 10162 | nla_nest_end(msg, data); |
| 10163 | |
| 10164 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10165 | if (ret) { |
| 10166 | wpa_printf(MSG_DEBUG, |
| 10167 | "nl80211: Driver setband function failed: %s", |
| 10168 | strerror(errno)); |
| 10169 | } |
| 10170 | return ret; |
| 10171 | } |
| 10172 | |
| 10173 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10174 | struct nl80211_pcl { |
| 10175 | unsigned int num; |
| 10176 | unsigned int *freq_list; |
| 10177 | }; |
| 10178 | |
| 10179 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) |
| 10180 | { |
| 10181 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 10182 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 10183 | struct nl80211_pcl *param = arg; |
| 10184 | struct nlattr *nl_vend, *attr; |
| 10185 | enum qca_iface_type iface_type; |
| 10186 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 10187 | unsigned int num, max_num; |
| 10188 | u32 *freqs; |
| 10189 | |
| 10190 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 10191 | genlmsg_attrlen(gnlh, 0), NULL); |
| 10192 | |
| 10193 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; |
| 10194 | if (!nl_vend) |
| 10195 | return NL_SKIP; |
| 10196 | |
| 10197 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 10198 | nla_data(nl_vend), nla_len(nl_vend), NULL); |
| 10199 | |
| 10200 | attr = tb_vendor[ |
| 10201 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; |
| 10202 | if (!attr) { |
| 10203 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); |
| 10204 | param->num = 0; |
| 10205 | return NL_SKIP; |
| 10206 | } |
| 10207 | |
| 10208 | iface_type = (enum qca_iface_type) nla_get_u32(attr); |
| 10209 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", |
| 10210 | iface_type); |
| 10211 | |
| 10212 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; |
| 10213 | if (!attr) { |
| 10214 | wpa_printf(MSG_ERROR, |
| 10215 | "nl80211: preferred_freq_list couldn't be found"); |
| 10216 | param->num = 0; |
| 10217 | return NL_SKIP; |
| 10218 | } |
| 10219 | |
| 10220 | /* |
| 10221 | * param->num has the maximum number of entries for which there |
| 10222 | * is room in the freq_list provided by the caller. |
| 10223 | */ |
| 10224 | freqs = nla_data(attr); |
| 10225 | max_num = nla_len(attr) / sizeof(u32); |
| 10226 | if (max_num > param->num) |
| 10227 | max_num = param->num; |
| 10228 | for (num = 0; num < max_num; num++) |
| 10229 | param->freq_list[num] = freqs[num]; |
| 10230 | param->num = num; |
| 10231 | |
| 10232 | return NL_SKIP; |
| 10233 | } |
| 10234 | |
| 10235 | |
| 10236 | static int nl80211_get_pref_freq_list(void *priv, |
| 10237 | enum wpa_driver_if_type if_type, |
| 10238 | unsigned int *num, |
| 10239 | unsigned int *freq_list) |
| 10240 | { |
| 10241 | struct i802_bss *bss = priv; |
| 10242 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10243 | struct nl_msg *msg; |
| 10244 | int ret; |
| 10245 | unsigned int i; |
| 10246 | struct nlattr *params; |
| 10247 | struct nl80211_pcl param; |
| 10248 | enum qca_iface_type iface_type; |
| 10249 | |
| 10250 | if (!drv->get_pref_freq_list) |
| 10251 | return -1; |
| 10252 | |
| 10253 | switch (if_type) { |
| 10254 | case WPA_IF_STATION: |
| 10255 | iface_type = QCA_IFACE_TYPE_STA; |
| 10256 | break; |
| 10257 | case WPA_IF_AP_BSS: |
| 10258 | iface_type = QCA_IFACE_TYPE_AP; |
| 10259 | break; |
| 10260 | case WPA_IF_P2P_GO: |
| 10261 | iface_type = QCA_IFACE_TYPE_P2P_GO; |
| 10262 | break; |
| 10263 | case WPA_IF_P2P_CLIENT: |
| 10264 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; |
| 10265 | break; |
| 10266 | case WPA_IF_IBSS: |
| 10267 | iface_type = QCA_IFACE_TYPE_IBSS; |
| 10268 | break; |
| 10269 | case WPA_IF_TDLS: |
| 10270 | iface_type = QCA_IFACE_TYPE_TDLS; |
| 10271 | break; |
| 10272 | default: |
| 10273 | return -1; |
| 10274 | } |
| 10275 | |
| 10276 | param.num = *num; |
| 10277 | param.freq_list = freq_list; |
| 10278 | |
| 10279 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10280 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || |
| 10281 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10282 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10283 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || |
| 10284 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10285 | nla_put_u32(msg, |
| 10286 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, |
| 10287 | iface_type)) { |
| 10288 | wpa_printf(MSG_ERROR, |
| 10289 | "%s: err in adding vendor_cmd and vendor_data", |
| 10290 | __func__); |
| 10291 | nlmsg_free(msg); |
| 10292 | return -1; |
| 10293 | } |
| 10294 | nla_nest_end(msg, params); |
| 10295 | |
| 10296 | os_memset(freq_list, 0, *num * sizeof(freq_list[0])); |
| 10297 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m); |
| 10298 | if (ret) { |
| 10299 | wpa_printf(MSG_ERROR, |
| 10300 | "%s: err in send_and_recv_msgs", __func__); |
| 10301 | return ret; |
| 10302 | } |
| 10303 | |
| 10304 | *num = param.num; |
| 10305 | |
| 10306 | for (i = 0; i < *num; i++) { |
| 10307 | wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d", |
| 10308 | i, freq_list[i]); |
| 10309 | } |
| 10310 | |
| 10311 | return 0; |
| 10312 | } |
| 10313 | |
| 10314 | |
| 10315 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
| 10316 | { |
| 10317 | struct i802_bss *bss = priv; |
| 10318 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10319 | struct nl_msg *msg; |
| 10320 | int ret; |
| 10321 | struct nlattr *params; |
| 10322 | |
| 10323 | if (!drv->set_prob_oper_freq) |
| 10324 | return -1; |
| 10325 | |
| 10326 | wpa_printf(MSG_DEBUG, |
| 10327 | "nl80211: Set P2P probable operating freq %u for ifindex %d", |
| 10328 | freq, bss->ifindex); |
| 10329 | |
| 10330 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10331 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10332 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10333 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || |
| 10334 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10335 | nla_put_u32(msg, |
| 10336 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, |
| 10337 | QCA_IFACE_TYPE_P2P_CLIENT) || |
| 10338 | nla_put_u32(msg, |
| 10339 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, |
| 10340 | freq)) { |
| 10341 | wpa_printf(MSG_ERROR, |
| 10342 | "%s: err in adding vendor_cmd and vendor_data", |
| 10343 | __func__); |
| 10344 | nlmsg_free(msg); |
| 10345 | return -1; |
| 10346 | } |
| 10347 | nla_nest_end(msg, params); |
| 10348 | |
| 10349 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10350 | msg = NULL; |
| 10351 | if (ret) { |
| 10352 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", |
| 10353 | __func__); |
| 10354 | return ret; |
| 10355 | } |
| 10356 | nlmsg_free(msg); |
| 10357 | return 0; |
| 10358 | } |
| 10359 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 10360 | |
| 10361 | static int nl80211_p2p_lo_start(void *priv, unsigned int freq, |
| 10362 | unsigned int period, unsigned int interval, |
| 10363 | unsigned int count, const u8 *device_types, |
| 10364 | size_t dev_types_len, |
| 10365 | const u8 *ies, size_t ies_len) |
| 10366 | { |
| 10367 | struct i802_bss *bss = priv; |
| 10368 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10369 | struct nl_msg *msg; |
| 10370 | struct nlattr *container; |
| 10371 | int ret; |
| 10372 | |
| 10373 | wpa_printf(MSG_DEBUG, |
| 10374 | "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u", |
| 10375 | freq, period, interval, count); |
| 10376 | |
| 10377 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 10378 | return -1; |
| 10379 | |
| 10380 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10381 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10382 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10383 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START)) |
| 10384 | goto fail; |
| 10385 | |
| 10386 | container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 10387 | if (!container) |
| 10388 | goto fail; |
| 10389 | |
| 10390 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL, |
| 10391 | freq) || |
| 10392 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD, |
| 10393 | period) || |
| 10394 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL, |
| 10395 | interval) || |
| 10396 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT, |
| 10397 | count) || |
| 10398 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES, |
| 10399 | dev_types_len, device_types) || |
| 10400 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE, |
| 10401 | ies_len, ies)) |
| 10402 | goto fail; |
| 10403 | |
| 10404 | nla_nest_end(msg, container); |
| 10405 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10406 | msg = NULL; |
| 10407 | if (ret) { |
| 10408 | wpa_printf(MSG_DEBUG, |
| 10409 | "nl80211: Failed to send P2P Listen offload vendor command"); |
| 10410 | goto fail; |
| 10411 | } |
| 10412 | |
| 10413 | return 0; |
| 10414 | |
| 10415 | fail: |
| 10416 | nlmsg_free(msg); |
| 10417 | return -1; |
| 10418 | } |
| 10419 | |
| 10420 | |
| 10421 | static int nl80211_p2p_lo_stop(void *priv) |
| 10422 | { |
| 10423 | struct i802_bss *bss = priv; |
| 10424 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10425 | struct nl_msg *msg; |
| 10426 | |
| 10427 | wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload"); |
| 10428 | |
| 10429 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 10430 | return -1; |
| 10431 | |
| 10432 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10433 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10434 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10435 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) { |
| 10436 | nlmsg_free(msg); |
| 10437 | return -1; |
| 10438 | } |
| 10439 | |
| 10440 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10441 | } |
| 10442 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 10443 | |
| 10444 | static int nl80211_set_tdls_mode(void *priv, int tdls_external_control) |
| 10445 | { |
| 10446 | struct i802_bss *bss = priv; |
| 10447 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10448 | struct nl_msg *msg; |
| 10449 | struct nlattr *params; |
| 10450 | int ret; |
| 10451 | u32 tdls_mode; |
| 10452 | |
| 10453 | wpa_printf(MSG_DEBUG, |
| 10454 | "nl80211: Set TDKS mode: tdls_external_control=%d", |
| 10455 | tdls_external_control); |
| 10456 | |
| 10457 | if (tdls_external_control == 1) |
| 10458 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT | |
| 10459 | QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL; |
| 10460 | else |
| 10461 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT; |
| 10462 | |
| 10463 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10464 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10465 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10466 | QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS)) |
| 10467 | goto fail; |
| 10468 | |
| 10469 | params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 10470 | if (!params) |
| 10471 | goto fail; |
| 10472 | |
| 10473 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE, |
| 10474 | tdls_mode)) |
| 10475 | goto fail; |
| 10476 | |
| 10477 | nla_nest_end(msg, params); |
| 10478 | |
| 10479 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10480 | msg = NULL; |
| 10481 | if (ret) { |
| 10482 | wpa_printf(MSG_ERROR, |
| 10483 | "nl80211: Set TDLS mode failed: ret=%d (%s)", |
| 10484 | ret, strerror(-ret)); |
| 10485 | goto fail; |
| 10486 | } |
| 10487 | return 0; |
| 10488 | fail: |
| 10489 | nlmsg_free(msg); |
| 10490 | return -1; |
| 10491 | } |
| 10492 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10493 | |
| 10494 | #ifdef CONFIG_MBO |
| 10495 | |
| 10496 | static enum mbo_transition_reject_reason |
| 10497 | nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status) |
| 10498 | { |
| 10499 | switch (status) { |
| 10500 | case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED: |
| 10501 | return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS; |
| 10502 | case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED: |
| 10503 | return MBO_TRANSITION_REJECT_REASON_DELAY; |
| 10504 | case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY: |
| 10505 | return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY; |
| 10506 | case QCA_STATUS_REJECT_LOW_RSSI: |
| 10507 | return MBO_TRANSITION_REJECT_REASON_RSSI; |
| 10508 | case QCA_STATUS_REJECT_HIGH_INTERFERENCE: |
| 10509 | return MBO_TRANSITION_REJECT_REASON_INTERFERENCE; |
| 10510 | case QCA_STATUS_REJECT_UNKNOWN: |
| 10511 | default: |
| 10512 | return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED; |
| 10513 | } |
| 10514 | } |
| 10515 | |
| 10516 | |
| 10517 | static void nl80211_parse_btm_candidate_info(struct candidate_list *candidate, |
| 10518 | struct nlattr *tb[], int num) |
| 10519 | { |
| 10520 | enum qca_wlan_btm_candidate_status status; |
| 10521 | char buf[50]; |
| 10522 | |
| 10523 | os_memcpy(candidate->bssid, |
| 10524 | nla_data(tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID]), |
| 10525 | ETH_ALEN); |
| 10526 | |
| 10527 | status = nla_get_u32( |
| 10528 | tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]); |
| 10529 | candidate->is_accept = status == QCA_STATUS_ACCEPT; |
| 10530 | candidate->reject_reason = nl80211_mbo_reject_reason_mapping(status); |
| 10531 | |
| 10532 | if (candidate->is_accept) |
| 10533 | os_snprintf(buf, sizeof(buf), "Accepted"); |
| 10534 | else |
| 10535 | os_snprintf(buf, sizeof(buf), |
| 10536 | "Rejected, Reject_reason: %d", |
| 10537 | candidate->reject_reason); |
| 10538 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR " %s", |
| 10539 | num, MAC2STR(candidate->bssid), buf); |
| 10540 | } |
| 10541 | |
| 10542 | |
| 10543 | static int |
| 10544 | nl80211_get_bss_transition_status_handler(struct nl_msg *msg, void *arg) |
| 10545 | { |
| 10546 | struct wpa_bss_candidate_info *info = arg; |
| 10547 | struct candidate_list *candidate = info->candidates; |
| 10548 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 10549 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 10550 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1]; |
| 10551 | static struct nla_policy policy[ |
| 10552 | QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1] = { |
| 10553 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] = { |
| 10554 | .minlen = ETH_ALEN |
| 10555 | }, |
| 10556 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS] = { |
| 10557 | .type = NLA_U32, |
| 10558 | }, |
| 10559 | }; |
| 10560 | struct nlattr *attr; |
| 10561 | int rem; |
| 10562 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 10563 | u8 num; |
| 10564 | |
| 10565 | num = info->num; /* number of candidates sent to driver */ |
| 10566 | info->num = 0; |
| 10567 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 10568 | genlmsg_attrlen(gnlh, 0), NULL); |
| 10569 | |
| 10570 | if (!tb_msg[NL80211_ATTR_VENDOR_DATA] || |
| 10571 | nla_parse_nested(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 10572 | tb_msg[NL80211_ATTR_VENDOR_DATA], NULL) || |
| 10573 | !tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO]) |
| 10574 | return NL_SKIP; |
| 10575 | |
| 10576 | wpa_printf(MSG_DEBUG, |
| 10577 | "nl80211: WNM Candidate list received from driver"); |
| 10578 | nla_for_each_nested(attr, |
| 10579 | tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO], |
| 10580 | rem) { |
| 10581 | if (info->num >= num || |
| 10582 | nla_parse_nested( |
| 10583 | tb, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX, |
| 10584 | attr, policy) || |
| 10585 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] || |
| 10586 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]) |
| 10587 | break; |
| 10588 | |
| 10589 | nl80211_parse_btm_candidate_info(candidate, tb, info->num); |
| 10590 | |
| 10591 | candidate++; |
| 10592 | info->num++; |
| 10593 | } |
| 10594 | |
| 10595 | return NL_SKIP; |
| 10596 | } |
| 10597 | |
| 10598 | |
| 10599 | static struct wpa_bss_candidate_info * |
| 10600 | nl80211_get_bss_transition_status(void *priv, struct wpa_bss_trans_info *params) |
| 10601 | { |
| 10602 | struct i802_bss *bss = priv; |
| 10603 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10604 | struct nl_msg *msg; |
| 10605 | struct nlattr *attr, *attr1, *attr2; |
| 10606 | struct wpa_bss_candidate_info *info; |
| 10607 | u8 i; |
| 10608 | int ret; |
| 10609 | u8 *pos; |
| 10610 | |
| 10611 | if (!drv->fetch_bss_trans_status) |
| 10612 | return NULL; |
| 10613 | |
| 10614 | info = os_zalloc(sizeof(*info)); |
| 10615 | if (!info) |
| 10616 | return NULL; |
| 10617 | /* Allocate memory for number of candidates sent to driver */ |
| 10618 | info->candidates = os_calloc(params->n_candidates, |
| 10619 | sizeof(*info->candidates)); |
| 10620 | if (!info->candidates) { |
| 10621 | os_free(info); |
| 10622 | return NULL; |
| 10623 | } |
| 10624 | |
| 10625 | /* Copy the number of candidates being sent to driver. This is used in |
| 10626 | * nl80211_get_bss_transition_status_handler() to limit the number of |
| 10627 | * candidates that can be populated in info->candidates and will be |
| 10628 | * later overwritten with the actual number of candidates received from |
| 10629 | * the driver. |
| 10630 | */ |
| 10631 | info->num = params->n_candidates; |
| 10632 | |
| 10633 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10634 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10635 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10636 | QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS)) |
| 10637 | goto fail; |
| 10638 | |
| 10639 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 10640 | if (!attr) |
| 10641 | goto fail; |
| 10642 | |
| 10643 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON, |
| 10644 | params->mbo_transition_reason)) |
| 10645 | goto fail; |
| 10646 | |
| 10647 | attr1 = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO); |
| 10648 | if (!attr1) |
| 10649 | goto fail; |
| 10650 | |
| 10651 | wpa_printf(MSG_DEBUG, |
| 10652 | "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d", |
| 10653 | params->mbo_transition_reason, params->n_candidates); |
| 10654 | pos = params->bssid; |
| 10655 | for (i = 0; i < params->n_candidates; i++) { |
| 10656 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR, i, |
| 10657 | MAC2STR(pos)); |
| 10658 | attr2 = nla_nest_start(msg, i); |
| 10659 | if (!attr2 || |
| 10660 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID, |
| 10661 | ETH_ALEN, pos)) |
| 10662 | goto fail; |
| 10663 | pos += ETH_ALEN; |
| 10664 | nla_nest_end(msg, attr2); |
| 10665 | } |
| 10666 | |
| 10667 | nla_nest_end(msg, attr1); |
| 10668 | nla_nest_end(msg, attr); |
| 10669 | |
| 10670 | ret = send_and_recv_msgs(drv, msg, |
| 10671 | nl80211_get_bss_transition_status_handler, |
| 10672 | info); |
| 10673 | msg = NULL; |
| 10674 | if (ret) { |
| 10675 | wpa_printf(MSG_ERROR, |
| 10676 | "nl80211: WNM Get BSS transition status failed: ret=%d (%s)", |
| 10677 | ret, strerror(-ret)); |
| 10678 | goto fail; |
| 10679 | } |
| 10680 | return info; |
| 10681 | |
| 10682 | fail: |
| 10683 | nlmsg_free(msg); |
| 10684 | os_free(info->candidates); |
| 10685 | os_free(info); |
| 10686 | return NULL; |
| 10687 | } |
| 10688 | |
| 10689 | |
| 10690 | /** |
| 10691 | * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow |
| 10692 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() |
| 10693 | * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore |
| 10694 | * Returns: 0 on success, -1 on failure |
| 10695 | */ |
| 10696 | static int nl80211_ignore_assoc_disallow(void *priv, int ignore_disallow) |
| 10697 | { |
| 10698 | struct i802_bss *bss = priv; |
| 10699 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10700 | struct nl_msg *msg; |
| 10701 | struct nlattr *attr; |
| 10702 | int ret = -1; |
| 10703 | |
| 10704 | if (!drv->set_wifi_conf_vendor_cmd_avail) |
| 10705 | return -1; |
| 10706 | |
| 10707 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10708 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10709 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10710 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) |
| 10711 | goto fail; |
| 10712 | |
| 10713 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 10714 | if (!attr) |
| 10715 | goto fail; |
| 10716 | |
| 10717 | wpa_printf(MSG_DEBUG, "nl80211: Set ignore_assoc_disallow %d", |
| 10718 | ignore_disallow); |
| 10719 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED, |
| 10720 | ignore_disallow)) |
| 10721 | goto fail; |
| 10722 | |
| 10723 | nla_nest_end(msg, attr); |
| 10724 | |
| 10725 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10726 | msg = NULL; |
| 10727 | if (ret) { |
| 10728 | wpa_printf(MSG_ERROR, |
| 10729 | "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)", |
| 10730 | ret, strerror(-ret)); |
| 10731 | goto fail; |
| 10732 | } |
| 10733 | |
| 10734 | fail: |
| 10735 | nlmsg_free(msg); |
| 10736 | return ret; |
| 10737 | } |
| 10738 | |
| 10739 | #endif /* CONFIG_MBO */ |
| 10740 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10741 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 10742 | |
| 10743 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10744 | static int nl80211_write_to_file(const char *name, unsigned int val) |
| 10745 | { |
| 10746 | int fd, len; |
| 10747 | char tmp[128]; |
| 10748 | |
| 10749 | fd = open(name, O_RDWR); |
| 10750 | if (fd < 0) { |
| 10751 | wpa_printf(MSG_ERROR, "nl80211: Failed to open %s: %s", |
| 10752 | name, strerror(errno)); |
| 10753 | return fd; |
| 10754 | } |
| 10755 | |
| 10756 | len = os_snprintf(tmp, sizeof(tmp), "%u\n", val); |
| 10757 | len = write(fd, tmp, len); |
| 10758 | if (len < 0) |
| 10759 | wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s", |
| 10760 | name, strerror(errno)); |
| 10761 | close(fd); |
| 10762 | |
| 10763 | return 0; |
| 10764 | } |
| 10765 | |
| 10766 | |
| 10767 | static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags) |
| 10768 | { |
| 10769 | struct i802_bss *bss = priv; |
| 10770 | char path[128]; |
| 10771 | int ret; |
| 10772 | |
| 10773 | wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x", |
| 10774 | filter_flags); |
| 10775 | |
| 10776 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 10777 | ret = os_snprintf(path, sizeof(path), |
| 10778 | "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast", |
| 10779 | bss->ifname); |
| 10780 | if (os_snprintf_error(sizeof(path), ret)) |
| 10781 | return -1; |
| 10782 | |
| 10783 | ret = nl80211_write_to_file(path, |
| 10784 | !!(filter_flags & |
| 10785 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 10786 | if (ret) { |
| 10787 | wpa_printf(MSG_ERROR, |
| 10788 | "nl80211: Failed to set IPv4 unicast in multicast filter"); |
| 10789 | return ret; |
| 10790 | } |
| 10791 | |
| 10792 | os_snprintf(path, sizeof(path), |
| 10793 | "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast", |
| 10794 | bss->ifname); |
| 10795 | ret = nl80211_write_to_file(path, |
| 10796 | !!(filter_flags & |
| 10797 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 10798 | |
| 10799 | if (ret) { |
| 10800 | wpa_printf(MSG_ERROR, |
| 10801 | "nl80211: Failed to set IPv6 unicast in multicast filter"); |
| 10802 | return ret; |
| 10803 | } |
| 10804 | |
| 10805 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 10806 | os_snprintf(path, sizeof(path), |
| 10807 | "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp", |
| 10808 | bss->ifname); |
| 10809 | ret = nl80211_write_to_file(path, |
| 10810 | !!(filter_flags & |
| 10811 | WPA_DATA_FRAME_FILTER_FLAG_ARP)); |
| 10812 | if (ret) { |
| 10813 | wpa_printf(MSG_ERROR, |
| 10814 | "nl80211: Failed set gratuitous ARP filter"); |
| 10815 | return ret; |
| 10816 | } |
| 10817 | |
| 10818 | /* Configure filtering of IPv6 NA frames */ |
| 10819 | os_snprintf(path, sizeof(path), |
| 10820 | "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na", |
| 10821 | bss->ifname); |
| 10822 | ret = nl80211_write_to_file(path, |
| 10823 | !!(filter_flags & |
| 10824 | WPA_DATA_FRAME_FILTER_FLAG_NA)); |
| 10825 | if (ret) { |
| 10826 | wpa_printf(MSG_ERROR, |
| 10827 | "nl80211: Failed to set unsolicited NA filter"); |
| 10828 | return ret; |
| 10829 | } |
| 10830 | |
| 10831 | return 0; |
| 10832 | } |
| 10833 | |
| 10834 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 10835 | static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type, |
| 10836 | const u8 **ext_capa, const u8 **ext_capa_mask, |
| 10837 | unsigned int *ext_capa_len) |
| 10838 | { |
| 10839 | struct i802_bss *bss = priv; |
| 10840 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10841 | enum nl80211_iftype nlmode; |
| 10842 | unsigned int i; |
| 10843 | |
| 10844 | if (!ext_capa || !ext_capa_mask || !ext_capa_len) |
| 10845 | return -1; |
| 10846 | |
| 10847 | nlmode = wpa_driver_nl80211_if_type(type); |
| 10848 | |
| 10849 | /* By default, use the per-radio values */ |
| 10850 | *ext_capa = drv->extended_capa; |
| 10851 | *ext_capa_mask = drv->extended_capa_mask; |
| 10852 | *ext_capa_len = drv->extended_capa_len; |
| 10853 | |
| 10854 | /* Replace the default value if a per-interface type value exists */ |
| 10855 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 10856 | if (nlmode == drv->iface_ext_capa[i].iftype) { |
| 10857 | *ext_capa = drv->iface_ext_capa[i].ext_capa; |
| 10858 | *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask; |
| 10859 | *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len; |
| 10860 | break; |
| 10861 | } |
| 10862 | } |
| 10863 | |
| 10864 | return 0; |
| 10865 | } |
| 10866 | |
| 10867 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10868 | static int nl80211_update_connection_params( |
| 10869 | void *priv, struct wpa_driver_associate_params *params, |
| 10870 | enum wpa_drv_update_connect_params_mask mask) |
| 10871 | { |
| 10872 | struct i802_bss *bss = priv; |
| 10873 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10874 | struct nl_msg *msg; |
| 10875 | int ret = -1; |
| 10876 | enum nl80211_auth_type type; |
| 10877 | |
| 10878 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS); |
| 10879 | if (!msg) |
| 10880 | goto fail; |
| 10881 | |
| 10882 | wpa_printf(MSG_DEBUG, "nl80211: Update connection params (ifindex=%d)", |
| 10883 | drv->ifindex); |
| 10884 | |
| 10885 | if ((mask & WPA_DRV_UPDATE_ASSOC_IES) && params->wpa_ie) { |
| 10886 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 10887 | params->wpa_ie)) |
| 10888 | goto fail; |
| 10889 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, |
| 10890 | params->wpa_ie_len); |
| 10891 | } |
| 10892 | |
| 10893 | if (mask & WPA_DRV_UPDATE_AUTH_TYPE) { |
| 10894 | type = get_nl_auth_type(params->auth_alg); |
| 10895 | if (type == NL80211_AUTHTYPE_MAX || |
| 10896 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 10897 | goto fail; |
| 10898 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
| 10899 | } |
| 10900 | |
| 10901 | if ((mask & WPA_DRV_UPDATE_FILS_ERP_INFO) && |
| 10902 | nl80211_put_fils_connect_params(drv, params, msg)) |
| 10903 | goto fail; |
| 10904 | |
| 10905 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10906 | msg = NULL; |
| 10907 | if (ret) |
| 10908 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 10909 | "nl80211: Update connect params command failed: ret=%d (%s)", |
| 10910 | ret, strerror(-ret)); |
| 10911 | |
| 10912 | fail: |
| 10913 | nlmsg_free(msg); |
| 10914 | return ret; |
| 10915 | } |
| 10916 | |
| 10917 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10918 | static int nl80211_send_external_auth_status(void *priv, |
| 10919 | struct external_auth *params) |
| 10920 | { |
| 10921 | struct i802_bss *bss = priv; |
| 10922 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10923 | struct nl_msg *msg = NULL; |
| 10924 | int ret = -1; |
| 10925 | |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 10926 | /* External auth command/status is intended for drivers that implement |
| 10927 | * intenral SME but want to offload authentication processing (e.g., |
| 10928 | * SAE) to hostapd/wpa_supplicant. Do nott send the status to drivers |
| 10929 | * which do not support AP SME or use wpa_supplicant/hostapd SME. |
| 10930 | */ |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 10931 | if ((is_ap_interface(drv->nlmode) && !bss->drv->device_ap_sme) || |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 10932 | (drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
| 10933 | return -1; |
| 10934 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10935 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 10936 | "nl80211: External auth status: %u", params->status); |
| 10937 | |
| 10938 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_EXTERNAL_AUTH); |
| 10939 | if (!msg || |
| 10940 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, params->status) || |
Hai Shalom | 5f92bc9 | 2019-04-18 11:54:11 -0700 | [diff] [blame] | 10941 | (params->ssid && params->ssid_len && |
| 10942 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || |
| 10943 | (params->pmkid && |
| 10944 | nla_put(msg, NL80211_ATTR_PMKID, PMKID_LEN, params->pmkid)) || |
| 10945 | (params->bssid && |
| 10946 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid))) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10947 | goto fail; |
| 10948 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10949 | msg = NULL; |
| 10950 | if (ret) { |
| 10951 | wpa_printf(MSG_DEBUG, |
| 10952 | "nl80211: External Auth status update failed: ret=%d (%s)", |
| 10953 | ret, strerror(-ret)); |
| 10954 | goto fail; |
| 10955 | } |
| 10956 | fail: |
| 10957 | nlmsg_free(msg); |
| 10958 | return ret; |
| 10959 | } |
| 10960 | |
| 10961 | |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 10962 | static int nl80211_set_4addr_mode(void *priv, const char *bridge_ifname, |
| 10963 | int val) |
| 10964 | { |
| 10965 | struct i802_bss *bss = priv; |
| 10966 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10967 | struct nl_msg *msg; |
| 10968 | int ret = -ENOBUFS; |
| 10969 | |
| 10970 | wpa_printf(MSG_DEBUG, "nl80211: %s 4addr mode (bridge_ifname: %s)", |
| 10971 | val ? "Enable" : "Disable", bridge_ifname); |
| 10972 | |
| 10973 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 10974 | if (!msg || nla_put_u8(msg, NL80211_ATTR_4ADDR, val)) |
| 10975 | goto fail; |
| 10976 | |
| 10977 | if (bridge_ifname[0] && bss->added_if_into_bridge && !val) { |
| 10978 | if (linux_br_del_if(drv->global->ioctl_sock, |
| 10979 | bridge_ifname, bss->ifname)) { |
| 10980 | wpa_printf(MSG_ERROR, |
| 10981 | "nl80211: Failed to remove interface %s from bridge %s", |
| 10982 | bss->ifname, bridge_ifname); |
| 10983 | return -1; |
| 10984 | } |
| 10985 | bss->added_if_into_bridge = 0; |
| 10986 | } |
| 10987 | |
| 10988 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10989 | msg = NULL; |
| 10990 | if (!ret) { |
| 10991 | if (bridge_ifname[0] && val && |
| 10992 | i802_check_bridge(drv, bss, bridge_ifname, bss->ifname) < 0) |
| 10993 | return -1; |
| 10994 | return 0; |
| 10995 | } |
| 10996 | |
| 10997 | fail: |
| 10998 | nlmsg_free(msg); |
| 10999 | wpa_printf(MSG_ERROR, "nl80211: Failed to enable/disable 4addr"); |
| 11000 | |
| 11001 | return ret; |
| 11002 | } |
| 11003 | |
| 11004 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11005 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 11006 | .name = "nl80211", |
| 11007 | .desc = "Linux nl80211/cfg80211", |
| 11008 | .get_bssid = wpa_driver_nl80211_get_bssid, |
| 11009 | .get_ssid = wpa_driver_nl80211_get_ssid, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11010 | .set_key = driver_nl80211_set_key, |
| 11011 | .scan2 = driver_nl80211_scan2, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11012 | .sched_scan = wpa_driver_nl80211_sched_scan, |
| 11013 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11014 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 11015 | .abort_scan = wpa_driver_nl80211_abort_scan, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11016 | .deauthenticate = driver_nl80211_deauthenticate, |
| 11017 | .authenticate = driver_nl80211_authenticate, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11018 | .associate = wpa_driver_nl80211_associate, |
| 11019 | .global_init = nl80211_global_init, |
| 11020 | .global_deinit = nl80211_global_deinit, |
| 11021 | .init2 = wpa_driver_nl80211_init, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11022 | .deinit = driver_nl80211_deinit, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11023 | .get_capa = wpa_driver_nl80211_get_capa, |
| 11024 | .set_operstate = wpa_driver_nl80211_set_operstate, |
| 11025 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
| 11026 | .set_country = wpa_driver_nl80211_set_country, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 11027 | .get_country = wpa_driver_nl80211_get_country, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11028 | .set_ap = wpa_driver_nl80211_set_ap, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 11029 | .set_acl = wpa_driver_nl80211_set_acl, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11030 | .if_add = wpa_driver_nl80211_if_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11031 | .if_remove = driver_nl80211_if_remove, |
| 11032 | .send_mlme = driver_nl80211_send_mlme, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11033 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11034 | .sta_add = wpa_driver_nl80211_sta_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11035 | .sta_remove = driver_nl80211_sta_remove, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11036 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
| 11037 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 11038 | .sta_set_airtime_weight = driver_nl80211_sta_set_airtime_weight, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11039 | .hapd_init = i802_init, |
| 11040 | .hapd_deinit = i802_deinit, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 11041 | .set_wds_sta = i802_set_wds_sta, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11042 | .get_seqnum = i802_get_seqnum, |
| 11043 | .flush = i802_flush, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11044 | .get_inact_sec = i802_get_inact_sec, |
| 11045 | .sta_clear_stats = i802_sta_clear_stats, |
| 11046 | .set_rts = i802_set_rts, |
| 11047 | .set_frag = i802_set_frag, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11048 | .set_tx_queue_params = i802_set_tx_queue_params, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11049 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11050 | .sta_deauth = i802_sta_deauth, |
| 11051 | .sta_disassoc = i802_sta_disassoc, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11052 | .read_sta_data = driver_nl80211_read_sta_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11053 | .set_freq = i802_set_freq, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11054 | .send_action = driver_nl80211_send_action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11055 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
| 11056 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
| 11057 | .cancel_remain_on_channel = |
| 11058 | wpa_driver_nl80211_cancel_remain_on_channel, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 11059 | .probe_req_report = driver_nl80211_probe_req_report, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11060 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 11061 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11062 | .resume = wpa_driver_nl80211_resume, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11063 | .signal_monitor = nl80211_signal_monitor, |
| 11064 | .signal_poll = nl80211_signal_poll, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 11065 | .channel_info = nl80211_channel_info, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11066 | .send_frame = nl80211_send_frame, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11067 | .set_param = nl80211_set_param, |
| 11068 | .get_radio_name = nl80211_get_radio_name, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 11069 | .add_pmkid = nl80211_add_pmkid, |
| 11070 | .remove_pmkid = nl80211_remove_pmkid, |
| 11071 | .flush_pmkid = nl80211_flush_pmkid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11072 | .set_rekey_info = nl80211_set_rekey_info, |
| 11073 | .poll_client = nl80211_poll_client, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11074 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 11075 | .start_dfs_cac = nl80211_start_radar_detection, |
| 11076 | .stop_ap = wpa_driver_nl80211_stop_ap, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11077 | #ifdef CONFIG_TDLS |
| 11078 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, |
| 11079 | .tdls_oper = nl80211_tdls_oper, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11080 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
| 11081 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11082 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 11083 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 11084 | .update_dh_ie = nl80211_update_dh_ie, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 11085 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 11086 | .get_survey = wpa_driver_nl80211_get_survey, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 11087 | .status = wpa_driver_nl80211_status, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 11088 | .switch_channel = nl80211_switch_channel, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11089 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 11090 | .set_noa = wpa_driver_set_p2p_noa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 11091 | .get_noa = wpa_driver_get_p2p_noa, |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 11092 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 11093 | #endif /* ANDROID_P2P */ |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 11094 | #ifdef ANDROID |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 11095 | #ifndef ANDROID_LIB_STUB |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 11096 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 11097 | #endif /* !ANDROID_LIB_STUB */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 11098 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 11099 | .vendor_cmd = nl80211_vendor_cmd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 11100 | .set_qos_map = nl80211_set_qos_map, |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 11101 | .set_wowlan = nl80211_set_wowlan, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 11102 | .set_mac_addr = nl80211_set_mac_addr, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11103 | #ifdef CONFIG_MESH |
| 11104 | .init_mesh = wpa_driver_nl80211_init_mesh, |
| 11105 | .join_mesh = wpa_driver_nl80211_join_mesh, |
| 11106 | .leave_mesh = wpa_driver_nl80211_leave_mesh, |
Hai Shalom | 81f62d8 | 2019-07-22 12:10:00 -0700 | [diff] [blame^] | 11107 | .probe_mesh_link = nl80211_probe_mesh_link, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11108 | #endif /* CONFIG_MESH */ |
| 11109 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
| 11110 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, |
| 11111 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
| 11112 | .br_set_net_param = wpa_driver_br_set_net_param, |
| 11113 | .add_tx_ts = nl80211_add_ts, |
| 11114 | .del_tx_ts = nl80211_del_ts, |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 11115 | .get_ifindex = nl80211_get_ifindex, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11116 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 11117 | .roaming = nl80211_roaming, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11118 | .disable_fils = nl80211_disable_fils, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 11119 | .do_acs = wpa_driver_do_acs, |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 11120 | .set_band = nl80211_set_band, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11121 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
| 11122 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 11123 | .p2p_lo_start = nl80211_p2p_lo_start, |
| 11124 | .p2p_lo_stop = nl80211_p2p_lo_stop, |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 11125 | .set_default_scan_ies = nl80211_set_default_scan_ies, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 11126 | .set_tdls_mode = nl80211_set_tdls_mode, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11127 | #ifdef CONFIG_MBO |
| 11128 | .get_bss_transition_status = nl80211_get_bss_transition_status, |
| 11129 | .ignore_assoc_disallow = nl80211_ignore_assoc_disallow, |
| 11130 | #endif /* CONFIG_MBO */ |
| 11131 | .set_bssid_blacklist = nl80211_set_bssid_blacklist, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 11132 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 11133 | .configure_data_frame_filters = nl80211_configure_data_frame_filters, |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 11134 | .get_ext_capab = nl80211_get_ext_capab, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 11135 | .update_connect_params = nl80211_update_connection_params, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 11136 | .send_external_auth_status = nl80211_send_external_auth_status, |
Hai Shalom | 74f70d4 | 2019-02-11 14:42:39 -0800 | [diff] [blame] | 11137 | .set_4addr_mode = nl80211_set_4addr_mode, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11138 | }; |