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 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 43 | #ifndef CONFIG_LIBNL20 |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 44 | /* |
| 45 | * libnl 1.1 has a bug, it tries to allocate socket numbers densely |
| 46 | * but when you free a socket again it will mess up its bitmap and |
| 47 | * and use the wrong number the next time it needs a socket ID. |
| 48 | * Therefore, we wrap the handle alloc/destroy and add our own pid |
| 49 | * accounting. |
| 50 | */ |
| 51 | static uint32_t port_bitmap[32] = { 0 }; |
| 52 | |
| 53 | static struct nl_handle *nl80211_handle_alloc(void *cb) |
| 54 | { |
| 55 | struct nl_handle *handle; |
| 56 | uint32_t pid = getpid() & 0x3FFFFF; |
| 57 | int i; |
| 58 | |
| 59 | handle = nl_handle_alloc_cb(cb); |
| 60 | |
| 61 | for (i = 0; i < 1024; i++) { |
| 62 | if (port_bitmap[i / 32] & (1 << (i % 32))) |
| 63 | continue; |
| 64 | port_bitmap[i / 32] |= 1 << (i % 32); |
| 65 | pid += i << 22; |
| 66 | break; |
| 67 | } |
| 68 | |
| 69 | nl_socket_set_local_port(handle, pid); |
| 70 | |
| 71 | return handle; |
| 72 | } |
| 73 | |
| 74 | static void nl80211_handle_destroy(struct nl_handle *handle) |
| 75 | { |
| 76 | uint32_t port = nl_socket_get_local_port(handle); |
| 77 | |
| 78 | port >>= 22; |
| 79 | port_bitmap[port / 32] &= ~(1 << (port % 32)); |
| 80 | |
| 81 | nl_handle_destroy(handle); |
| 82 | } |
| 83 | #endif /* CONFIG_LIBNL20 */ |
| 84 | |
| 85 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 86 | #ifdef ANDROID |
| 87 | /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */ |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 88 | #undef nl_socket_set_nonblocking |
| 89 | #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 90 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 91 | #endif /* ANDROID */ |
| 92 | |
| 93 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 94 | static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg) |
| 95 | { |
| 96 | struct nl_handle *handle; |
| 97 | |
| 98 | handle = nl80211_handle_alloc(cb); |
| 99 | if (handle == NULL) { |
| 100 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 101 | "callbacks (%s)", dbg); |
| 102 | return NULL; |
| 103 | } |
| 104 | |
| 105 | if (genl_connect(handle)) { |
| 106 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " |
| 107 | "netlink (%s)", dbg); |
| 108 | nl80211_handle_destroy(handle); |
| 109 | return NULL; |
| 110 | } |
| 111 | |
| 112 | return handle; |
| 113 | } |
| 114 | |
| 115 | |
| 116 | static void nl_destroy_handles(struct nl_handle **handle) |
| 117 | { |
| 118 | if (*handle == NULL) |
| 119 | return; |
| 120 | nl80211_handle_destroy(*handle); |
| 121 | *handle = NULL; |
| 122 | } |
| 123 | |
| 124 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 125 | #if __WORDSIZE == 64 |
| 126 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL |
| 127 | #else |
| 128 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL |
| 129 | #endif |
| 130 | |
| 131 | static void nl80211_register_eloop_read(struct nl_handle **handle, |
| 132 | eloop_sock_handler handler, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 133 | void *eloop_data, int persist) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 134 | { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 135 | #ifdef CONFIG_LIBNL20 |
| 136 | /* |
| 137 | * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB) |
| 138 | * by default. It is possible to hit that limit in some cases where |
| 139 | * operations are blocked, e.g., with a burst of Deauthentication frames |
| 140 | * to hostapd and STA entry deletion. Try to increase the buffer to make |
| 141 | * this less likely to occur. |
| 142 | */ |
| 143 | if (nl_socket_set_buffer_size(*handle, 262144, 0) < 0) { |
| 144 | wpa_printf(MSG_DEBUG, |
| 145 | "nl80211: Could not set nl_socket RX buffer size: %s", |
| 146 | strerror(errno)); |
| 147 | /* continue anyway with the default (smaller) buffer */ |
| 148 | } |
| 149 | #endif /* CONFIG_LIBNL20 */ |
| 150 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 151 | nl_socket_set_nonblocking(*handle); |
| 152 | eloop_register_read_sock(nl_socket_get_fd(*handle), handler, |
| 153 | eloop_data, *handle); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 154 | if (!persist) |
| 155 | *handle = (void *) (((intptr_t) *handle) ^ |
| 156 | ELOOP_SOCKET_INVALID); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 160 | static void nl80211_destroy_eloop_handle(struct nl_handle **handle, int persist) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 161 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 162 | if (!persist) |
| 163 | *handle = (void *) (((intptr_t) *handle) ^ |
| 164 | ELOOP_SOCKET_INVALID); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 165 | eloop_unregister_read_sock(nl_socket_get_fd(*handle)); |
| 166 | nl_destroy_handles(handle); |
| 167 | } |
| 168 | |
| 169 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 170 | static void nl80211_global_deinit(void *priv); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 171 | static void nl80211_check_global(struct nl80211_global *global); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 172 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 173 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 174 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 175 | struct hostapd_freq_params *freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 176 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 177 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 178 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 179 | const u8 *set_addr, int first, |
| 180 | const char *driver_params); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 181 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 182 | unsigned int freq, unsigned int wait, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 183 | const u8 *buf, size_t buf_len, u64 *cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 184 | int no_cck, int no_ack, int offchanok, |
| 185 | const u16 *csa_offs, size_t csa_offs_len); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 186 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, |
| 187 | int report); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 188 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 189 | #define IFIDX_ANY -1 |
| 190 | |
| 191 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 192 | int ifidx_reason); |
| 193 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 194 | int ifidx_reason); |
| 195 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 196 | int ifidx_reason); |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 197 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 198 | static int nl80211_set_channel(struct i802_bss *bss, |
| 199 | struct hostapd_freq_params *freq, int set_chan); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 200 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 201 | int ifindex, int disabled); |
| 202 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 203 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 204 | int reset_mode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 205 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 206 | static int i802_set_iface_flags(struct i802_bss *bss, int up); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 207 | static int nl80211_set_param(void *priv, const char *param); |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 208 | #ifdef CONFIG_MESH |
| 209 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
| 210 | struct wpa_driver_mesh_bss_params *params); |
| 211 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 212 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
| 213 | int reason); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 214 | |
| 215 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 216 | /* Converts nl80211_chan_width to a common format */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 217 | enum chan_width convert2width(int width) |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 218 | { |
| 219 | switch (width) { |
| 220 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 221 | return CHAN_WIDTH_20_NOHT; |
| 222 | case NL80211_CHAN_WIDTH_20: |
| 223 | return CHAN_WIDTH_20; |
| 224 | case NL80211_CHAN_WIDTH_40: |
| 225 | return CHAN_WIDTH_40; |
| 226 | case NL80211_CHAN_WIDTH_80: |
| 227 | return CHAN_WIDTH_80; |
| 228 | case NL80211_CHAN_WIDTH_80P80: |
| 229 | return CHAN_WIDTH_80P80; |
| 230 | case NL80211_CHAN_WIDTH_160: |
| 231 | return CHAN_WIDTH_160; |
| 232 | } |
| 233 | return CHAN_WIDTH_UNKNOWN; |
| 234 | } |
| 235 | |
| 236 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 237 | int is_ap_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 238 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 239 | return nlmode == NL80211_IFTYPE_AP || |
| 240 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 244 | int is_sta_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 245 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 246 | return nlmode == NL80211_IFTYPE_STATION || |
| 247 | nlmode == NL80211_IFTYPE_P2P_CLIENT; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 251 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 252 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 253 | return nlmode == NL80211_IFTYPE_P2P_CLIENT || |
| 254 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 255 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 256 | |
| 257 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 258 | struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, |
| 259 | int ifindex) |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 260 | { |
| 261 | struct i802_bss *bss; |
| 262 | |
| 263 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 264 | if (bss->ifindex == ifindex) |
| 265 | return bss; |
| 266 | } |
| 267 | |
| 268 | return NULL; |
| 269 | } |
| 270 | |
| 271 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 272 | static int is_mesh_interface(enum nl80211_iftype nlmode) |
| 273 | { |
| 274 | return nlmode == NL80211_IFTYPE_MESH_POINT; |
| 275 | } |
| 276 | |
| 277 | |
| 278 | void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 279 | { |
| 280 | if (drv->associated) |
| 281 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); |
| 282 | drv->associated = 0; |
| 283 | os_memset(drv->bssid, 0, ETH_ALEN); |
| 284 | } |
| 285 | |
| 286 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 287 | /* nl80211 code */ |
| 288 | static int ack_handler(struct nl_msg *msg, void *arg) |
| 289 | { |
| 290 | int *err = arg; |
| 291 | *err = 0; |
| 292 | return NL_STOP; |
| 293 | } |
| 294 | |
| 295 | static int finish_handler(struct nl_msg *msg, void *arg) |
| 296 | { |
| 297 | int *ret = arg; |
| 298 | *ret = 0; |
| 299 | return NL_SKIP; |
| 300 | } |
| 301 | |
| 302 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, |
| 303 | void *arg) |
| 304 | { |
| 305 | int *ret = arg; |
| 306 | *ret = err->error; |
| 307 | return NL_SKIP; |
| 308 | } |
| 309 | |
| 310 | |
| 311 | static int no_seq_check(struct nl_msg *msg, void *arg) |
| 312 | { |
| 313 | return NL_OK; |
| 314 | } |
| 315 | |
| 316 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 317 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
| 318 | { |
| 319 | /* |
| 320 | * Clear nlmsg data, e.g., to make sure key material is not left in |
| 321 | * heap memory for unnecessarily long time. |
| 322 | */ |
| 323 | if (msg) { |
| 324 | struct nlmsghdr *hdr = nlmsg_hdr(msg); |
| 325 | void *data = nlmsg_data(hdr); |
| 326 | /* |
| 327 | * This would use nlmsg_datalen() or the older nlmsg_len() if |
| 328 | * only libnl were to maintain a stable API.. Neither will work |
| 329 | * with all released versions, so just calculate the length |
| 330 | * here. |
| 331 | */ |
| 332 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; |
| 333 | |
| 334 | os_memset(data, 0, len); |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 339 | static int send_and_recv(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 340 | struct nl_handle *nl_handle, struct nl_msg *msg, |
| 341 | int (*valid_handler)(struct nl_msg *, void *), |
| 342 | void *valid_data) |
| 343 | { |
| 344 | struct nl_cb *cb; |
| 345 | int err = -ENOMEM; |
| 346 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 347 | if (!msg) |
| 348 | return -ENOMEM; |
| 349 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 350 | cb = nl_cb_clone(global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 351 | if (!cb) |
| 352 | goto out; |
| 353 | |
| 354 | err = nl_send_auto_complete(nl_handle, msg); |
| 355 | if (err < 0) |
| 356 | goto out; |
| 357 | |
| 358 | err = 1; |
| 359 | |
| 360 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); |
| 361 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
| 362 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
| 363 | |
| 364 | if (valid_handler) |
| 365 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 366 | valid_handler, valid_data); |
| 367 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 368 | while (err > 0) { |
| 369 | int res = nl_recvmsgs(nl_handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 370 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 371 | wpa_printf(MSG_INFO, |
| 372 | "nl80211: %s->nl_recvmsgs failed: %d", |
| 373 | __func__, res); |
| 374 | } |
| 375 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 376 | out: |
| 377 | nl_cb_put(cb); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 378 | if (!valid_handler && valid_data == (void *) -1) |
| 379 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 380 | nlmsg_free(msg); |
| 381 | return err; |
| 382 | } |
| 383 | |
| 384 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 385 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
| 386 | struct nl_msg *msg, |
| 387 | int (*valid_handler)(struct nl_msg *, void *), |
| 388 | void *valid_data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 389 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 390 | return send_and_recv(drv->global, drv->global->nl, msg, |
| 391 | valid_handler, valid_data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | |
| 395 | struct family_data { |
| 396 | const char *group; |
| 397 | int id; |
| 398 | }; |
| 399 | |
| 400 | |
| 401 | static int family_handler(struct nl_msg *msg, void *arg) |
| 402 | { |
| 403 | struct family_data *res = arg; |
| 404 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; |
| 405 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 406 | struct nlattr *mcgrp; |
| 407 | int i; |
| 408 | |
| 409 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 410 | genlmsg_attrlen(gnlh, 0), NULL); |
| 411 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) |
| 412 | return NL_SKIP; |
| 413 | |
| 414 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { |
| 415 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; |
| 416 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), |
| 417 | nla_len(mcgrp), NULL); |
| 418 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || |
| 419 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || |
| 420 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), |
| 421 | res->group, |
| 422 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) |
| 423 | continue; |
| 424 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); |
| 425 | break; |
| 426 | }; |
| 427 | |
| 428 | return NL_SKIP; |
| 429 | } |
| 430 | |
| 431 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 432 | static int nl_get_multicast_id(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 433 | const char *family, const char *group) |
| 434 | { |
| 435 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 436 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 437 | struct family_data res = { group, -ENOENT }; |
| 438 | |
| 439 | msg = nlmsg_alloc(); |
| 440 | if (!msg) |
| 441 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 442 | if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
| 443 | 0, 0, CTRL_CMD_GETFAMILY, 0) || |
| 444 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { |
| 445 | nlmsg_free(msg); |
| 446 | return -1; |
| 447 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 448 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 449 | ret = send_and_recv(global, global->nl, msg, family_handler, &res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 450 | if (ret == 0) |
| 451 | ret = res.id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 452 | return ret; |
| 453 | } |
| 454 | |
| 455 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 456 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
| 457 | struct nl_msg *msg, int flags, uint8_t cmd) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 458 | { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 459 | if (TEST_FAIL()) |
| 460 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 461 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
| 462 | 0, flags, cmd, 0); |
| 463 | } |
| 464 | |
| 465 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 466 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
| 467 | { |
| 468 | if (bss->wdev_id_set) |
| 469 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); |
| 470 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 471 | } |
| 472 | |
| 473 | |
| 474 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 475 | { |
| 476 | struct nl_msg *msg; |
| 477 | |
| 478 | msg = nlmsg_alloc(); |
| 479 | if (!msg) |
| 480 | return NULL; |
| 481 | |
| 482 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || |
| 483 | nl80211_set_iface_id(msg, bss) < 0) { |
| 484 | nlmsg_free(msg); |
| 485 | return NULL; |
| 486 | } |
| 487 | |
| 488 | return msg; |
| 489 | } |
| 490 | |
| 491 | |
| 492 | static struct nl_msg * |
| 493 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, |
| 494 | int flags, uint8_t cmd) |
| 495 | { |
| 496 | struct nl_msg *msg; |
| 497 | |
| 498 | msg = nlmsg_alloc(); |
| 499 | if (!msg) |
| 500 | return NULL; |
| 501 | |
| 502 | if (!nl80211_cmd(drv, msg, flags, cmd) || |
| 503 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { |
| 504 | nlmsg_free(msg); |
| 505 | return NULL; |
| 506 | } |
| 507 | |
| 508 | return msg; |
| 509 | } |
| 510 | |
| 511 | |
| 512 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, |
| 513 | uint8_t cmd) |
| 514 | { |
| 515 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); |
| 516 | } |
| 517 | |
| 518 | |
| 519 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 520 | { |
| 521 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); |
| 522 | } |
| 523 | |
| 524 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 525 | struct wiphy_idx_data { |
| 526 | int wiphy_idx; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 527 | enum nl80211_iftype nlmode; |
| 528 | u8 *macaddr; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 529 | }; |
| 530 | |
| 531 | |
| 532 | static int netdev_info_handler(struct nl_msg *msg, void *arg) |
| 533 | { |
| 534 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 535 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 536 | struct wiphy_idx_data *info = arg; |
| 537 | |
| 538 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 539 | genlmsg_attrlen(gnlh, 0), NULL); |
| 540 | |
| 541 | if (tb[NL80211_ATTR_WIPHY]) |
| 542 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 543 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 544 | if (tb[NL80211_ATTR_IFTYPE]) |
| 545 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); |
| 546 | |
| 547 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
| 548 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 549 | ETH_ALEN); |
| 550 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 551 | return NL_SKIP; |
| 552 | } |
| 553 | |
| 554 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 555 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 556 | { |
| 557 | struct nl_msg *msg; |
| 558 | struct wiphy_idx_data data = { |
| 559 | .wiphy_idx = -1, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 560 | .macaddr = NULL, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 561 | }; |
| 562 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 563 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 564 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 565 | |
| 566 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) |
| 567 | return data.wiphy_idx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 568 | return -1; |
| 569 | } |
| 570 | |
| 571 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 572 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
| 573 | { |
| 574 | struct nl_msg *msg; |
| 575 | struct wiphy_idx_data data = { |
| 576 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
| 577 | .macaddr = NULL, |
| 578 | }; |
| 579 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 580 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 581 | return NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 582 | |
| 583 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) |
| 584 | return data.nlmode; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 585 | return NL80211_IFTYPE_UNSPECIFIED; |
| 586 | } |
| 587 | |
| 588 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 589 | static int nl80211_get_macaddr(struct i802_bss *bss) |
| 590 | { |
| 591 | struct nl_msg *msg; |
| 592 | struct wiphy_idx_data data = { |
| 593 | .macaddr = bss->addr, |
| 594 | }; |
| 595 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 596 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 597 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 598 | |
| 599 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 600 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 601 | |
| 602 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 603 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
| 604 | struct nl80211_wiphy_data *w) |
| 605 | { |
| 606 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 607 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 608 | |
| 609 | msg = nlmsg_alloc(); |
| 610 | if (!msg) |
| 611 | return -1; |
| 612 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 613 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
| 614 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { |
| 615 | nlmsg_free(msg); |
| 616 | return -1; |
| 617 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 618 | |
| 619 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 620 | if (ret) { |
| 621 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " |
| 622 | "failed: ret=%d (%s)", |
| 623 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 624 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 625 | return ret; |
| 626 | } |
| 627 | |
| 628 | |
| 629 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) |
| 630 | { |
| 631 | struct nl80211_wiphy_data *w = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 632 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 633 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 634 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 635 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 636 | res = nl_recvmsgs(handle, w->nl_cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 637 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 638 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 639 | __func__, res); |
| 640 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | |
| 644 | static int process_beacon_event(struct nl_msg *msg, void *arg) |
| 645 | { |
| 646 | struct nl80211_wiphy_data *w = arg; |
| 647 | struct wpa_driver_nl80211_data *drv; |
| 648 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 649 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 650 | union wpa_event_data event; |
| 651 | |
| 652 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 653 | genlmsg_attrlen(gnlh, 0), NULL); |
| 654 | |
| 655 | if (gnlh->cmd != NL80211_CMD_FRAME) { |
| 656 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", |
| 657 | gnlh->cmd); |
| 658 | return NL_SKIP; |
| 659 | } |
| 660 | |
| 661 | if (!tb[NL80211_ATTR_FRAME]) |
| 662 | return NL_SKIP; |
| 663 | |
| 664 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, |
| 665 | wiphy_list) { |
| 666 | os_memset(&event, 0, sizeof(event)); |
| 667 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); |
| 668 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); |
| 669 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
| 670 | } |
| 671 | |
| 672 | return NL_SKIP; |
| 673 | } |
| 674 | |
| 675 | |
| 676 | static struct nl80211_wiphy_data * |
| 677 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) |
| 678 | { |
| 679 | static DEFINE_DL_LIST(nl80211_wiphys); |
| 680 | struct nl80211_wiphy_data *w; |
| 681 | int wiphy_idx, found = 0; |
| 682 | struct i802_bss *tmp_bss; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 683 | u8 channel; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 684 | |
| 685 | if (bss->wiphy_data != NULL) |
| 686 | return bss->wiphy_data; |
| 687 | |
| 688 | wiphy_idx = nl80211_get_wiphy_index(bss); |
| 689 | |
| 690 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { |
| 691 | if (w->wiphy_idx == wiphy_idx) |
| 692 | goto add; |
| 693 | } |
| 694 | |
| 695 | /* alloc new one */ |
| 696 | w = os_zalloc(sizeof(*w)); |
| 697 | if (w == NULL) |
| 698 | return NULL; |
| 699 | w->wiphy_idx = wiphy_idx; |
| 700 | dl_list_init(&w->bsss); |
| 701 | dl_list_init(&w->drvs); |
| 702 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 703 | /* Beacon frames not supported in IEEE 802.11ad */ |
| 704 | if (ieee80211_freq_to_chan(bss->freq, &channel) != |
| 705 | HOSTAPD_MODE_IEEE80211AD) { |
| 706 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 707 | if (!w->nl_cb) { |
| 708 | os_free(w); |
| 709 | return NULL; |
| 710 | } |
| 711 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 712 | no_seq_check, NULL); |
| 713 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 714 | process_beacon_event, w); |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 715 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 716 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, |
| 717 | "wiphy beacons"); |
| 718 | if (w->nl_beacons == NULL) { |
| 719 | os_free(w); |
| 720 | return NULL; |
| 721 | } |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 722 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 723 | if (nl80211_register_beacons(bss->drv, w)) { |
| 724 | nl_destroy_handles(&w->nl_beacons); |
| 725 | os_free(w); |
| 726 | return NULL; |
| 727 | } |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 728 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 729 | nl80211_register_eloop_read(&w->nl_beacons, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 730 | nl80211_recv_beacons, w, 0); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 731 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 732 | |
| 733 | dl_list_add(&nl80211_wiphys, &w->list); |
| 734 | |
| 735 | add: |
| 736 | /* drv entry for this bss already there? */ |
| 737 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 738 | if (tmp_bss->drv == bss->drv) { |
| 739 | found = 1; |
| 740 | break; |
| 741 | } |
| 742 | } |
| 743 | /* if not add it */ |
| 744 | if (!found) |
| 745 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); |
| 746 | |
| 747 | dl_list_add(&w->bsss, &bss->wiphy_list); |
| 748 | bss->wiphy_data = w; |
| 749 | return w; |
| 750 | } |
| 751 | |
| 752 | |
| 753 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) |
| 754 | { |
| 755 | struct nl80211_wiphy_data *w = bss->wiphy_data; |
| 756 | struct i802_bss *tmp_bss; |
| 757 | int found = 0; |
| 758 | |
| 759 | if (w == NULL) |
| 760 | return; |
| 761 | bss->wiphy_data = NULL; |
| 762 | dl_list_del(&bss->wiphy_list); |
| 763 | |
| 764 | /* still any for this drv present? */ |
| 765 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 766 | if (tmp_bss->drv == bss->drv) { |
| 767 | found = 1; |
| 768 | break; |
| 769 | } |
| 770 | } |
| 771 | /* if not remove it */ |
| 772 | if (!found) |
| 773 | dl_list_del(&bss->drv->wiphy_list); |
| 774 | |
| 775 | if (!dl_list_empty(&w->bsss)) |
| 776 | return; |
| 777 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 778 | if (w->nl_beacons) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 779 | nl80211_destroy_eloop_handle(&w->nl_beacons, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 780 | |
| 781 | nl_cb_put(w->nl_cb); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 782 | dl_list_del(&w->list); |
| 783 | os_free(w); |
| 784 | } |
| 785 | |
| 786 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 787 | static unsigned int nl80211_get_ifindex(void *priv) |
| 788 | { |
| 789 | struct i802_bss *bss = priv; |
| 790 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 791 | |
| 792 | return drv->ifindex; |
| 793 | } |
| 794 | |
| 795 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 796 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
| 797 | { |
| 798 | struct i802_bss *bss = priv; |
| 799 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 800 | if (!drv->associated) |
| 801 | return -1; |
| 802 | os_memcpy(bssid, drv->bssid, ETH_ALEN); |
| 803 | return 0; |
| 804 | } |
| 805 | |
| 806 | |
| 807 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
| 808 | { |
| 809 | struct i802_bss *bss = priv; |
| 810 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 811 | if (!drv->associated) |
| 812 | return -1; |
| 813 | os_memcpy(ssid, drv->ssid, drv->ssid_len); |
| 814 | return drv->ssid_len; |
| 815 | } |
| 816 | |
| 817 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 818 | static void wpa_driver_nl80211_event_newlink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 819 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 820 | int ifindex, const char *ifname) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 821 | { |
| 822 | union wpa_event_data event; |
| 823 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 824 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 825 | if (if_nametoindex(drv->first_bss->ifname) == 0) { |
| 826 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", |
| 827 | drv->first_bss->ifname); |
| 828 | return; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 829 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 830 | if (!drv->if_removed) |
| 831 | return; |
| 832 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", |
| 833 | drv->first_bss->ifname); |
| 834 | drv->if_removed = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 837 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 838 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 839 | os_strlcpy(event.interface_status.ifname, ifname, |
| 840 | sizeof(event.interface_status.ifname)); |
| 841 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 842 | if (drv) |
| 843 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 844 | else |
| 845 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 846 | &event); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | |
| 850 | static void wpa_driver_nl80211_event_dellink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 851 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 852 | int ifindex, const char *ifname) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 853 | { |
| 854 | union wpa_event_data event; |
| 855 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 856 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 857 | if (drv->if_removed) { |
| 858 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", |
| 859 | ifname); |
| 860 | return; |
| 861 | } |
| 862 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
| 863 | ifname); |
| 864 | drv->if_removed = 1; |
| 865 | } else { |
| 866 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", |
| 867 | ifname); |
| 868 | } |
| 869 | |
| 870 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 871 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 872 | os_strlcpy(event.interface_status.ifname, ifname, |
| 873 | sizeof(event.interface_status.ifname)); |
| 874 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 875 | if (drv) |
| 876 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 877 | else |
| 878 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 879 | &event); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | |
| 883 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
| 884 | u8 *buf, size_t len) |
| 885 | { |
| 886 | int attrlen, rta_len; |
| 887 | struct rtattr *attr; |
| 888 | |
| 889 | attrlen = len; |
| 890 | attr = (struct rtattr *) buf; |
| 891 | |
| 892 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
| 893 | while (RTA_OK(attr, attrlen)) { |
| 894 | if (attr->rta_type == IFLA_IFNAME) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 895 | if (os_strcmp(((char *) attr) + rta_len, |
| 896 | drv->first_bss->ifname) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 897 | return 1; |
| 898 | else |
| 899 | break; |
| 900 | } |
| 901 | attr = RTA_NEXT(attr, attrlen); |
| 902 | } |
| 903 | |
| 904 | return 0; |
| 905 | } |
| 906 | |
| 907 | |
| 908 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, |
| 909 | int ifindex, u8 *buf, size_t len) |
| 910 | { |
| 911 | if (drv->ifindex == ifindex) |
| 912 | return 1; |
| 913 | |
| 914 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 915 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 916 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
| 917 | "interface"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 918 | if (wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL) < 0) |
| 919 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 920 | return 1; |
| 921 | } |
| 922 | |
| 923 | return 0; |
| 924 | } |
| 925 | |
| 926 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 927 | static struct wpa_driver_nl80211_data * |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 928 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len, |
| 929 | int *init_failed) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 930 | { |
| 931 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 932 | int res; |
| 933 | |
| 934 | if (init_failed) |
| 935 | *init_failed = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 936 | dl_list_for_each(drv, &global->interfaces, |
| 937 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 938 | res = wpa_driver_nl80211_own_ifindex(drv, idx, buf, len); |
| 939 | if (res < 0) { |
| 940 | wpa_printf(MSG_DEBUG, |
| 941 | "nl80211: Found matching own interface, but failed to complete reinitialization"); |
| 942 | if (init_failed) |
| 943 | *init_failed = 1; |
| 944 | return drv; |
| 945 | } |
| 946 | if (res > 0 || have_ifidx(drv, idx, IFIDX_ANY)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 947 | return drv; |
| 948 | } |
| 949 | return NULL; |
| 950 | } |
| 951 | |
| 952 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 953 | static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 954 | int ifindex, int notify) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 955 | { |
| 956 | struct i802_bss *bss; |
| 957 | u8 addr[ETH_ALEN]; |
| 958 | |
| 959 | bss = get_bss_ifindex(drv, ifindex); |
| 960 | if (bss && |
| 961 | linux_get_ifhwaddr(drv->global->ioctl_sock, |
| 962 | bss->ifname, addr) < 0) { |
| 963 | wpa_printf(MSG_DEBUG, |
| 964 | "nl80211: %s: failed to re-read MAC address", |
| 965 | bss->ifname); |
| 966 | } else if (bss && os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { |
| 967 | wpa_printf(MSG_DEBUG, |
| 968 | "nl80211: Own MAC address on ifindex %d (%s) changed from " |
| 969 | MACSTR " to " MACSTR, |
| 970 | ifindex, bss->ifname, |
| 971 | MAC2STR(bss->addr), MAC2STR(addr)); |
| 972 | os_memcpy(bss->addr, addr, ETH_ALEN); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 973 | if (notify) |
| 974 | wpa_supplicant_event(drv->ctx, |
| 975 | EVENT_INTERFACE_MAC_CHANGED, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 976 | } |
| 977 | } |
| 978 | |
| 979 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 980 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
| 981 | struct ifinfomsg *ifi, |
| 982 | u8 *buf, size_t len) |
| 983 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 984 | struct nl80211_global *global = ctx; |
| 985 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 986 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 987 | struct rtattr *attr; |
| 988 | u32 brid = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 989 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 990 | char ifname[IFNAMSIZ + 1]; |
| 991 | char extra[100], *pos, *end; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 992 | int init_failed; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 993 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 994 | extra[0] = '\0'; |
| 995 | pos = extra; |
| 996 | end = pos + sizeof(extra); |
| 997 | ifname[0] = '\0'; |
| 998 | |
| 999 | attrlen = len; |
| 1000 | attr = (struct rtattr *) buf; |
| 1001 | while (RTA_OK(attr, attrlen)) { |
| 1002 | switch (attr->rta_type) { |
| 1003 | case IFLA_IFNAME: |
| 1004 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) |
| 1005 | break; |
| 1006 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1007 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1008 | break; |
| 1009 | case IFLA_MASTER: |
| 1010 | brid = nla_get_u32((struct nlattr *) attr); |
| 1011 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1012 | break; |
| 1013 | case IFLA_WIRELESS: |
| 1014 | pos += os_snprintf(pos, end - pos, " wext"); |
| 1015 | break; |
| 1016 | case IFLA_OPERSTATE: |
| 1017 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1018 | nla_get_u32((struct nlattr *) attr)); |
| 1019 | break; |
| 1020 | case IFLA_LINKMODE: |
| 1021 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1022 | nla_get_u32((struct nlattr *) attr)); |
| 1023 | break; |
| 1024 | } |
| 1025 | attr = RTA_NEXT(attr, attrlen); |
| 1026 | } |
| 1027 | extra[sizeof(extra) - 1] = '\0'; |
| 1028 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1029 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1030 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1031 | ifi->ifi_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1032 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1033 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1034 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1035 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1036 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1037 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, &init_failed); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1038 | if (!drv) |
| 1039 | goto event_newlink; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1040 | if (init_failed) |
| 1041 | return; /* do not update interface state */ |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1042 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1043 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1044 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1045 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1046 | linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1047 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1048 | "event since interface %s is up", namebuf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1049 | drv->ignore_if_down_event = 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1050 | /* Re-read MAC address as it may have changed */ |
| 1051 | nl80211_refresh_mac(drv, ifi->ifi_index, 1); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1052 | return; |
| 1053 | } |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1054 | wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", |
| 1055 | namebuf, ifname); |
| 1056 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 1057 | wpa_printf(MSG_DEBUG, |
| 1058 | "nl80211: Not the main interface (%s) - do not indicate interface down", |
| 1059 | drv->first_bss->ifname); |
| 1060 | } else if (drv->ignore_if_down_event) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1061 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1062 | "event generated by mode change"); |
| 1063 | drv->ignore_if_down_event = 0; |
| 1064 | } else { |
| 1065 | drv->if_disabled = 1; |
| 1066 | wpa_supplicant_event(drv->ctx, |
| 1067 | EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1068 | |
| 1069 | /* |
| 1070 | * Try to get drv again, since it may be removed as |
| 1071 | * part of the EVENT_INTERFACE_DISABLED handling for |
| 1072 | * dynamic interfaces |
| 1073 | */ |
| 1074 | drv = nl80211_find_drv(global, ifi->ifi_index, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1075 | buf, len, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1076 | if (!drv) |
| 1077 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1078 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1082 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1083 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1084 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1085 | "event since interface %s is down", |
| 1086 | namebuf); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1087 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1088 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1089 | "event since interface %s does not exist", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1090 | drv->first_bss->ifname); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1091 | } else if (drv->if_removed) { |
| 1092 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1093 | "event since interface %s is marked " |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1094 | "removed", drv->first_bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1095 | } else { |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1096 | /* Re-read MAC address as it may have changed */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1097 | nl80211_refresh_mac(drv, ifi->ifi_index, 0); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1098 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1099 | wpa_printf(MSG_DEBUG, "nl80211: Interface up"); |
| 1100 | drv->if_disabled = 0; |
| 1101 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, |
| 1102 | NULL); |
| 1103 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
| 1106 | /* |
| 1107 | * Some drivers send the association event before the operup event--in |
| 1108 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() |
| 1109 | * fails. This will hit us when wpa_supplicant does not need to do |
| 1110 | * IEEE 802.1X authentication |
| 1111 | */ |
| 1112 | if (drv->operstate == 1 && |
| 1113 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1114 | !(ifi->ifi_flags & IFF_RUNNING)) { |
| 1115 | 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] | 1116 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1117 | -1, IF_OPER_UP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1118 | } |
| 1119 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1120 | event_newlink: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1121 | if (ifname[0]) |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1122 | wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index, |
| 1123 | ifname); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1124 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1125 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1126 | struct i802_bss *bss; |
| 1127 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1128 | /* device has been added to bridge */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1129 | if (!if_indextoname(brid, namebuf)) { |
| 1130 | wpa_printf(MSG_DEBUG, |
| 1131 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1132 | brid); |
| 1133 | return; |
| 1134 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1135 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
| 1136 | brid, namebuf); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1137 | add_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1138 | |
| 1139 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 1140 | if (os_strcmp(ifname, bss->ifname) == 0) { |
| 1141 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); |
| 1142 | break; |
| 1143 | } |
| 1144 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1145 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1146 | } |
| 1147 | |
| 1148 | |
| 1149 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
| 1150 | struct ifinfomsg *ifi, |
| 1151 | u8 *buf, size_t len) |
| 1152 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1153 | struct nl80211_global *global = ctx; |
| 1154 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1155 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1156 | struct rtattr *attr; |
| 1157 | u32 brid = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1158 | char ifname[IFNAMSIZ + 1]; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1159 | char extra[100], *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1160 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1161 | extra[0] = '\0'; |
| 1162 | pos = extra; |
| 1163 | end = pos + sizeof(extra); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1164 | ifname[0] = '\0'; |
| 1165 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1166 | attrlen = len; |
| 1167 | attr = (struct rtattr *) buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1168 | while (RTA_OK(attr, attrlen)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1169 | switch (attr->rta_type) { |
| 1170 | case IFLA_IFNAME: |
| 1171 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) |
| 1172 | break; |
| 1173 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1174 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1175 | break; |
| 1176 | case IFLA_MASTER: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1177 | brid = nla_get_u32((struct nlattr *) attr); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1178 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1179 | break; |
| 1180 | case IFLA_OPERSTATE: |
| 1181 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1182 | nla_get_u32((struct nlattr *) attr)); |
| 1183 | break; |
| 1184 | case IFLA_LINKMODE: |
| 1185 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1186 | nla_get_u32((struct nlattr *) attr)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1187 | break; |
| 1188 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1189 | attr = RTA_NEXT(attr, attrlen); |
| 1190 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1191 | extra[sizeof(extra) - 1] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1192 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1193 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1194 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1195 | ifi->ifi_flags, |
| 1196 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1197 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1198 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1199 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1200 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1201 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1202 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1203 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1204 | /* device has been removed from bridge */ |
| 1205 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1206 | |
| 1207 | if (!if_indextoname(brid, namebuf)) { |
| 1208 | wpa_printf(MSG_DEBUG, |
| 1209 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1210 | brid); |
| 1211 | } else { |
| 1212 | wpa_printf(MSG_DEBUG, |
| 1213 | "nl80211: Remove ifindex %u for bridge %s", |
| 1214 | brid, namebuf); |
| 1215 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1216 | del_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1217 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1218 | |
| 1219 | if (ifi->ifi_family != AF_BRIDGE || !brid) |
| 1220 | wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index, |
| 1221 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1222 | } |
| 1223 | |
| 1224 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1225 | struct nl80211_get_assoc_freq_arg { |
| 1226 | struct wpa_driver_nl80211_data *drv; |
| 1227 | unsigned int assoc_freq; |
| 1228 | unsigned int ibss_freq; |
| 1229 | u8 assoc_bssid[ETH_ALEN]; |
| 1230 | u8 assoc_ssid[SSID_MAX_LEN]; |
| 1231 | u8 assoc_ssid_len; |
| 1232 | }; |
| 1233 | |
| 1234 | static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg) |
| 1235 | { |
| 1236 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1237 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1238 | struct nlattr *bss[NL80211_BSS_MAX + 1]; |
| 1239 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { |
| 1240 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, |
| 1241 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, |
| 1242 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, |
| 1243 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
| 1244 | }; |
| 1245 | struct nl80211_get_assoc_freq_arg *ctx = arg; |
| 1246 | enum nl80211_bss_status status; |
| 1247 | |
| 1248 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1249 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1250 | if (!tb[NL80211_ATTR_BSS] || |
| 1251 | nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], |
| 1252 | bss_policy) || |
| 1253 | !bss[NL80211_BSS_STATUS]) |
| 1254 | return NL_SKIP; |
| 1255 | |
| 1256 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); |
| 1257 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1258 | bss[NL80211_BSS_FREQUENCY]) { |
| 1259 | ctx->assoc_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1260 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", |
| 1261 | ctx->assoc_freq); |
| 1262 | } |
| 1263 | if (status == NL80211_BSS_STATUS_IBSS_JOINED && |
| 1264 | bss[NL80211_BSS_FREQUENCY]) { |
| 1265 | ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1266 | wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz", |
| 1267 | ctx->ibss_freq); |
| 1268 | } |
| 1269 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1270 | bss[NL80211_BSS_BSSID]) { |
| 1271 | os_memcpy(ctx->assoc_bssid, |
| 1272 | nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN); |
| 1273 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " |
| 1274 | MACSTR, MAC2STR(ctx->assoc_bssid)); |
| 1275 | } |
| 1276 | |
| 1277 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1278 | bss[NL80211_BSS_INFORMATION_ELEMENTS]) { |
| 1279 | const u8 *ie, *ssid; |
| 1280 | size_t ie_len; |
| 1281 | |
| 1282 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1283 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1284 | ssid = get_ie(ie, ie_len, WLAN_EID_SSID); |
| 1285 | if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) { |
| 1286 | ctx->assoc_ssid_len = ssid[1]; |
| 1287 | os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]); |
| 1288 | } |
| 1289 | } |
| 1290 | |
| 1291 | return NL_SKIP; |
| 1292 | } |
| 1293 | |
| 1294 | |
| 1295 | 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] | 1296 | { |
| 1297 | struct nl_msg *msg; |
| 1298 | int ret; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1299 | struct nl80211_get_assoc_freq_arg arg; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1300 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1301 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1302 | os_memset(&arg, 0, sizeof(arg)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1303 | arg.drv = drv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1304 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
| 1305 | &arg); |
| 1306 | if (ret == 0) { |
| 1307 | os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len); |
| 1308 | return arg.assoc_ssid_len; |
| 1309 | } |
| 1310 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)", |
| 1311 | ret, strerror(-ret)); |
| 1312 | return ret; |
| 1313 | } |
| 1314 | |
| 1315 | |
| 1316 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
| 1317 | { |
| 1318 | struct nl_msg *msg; |
| 1319 | int ret; |
| 1320 | struct nl80211_get_assoc_freq_arg arg; |
| 1321 | |
| 1322 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
| 1323 | os_memset(&arg, 0, sizeof(arg)); |
| 1324 | arg.drv = drv; |
| 1325 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
| 1326 | &arg); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1327 | if (ret == 0) { |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1328 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
| 1329 | arg.ibss_freq : arg.assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1330 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1331 | "associated BSS from scan results: %u MHz", freq); |
| 1332 | if (freq) |
| 1333 | drv->assoc_freq = freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1334 | return drv->assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1335 | } |
| 1336 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
| 1337 | "(%s)", ret, strerror(-ret)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1338 | return drv->assoc_freq; |
| 1339 | } |
| 1340 | |
| 1341 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1342 | static int get_link_signal(struct nl_msg *msg, void *arg) |
| 1343 | { |
| 1344 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1345 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1346 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; |
| 1347 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { |
| 1348 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1349 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1350 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1351 | }; |
| 1352 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
| 1353 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 1354 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 1355 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 1356 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, |
| 1357 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 1358 | }; |
| 1359 | struct wpa_signal_info *sig_change = arg; |
| 1360 | |
| 1361 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1362 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1363 | if (!tb[NL80211_ATTR_STA_INFO] || |
| 1364 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, |
| 1365 | tb[NL80211_ATTR_STA_INFO], policy)) |
| 1366 | return NL_SKIP; |
| 1367 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) |
| 1368 | return NL_SKIP; |
| 1369 | |
| 1370 | sig_change->current_signal = |
| 1371 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); |
| 1372 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1373 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
| 1374 | sig_change->avg_signal = |
| 1375 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); |
| 1376 | else |
| 1377 | sig_change->avg_signal = 0; |
| 1378 | |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1379 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
| 1380 | sig_change->avg_beacon_signal = |
| 1381 | (s8) |
| 1382 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); |
| 1383 | else |
| 1384 | sig_change->avg_beacon_signal = 0; |
| 1385 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1386 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
| 1387 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, |
| 1388 | sinfo[NL80211_STA_INFO_TX_BITRATE], |
| 1389 | rate_policy)) { |
| 1390 | sig_change->current_txrate = 0; |
| 1391 | } else { |
| 1392 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { |
| 1393 | sig_change->current_txrate = |
| 1394 | nla_get_u16(rinfo[ |
| 1395 | NL80211_RATE_INFO_BITRATE]) * 100; |
| 1396 | } |
| 1397 | } |
| 1398 | } |
| 1399 | |
| 1400 | return NL_SKIP; |
| 1401 | } |
| 1402 | |
| 1403 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1404 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
| 1405 | struct wpa_signal_info *sig) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1406 | { |
| 1407 | struct nl_msg *msg; |
| 1408 | |
| 1409 | sig->current_signal = -9999; |
| 1410 | sig->current_txrate = 0; |
| 1411 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1412 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
| 1413 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) { |
| 1414 | nlmsg_free(msg); |
| 1415 | return -ENOBUFS; |
| 1416 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1417 | |
| 1418 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | |
| 1422 | static int get_link_noise(struct nl_msg *msg, void *arg) |
| 1423 | { |
| 1424 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1425 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1426 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 1427 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 1428 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 1429 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 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 | |
| 1436 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 1437 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); |
| 1438 | return NL_SKIP; |
| 1439 | } |
| 1440 | |
| 1441 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 1442 | tb[NL80211_ATTR_SURVEY_INFO], |
| 1443 | survey_policy)) { |
| 1444 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " |
| 1445 | "attributes!"); |
| 1446 | return NL_SKIP; |
| 1447 | } |
| 1448 | |
| 1449 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 1450 | return NL_SKIP; |
| 1451 | |
| 1452 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 1453 | sig_change->frequency) |
| 1454 | return NL_SKIP; |
| 1455 | |
| 1456 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 1457 | return NL_SKIP; |
| 1458 | |
| 1459 | sig_change->current_noise = |
| 1460 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 1461 | |
| 1462 | return NL_SKIP; |
| 1463 | } |
| 1464 | |
| 1465 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1466 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
| 1467 | struct wpa_signal_info *sig_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1468 | { |
| 1469 | struct nl_msg *msg; |
| 1470 | |
| 1471 | sig_change->current_noise = 9999; |
| 1472 | sig_change->frequency = drv->assoc_freq; |
| 1473 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1474 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1475 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1476 | } |
| 1477 | |
| 1478 | |
| 1479 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
| 1480 | void *handle) |
| 1481 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1482 | struct nl_cb *cb = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1483 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1484 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1485 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1486 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1487 | res = nl_recvmsgs(handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 1488 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1489 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 1490 | __func__, res); |
| 1491 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | |
| 1495 | /** |
| 1496 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain |
| 1497 | * @priv: driver_nl80211 private data |
| 1498 | * @alpha2_arg: country to which to switch to |
| 1499 | * Returns: 0 on success, -1 on failure |
| 1500 | * |
| 1501 | * This asks nl80211 to set the regulatory domain for given |
| 1502 | * country ISO / IEC alpha2. |
| 1503 | */ |
| 1504 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) |
| 1505 | { |
| 1506 | struct i802_bss *bss = priv; |
| 1507 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1508 | char alpha2[3]; |
| 1509 | struct nl_msg *msg; |
| 1510 | |
| 1511 | msg = nlmsg_alloc(); |
| 1512 | if (!msg) |
| 1513 | return -ENOMEM; |
| 1514 | |
| 1515 | alpha2[0] = alpha2_arg[0]; |
| 1516 | alpha2[1] = alpha2_arg[1]; |
| 1517 | alpha2[2] = '\0'; |
| 1518 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1519 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
| 1520 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { |
| 1521 | nlmsg_free(msg); |
| 1522 | return -EINVAL; |
| 1523 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1524 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) |
| 1525 | return -EINVAL; |
| 1526 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1527 | } |
| 1528 | |
| 1529 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1530 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
| 1531 | { |
| 1532 | char *alpha2 = arg; |
| 1533 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 1534 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1535 | |
| 1536 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1537 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1538 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { |
| 1539 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); |
| 1540 | return NL_SKIP; |
| 1541 | } |
| 1542 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); |
| 1543 | return NL_SKIP; |
| 1544 | } |
| 1545 | |
| 1546 | |
| 1547 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) |
| 1548 | { |
| 1549 | struct i802_bss *bss = priv; |
| 1550 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1551 | struct nl_msg *msg; |
| 1552 | int ret; |
| 1553 | |
| 1554 | msg = nlmsg_alloc(); |
| 1555 | if (!msg) |
| 1556 | return -ENOMEM; |
| 1557 | |
| 1558 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
| 1559 | alpha2[0] = '\0'; |
| 1560 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2); |
| 1561 | if (!alpha2[0]) |
| 1562 | ret = -1; |
| 1563 | |
| 1564 | return ret; |
| 1565 | } |
| 1566 | |
| 1567 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1568 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1569 | { |
| 1570 | int ret; |
| 1571 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1572 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1573 | if (global->nl_cb == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1574 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 1575 | "callbacks"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1576 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1579 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
| 1580 | if (global->nl == NULL) |
| 1581 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1582 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1583 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
| 1584 | if (global->nl80211_id < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1585 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
| 1586 | "found"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1587 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1588 | } |
| 1589 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1590 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
| 1591 | if (global->nl_event == NULL) |
| 1592 | goto err; |
| 1593 | |
| 1594 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1595 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1596 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1597 | if (ret < 0) { |
| 1598 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1599 | "membership for scan events: %d (%s)", |
| 1600 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1601 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1602 | } |
| 1603 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1604 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1605 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1606 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1607 | if (ret < 0) { |
| 1608 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1609 | "membership for mlme events: %d (%s)", |
| 1610 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1611 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1612 | } |
| 1613 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1614 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1615 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1616 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1617 | if (ret < 0) { |
| 1618 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1619 | "membership for regulatory events: %d (%s)", |
| 1620 | ret, strerror(-ret)); |
| 1621 | /* Continue without regulatory events */ |
| 1622 | } |
| 1623 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1624 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
| 1625 | if (ret >= 0) |
| 1626 | ret = nl_socket_add_membership(global->nl_event, ret); |
| 1627 | if (ret < 0) { |
| 1628 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1629 | "membership for vendor events: %d (%s)", |
| 1630 | ret, strerror(-ret)); |
| 1631 | /* Continue without vendor events */ |
| 1632 | } |
| 1633 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1634 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1635 | no_seq_check, NULL); |
| 1636 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1637 | process_global_event, global); |
| 1638 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1639 | nl80211_register_eloop_read(&global->nl_event, |
| 1640 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1641 | global->nl_cb, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1642 | |
| 1643 | return 0; |
| 1644 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1645 | err: |
| 1646 | nl_destroy_handles(&global->nl_event); |
| 1647 | nl_destroy_handles(&global->nl); |
| 1648 | nl_cb_put(global->nl_cb); |
| 1649 | global->nl_cb = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1650 | return -1; |
| 1651 | } |
| 1652 | |
| 1653 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1654 | static void nl80211_check_global(struct nl80211_global *global) |
| 1655 | { |
| 1656 | struct nl_handle *handle; |
| 1657 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; |
| 1658 | int ret; |
| 1659 | unsigned int i; |
| 1660 | |
| 1661 | /* |
| 1662 | * Try to re-add memberships to handle case of cfg80211 getting reloaded |
| 1663 | * and all registration having been cleared. |
| 1664 | */ |
| 1665 | handle = (void *) (((intptr_t) global->nl_event) ^ |
| 1666 | ELOOP_SOCKET_INVALID); |
| 1667 | |
| 1668 | for (i = 0; groups[i]; i++) { |
| 1669 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); |
| 1670 | if (ret >= 0) |
| 1671 | ret = nl_socket_add_membership(handle, ret); |
| 1672 | if (ret < 0) { |
| 1673 | wpa_printf(MSG_INFO, |
| 1674 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", |
| 1675 | groups[i], ret, strerror(-ret)); |
| 1676 | } |
| 1677 | } |
| 1678 | } |
| 1679 | |
| 1680 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1681 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
| 1682 | { |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1683 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1684 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1685 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1686 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1687 | /* |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1688 | * rtnetlink ifdown handler will report interfaces other than the P2P |
| 1689 | * Device interface as disabled. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1690 | */ |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1691 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 1692 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1693 | } |
| 1694 | |
| 1695 | |
| 1696 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) |
| 1697 | { |
| 1698 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1699 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1700 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1701 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
| 1702 | "after rfkill unblock"); |
| 1703 | return; |
| 1704 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1705 | |
| 1706 | if (is_p2p_net_interface(drv->nlmode)) |
| 1707 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
| 1708 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1709 | /* |
| 1710 | * rtnetlink ifup handler will report interfaces other than the P2P |
| 1711 | * Device interface as enabled. |
| 1712 | */ |
| 1713 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 1714 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1718 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
| 1719 | void *eloop_ctx, |
| 1720 | void *handle) |
| 1721 | { |
| 1722 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 1723 | u8 data[2048]; |
| 1724 | struct msghdr msg; |
| 1725 | struct iovec entry; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1726 | u8 control[512]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1727 | struct cmsghdr *cmsg; |
| 1728 | int res, found_ee = 0, found_wifi = 0, acked = 0; |
| 1729 | union wpa_event_data event; |
| 1730 | |
| 1731 | memset(&msg, 0, sizeof(msg)); |
| 1732 | msg.msg_iov = &entry; |
| 1733 | msg.msg_iovlen = 1; |
| 1734 | entry.iov_base = data; |
| 1735 | entry.iov_len = sizeof(data); |
| 1736 | msg.msg_control = &control; |
| 1737 | msg.msg_controllen = sizeof(control); |
| 1738 | |
| 1739 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); |
| 1740 | /* if error or not fitting 802.3 header, return */ |
| 1741 | if (res < 14) |
| 1742 | return; |
| 1743 | |
| 1744 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
| 1745 | { |
| 1746 | if (cmsg->cmsg_level == SOL_SOCKET && |
| 1747 | cmsg->cmsg_type == SCM_WIFI_STATUS) { |
| 1748 | int *ack; |
| 1749 | |
| 1750 | found_wifi = 1; |
| 1751 | ack = (void *)CMSG_DATA(cmsg); |
| 1752 | acked = *ack; |
| 1753 | } |
| 1754 | |
| 1755 | if (cmsg->cmsg_level == SOL_PACKET && |
| 1756 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { |
| 1757 | struct sock_extended_err *err = |
| 1758 | (struct sock_extended_err *)CMSG_DATA(cmsg); |
| 1759 | |
| 1760 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) |
| 1761 | found_ee = 1; |
| 1762 | } |
| 1763 | } |
| 1764 | |
| 1765 | if (!found_ee || !found_wifi) |
| 1766 | return; |
| 1767 | |
| 1768 | memset(&event, 0, sizeof(event)); |
| 1769 | event.eapol_tx_status.dst = data; |
| 1770 | event.eapol_tx_status.data = data + 14; |
| 1771 | event.eapol_tx_status.data_len = res - 14; |
| 1772 | event.eapol_tx_status.ack = acked; |
| 1773 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); |
| 1774 | } |
| 1775 | |
| 1776 | |
| 1777 | static int nl80211_init_bss(struct i802_bss *bss) |
| 1778 | { |
| 1779 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1780 | if (!bss->nl_cb) |
| 1781 | return -1; |
| 1782 | |
| 1783 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1784 | no_seq_check, NULL); |
| 1785 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1786 | process_bss_event, bss); |
| 1787 | |
| 1788 | return 0; |
| 1789 | } |
| 1790 | |
| 1791 | |
| 1792 | static void nl80211_destroy_bss(struct i802_bss *bss) |
| 1793 | { |
| 1794 | nl_cb_put(bss->nl_cb); |
| 1795 | bss->nl_cb = NULL; |
| 1796 | } |
| 1797 | |
| 1798 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1799 | static void |
| 1800 | wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv) |
| 1801 | { |
| 1802 | struct rfkill_config *rcfg; |
| 1803 | |
| 1804 | if (drv->rfkill) |
| 1805 | return; |
| 1806 | |
| 1807 | rcfg = os_zalloc(sizeof(*rcfg)); |
| 1808 | if (!rcfg) |
| 1809 | return; |
| 1810 | |
| 1811 | rcfg->ctx = drv; |
| 1812 | |
| 1813 | /* rfkill uses netdev sysfs for initialization. However, P2P Device is |
| 1814 | * not associated with a netdev, so use the name of some other interface |
| 1815 | * sharing the same wiphy as the P2P Device interface. |
| 1816 | * |
| 1817 | * Note: This is valid, as a P2P Device interface is always dynamically |
| 1818 | * created and is created only once another wpa_s interface was added. |
| 1819 | */ |
| 1820 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 1821 | struct nl80211_global *global = drv->global; |
| 1822 | struct wpa_driver_nl80211_data *tmp1; |
| 1823 | |
| 1824 | dl_list_for_each(tmp1, &global->interfaces, |
| 1825 | struct wpa_driver_nl80211_data, list) { |
| 1826 | if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx || |
| 1827 | !tmp1->rfkill) |
| 1828 | continue; |
| 1829 | |
| 1830 | wpa_printf(MSG_DEBUG, |
| 1831 | "nl80211: Use (%s) to initialize P2P Device rfkill", |
| 1832 | tmp1->first_bss->ifname); |
| 1833 | os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname, |
| 1834 | sizeof(rcfg->ifname)); |
| 1835 | break; |
| 1836 | } |
| 1837 | } else { |
| 1838 | os_strlcpy(rcfg->ifname, drv->first_bss->ifname, |
| 1839 | sizeof(rcfg->ifname)); |
| 1840 | } |
| 1841 | |
| 1842 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; |
| 1843 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; |
| 1844 | drv->rfkill = rfkill_init(rcfg); |
| 1845 | if (!drv->rfkill) { |
| 1846 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
| 1847 | os_free(rcfg); |
| 1848 | } |
| 1849 | } |
| 1850 | |
| 1851 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1852 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
| 1853 | void *global_priv, int hostapd, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1854 | const u8 *set_addr, |
| 1855 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1856 | { |
| 1857 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1858 | struct i802_bss *bss; |
| 1859 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1860 | if (global_priv == NULL) |
| 1861 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1862 | drv = os_zalloc(sizeof(*drv)); |
| 1863 | if (drv == NULL) |
| 1864 | return NULL; |
| 1865 | drv->global = global_priv; |
| 1866 | drv->ctx = ctx; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1867 | drv->hostapd = !!hostapd; |
| 1868 | drv->eapol_sock = -1; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1869 | |
| 1870 | /* |
| 1871 | * There is no driver capability flag for this, so assume it is |
| 1872 | * supported and disable this on first attempt to use if the driver |
| 1873 | * rejects the command due to missing support. |
| 1874 | */ |
| 1875 | drv->set_rekey_offload = 1; |
| 1876 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1877 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
| 1878 | drv->if_indices = drv->default_if_indices; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1879 | drv->if_indices_reason = drv->default_if_indices_reason; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1880 | |
| 1881 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); |
| 1882 | if (!drv->first_bss) { |
| 1883 | os_free(drv); |
| 1884 | return NULL; |
| 1885 | } |
| 1886 | bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1887 | bss->drv = drv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1888 | bss->ctx = ctx; |
| 1889 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1890 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
| 1891 | drv->monitor_ifidx = -1; |
| 1892 | drv->monitor_sock = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1893 | drv->eapol_tx_sock = -1; |
| 1894 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1895 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1896 | if (nl80211_init_bss(bss)) |
| 1897 | goto failed; |
| 1898 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1899 | 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] | 1900 | goto failed; |
| 1901 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1902 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
| 1903 | if (drv->eapol_tx_sock < 0) |
| 1904 | goto failed; |
| 1905 | |
| 1906 | if (drv->data_tx_status) { |
| 1907 | int enabled = 1; |
| 1908 | |
| 1909 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, |
| 1910 | &enabled, sizeof(enabled)) < 0) { |
| 1911 | wpa_printf(MSG_DEBUG, |
| 1912 | "nl80211: wifi status sockopt failed\n"); |
| 1913 | drv->data_tx_status = 0; |
| 1914 | if (!drv->use_monitor) |
| 1915 | drv->capa.flags &= |
| 1916 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
| 1917 | } else { |
| 1918 | eloop_register_read_sock(drv->eapol_tx_sock, |
| 1919 | wpa_driver_nl80211_handle_eapol_tx_status, |
| 1920 | drv, NULL); |
| 1921 | } |
| 1922 | } |
| 1923 | |
| 1924 | if (drv->global) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1925 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1926 | dl_list_add(&drv->global->interfaces, &drv->list); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1927 | drv->in_interface_list = 1; |
| 1928 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1929 | |
| 1930 | return bss; |
| 1931 | |
| 1932 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1933 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1934 | return NULL; |
| 1935 | } |
| 1936 | |
| 1937 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1938 | /** |
| 1939 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface |
| 1940 | * @ctx: context to be used when calling wpa_supplicant functions, |
| 1941 | * e.g., wpa_supplicant_event() |
| 1942 | * @ifname: interface name, e.g., wlan0 |
| 1943 | * @global_priv: private driver global data from global_init() |
| 1944 | * Returns: Pointer to private data, %NULL on failure |
| 1945 | */ |
| 1946 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
| 1947 | void *global_priv) |
| 1948 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1949 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
| 1950 | NULL); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1954 | static int nl80211_register_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1955 | struct nl_handle *nl_handle, |
| 1956 | u16 type, const u8 *match, size_t match_len) |
| 1957 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1958 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1959 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1960 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1961 | char buf[30]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1962 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1963 | buf[0] = '\0'; |
| 1964 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 1965 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s", |
| 1966 | type, fc2str(type), nl_handle, buf); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1967 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1968 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) || |
| 1969 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
| 1970 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { |
| 1971 | nlmsg_free(msg); |
| 1972 | return -1; |
| 1973 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1974 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1975 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1976 | if (ret) { |
| 1977 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
| 1978 | "failed (type=%u): ret=%d (%s)", |
| 1979 | type, ret, strerror(-ret)); |
| 1980 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", |
| 1981 | match, match_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1982 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1983 | return ret; |
| 1984 | } |
| 1985 | |
| 1986 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1987 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
| 1988 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1989 | if (bss->nl_mgmt) { |
| 1990 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
| 1991 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
| 1992 | return -1; |
| 1993 | } |
| 1994 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1995 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1996 | if (bss->nl_mgmt == NULL) |
| 1997 | return -1; |
| 1998 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1999 | return 0; |
| 2000 | } |
| 2001 | |
| 2002 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2003 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
| 2004 | { |
| 2005 | nl80211_register_eloop_read(&bss->nl_mgmt, |
| 2006 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2007 | bss->nl_cb, 0); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2008 | } |
| 2009 | |
| 2010 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2011 | static int nl80211_register_action_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2012 | const u8 *match, size_t match_len) |
| 2013 | { |
| 2014 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2015 | return nl80211_register_frame(bss, bss->nl_mgmt, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2016 | type, match, match_len); |
| 2017 | } |
| 2018 | |
| 2019 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2020 | static int nl80211_init_connect_handle(struct i802_bss *bss) |
| 2021 | { |
| 2022 | if (bss->nl_connect) { |
| 2023 | wpa_printf(MSG_DEBUG, |
| 2024 | "nl80211: Connect handle already created (nl_connect=%p)", |
| 2025 | bss->nl_connect); |
| 2026 | return -1; |
| 2027 | } |
| 2028 | |
| 2029 | bss->nl_connect = nl_create_handle(bss->nl_cb, "connect"); |
| 2030 | if (!bss->nl_connect) |
| 2031 | return -1; |
| 2032 | nl80211_register_eloop_read(&bss->nl_connect, |
| 2033 | wpa_driver_nl80211_event_receive, |
| 2034 | bss->nl_cb, 1); |
| 2035 | return 0; |
| 2036 | } |
| 2037 | |
| 2038 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2039 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2040 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2041 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2042 | int ret = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2043 | |
| 2044 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2045 | return -1; |
| 2046 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
| 2047 | "handle %p", bss->nl_mgmt); |
| 2048 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2049 | if (drv->nlmode == NL80211_IFTYPE_ADHOC || |
| 2050 | ((drv->capa.flags & WPA_DRIVER_FLAGS_SAE) && |
| 2051 | !(drv->capa.flags & WPA_DRIVER_FLAGS_SME))) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2052 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
| 2053 | |
| 2054 | /* register for any AUTH message */ |
| 2055 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); |
| 2056 | } |
| 2057 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2058 | #ifdef CONFIG_INTERWORKING |
| 2059 | /* QoS Map Configure */ |
| 2060 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2061 | ret = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2062 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2063 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2064 | /* GAS Initial Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2065 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2066 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2067 | /* GAS Initial Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2068 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2069 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2070 | /* GAS Comeback Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2071 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2072 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2073 | /* GAS Comeback Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2074 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2075 | ret = -1; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2076 | /* Protected GAS Initial Request */ |
| 2077 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) |
| 2078 | ret = -1; |
| 2079 | /* Protected GAS Initial Response */ |
| 2080 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) |
| 2081 | ret = -1; |
| 2082 | /* Protected GAS Comeback Request */ |
| 2083 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) |
| 2084 | ret = -1; |
| 2085 | /* Protected GAS Comeback Response */ |
| 2086 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) |
| 2087 | ret = -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2088 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2089 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2090 | /* P2P Public Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2091 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2092 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
| 2093 | 6) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2094 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2095 | /* P2P Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2096 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2097 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
| 2098 | 5) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2099 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2100 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2101 | #ifdef CONFIG_DPP |
| 2102 | /* DPP Public Action */ |
| 2103 | if (nl80211_register_action_frame(bss, |
| 2104 | (u8 *) "\x04\x09\x50\x6f\x9a\x1a", |
| 2105 | 6) < 0) |
| 2106 | ret = -1; |
| 2107 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2108 | #ifdef CONFIG_IEEE80211W |
| 2109 | /* SA Query Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2110 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2111 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2112 | #endif /* CONFIG_IEEE80211W */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2113 | #ifdef CONFIG_TDLS |
| 2114 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { |
| 2115 | /* TDLS Discovery Response */ |
| 2116 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
| 2117 | 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2118 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2119 | } |
| 2120 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2121 | #ifdef CONFIG_FST |
| 2122 | /* FST Action frames */ |
| 2123 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2124 | ret = -1; |
| 2125 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2126 | |
| 2127 | /* FT Action frames */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2128 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2129 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2130 | else |
| 2131 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | |
| 2132 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; |
| 2133 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2134 | /* WNM - BSS Transition Management Request */ |
| 2135 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2136 | ret = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2137 | /* WNM-Sleep Mode Response */ |
| 2138 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2139 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2140 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2141 | #ifdef CONFIG_HS20 |
| 2142 | /* WNM-Notification */ |
| 2143 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2144 | ret = -1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2145 | #endif /* CONFIG_HS20 */ |
| 2146 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2147 | /* WMM-AC ADDTS Response */ |
| 2148 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) |
| 2149 | ret = -1; |
| 2150 | |
| 2151 | /* WMM-AC DELTS */ |
| 2152 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) |
| 2153 | ret = -1; |
| 2154 | |
| 2155 | /* Radio Measurement - Neighbor Report Response */ |
| 2156 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) |
| 2157 | ret = -1; |
| 2158 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2159 | /* Radio Measurement - Radio Measurement Request */ |
| 2160 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0) |
| 2161 | ret = -1; |
| 2162 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2163 | /* Radio Measurement - Link Measurement Request */ |
| 2164 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && |
| 2165 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) |
| 2166 | ret = -1; |
| 2167 | |
| 2168 | nl80211_mgmt_handle_register_eloop(bss); |
| 2169 | |
| 2170 | return ret; |
| 2171 | } |
| 2172 | |
| 2173 | |
| 2174 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
| 2175 | { |
| 2176 | int ret = 0; |
| 2177 | |
| 2178 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2179 | return -1; |
| 2180 | |
| 2181 | wpa_printf(MSG_DEBUG, |
| 2182 | "nl80211: Subscribe to mgmt frames with mesh handle %p", |
| 2183 | bss->nl_mgmt); |
| 2184 | |
| 2185 | /* Auth frames for mesh SAE */ |
| 2186 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2187 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2188 | (WLAN_FC_STYPE_AUTH << 4), |
| 2189 | NULL, 0) < 0) |
| 2190 | ret = -1; |
| 2191 | |
| 2192 | /* Mesh peering open */ |
| 2193 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) |
| 2194 | ret = -1; |
| 2195 | /* Mesh peering confirm */ |
| 2196 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) |
| 2197 | ret = -1; |
| 2198 | /* Mesh peering close */ |
| 2199 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) |
| 2200 | ret = -1; |
| 2201 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2202 | nl80211_mgmt_handle_register_eloop(bss); |
| 2203 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2204 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2205 | } |
| 2206 | |
| 2207 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2208 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
| 2209 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2210 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2211 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2212 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2213 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
| 2214 | 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] | 2215 | if (ret) { |
| 2216 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " |
| 2217 | "failed: ret=%d (%s)", |
| 2218 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2219 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2220 | return ret; |
| 2221 | } |
| 2222 | |
| 2223 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2224 | static int nl80211_action_subscribe_ap(struct i802_bss *bss) |
| 2225 | { |
| 2226 | int ret = 0; |
| 2227 | |
| 2228 | /* Public Action frames */ |
| 2229 | if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0) |
| 2230 | ret = -1; |
| 2231 | /* RRM Measurement Report */ |
| 2232 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0) |
| 2233 | ret = -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2234 | /* RRM Link Measurement Report */ |
| 2235 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0) |
| 2236 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2237 | /* RRM Neighbor Report Request */ |
| 2238 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0) |
| 2239 | ret = -1; |
| 2240 | /* FT Action frames */ |
| 2241 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
| 2242 | ret = -1; |
| 2243 | #ifdef CONFIG_IEEE80211W |
| 2244 | /* SA Query */ |
| 2245 | if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0) |
| 2246 | ret = -1; |
| 2247 | #endif /* CONFIG_IEEE80211W */ |
| 2248 | /* Protected Dual of Public Action */ |
| 2249 | if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0) |
| 2250 | ret = -1; |
| 2251 | /* WNM */ |
| 2252 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0) |
| 2253 | ret = -1; |
| 2254 | /* WMM */ |
| 2255 | if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0) |
| 2256 | ret = -1; |
| 2257 | #ifdef CONFIG_FST |
| 2258 | /* FST Action frames */ |
| 2259 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2260 | ret = -1; |
| 2261 | #endif /* CONFIG_FST */ |
| 2262 | /* Vendor-specific */ |
| 2263 | if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0) |
| 2264 | ret = -1; |
| 2265 | |
| 2266 | return ret; |
| 2267 | } |
| 2268 | |
| 2269 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2270 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
| 2271 | { |
| 2272 | static const int stypes[] = { |
| 2273 | WLAN_FC_STYPE_AUTH, |
| 2274 | WLAN_FC_STYPE_ASSOC_REQ, |
| 2275 | WLAN_FC_STYPE_REASSOC_REQ, |
| 2276 | WLAN_FC_STYPE_DISASSOC, |
| 2277 | WLAN_FC_STYPE_DEAUTH, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2278 | WLAN_FC_STYPE_PROBE_REQ, |
| 2279 | /* Beacon doesn't work as mac80211 doesn't currently allow |
| 2280 | * it, but it wouldn't really be the right thing anyway as |
| 2281 | * it isn't per interface ... maybe just dump the scan |
| 2282 | * results periodically for OLBC? |
| 2283 | */ |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2284 | /* WLAN_FC_STYPE_BEACON, */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2285 | }; |
| 2286 | unsigned int i; |
| 2287 | |
| 2288 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2289 | return -1; |
| 2290 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2291 | "handle %p", bss->nl_mgmt); |
| 2292 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2293 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2294 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2295 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2296 | (stypes[i] << 4), |
| 2297 | NULL, 0) < 0) { |
| 2298 | goto out_err; |
| 2299 | } |
| 2300 | } |
| 2301 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2302 | if (nl80211_action_subscribe_ap(bss)) |
| 2303 | goto out_err; |
| 2304 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2305 | if (nl80211_register_spurious_class3(bss)) |
| 2306 | goto out_err; |
| 2307 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2308 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2309 | return 0; |
| 2310 | |
| 2311 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2312 | nl_destroy_handles(&bss->nl_mgmt); |
| 2313 | return -1; |
| 2314 | } |
| 2315 | |
| 2316 | |
| 2317 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
| 2318 | { |
| 2319 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2320 | return -1; |
| 2321 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2322 | "handle %p (device SME)", bss->nl_mgmt); |
| 2323 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2324 | if (nl80211_action_subscribe_ap(bss)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2325 | goto out_err; |
| 2326 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2327 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2328 | return 0; |
| 2329 | |
| 2330 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2331 | nl_destroy_handles(&bss->nl_mgmt); |
| 2332 | return -1; |
| 2333 | } |
| 2334 | |
| 2335 | |
| 2336 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
| 2337 | { |
| 2338 | if (bss->nl_mgmt == NULL) |
| 2339 | return; |
| 2340 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
| 2341 | "(%s)", bss->nl_mgmt, reason); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2342 | nl80211_destroy_eloop_handle(&bss->nl_mgmt, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2343 | |
| 2344 | nl80211_put_wiphy_data_ap(bss); |
| 2345 | } |
| 2346 | |
| 2347 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2348 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
| 2349 | { |
| 2350 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); |
| 2351 | } |
| 2352 | |
| 2353 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2354 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
| 2355 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2356 | struct nl_msg *msg; |
| 2357 | int ret; |
| 2358 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2359 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
| 2360 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2361 | |
| 2362 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", |
| 2363 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2364 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2365 | } |
| 2366 | |
| 2367 | |
| 2368 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
| 2369 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2370 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2371 | int ret; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2372 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2373 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
| 2374 | NL80211_CMD_STOP_P2P_DEVICE); |
| 2375 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2376 | |
| 2377 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
| 2378 | start ? "Start" : "Stop", |
| 2379 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2380 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2381 | return ret; |
| 2382 | } |
| 2383 | |
| 2384 | |
| 2385 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
| 2386 | { |
| 2387 | enum nl80211_iftype nlmode; |
| 2388 | |
| 2389 | nlmode = nl80211_get_ifmode(bss); |
| 2390 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2391 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, |
| 2392 | bss->ifname, up); |
| 2393 | } |
| 2394 | |
| 2395 | /* P2P Device has start/stop which is equivalent */ |
| 2396 | return nl80211_set_p2pdev(bss, up); |
| 2397 | } |
| 2398 | |
| 2399 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2400 | #ifdef CONFIG_TESTING_OPTIONS |
| 2401 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) |
| 2402 | { |
| 2403 | /* struct wpa_driver_nl80211_data *drv = arg; */ |
| 2404 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 2405 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2406 | |
| 2407 | |
| 2408 | wpa_printf(MSG_DEBUG, |
| 2409 | "nl80211: QCA vendor test command response received"); |
| 2410 | |
| 2411 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2412 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2413 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { |
| 2414 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); |
| 2415 | return NL_SKIP; |
| 2416 | } |
| 2417 | |
| 2418 | wpa_hexdump(MSG_DEBUG, |
| 2419 | "nl80211: Received QCA vendor test command response", |
| 2420 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), |
| 2421 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); |
| 2422 | |
| 2423 | return NL_SKIP; |
| 2424 | } |
| 2425 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2426 | |
| 2427 | |
| 2428 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) |
| 2429 | { |
| 2430 | #ifdef CONFIG_TESTING_OPTIONS |
| 2431 | struct nl_msg *msg; |
| 2432 | struct nlattr *params; |
| 2433 | int ret; |
| 2434 | |
| 2435 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2436 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2437 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2438 | QCA_NL80211_VENDOR_SUBCMD_TEST) || |
| 2439 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 2440 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { |
| 2441 | nlmsg_free(msg); |
| 2442 | return; |
| 2443 | } |
| 2444 | nla_nest_end(msg, params); |
| 2445 | |
| 2446 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv); |
| 2447 | wpa_printf(MSG_DEBUG, |
| 2448 | "nl80211: QCA vendor test command returned %d (%s)", |
| 2449 | ret, strerror(-ret)); |
| 2450 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2451 | } |
| 2452 | |
| 2453 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2454 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2455 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2456 | const u8 *set_addr, int first, |
| 2457 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2458 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2459 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2460 | int send_rfkill_event = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2461 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2462 | |
| 2463 | drv->ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2464 | bss->ifindex = drv->ifindex; |
| 2465 | bss->wdev_id = drv->global->if_add_wdevid; |
| 2466 | bss->wdev_id_set = drv->global->if_add_wdevid_set; |
| 2467 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2468 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
| 2469 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2470 | drv->global->if_add_wdevid_set = 0; |
| 2471 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2472 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2473 | bss->static_ap = 1; |
| 2474 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 2475 | if (first && |
| 2476 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && |
| 2477 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) |
| 2478 | drv->start_iface_up = 1; |
| 2479 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2480 | if (wpa_driver_nl80211_capa(drv)) |
| 2481 | return -1; |
| 2482 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2483 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
| 2484 | return -1; |
| 2485 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2486 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
| 2487 | bss->ifname, drv->phyname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2488 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2489 | if (set_addr && |
| 2490 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || |
| 2491 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2492 | set_addr))) |
| 2493 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2494 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2495 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2496 | drv->start_mode_ap = 1; |
| 2497 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2498 | if (drv->hostapd || bss->static_ap) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2499 | nlmode = NL80211_IFTYPE_AP; |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 2500 | else if (bss->if_dynamic || |
| 2501 | nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2502 | nlmode = nl80211_get_ifmode(bss); |
| 2503 | else |
| 2504 | nlmode = NL80211_IFTYPE_STATION; |
| 2505 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2506 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2507 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2508 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2509 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2510 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2511 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2512 | nl80211_get_macaddr(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2513 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2514 | wpa_driver_nl80211_drv_init_rfkill(drv); |
| 2515 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2516 | if (!rfkill_is_blocked(drv->rfkill)) { |
| 2517 | int ret = i802_set_iface_flags(bss, 1); |
| 2518 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2519 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
| 2520 | "interface '%s' UP", bss->ifname); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2521 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2522 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2523 | |
| 2524 | if (is_p2p_net_interface(nlmode)) |
| 2525 | nl80211_disable_11b_rates(bss->drv, |
| 2526 | bss->drv->ifindex, 1); |
| 2527 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2528 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2529 | return ret; |
| 2530 | } else { |
| 2531 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " |
| 2532 | "interface '%s' due to rfkill", bss->ifname); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2533 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 2534 | drv->if_disabled = 1; |
| 2535 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2536 | send_rfkill_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2537 | } |
| 2538 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2539 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2540 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
| 2541 | 1, IF_OPER_DORMANT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2542 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2543 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2544 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2545 | bss->addr)) |
| 2546 | return -1; |
| 2547 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); |
| 2548 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2549 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2550 | if (send_rfkill_event) { |
| 2551 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, |
| 2552 | drv, drv->ctx); |
| 2553 | } |
| 2554 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2555 | if (drv->vendor_cmd_test_avail) |
| 2556 | qca_vendor_test(drv); |
| 2557 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2558 | nl80211_init_connect_handle(bss); |
| 2559 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2560 | return 0; |
| 2561 | } |
| 2562 | |
| 2563 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2564 | static int wpa_driver_nl80211_del_beacon(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2565 | { |
| 2566 | struct nl_msg *msg; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2567 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2568 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2569 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
| 2570 | drv->ifindex); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2571 | nl80211_put_wiphy_data_ap(bss); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2572 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2573 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2574 | } |
| 2575 | |
| 2576 | |
| 2577 | /** |
| 2578 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2579 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2580 | * |
| 2581 | * Shut down driver interface and processing of driver events. Free |
| 2582 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). |
| 2583 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2584 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2585 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2586 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2587 | unsigned int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2588 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2589 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
| 2590 | bss->ifname, drv->disabled_11b_rates); |
| 2591 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2592 | bss->in_deinit = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2593 | if (drv->data_tx_status) |
| 2594 | eloop_unregister_read_sock(drv->eapol_tx_sock); |
| 2595 | if (drv->eapol_tx_sock >= 0) |
| 2596 | close(drv->eapol_tx_sock); |
| 2597 | |
| 2598 | if (bss->nl_preq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2599 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 2600 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2601 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 2602 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2603 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2604 | "interface %s from bridge %s: %s", |
| 2605 | bss->ifname, bss->brname, strerror(errno)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2606 | if (drv->rtnl_sk) |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 2607 | nl80211_handle_destroy(drv->rtnl_sk); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2608 | } |
| 2609 | if (bss->added_bridge) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2610 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
| 2611 | 0) < 0) |
| 2612 | wpa_printf(MSG_INFO, |
| 2613 | "nl80211: Could not set bridge %s down", |
| 2614 | bss->brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2615 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2616 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2617 | "bridge %s: %s", |
| 2618 | bss->brname, strerror(errno)); |
| 2619 | } |
| 2620 | |
| 2621 | nl80211_remove_monitor_interface(drv); |
| 2622 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2623 | if (is_ap_interface(drv->nlmode)) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2624 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2625 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2626 | if (drv->eapol_sock >= 0) { |
| 2627 | eloop_unregister_read_sock(drv->eapol_sock); |
| 2628 | close(drv->eapol_sock); |
| 2629 | } |
| 2630 | |
| 2631 | if (drv->if_indices != drv->default_if_indices) |
| 2632 | os_free(drv->if_indices); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2633 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2634 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
| 2635 | os_free(drv->if_indices_reason); |
| 2636 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2637 | if (drv->disabled_11b_rates) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2638 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 2639 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2640 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
| 2641 | IF_OPER_UP); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 2642 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2643 | rfkill_deinit(drv->rfkill); |
| 2644 | |
| 2645 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 2646 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2647 | if (!drv->start_iface_up) |
| 2648 | (void) i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2649 | |
| 2650 | if (drv->addr_changed) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2651 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 2652 | 0) < 0) { |
| 2653 | wpa_printf(MSG_DEBUG, |
| 2654 | "nl80211: Could not set interface down to restore permanent MAC address"); |
| 2655 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2656 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2657 | drv->perm_addr) < 0) { |
| 2658 | wpa_printf(MSG_DEBUG, |
| 2659 | "nl80211: Could not restore permanent MAC address"); |
| 2660 | } |
| 2661 | } |
| 2662 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2663 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2664 | if (!drv->hostapd || !drv->start_mode_ap) |
| 2665 | wpa_driver_nl80211_set_mode(bss, |
| 2666 | NL80211_IFTYPE_STATION); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2667 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2668 | } else { |
| 2669 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
| 2670 | nl80211_del_p2pdev(bss); |
| 2671 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2672 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2673 | if (bss->nl_connect) |
| 2674 | nl80211_destroy_eloop_handle(&bss->nl_connect, 1); |
| 2675 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2676 | nl80211_destroy_bss(drv->first_bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2677 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2678 | os_free(drv->filter_ssids); |
| 2679 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2680 | os_free(drv->auth_ie); |
| 2681 | |
| 2682 | if (drv->in_interface_list) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2683 | dl_list_del(&drv->list); |
| 2684 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2685 | os_free(drv->extended_capa); |
| 2686 | os_free(drv->extended_capa_mask); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2687 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 2688 | os_free(drv->iface_ext_capa[i].ext_capa); |
| 2689 | os_free(drv->iface_ext_capa[i].ext_capa_mask); |
| 2690 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2691 | os_free(drv->first_bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2692 | os_free(drv); |
| 2693 | } |
| 2694 | |
| 2695 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2696 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
| 2697 | { |
| 2698 | switch (alg) { |
| 2699 | case WPA_ALG_WEP: |
| 2700 | if (key_len == 5) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2701 | return RSN_CIPHER_SUITE_WEP40; |
| 2702 | return RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2703 | case WPA_ALG_TKIP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2704 | return RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2705 | case WPA_ALG_CCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2706 | return RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2707 | case WPA_ALG_GCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2708 | return RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2709 | case WPA_ALG_CCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2710 | return RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2711 | case WPA_ALG_GCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2712 | return RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2713 | case WPA_ALG_IGTK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2714 | return RSN_CIPHER_SUITE_AES_128_CMAC; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2715 | case WPA_ALG_BIP_GMAC_128: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2716 | return RSN_CIPHER_SUITE_BIP_GMAC_128; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2717 | case WPA_ALG_BIP_GMAC_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2718 | return RSN_CIPHER_SUITE_BIP_GMAC_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2719 | case WPA_ALG_BIP_CMAC_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2720 | return RSN_CIPHER_SUITE_BIP_CMAC_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2721 | case WPA_ALG_SMS4: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2722 | return RSN_CIPHER_SUITE_SMS4; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2723 | case WPA_ALG_KRK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2724 | return RSN_CIPHER_SUITE_KRK; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2725 | case WPA_ALG_NONE: |
| 2726 | case WPA_ALG_PMK: |
| 2727 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", |
| 2728 | alg); |
| 2729 | return 0; |
| 2730 | } |
| 2731 | |
| 2732 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", |
| 2733 | alg); |
| 2734 | return 0; |
| 2735 | } |
| 2736 | |
| 2737 | |
| 2738 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) |
| 2739 | { |
| 2740 | switch (cipher) { |
| 2741 | case WPA_CIPHER_CCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2742 | return RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2743 | case WPA_CIPHER_GCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2744 | return RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2745 | case WPA_CIPHER_CCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2746 | return RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2747 | case WPA_CIPHER_GCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2748 | return RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2749 | case WPA_CIPHER_TKIP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2750 | return RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2751 | case WPA_CIPHER_WEP104: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2752 | return RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2753 | case WPA_CIPHER_WEP40: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2754 | return RSN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2755 | case WPA_CIPHER_GTK_NOT_USED: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2756 | return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2757 | } |
| 2758 | |
| 2759 | return 0; |
| 2760 | } |
| 2761 | |
| 2762 | |
| 2763 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], |
| 2764 | int max_suites) |
| 2765 | { |
| 2766 | int num_suites = 0; |
| 2767 | |
| 2768 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2769 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2770 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2771 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2772 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2773 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2774 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2775 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2776 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2777 | suites[num_suites++] = RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2778 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2779 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2780 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2781 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2782 | |
| 2783 | return num_suites; |
| 2784 | } |
| 2785 | |
| 2786 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2787 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2788 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 2789 | const u8 *key, size_t key_len) |
| 2790 | { |
| 2791 | struct nl_msg *msg; |
| 2792 | int ret; |
| 2793 | |
| 2794 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
| 2795 | return 0; |
| 2796 | |
| 2797 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2798 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2799 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2800 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || |
| 2801 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { |
| 2802 | nl80211_nlmsg_clear(msg); |
| 2803 | nlmsg_free(msg); |
| 2804 | return -1; |
| 2805 | } |
| 2806 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 2807 | if (ret) { |
| 2808 | wpa_printf(MSG_DEBUG, |
| 2809 | "nl80211: Key management set key failed: ret=%d (%s)", |
| 2810 | ret, strerror(-ret)); |
| 2811 | } |
| 2812 | |
| 2813 | return ret; |
| 2814 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2815 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2816 | |
| 2817 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2818 | static int nl80211_set_pmk(struct wpa_driver_nl80211_data *drv, |
| 2819 | const u8 *key, size_t key_len, |
| 2820 | const u8 *addr) |
| 2821 | { |
| 2822 | struct nl_msg *msg = NULL; |
| 2823 | int ret; |
| 2824 | |
| 2825 | /* |
| 2826 | * If the authenticator address is not set, assume it is |
| 2827 | * the current BSSID. |
| 2828 | */ |
| 2829 | if (!addr && drv->associated) |
| 2830 | addr = drv->bssid; |
| 2831 | else if (!addr) |
| 2832 | return -1; |
| 2833 | |
| 2834 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK to the driver for " MACSTR, |
| 2835 | MAC2STR(addr)); |
| 2836 | wpa_hexdump_key(MSG_DEBUG, "nl80211: PMK", key, key_len); |
| 2837 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_PMK); |
| 2838 | if (!msg || |
| 2839 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 2840 | nla_put(msg, NL80211_ATTR_PMK, key_len, key)) { |
| 2841 | nl80211_nlmsg_clear(msg); |
| 2842 | nlmsg_free(msg); |
| 2843 | return -ENOBUFS; |
| 2844 | } |
| 2845 | |
| 2846 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 2847 | if (ret) { |
| 2848 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK failed: ret=%d (%s)", |
| 2849 | ret, strerror(-ret)); |
| 2850 | } |
| 2851 | |
| 2852 | return ret; |
| 2853 | } |
| 2854 | |
| 2855 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2856 | 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] | 2857 | enum wpa_alg alg, const u8 *addr, |
| 2858 | int key_idx, int set_tx, |
| 2859 | const u8 *seq, size_t seq_len, |
| 2860 | const u8 *key, size_t key_len) |
| 2861 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2862 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2863 | int ifindex; |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2864 | struct nl_msg *msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2865 | int ret; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2866 | int tdls = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2867 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2868 | /* Ignore for P2P Device */ |
| 2869 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2870 | return 0; |
| 2871 | |
| 2872 | ifindex = if_nametoindex(ifname); |
| 2873 | 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] | 2874 | "set_tx=%d seq_len=%lu key_len=%lu", |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2875 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2876 | (unsigned long) seq_len, (unsigned long) key_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2877 | #ifdef CONFIG_TDLS |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2878 | if (key_idx == -1) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2879 | key_idx = 0; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2880 | tdls = 1; |
| 2881 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2882 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2883 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2884 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2885 | if (alg == WPA_ALG_PMK && |
| 2886 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { |
| 2887 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
| 2888 | __func__); |
| 2889 | ret = issue_key_mgmt_set_key(drv, key, key_len); |
| 2890 | return ret; |
| 2891 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2892 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2893 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2894 | if (alg == WPA_ALG_PMK && |
| 2895 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE)) |
| 2896 | return nl80211_set_pmk(drv, key, key_len, addr); |
| 2897 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2898 | if (alg == WPA_ALG_NONE) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2899 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
| 2900 | if (!msg) |
| 2901 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2902 | } else { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2903 | u32 suite; |
| 2904 | |
| 2905 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 2906 | if (!suite) |
| 2907 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2908 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
| 2909 | if (!msg || |
| 2910 | nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2911 | nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, suite)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2912 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2913 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2914 | } |
| 2915 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2916 | if (seq && seq_len) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2917 | if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq)) |
| 2918 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2919 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
| 2920 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2921 | |
| 2922 | if (addr && !is_broadcast_ether_addr(addr)) { |
| 2923 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2924 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 2925 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2926 | |
| 2927 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { |
| 2928 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2929 | if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, |
| 2930 | NL80211_KEYTYPE_GROUP)) |
| 2931 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2932 | } |
| 2933 | } else if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2934 | struct nlattr *types; |
| 2935 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2936 | wpa_printf(MSG_DEBUG, " broadcast key"); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2937 | |
| 2938 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2939 | if (!types || |
| 2940 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 2941 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2942 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2943 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2944 | if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2945 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2946 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2947 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2948 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
| 2949 | ret = 0; |
| 2950 | if (ret) |
| 2951 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", |
| 2952 | ret, strerror(-ret)); |
| 2953 | |
| 2954 | /* |
| 2955 | * If we failed or don't need to set the default TX key (below), |
| 2956 | * we're done here. |
| 2957 | */ |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2958 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2959 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2960 | if (is_ap_interface(drv->nlmode) && addr && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2961 | !is_broadcast_ether_addr(addr)) |
| 2962 | return ret; |
| 2963 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2964 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
| 2965 | if (!msg || |
| 2966 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2967 | nla_put_flag(msg, (alg == WPA_ALG_IGTK || |
| 2968 | alg == WPA_ALG_BIP_GMAC_128 || |
| 2969 | alg == WPA_ALG_BIP_GMAC_256 || |
| 2970 | alg == WPA_ALG_BIP_CMAC_256) ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2971 | NL80211_ATTR_KEY_DEFAULT_MGMT : |
| 2972 | NL80211_ATTR_KEY_DEFAULT)) |
| 2973 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2974 | if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2975 | struct nlattr *types; |
| 2976 | |
| 2977 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2978 | if (!types || |
| 2979 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 2980 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2981 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2982 | } else if (addr) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2983 | struct nlattr *types; |
| 2984 | |
| 2985 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2986 | if (!types || |
| 2987 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) |
| 2988 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2989 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2990 | } |
| 2991 | |
| 2992 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 2993 | if (ret == -ENOENT) |
| 2994 | ret = 0; |
| 2995 | if (ret) |
| 2996 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " |
| 2997 | "err=%d %s)", ret, strerror(-ret)); |
| 2998 | return ret; |
| 2999 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3000 | fail: |
| 3001 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3002 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3003 | return -ENOBUFS; |
| 3004 | } |
| 3005 | |
| 3006 | |
| 3007 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
| 3008 | int key_idx, int defkey, |
| 3009 | const u8 *seq, size_t seq_len, |
| 3010 | const u8 *key, size_t key_len) |
| 3011 | { |
| 3012 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3013 | u32 suite; |
| 3014 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3015 | if (!key_attr) |
| 3016 | return -1; |
| 3017 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3018 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 3019 | if (!suite) |
| 3020 | return -1; |
| 3021 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3022 | if (defkey && alg == WPA_ALG_IGTK) { |
| 3023 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) |
| 3024 | return -1; |
| 3025 | } else if (defkey) { |
| 3026 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) |
| 3027 | return -1; |
| 3028 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3029 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3030 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3031 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3032 | (seq && seq_len && |
| 3033 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || |
| 3034 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) |
| 3035 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3036 | |
| 3037 | nla_nest_end(msg, key_attr); |
| 3038 | |
| 3039 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
| 3042 | |
| 3043 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
| 3044 | struct nl_msg *msg) |
| 3045 | { |
| 3046 | int i, privacy = 0; |
| 3047 | struct nlattr *nl_keys, *nl_key; |
| 3048 | |
| 3049 | for (i = 0; i < 4; i++) { |
| 3050 | if (!params->wep_key[i]) |
| 3051 | continue; |
| 3052 | privacy = 1; |
| 3053 | break; |
| 3054 | } |
| 3055 | if (params->wps == WPS_MODE_PRIVACY) |
| 3056 | privacy = 1; |
| 3057 | if (params->pairwise_suite && |
| 3058 | params->pairwise_suite != WPA_CIPHER_NONE) |
| 3059 | privacy = 1; |
| 3060 | |
| 3061 | if (!privacy) |
| 3062 | return 0; |
| 3063 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3064 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 3065 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3066 | |
| 3067 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); |
| 3068 | if (!nl_keys) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3069 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3070 | |
| 3071 | for (i = 0; i < 4; i++) { |
| 3072 | if (!params->wep_key[i]) |
| 3073 | continue; |
| 3074 | |
| 3075 | nl_key = nla_nest_start(msg, i); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3076 | if (!nl_key || |
| 3077 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], |
| 3078 | params->wep_key[i]) || |
| 3079 | nla_put_u32(msg, NL80211_KEY_CIPHER, |
| 3080 | params->wep_key_len[i] == 5 ? |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3081 | RSN_CIPHER_SUITE_WEP40 : |
| 3082 | RSN_CIPHER_SUITE_WEP104) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3083 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
| 3084 | (i == params->wep_tx_keyidx && |
| 3085 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) |
| 3086 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3087 | |
| 3088 | nla_nest_end(msg, nl_key); |
| 3089 | } |
| 3090 | nla_nest_end(msg, nl_keys); |
| 3091 | |
| 3092 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3093 | } |
| 3094 | |
| 3095 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3096 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 3097 | const u8 *addr, int cmd, u16 reason_code, |
| 3098 | int local_state_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3099 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3100 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3101 | struct nl_msg *msg; |
| 3102 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3103 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
| 3104 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
| 3105 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 3106 | (local_state_change && |
| 3107 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { |
| 3108 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3109 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3110 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3111 | |
| 3112 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3113 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3114 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 3115 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", |
| 3116 | reason_code, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3117 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3118 | return ret; |
| 3119 | } |
| 3120 | |
| 3121 | |
| 3122 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3123 | int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3124 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3125 | int ret; |
| 3126 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3127 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3128 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3129 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3130 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
| 3131 | reason_code, 0); |
| 3132 | /* |
| 3133 | * For locally generated disconnect, supplicant already generates a |
| 3134 | * DEAUTH event, so ignore the event from NL80211. |
| 3135 | */ |
| 3136 | drv->ignore_next_local_disconnect = ret == 0; |
| 3137 | |
| 3138 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3139 | } |
| 3140 | |
| 3141 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3142 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
| 3143 | const u8 *addr, int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3144 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3145 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3146 | int ret; |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3147 | |
| 3148 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3149 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3150 | return nl80211_leave_ibss(drv, 1); |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3151 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3152 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3153 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3154 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
| 3155 | __func__, MAC2STR(addr), reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3156 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3157 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
| 3158 | reason_code, 0); |
| 3159 | /* |
| 3160 | * For locally generated deauthenticate, supplicant already generates a |
| 3161 | * DEAUTH event, so ignore the event from NL80211. |
| 3162 | */ |
| 3163 | drv->ignore_next_local_deauth = ret == 0; |
| 3164 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3165 | } |
| 3166 | |
| 3167 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3168 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
| 3169 | struct wpa_driver_auth_params *params) |
| 3170 | { |
| 3171 | int i; |
| 3172 | |
| 3173 | drv->auth_freq = params->freq; |
| 3174 | drv->auth_alg = params->auth_alg; |
| 3175 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; |
| 3176 | drv->auth_local_state_change = params->local_state_change; |
| 3177 | drv->auth_p2p = params->p2p; |
| 3178 | |
| 3179 | if (params->bssid) |
| 3180 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); |
| 3181 | else |
| 3182 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); |
| 3183 | |
| 3184 | if (params->ssid) { |
| 3185 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); |
| 3186 | drv->auth_ssid_len = params->ssid_len; |
| 3187 | } else |
| 3188 | drv->auth_ssid_len = 0; |
| 3189 | |
| 3190 | |
| 3191 | os_free(drv->auth_ie); |
| 3192 | drv->auth_ie = NULL; |
| 3193 | drv->auth_ie_len = 0; |
| 3194 | if (params->ie) { |
| 3195 | drv->auth_ie = os_malloc(params->ie_len); |
| 3196 | if (drv->auth_ie) { |
| 3197 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); |
| 3198 | drv->auth_ie_len = params->ie_len; |
| 3199 | } |
| 3200 | } |
| 3201 | |
| 3202 | for (i = 0; i < 4; i++) { |
| 3203 | if (params->wep_key[i] && params->wep_key_len[i] && |
| 3204 | params->wep_key_len[i] <= 16) { |
| 3205 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], |
| 3206 | params->wep_key_len[i]); |
| 3207 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; |
| 3208 | } else |
| 3209 | drv->auth_wep_key_len[i] = 0; |
| 3210 | } |
| 3211 | } |
| 3212 | |
| 3213 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3214 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
| 3215 | { |
| 3216 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3217 | |
| 3218 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) |
| 3219 | return; |
| 3220 | |
| 3221 | /* |
| 3222 | * Looks like we failed to unmask 11b rates previously. This could |
| 3223 | * happen, e.g., if the interface was down at the point in time when a |
| 3224 | * P2P group was terminated. |
| 3225 | */ |
| 3226 | wpa_printf(MSG_DEBUG, |
| 3227 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", |
| 3228 | bss->ifname); |
| 3229 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 3230 | } |
| 3231 | |
| 3232 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3233 | static enum nl80211_auth_type get_nl_auth_type(int wpa_auth_alg) |
| 3234 | { |
| 3235 | if (wpa_auth_alg & WPA_AUTH_ALG_OPEN) |
| 3236 | return NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 3237 | if (wpa_auth_alg & WPA_AUTH_ALG_SHARED) |
| 3238 | return NL80211_AUTHTYPE_SHARED_KEY; |
| 3239 | if (wpa_auth_alg & WPA_AUTH_ALG_LEAP) |
| 3240 | return NL80211_AUTHTYPE_NETWORK_EAP; |
| 3241 | if (wpa_auth_alg & WPA_AUTH_ALG_FT) |
| 3242 | return NL80211_AUTHTYPE_FT; |
| 3243 | if (wpa_auth_alg & WPA_AUTH_ALG_SAE) |
| 3244 | return NL80211_AUTHTYPE_SAE; |
| 3245 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS) |
| 3246 | return NL80211_AUTHTYPE_FILS_SK; |
| 3247 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS_SK_PFS) |
| 3248 | return NL80211_AUTHTYPE_FILS_SK_PFS; |
| 3249 | |
| 3250 | return NL80211_AUTHTYPE_MAX; |
| 3251 | } |
| 3252 | |
| 3253 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3254 | static int wpa_driver_nl80211_authenticate( |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3255 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3256 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3257 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3258 | int ret = -1, i; |
| 3259 | struct nl_msg *msg; |
| 3260 | enum nl80211_auth_type type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3261 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3262 | int count = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3263 | int is_retry; |
| 3264 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3265 | nl80211_unmask_11b_rates(bss); |
| 3266 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3267 | is_retry = drv->retry_auth; |
| 3268 | drv->retry_auth = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3269 | drv->ignore_deauth_event = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3270 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3271 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3272 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3273 | if (params->bssid) |
| 3274 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 3275 | else |
| 3276 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3277 | /* FIX: IBSS mode */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3278 | nlmode = params->p2p ? |
| 3279 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 3280 | if (drv->nlmode != nlmode && |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3281 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3282 | return -1; |
| 3283 | |
| 3284 | retry: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3285 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
| 3286 | drv->ifindex); |
| 3287 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3288 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
| 3289 | if (!msg) |
| 3290 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3291 | |
| 3292 | for (i = 0; i < 4; i++) { |
| 3293 | if (!params->wep_key[i]) |
| 3294 | continue; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3295 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3296 | NULL, i, |
| 3297 | i == params->wep_tx_keyidx, NULL, 0, |
| 3298 | params->wep_key[i], |
| 3299 | params->wep_key_len[i]); |
| 3300 | if (params->wep_tx_keyidx != i) |
| 3301 | continue; |
| 3302 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3303 | params->wep_key[i], params->wep_key_len[i])) |
| 3304 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3305 | } |
| 3306 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3307 | if (params->bssid) { |
| 3308 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 3309 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3310 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 3311 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3312 | } |
| 3313 | if (params->freq) { |
| 3314 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3315 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
| 3316 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3317 | } |
| 3318 | if (params->ssid) { |
| 3319 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 3320 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3321 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 3322 | params->ssid)) |
| 3323 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3324 | } |
| 3325 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3326 | if (params->ie && |
| 3327 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) |
| 3328 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3329 | if (params->auth_data) { |
| 3330 | wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data, |
| 3331 | params->auth_data_len); |
| 3332 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len, |
| 3333 | params->auth_data)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3334 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3335 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3336 | type = get_nl_auth_type(params->auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3337 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3338 | if (type == NL80211_AUTHTYPE_MAX || |
| 3339 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3340 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3341 | if (params->local_state_change) { |
| 3342 | wpa_printf(MSG_DEBUG, " * Local state change only"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3343 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
| 3344 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3345 | } |
| 3346 | |
| 3347 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3348 | msg = NULL; |
| 3349 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3350 | wpa_dbg(drv->ctx, MSG_DEBUG, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3351 | "nl80211: MLME command failed (auth): count=%d ret=%d (%s)", |
| 3352 | count, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3353 | count++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3354 | if ((ret == -EALREADY || ret == -EEXIST) && count == 1 && |
| 3355 | params->bssid && !params->local_state_change) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3356 | /* |
| 3357 | * mac80211 does not currently accept new |
| 3358 | * authentication if we are already authenticated. As a |
| 3359 | * workaround, force deauthentication and try again. |
| 3360 | */ |
| 3361 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " |
| 3362 | "after forced deauthentication"); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3363 | drv->ignore_deauth_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3364 | wpa_driver_nl80211_deauthenticate( |
| 3365 | bss, params->bssid, |
| 3366 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 3367 | nlmsg_free(msg); |
| 3368 | goto retry; |
| 3369 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3370 | |
| 3371 | if (ret == -ENOENT && params->freq && !is_retry) { |
| 3372 | /* |
| 3373 | * cfg80211 has likely expired the BSS entry even |
| 3374 | * though it was previously available in our internal |
| 3375 | * BSS table. To recover quickly, start a single |
| 3376 | * channel scan on the specified channel. |
| 3377 | */ |
| 3378 | struct wpa_driver_scan_params scan; |
| 3379 | int freqs[2]; |
| 3380 | |
| 3381 | os_memset(&scan, 0, sizeof(scan)); |
| 3382 | scan.num_ssids = 1; |
| 3383 | if (params->ssid) { |
| 3384 | scan.ssids[0].ssid = params->ssid; |
| 3385 | scan.ssids[0].ssid_len = params->ssid_len; |
| 3386 | } |
| 3387 | freqs[0] = params->freq; |
| 3388 | freqs[1] = 0; |
| 3389 | scan.freqs = freqs; |
| 3390 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " |
| 3391 | "channel scan to refresh cfg80211 BSS " |
| 3392 | "entry"); |
| 3393 | ret = wpa_driver_nl80211_scan(bss, &scan); |
| 3394 | if (ret == 0) { |
| 3395 | nl80211_copy_auth_params(drv, params); |
| 3396 | drv->scan_for_auth = 1; |
| 3397 | } |
| 3398 | } else if (is_retry) { |
| 3399 | /* |
| 3400 | * Need to indicate this with an event since the return |
| 3401 | * value from the retry is not delivered to core code. |
| 3402 | */ |
| 3403 | union wpa_event_data event; |
| 3404 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " |
| 3405 | "failed"); |
| 3406 | os_memset(&event, 0, sizeof(event)); |
| 3407 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, |
| 3408 | ETH_ALEN); |
| 3409 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, |
| 3410 | &event); |
| 3411 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3412 | } else { |
| 3413 | wpa_printf(MSG_DEBUG, |
| 3414 | "nl80211: Authentication request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3415 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3416 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3417 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3418 | nlmsg_free(msg); |
| 3419 | return ret; |
| 3420 | } |
| 3421 | |
| 3422 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3423 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3424 | { |
| 3425 | struct wpa_driver_auth_params params; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3426 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3427 | int i; |
| 3428 | |
| 3429 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); |
| 3430 | |
| 3431 | os_memset(¶ms, 0, sizeof(params)); |
| 3432 | params.freq = drv->auth_freq; |
| 3433 | params.auth_alg = drv->auth_alg; |
| 3434 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; |
| 3435 | params.local_state_change = drv->auth_local_state_change; |
| 3436 | params.p2p = drv->auth_p2p; |
| 3437 | |
| 3438 | if (!is_zero_ether_addr(drv->auth_bssid_)) |
| 3439 | params.bssid = drv->auth_bssid_; |
| 3440 | |
| 3441 | if (drv->auth_ssid_len) { |
| 3442 | params.ssid = drv->auth_ssid; |
| 3443 | params.ssid_len = drv->auth_ssid_len; |
| 3444 | } |
| 3445 | |
| 3446 | params.ie = drv->auth_ie; |
| 3447 | params.ie_len = drv->auth_ie_len; |
| 3448 | |
| 3449 | for (i = 0; i < 4; i++) { |
| 3450 | if (drv->auth_wep_key_len[i]) { |
| 3451 | params.wep_key[i] = drv->auth_wep_key[i]; |
| 3452 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; |
| 3453 | } |
| 3454 | } |
| 3455 | |
| 3456 | drv->retry_auth = 1; |
| 3457 | return wpa_driver_nl80211_authenticate(bss, ¶ms); |
| 3458 | } |
| 3459 | |
| 3460 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3461 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
| 3462 | const void *data, size_t len, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3463 | int encrypt, int noack, |
| 3464 | unsigned int freq, int no_cck, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3465 | int offchanok, unsigned int wait_time, |
| 3466 | const u16 *csa_offs, |
| 3467 | size_t csa_offs_len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3468 | { |
| 3469 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3470 | u64 cookie; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3471 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3472 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 3473 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3474 | freq = nl80211_get_assoc_freq(drv); |
| 3475 | wpa_printf(MSG_DEBUG, |
| 3476 | "nl80211: send_frame - Use assoc_freq=%u for IBSS", |
| 3477 | freq); |
| 3478 | } |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3479 | if (freq == 0) { |
| 3480 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", |
| 3481 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3482 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3483 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3484 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3485 | if (drv->use_monitor) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3486 | 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] | 3487 | freq, bss->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3488 | return nl80211_send_monitor(drv, data, len, encrypt, noack); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3489 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3490 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3491 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3492 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3493 | &cookie, no_cck, noack, offchanok, |
| 3494 | csa_offs, csa_offs_len); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3495 | if (res == 0 && !noack) { |
| 3496 | const struct ieee80211_mgmt *mgmt; |
| 3497 | u16 fc; |
| 3498 | |
| 3499 | mgmt = (const struct ieee80211_mgmt *) data; |
| 3500 | fc = le_to_host16(mgmt->frame_control); |
| 3501 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3502 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { |
| 3503 | wpa_printf(MSG_MSGDUMP, |
| 3504 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", |
| 3505 | (long long unsigned int) |
| 3506 | drv->send_action_cookie, |
| 3507 | (long long unsigned int) cookie); |
| 3508 | drv->send_action_cookie = cookie; |
| 3509 | } |
| 3510 | } |
| 3511 | |
| 3512 | return res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3516 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
| 3517 | size_t data_len, int noack, |
| 3518 | unsigned int freq, int no_cck, |
| 3519 | int offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3520 | unsigned int wait_time, |
| 3521 | const u16 *csa_offs, |
| 3522 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3523 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3524 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3525 | struct ieee80211_mgmt *mgmt; |
| 3526 | int encrypt = 1; |
| 3527 | u16 fc; |
| 3528 | |
| 3529 | mgmt = (struct ieee80211_mgmt *) data; |
| 3530 | fc = le_to_host16(mgmt->frame_control); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 3531 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR |
| 3532 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d", |
| 3533 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, |
| 3534 | fc, fc2str(fc), drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3535 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3536 | if ((is_sta_interface(drv->nlmode) || |
| 3537 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3538 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3539 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { |
| 3540 | /* |
| 3541 | * The use of last_mgmt_freq is a bit of a hack, |
| 3542 | * but it works due to the single-threaded nature |
| 3543 | * of wpa_supplicant. |
| 3544 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3545 | if (freq == 0) { |
| 3546 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", |
| 3547 | drv->last_mgmt_freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3548 | freq = drv->last_mgmt_freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3549 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3550 | return nl80211_send_frame_cmd(bss, freq, 0, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3551 | data, data_len, NULL, 1, noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3552 | 1, csa_offs, csa_offs_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3553 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3554 | |
| 3555 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3556 | if (freq == 0) { |
| 3557 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", |
| 3558 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3559 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3560 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3561 | return nl80211_send_frame_cmd(bss, freq, |
| 3562 | (int) freq == bss->freq ? 0 : |
| 3563 | wait_time, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3564 | data, data_len, |
| 3565 | &drv->send_action_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3566 | no_cck, noack, offchanok, |
| 3567 | csa_offs, csa_offs_len); |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 3568 | } |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 3569 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3570 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3571 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 3572 | /* |
| 3573 | * Only one of the authentication frame types is encrypted. |
| 3574 | * In order for static WEP encryption to work properly (i.e., |
| 3575 | * to not encrypt the frame), we need to tell mac80211 about |
| 3576 | * the frames that must not be encrypted. |
| 3577 | */ |
| 3578 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 3579 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); |
| 3580 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
| 3581 | encrypt = 0; |
| 3582 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3583 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3584 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3585 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3586 | noack, freq, no_cck, offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3587 | wait_time, csa_offs, |
| 3588 | csa_offs_len); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3589 | } |
| 3590 | |
| 3591 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3592 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
| 3593 | { |
| 3594 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 3595 | u8 rates_len = 0; |
| 3596 | int i; |
| 3597 | |
| 3598 | if (!basic_rates) |
| 3599 | return 0; |
| 3600 | |
| 3601 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) |
| 3602 | rates[rates_len++] = basic_rates[i] / 5; |
| 3603 | |
| 3604 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); |
| 3605 | } |
| 3606 | |
| 3607 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3608 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
| 3609 | int slot, int ht_opmode, int ap_isolate, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3610 | const int *basic_rates) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3611 | { |
| 3612 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3613 | struct nl_msg *msg; |
| 3614 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3615 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
| 3616 | (cts >= 0 && |
| 3617 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || |
| 3618 | (preamble >= 0 && |
| 3619 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || |
| 3620 | (slot >= 0 && |
| 3621 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || |
| 3622 | (ht_opmode >= 0 && |
| 3623 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || |
| 3624 | (ap_isolate >= 0 && |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3625 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
| 3626 | nl80211_put_basic_rates(msg, basic_rates)) { |
| 3627 | nlmsg_free(msg); |
| 3628 | return -ENOBUFS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3629 | } |
| 3630 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3631 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3632 | } |
| 3633 | |
| 3634 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3635 | static int wpa_driver_nl80211_set_acl(void *priv, |
| 3636 | struct hostapd_acl_params *params) |
| 3637 | { |
| 3638 | struct i802_bss *bss = priv; |
| 3639 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3640 | struct nl_msg *msg; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3641 | struct nl_msg *acl; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3642 | unsigned int i; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3643 | int ret; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3644 | |
| 3645 | if (!(drv->capa.max_acl_mac_addrs)) |
| 3646 | return -ENOTSUP; |
| 3647 | |
| 3648 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) |
| 3649 | return -ENOTSUP; |
| 3650 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3651 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
| 3652 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); |
| 3653 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3654 | acl = nlmsg_alloc(); |
| 3655 | if (!acl) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3656 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3657 | for (i = 0; i < params->num_mac_acl; i++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3658 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { |
| 3659 | nlmsg_free(acl); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3660 | return -ENOMEM; |
| 3661 | } |
| 3662 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3663 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3664 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
| 3665 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
| 3666 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : |
| 3667 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || |
| 3668 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
| 3669 | nlmsg_free(msg); |
| 3670 | nlmsg_free(acl); |
| 3671 | return -ENOMEM; |
| 3672 | } |
| 3673 | nlmsg_free(acl); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3674 | |
| 3675 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3676 | if (ret) { |
| 3677 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", |
| 3678 | ret, strerror(-ret)); |
| 3679 | } |
| 3680 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3681 | return ret; |
| 3682 | } |
| 3683 | |
| 3684 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3685 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
| 3686 | { |
| 3687 | if (beacon_int > 0) { |
| 3688 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); |
| 3689 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 3690 | beacon_int); |
| 3691 | } |
| 3692 | |
| 3693 | return 0; |
| 3694 | } |
| 3695 | |
| 3696 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3697 | static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period) |
| 3698 | { |
| 3699 | if (dtim_period > 0) { |
| 3700 | wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period); |
| 3701 | return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); |
| 3702 | } |
| 3703 | |
| 3704 | return 0; |
| 3705 | } |
| 3706 | |
| 3707 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3708 | #ifdef CONFIG_MESH |
| 3709 | static int nl80211_set_mesh_config(void *priv, |
| 3710 | struct wpa_driver_mesh_bss_params *params) |
| 3711 | { |
| 3712 | struct i802_bss *bss = priv; |
| 3713 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3714 | struct nl_msg *msg; |
| 3715 | int ret; |
| 3716 | |
| 3717 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG); |
| 3718 | if (!msg) |
| 3719 | return -1; |
| 3720 | |
| 3721 | ret = nl80211_put_mesh_config(msg, params); |
| 3722 | if (ret < 0) { |
| 3723 | nlmsg_free(msg); |
| 3724 | return ret; |
| 3725 | } |
| 3726 | |
| 3727 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3728 | if (ret) { |
| 3729 | wpa_printf(MSG_ERROR, |
| 3730 | "nl80211: Mesh config set failed: %d (%s)", |
| 3731 | ret, strerror(-ret)); |
| 3732 | return ret; |
| 3733 | } |
| 3734 | return 0; |
| 3735 | } |
| 3736 | #endif /* CONFIG_MESH */ |
| 3737 | |
| 3738 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3739 | static int nl80211_put_beacon_rate(struct nl_msg *msg, const u64 flags, |
| 3740 | struct wpa_driver_ap_params *params) |
| 3741 | { |
| 3742 | struct nlattr *bands, *band; |
| 3743 | struct nl80211_txrate_vht vht_rate; |
| 3744 | |
| 3745 | if (!params->freq || |
| 3746 | (params->beacon_rate == 0 && |
| 3747 | params->rate_type == BEACON_RATE_LEGACY)) |
| 3748 | return 0; |
| 3749 | |
| 3750 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 3751 | if (!bands) |
| 3752 | return -1; |
| 3753 | |
| 3754 | switch (params->freq->mode) { |
| 3755 | case HOSTAPD_MODE_IEEE80211B: |
| 3756 | case HOSTAPD_MODE_IEEE80211G: |
| 3757 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
| 3758 | break; |
| 3759 | case HOSTAPD_MODE_IEEE80211A: |
| 3760 | band = nla_nest_start(msg, NL80211_BAND_5GHZ); |
| 3761 | break; |
| 3762 | case HOSTAPD_MODE_IEEE80211AD: |
| 3763 | band = nla_nest_start(msg, NL80211_BAND_60GHZ); |
| 3764 | break; |
| 3765 | default: |
| 3766 | return 0; |
| 3767 | } |
| 3768 | |
| 3769 | if (!band) |
| 3770 | return -1; |
| 3771 | |
| 3772 | os_memset(&vht_rate, 0, sizeof(vht_rate)); |
| 3773 | |
| 3774 | switch (params->rate_type) { |
| 3775 | case BEACON_RATE_LEGACY: |
| 3776 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) { |
| 3777 | wpa_printf(MSG_INFO, |
| 3778 | "nl80211: Driver does not support setting Beacon frame rate (legacy)"); |
| 3779 | return -1; |
| 3780 | } |
| 3781 | |
| 3782 | if (nla_put_u8(msg, NL80211_TXRATE_LEGACY, |
| 3783 | (u8) params->beacon_rate / 5) || |
| 3784 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || |
| 3785 | (params->freq->vht_enabled && |
| 3786 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 3787 | &vht_rate))) |
| 3788 | return -1; |
| 3789 | |
| 3790 | wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)", |
| 3791 | params->beacon_rate); |
| 3792 | break; |
| 3793 | case BEACON_RATE_HT: |
| 3794 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) { |
| 3795 | wpa_printf(MSG_INFO, |
| 3796 | "nl80211: Driver does not support setting Beacon frame rate (HT)"); |
| 3797 | return -1; |
| 3798 | } |
| 3799 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || |
| 3800 | nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) || |
| 3801 | (params->freq->vht_enabled && |
| 3802 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 3803 | &vht_rate))) |
| 3804 | return -1; |
| 3805 | wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u", |
| 3806 | params->beacon_rate); |
| 3807 | break; |
| 3808 | case BEACON_RATE_VHT: |
| 3809 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) { |
| 3810 | wpa_printf(MSG_INFO, |
| 3811 | "nl80211: Driver does not support setting Beacon frame rate (VHT)"); |
| 3812 | return -1; |
| 3813 | } |
| 3814 | vht_rate.mcs[0] = BIT(params->beacon_rate); |
| 3815 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL)) |
| 3816 | return -1; |
| 3817 | if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL)) |
| 3818 | return -1; |
| 3819 | if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 3820 | &vht_rate)) |
| 3821 | return -1; |
| 3822 | wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u", |
| 3823 | params->beacon_rate); |
| 3824 | break; |
| 3825 | } |
| 3826 | |
| 3827 | nla_nest_end(msg, band); |
| 3828 | nla_nest_end(msg, bands); |
| 3829 | |
| 3830 | return 0; |
| 3831 | } |
| 3832 | |
| 3833 | |
| 3834 | static int nl80211_set_multicast_to_unicast(struct i802_bss *bss, |
| 3835 | int multicast_to_unicast) |
| 3836 | { |
| 3837 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3838 | struct nl_msg *msg; |
| 3839 | int ret; |
| 3840 | |
| 3841 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST); |
| 3842 | if (!msg || |
| 3843 | (multicast_to_unicast && |
| 3844 | nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) { |
| 3845 | wpa_printf(MSG_ERROR, |
| 3846 | "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s", |
| 3847 | bss->ifname); |
| 3848 | nlmsg_free(msg); |
| 3849 | return -ENOBUFS; |
| 3850 | } |
| 3851 | |
| 3852 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3853 | |
| 3854 | switch (ret) { |
| 3855 | case 0: |
| 3856 | wpa_printf(MSG_DEBUG, |
| 3857 | "nl80211: multicast to unicast %s on interface %s", |
| 3858 | multicast_to_unicast ? "enabled" : "disabled", |
| 3859 | bss->ifname); |
| 3860 | break; |
| 3861 | case -EOPNOTSUPP: |
| 3862 | if (!multicast_to_unicast) |
| 3863 | break; |
| 3864 | wpa_printf(MSG_INFO, |
| 3865 | "nl80211: multicast to unicast not supported on interface %s", |
| 3866 | bss->ifname); |
| 3867 | break; |
| 3868 | default: |
| 3869 | wpa_printf(MSG_ERROR, |
| 3870 | "nl80211: %s multicast to unicast failed with %d (%s) on interface %s", |
| 3871 | multicast_to_unicast ? "enabling" : "disabling", |
| 3872 | ret, strerror(-ret), bss->ifname); |
| 3873 | break; |
| 3874 | } |
| 3875 | |
| 3876 | return ret; |
| 3877 | } |
| 3878 | |
| 3879 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3880 | static int wpa_driver_nl80211_set_ap(void *priv, |
| 3881 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3882 | { |
| 3883 | struct i802_bss *bss = priv; |
| 3884 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3885 | struct nl_msg *msg; |
| 3886 | u8 cmd = NL80211_CMD_NEW_BEACON; |
| 3887 | int ret; |
| 3888 | int beacon_set; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3889 | int num_suites; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3890 | int smps_mode; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3891 | u32 suites[10], suite; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3892 | u32 ver; |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3893 | #ifdef CONFIG_MESH |
| 3894 | struct wpa_driver_mesh_bss_params mesh_params; |
| 3895 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3896 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3897 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3898 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3899 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
| 3900 | beacon_set); |
| 3901 | if (beacon_set) |
| 3902 | cmd = NL80211_CMD_SET_BEACON; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3903 | else if (!drv->device_ap_sme && !drv->use_monitor && |
| 3904 | !nl80211_get_wiphy_data_ap(bss)) |
| 3905 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3906 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3907 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
| 3908 | params->head, params->head_len); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3909 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
| 3910 | params->tail, params->tail_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3911 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3912 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3913 | wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate); |
| 3914 | wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3915 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3916 | wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid", |
| 3917 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3918 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 3919 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
| 3920 | params->head) || |
| 3921 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, |
| 3922 | params->tail) || |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3923 | nl80211_put_beacon_int(msg, params->beacon_int) || |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3924 | nl80211_put_beacon_rate(msg, drv->capa.flags, params) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3925 | nl80211_put_dtim_period(msg, params->dtim_period) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3926 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 3927 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3928 | if (params->proberesp && params->proberesp_len) { |
| 3929 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", |
| 3930 | params->proberesp, params->proberesp_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3931 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
| 3932 | params->proberesp)) |
| 3933 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3934 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3935 | switch (params->hide_ssid) { |
| 3936 | case NO_SSID_HIDING: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3937 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3938 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3939 | NL80211_HIDDEN_SSID_NOT_IN_USE)) |
| 3940 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3941 | break; |
| 3942 | case HIDDEN_SSID_ZERO_LEN: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3943 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3944 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3945 | NL80211_HIDDEN_SSID_ZERO_LEN)) |
| 3946 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3947 | break; |
| 3948 | case HIDDEN_SSID_ZERO_CONTENTS: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3949 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3950 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3951 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) |
| 3952 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3953 | break; |
| 3954 | } |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3955 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3956 | if (params->privacy && |
| 3957 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 3958 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3959 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3960 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
| 3961 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { |
| 3962 | /* Leave out the attribute */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3963 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
| 3964 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 3965 | NL80211_AUTHTYPE_SHARED_KEY)) |
| 3966 | goto fail; |
| 3967 | } else { |
| 3968 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 3969 | NL80211_AUTHTYPE_OPEN_SYSTEM)) |
| 3970 | goto fail; |
| 3971 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3972 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3973 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3974 | ver = 0; |
| 3975 | if (params->wpa_version & WPA_PROTO_WPA) |
| 3976 | ver |= NL80211_WPA_VERSION_1; |
| 3977 | if (params->wpa_version & WPA_PROTO_RSN) |
| 3978 | ver |= NL80211_WPA_VERSION_2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3979 | if (ver && |
| 3980 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 3981 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3982 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3983 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
| 3984 | params->key_mgmt_suites); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3985 | num_suites = 0; |
| 3986 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3987 | suites[num_suites++] = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3988 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3989 | suites[num_suites++] = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3990 | if (num_suites && |
| 3991 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), |
| 3992 | suites)) |
| 3993 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3994 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3995 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3996 | (!params->pairwise_ciphers || |
| 3997 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) && |
| 3998 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 3999 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4000 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4001 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4002 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
| 4003 | params->pairwise_ciphers); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4004 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
| 4005 | suites, ARRAY_SIZE(suites)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4006 | if (num_suites && |
| 4007 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 4008 | num_suites * sizeof(u32), suites)) |
| 4009 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4010 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4011 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
| 4012 | params->group_cipher); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4013 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4014 | if (suite && |
| 4015 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) |
| 4016 | goto fail; |
| 4017 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 4018 | if (params->ht_opmode != -1) { |
| 4019 | switch (params->smps_mode) { |
| 4020 | case HT_CAP_INFO_SMPS_DYNAMIC: |
| 4021 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic"); |
| 4022 | smps_mode = NL80211_SMPS_DYNAMIC; |
| 4023 | break; |
| 4024 | case HT_CAP_INFO_SMPS_STATIC: |
| 4025 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static"); |
| 4026 | smps_mode = NL80211_SMPS_STATIC; |
| 4027 | break; |
| 4028 | default: |
| 4029 | /* invalid - fallback to smps off */ |
| 4030 | case HT_CAP_INFO_SMPS_DISABLED: |
| 4031 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off"); |
| 4032 | smps_mode = NL80211_SMPS_OFF; |
| 4033 | break; |
| 4034 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4035 | if (nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, smps_mode)) |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 4036 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4037 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4038 | |
| 4039 | if (params->beacon_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4040 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
| 4041 | params->beacon_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4042 | if (nla_put(msg, NL80211_ATTR_IE, |
| 4043 | wpabuf_len(params->beacon_ies), |
| 4044 | wpabuf_head(params->beacon_ies))) |
| 4045 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4046 | } |
| 4047 | if (params->proberesp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4048 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
| 4049 | params->proberesp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4050 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 4051 | wpabuf_len(params->proberesp_ies), |
| 4052 | wpabuf_head(params->proberesp_ies))) |
| 4053 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4054 | } |
| 4055 | if (params->assocresp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4056 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
| 4057 | params->assocresp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4058 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 4059 | wpabuf_len(params->assocresp_ies), |
| 4060 | wpabuf_head(params->assocresp_ies))) |
| 4061 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4062 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4063 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4064 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4065 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
| 4066 | params->ap_max_inactivity); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4067 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
| 4068 | params->ap_max_inactivity)) |
| 4069 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4070 | } |
| 4071 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4072 | #ifdef CONFIG_P2P |
| 4073 | if (params->p2p_go_ctwindow > 0) { |
| 4074 | if (drv->p2p_go_ctwindow_supported) { |
| 4075 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", |
| 4076 | params->p2p_go_ctwindow); |
| 4077 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, |
| 4078 | params->p2p_go_ctwindow)) |
| 4079 | goto fail; |
| 4080 | } else { |
| 4081 | wpa_printf(MSG_INFO, |
| 4082 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); |
| 4083 | } |
| 4084 | } |
| 4085 | #endif /* CONFIG_P2P */ |
| 4086 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4087 | if (params->pbss) { |
| 4088 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); |
| 4089 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 4090 | goto fail; |
| 4091 | } |
| 4092 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4093 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4094 | if (ret) { |
| 4095 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", |
| 4096 | ret, strerror(-ret)); |
| 4097 | } else { |
| 4098 | bss->beacon_set = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4099 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
| 4100 | params->short_slot_time, params->ht_opmode, |
| 4101 | params->isolate, params->basic_rates); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4102 | nl80211_set_multicast_to_unicast(bss, |
| 4103 | params->multicast_to_unicast); |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4104 | if (beacon_set && params->freq && |
| 4105 | params->freq->bandwidth != bss->bandwidth) { |
| 4106 | wpa_printf(MSG_DEBUG, |
| 4107 | "nl80211: Update BSS %s bandwidth: %d -> %d", |
| 4108 | bss->ifname, bss->bandwidth, |
| 4109 | params->freq->bandwidth); |
| 4110 | ret = nl80211_set_channel(bss, params->freq, 1); |
| 4111 | if (ret) { |
| 4112 | wpa_printf(MSG_DEBUG, |
| 4113 | "nl80211: Frequency set failed: %d (%s)", |
| 4114 | ret, strerror(-ret)); |
| 4115 | } else { |
| 4116 | wpa_printf(MSG_DEBUG, |
| 4117 | "nl80211: Frequency set succeeded for ht2040 coex"); |
| 4118 | bss->bandwidth = params->freq->bandwidth; |
| 4119 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4120 | } else if (!beacon_set && params->freq) { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4121 | /* |
| 4122 | * cfg80211 updates the driver on frequence change in AP |
| 4123 | * mode only at the point when beaconing is started, so |
| 4124 | * set the initial value here. |
| 4125 | */ |
| 4126 | bss->bandwidth = params->freq->bandwidth; |
| 4127 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4128 | } |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4129 | |
| 4130 | #ifdef CONFIG_MESH |
| 4131 | if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) { |
| 4132 | os_memset(&mesh_params, 0, sizeof(mesh_params)); |
| 4133 | mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE; |
| 4134 | mesh_params.ht_opmode = params->ht_opmode; |
| 4135 | ret = nl80211_set_mesh_config(priv, &mesh_params); |
| 4136 | if (ret < 0) |
| 4137 | return ret; |
| 4138 | } |
| 4139 | #endif /* CONFIG_MESH */ |
| 4140 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4141 | return ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4142 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4143 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4144 | return -ENOBUFS; |
| 4145 | } |
| 4146 | |
| 4147 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4148 | static int nl80211_put_freq_params(struct nl_msg *msg, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4149 | const struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4150 | { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4151 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4152 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
| 4153 | return -ENOBUFS; |
| 4154 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4155 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
| 4156 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); |
| 4157 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4158 | if (freq->vht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4159 | enum nl80211_chan_width cw; |
| 4160 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4161 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4162 | switch (freq->bandwidth) { |
| 4163 | case 20: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4164 | cw = NL80211_CHAN_WIDTH_20; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4165 | break; |
| 4166 | case 40: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4167 | cw = NL80211_CHAN_WIDTH_40; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4168 | break; |
| 4169 | case 80: |
| 4170 | if (freq->center_freq2) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4171 | cw = NL80211_CHAN_WIDTH_80P80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4172 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4173 | cw = NL80211_CHAN_WIDTH_80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4174 | break; |
| 4175 | case 160: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4176 | cw = NL80211_CHAN_WIDTH_160; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4177 | break; |
| 4178 | default: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4179 | return -EINVAL; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4180 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4181 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4182 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
| 4183 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", |
| 4184 | freq->center_freq1); |
| 4185 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", |
| 4186 | freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4187 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
| 4188 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, |
| 4189 | freq->center_freq1) || |
| 4190 | (freq->center_freq2 && |
| 4191 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 4192 | freq->center_freq2))) |
| 4193 | return -ENOBUFS; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4194 | } else if (freq->ht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4195 | enum nl80211_channel_type ct; |
| 4196 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4197 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
| 4198 | freq->sec_channel_offset); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4199 | switch (freq->sec_channel_offset) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4200 | case -1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4201 | ct = NL80211_CHAN_HT40MINUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4202 | break; |
| 4203 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4204 | ct = NL80211_CHAN_HT40PLUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4205 | break; |
| 4206 | default: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4207 | ct = NL80211_CHAN_HT20; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4208 | break; |
| 4209 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4210 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4211 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4212 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
| 4213 | return -ENOBUFS; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4214 | } else { |
| 4215 | wpa_printf(MSG_DEBUG, " * channel_type=%d", |
| 4216 | NL80211_CHAN_NO_HT); |
| 4217 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 4218 | NL80211_CHAN_NO_HT)) |
| 4219 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4220 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4221 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4222 | } |
| 4223 | |
| 4224 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4225 | static int nl80211_set_channel(struct i802_bss *bss, |
| 4226 | struct hostapd_freq_params *freq, int set_chan) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4227 | { |
| 4228 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4229 | struct nl_msg *msg; |
| 4230 | int ret; |
| 4231 | |
| 4232 | wpa_printf(MSG_DEBUG, |
| 4233 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
| 4234 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 4235 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4236 | |
| 4237 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
| 4238 | NL80211_CMD_SET_WIPHY); |
| 4239 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { |
| 4240 | nlmsg_free(msg); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4241 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4242 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4243 | |
| 4244 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4245 | if (ret == 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4246 | bss->freq = freq->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4247 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4248 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4249 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4250 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4251 | return -1; |
| 4252 | } |
| 4253 | |
| 4254 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4255 | static u32 sta_flags_nl80211(int flags) |
| 4256 | { |
| 4257 | u32 f = 0; |
| 4258 | |
| 4259 | if (flags & WPA_STA_AUTHORIZED) |
| 4260 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 4261 | if (flags & WPA_STA_WMM) |
| 4262 | f |= BIT(NL80211_STA_FLAG_WME); |
| 4263 | if (flags & WPA_STA_SHORT_PREAMBLE) |
| 4264 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
| 4265 | if (flags & WPA_STA_MFP) |
| 4266 | f |= BIT(NL80211_STA_FLAG_MFP); |
| 4267 | if (flags & WPA_STA_TDLS_PEER) |
| 4268 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4269 | if (flags & WPA_STA_AUTHENTICATED) |
| 4270 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4271 | if (flags & WPA_STA_ASSOCIATED) |
| 4272 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4273 | |
| 4274 | return f; |
| 4275 | } |
| 4276 | |
| 4277 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4278 | #ifdef CONFIG_MESH |
| 4279 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) |
| 4280 | { |
| 4281 | switch (state) { |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4282 | case PLINK_IDLE: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4283 | return NL80211_PLINK_LISTEN; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4284 | case PLINK_OPN_SNT: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4285 | return NL80211_PLINK_OPN_SNT; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4286 | case PLINK_OPN_RCVD: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4287 | return NL80211_PLINK_OPN_RCVD; |
| 4288 | case PLINK_CNF_RCVD: |
| 4289 | return NL80211_PLINK_CNF_RCVD; |
| 4290 | case PLINK_ESTAB: |
| 4291 | return NL80211_PLINK_ESTAB; |
| 4292 | case PLINK_HOLDING: |
| 4293 | return NL80211_PLINK_HOLDING; |
| 4294 | case PLINK_BLOCKED: |
| 4295 | return NL80211_PLINK_BLOCKED; |
| 4296 | default: |
| 4297 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", |
| 4298 | state); |
| 4299 | } |
| 4300 | return -1; |
| 4301 | } |
| 4302 | #endif /* CONFIG_MESH */ |
| 4303 | |
| 4304 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4305 | static int wpa_driver_nl80211_sta_add(void *priv, |
| 4306 | struct hostapd_sta_add_params *params) |
| 4307 | { |
| 4308 | struct i802_bss *bss = priv; |
| 4309 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4310 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4311 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4312 | int ret = -ENOBUFS; |
| 4313 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4314 | if ((params->flags & WPA_STA_TDLS_PEER) && |
| 4315 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 4316 | return -EOPNOTSUPP; |
| 4317 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4318 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
| 4319 | params->set ? "Set" : "Add", MAC2STR(params->addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4320 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
| 4321 | NL80211_CMD_NEW_STATION); |
| 4322 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) |
| 4323 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4324 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4325 | /* |
| 4326 | * Set the below properties only in one of the following cases: |
| 4327 | * 1. New station is added, already associated. |
| 4328 | * 2. Set WPA_STA_TDLS_PEER station. |
| 4329 | * 3. Set an already added unassociated station, if driver supports |
| 4330 | * full AP client state. (Set these properties after station became |
| 4331 | * associated will be rejected by the driver). |
| 4332 | */ |
| 4333 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
| 4334 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 4335 | (params->flags & WPA_STA_ASSOCIATED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4336 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
| 4337 | params->supp_rates, params->supp_rates_len); |
| 4338 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
| 4339 | params->capability); |
| 4340 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, |
| 4341 | params->supp_rates_len, params->supp_rates) || |
| 4342 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, |
| 4343 | params->capability)) |
| 4344 | goto fail; |
| 4345 | |
| 4346 | if (params->ht_capabilities) { |
| 4347 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
| 4348 | (u8 *) params->ht_capabilities, |
| 4349 | sizeof(*params->ht_capabilities)); |
| 4350 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
| 4351 | sizeof(*params->ht_capabilities), |
| 4352 | params->ht_capabilities)) |
| 4353 | goto fail; |
| 4354 | } |
| 4355 | |
| 4356 | if (params->vht_capabilities) { |
| 4357 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
| 4358 | (u8 *) params->vht_capabilities, |
| 4359 | sizeof(*params->vht_capabilities)); |
| 4360 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
| 4361 | sizeof(*params->vht_capabilities), |
| 4362 | params->vht_capabilities)) |
| 4363 | goto fail; |
| 4364 | } |
| 4365 | |
| 4366 | if (params->ext_capab) { |
| 4367 | wpa_hexdump(MSG_DEBUG, " * ext_capab", |
| 4368 | params->ext_capab, params->ext_capab_len); |
| 4369 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
| 4370 | params->ext_capab_len, params->ext_capab)) |
| 4371 | goto fail; |
| 4372 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4373 | |
| 4374 | if (is_ap_interface(drv->nlmode) && |
| 4375 | nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS, |
| 4376 | params->support_p2p_ps ? |
| 4377 | NL80211_P2P_PS_SUPPORTED : |
| 4378 | NL80211_P2P_PS_UNSUPPORTED)) |
| 4379 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4380 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4381 | if (!params->set) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4382 | if (params->aid) { |
| 4383 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4384 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
| 4385 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4386 | } else { |
| 4387 | /* |
| 4388 | * cfg80211 validates that AID is non-zero, so we have |
| 4389 | * to make this a non-zero value for the TDLS case where |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4390 | * a dummy STA entry is used for now and for a station |
| 4391 | * that is still not associated. |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4392 | */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4393 | wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)", |
| 4394 | (params->flags & WPA_STA_TDLS_PEER) ? |
| 4395 | "TDLS" : "UNASSOC_STA"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4396 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
| 4397 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4398 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4399 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 4400 | params->listen_interval); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4401 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 4402 | params->listen_interval)) |
| 4403 | goto fail; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4404 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
| 4405 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4406 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
| 4407 | goto fail; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4408 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 4409 | (params->flags & WPA_STA_ASSOCIATED)) { |
| 4410 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
| 4411 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 4412 | params->listen_interval); |
| 4413 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || |
| 4414 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 4415 | params->listen_interval)) |
| 4416 | goto fail; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4417 | } |
| 4418 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 4419 | if (params->vht_opmode_enabled) { |
| 4420 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4421 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
| 4422 | params->vht_opmode)) |
| 4423 | goto fail; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4424 | } |
| 4425 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4426 | if (params->supp_channels) { |
| 4427 | wpa_hexdump(MSG_DEBUG, " * supported channels", |
| 4428 | params->supp_channels, params->supp_channels_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4429 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
| 4430 | params->supp_channels_len, params->supp_channels)) |
| 4431 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4432 | } |
| 4433 | |
| 4434 | if (params->supp_oper_classes) { |
| 4435 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", |
| 4436 | params->supp_oper_classes, |
| 4437 | params->supp_oper_classes_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4438 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
| 4439 | params->supp_oper_classes_len, |
| 4440 | params->supp_oper_classes)) |
| 4441 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4442 | } |
| 4443 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4444 | os_memset(&upd, 0, sizeof(upd)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4445 | upd.set = sta_flags_nl80211(params->flags); |
| 4446 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4447 | |
| 4448 | /* |
| 4449 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH |
| 4450 | * flags, as nl80211 driver moves a new station, by default, into |
| 4451 | * associated state. |
| 4452 | * |
| 4453 | * On the other hand, if the driver supports that feature and the |
| 4454 | * station is added in unauthenticated state, set the |
| 4455 | * authenticated/associated bits in the mask to prevent moving this |
| 4456 | * station to associated state before it is actually associated. |
| 4457 | * |
| 4458 | * This is irrelevant for mesh mode where the station is added to the |
| 4459 | * driver as authenticated already, and ASSOCIATED isn't part of the |
| 4460 | * nl80211 API. |
| 4461 | */ |
| 4462 | if (!is_mesh_interface(drv->nlmode)) { |
| 4463 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { |
| 4464 | wpa_printf(MSG_DEBUG, |
| 4465 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); |
| 4466 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4467 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); |
| 4468 | } else if (!params->set && |
| 4469 | !(params->flags & WPA_STA_TDLS_PEER)) { |
| 4470 | if (!(params->flags & WPA_STA_AUTHENTICATED)) |
| 4471 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
| 4472 | if (!(params->flags & WPA_STA_ASSOCIATED)) |
| 4473 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 4474 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4475 | #ifdef CONFIG_MESH |
| 4476 | } else { |
| 4477 | if (params->plink_state == PLINK_ESTAB && params->peer_aid) { |
| 4478 | ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID, |
| 4479 | params->peer_aid); |
| 4480 | if (ret) |
| 4481 | goto fail; |
| 4482 | } |
| 4483 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4484 | } |
| 4485 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4486 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
| 4487 | upd.set, upd.mask); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4488 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 4489 | goto fail; |
| 4490 | |
| 4491 | #ifdef CONFIG_MESH |
| 4492 | if (params->plink_state && |
| 4493 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, |
| 4494 | sta_plink_state_nl80211(params->plink_state))) |
| 4495 | goto fail; |
| 4496 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4497 | |
| 4498 | if (params->flags & WPA_STA_WMM) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4499 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 4500 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4501 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4502 | if (!wme || |
| 4503 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 4504 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || |
| 4505 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, |
| 4506 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
| 4507 | WMM_QOSINFO_STA_SP_MASK)) |
| 4508 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4509 | nla_nest_end(msg, wme); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4510 | } |
| 4511 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4512 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4513 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4514 | if (ret) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4515 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
| 4516 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, |
| 4517 | strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4518 | if (ret == -EEXIST) |
| 4519 | ret = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4520 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4521 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4522 | return ret; |
| 4523 | } |
| 4524 | |
| 4525 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4526 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
| 4527 | { |
| 4528 | #ifdef CONFIG_LIBNL3_ROUTE |
| 4529 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4530 | struct rtnl_neigh *rn; |
| 4531 | struct nl_addr *nl_addr; |
| 4532 | int err; |
| 4533 | |
| 4534 | rn = rtnl_neigh_alloc(); |
| 4535 | if (!rn) |
| 4536 | return; |
| 4537 | |
| 4538 | rtnl_neigh_set_family(rn, AF_BRIDGE); |
| 4539 | rtnl_neigh_set_ifindex(rn, bss->ifindex); |
| 4540 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); |
| 4541 | if (!nl_addr) { |
| 4542 | rtnl_neigh_put(rn); |
| 4543 | return; |
| 4544 | } |
| 4545 | rtnl_neigh_set_lladdr(rn, nl_addr); |
| 4546 | |
| 4547 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 4548 | if (err < 0) { |
| 4549 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " |
| 4550 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), |
| 4551 | bss->ifindex, nl_geterror(err)); |
| 4552 | } else { |
| 4553 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " |
| 4554 | MACSTR, MAC2STR(addr)); |
| 4555 | } |
| 4556 | |
| 4557 | nl_addr_put(nl_addr); |
| 4558 | rtnl_neigh_put(rn); |
| 4559 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 4560 | } |
| 4561 | |
| 4562 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4563 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
| 4564 | int deauth, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4565 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4566 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4567 | struct nl_msg *msg; |
| 4568 | int ret; |
| 4569 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4570 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
| 4571 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 4572 | (deauth == 0 && |
| 4573 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 4574 | WLAN_FC_STYPE_DISASSOC)) || |
| 4575 | (deauth == 1 && |
| 4576 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 4577 | WLAN_FC_STYPE_DEAUTH)) || |
| 4578 | (reason_code && |
| 4579 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { |
| 4580 | nlmsg_free(msg); |
| 4581 | return -ENOBUFS; |
| 4582 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4583 | |
| 4584 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 4585 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
| 4586 | " --> %d (%s)", |
| 4587 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4588 | |
| 4589 | if (drv->rtnl_sk) |
| 4590 | rtnl_neigh_delete_fdb_entry(bss, addr); |
| 4591 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4592 | if (ret == -ENOENT) |
| 4593 | return 0; |
| 4594 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4595 | } |
| 4596 | |
| 4597 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4598 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4599 | { |
| 4600 | struct nl_msg *msg; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4601 | struct wpa_driver_nl80211_data *drv2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4602 | |
| 4603 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
| 4604 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4605 | /* stop listening for EAPOL on this interface */ |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4606 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 4607 | struct wpa_driver_nl80211_data, list) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4608 | { |
| 4609 | del_ifidx(drv2, ifidx, IFIDX_ANY); |
| 4610 | /* Remove all bridges learned for this iface */ |
| 4611 | del_ifidx(drv2, IFIDX_ANY, ifidx); |
| 4612 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4613 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4614 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4615 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 4616 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4617 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
| 4618 | } |
| 4619 | |
| 4620 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 4621 | const char * nl80211_iftype_str(enum nl80211_iftype mode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4622 | { |
| 4623 | switch (mode) { |
| 4624 | case NL80211_IFTYPE_ADHOC: |
| 4625 | return "ADHOC"; |
| 4626 | case NL80211_IFTYPE_STATION: |
| 4627 | return "STATION"; |
| 4628 | case NL80211_IFTYPE_AP: |
| 4629 | return "AP"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 4630 | case NL80211_IFTYPE_AP_VLAN: |
| 4631 | return "AP_VLAN"; |
| 4632 | case NL80211_IFTYPE_WDS: |
| 4633 | return "WDS"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4634 | case NL80211_IFTYPE_MONITOR: |
| 4635 | return "MONITOR"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 4636 | case NL80211_IFTYPE_MESH_POINT: |
| 4637 | return "MESH_POINT"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4638 | case NL80211_IFTYPE_P2P_CLIENT: |
| 4639 | return "P2P_CLIENT"; |
| 4640 | case NL80211_IFTYPE_P2P_GO: |
| 4641 | return "P2P_GO"; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4642 | case NL80211_IFTYPE_P2P_DEVICE: |
| 4643 | return "P2P_DEVICE"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4644 | default: |
| 4645 | return "unknown"; |
| 4646 | } |
| 4647 | } |
| 4648 | |
| 4649 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4650 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
| 4651 | const char *ifname, |
| 4652 | enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4653 | const u8 *addr, int wds, |
| 4654 | int (*handler)(struct nl_msg *, void *), |
| 4655 | void *arg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4656 | { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4657 | struct nl_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4658 | int ifidx; |
| 4659 | int ret = -ENOBUFS; |
| 4660 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4661 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
| 4662 | iftype, nl80211_iftype_str(iftype)); |
| 4663 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4664 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
| 4665 | if (!msg || |
| 4666 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
| 4667 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) |
| 4668 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4669 | |
| 4670 | if (iftype == NL80211_IFTYPE_MONITOR) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4671 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4672 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4673 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4674 | if (!flags || |
| 4675 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) |
| 4676 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4677 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4678 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4679 | } else if (wds) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4680 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
| 4681 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4682 | } |
| 4683 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4684 | /* |
| 4685 | * Tell cfg80211 that the interface belongs to the socket that created |
| 4686 | * it, and the interface should be deleted when the socket is closed. |
| 4687 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4688 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 4689 | goto fail; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4690 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4691 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4692 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4693 | if (ret) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4694 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4695 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4696 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
| 4697 | ifname, ret, strerror(-ret)); |
| 4698 | return ret; |
| 4699 | } |
| 4700 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4701 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
| 4702 | return 0; |
| 4703 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4704 | ifidx = if_nametoindex(ifname); |
| 4705 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
| 4706 | ifname, ifidx); |
| 4707 | |
| 4708 | if (ifidx <= 0) |
| 4709 | return -1; |
| 4710 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4711 | /* |
| 4712 | * Some virtual interfaces need to process EAPOL packets and events on |
| 4713 | * the parent interface. This is used mainly with hostapd. |
| 4714 | */ |
| 4715 | if (drv->hostapd || |
| 4716 | iftype == NL80211_IFTYPE_AP_VLAN || |
| 4717 | iftype == NL80211_IFTYPE_WDS || |
| 4718 | iftype == NL80211_IFTYPE_MONITOR) { |
| 4719 | /* start listening for EAPOL on this interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4720 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4721 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4722 | |
| 4723 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4724 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4725 | nl80211_remove_iface(drv, ifidx); |
| 4726 | return -1; |
| 4727 | } |
| 4728 | |
| 4729 | return ifidx; |
| 4730 | } |
| 4731 | |
| 4732 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4733 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
| 4734 | const char *ifname, enum nl80211_iftype iftype, |
| 4735 | const u8 *addr, int wds, |
| 4736 | int (*handler)(struct nl_msg *, void *), |
| 4737 | void *arg, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4738 | { |
| 4739 | int ret; |
| 4740 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4741 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
| 4742 | arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4743 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4744 | /* if error occurred and interface exists already */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4745 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4746 | if (use_existing) { |
| 4747 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", |
| 4748 | ifname); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 4749 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
| 4750 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4751 | addr) < 0 && |
| 4752 | (linux_set_iface_flags(drv->global->ioctl_sock, |
| 4753 | ifname, 0) < 0 || |
| 4754 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4755 | addr) < 0 || |
| 4756 | linux_set_iface_flags(drv->global->ioctl_sock, |
| 4757 | ifname, 1) < 0)) |
| 4758 | return -1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4759 | return -ENFILE; |
| 4760 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4761 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
| 4762 | |
| 4763 | /* Try to remove the interface that was already there. */ |
| 4764 | nl80211_remove_iface(drv, if_nametoindex(ifname)); |
| 4765 | |
| 4766 | /* Try to create the interface again */ |
| 4767 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4768 | wds, handler, arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4769 | } |
| 4770 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4771 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
| 4772 | wpa_printf(MSG_DEBUG, |
| 4773 | "nl80211: Interface %s created for P2P - disable 11b rates", |
| 4774 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4775 | nl80211_disable_11b_rates(drv, ret, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4776 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4777 | |
| 4778 | return ret; |
| 4779 | } |
| 4780 | |
| 4781 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4782 | static int nl80211_setup_ap(struct i802_bss *bss) |
| 4783 | { |
| 4784 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4785 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4786 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 4787 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4788 | |
| 4789 | /* |
| 4790 | * Disable Probe Request reporting unless we need it in this way for |
| 4791 | * devices that include the AP SME, in the other case (unless using |
| 4792 | * monitor iface) we'll get it through the nl_mgmt socket instead. |
| 4793 | */ |
| 4794 | if (!drv->device_ap_sme) |
| 4795 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4796 | |
| 4797 | if (!drv->device_ap_sme && !drv->use_monitor) |
| 4798 | if (nl80211_mgmt_subscribe_ap(bss)) |
| 4799 | return -1; |
| 4800 | |
| 4801 | if (drv->device_ap_sme && !drv->use_monitor) |
| 4802 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4803 | wpa_printf(MSG_DEBUG, |
| 4804 | "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] | 4805 | |
| 4806 | if (!drv->device_ap_sme && drv->use_monitor && |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 4807 | nl80211_create_monitor_interface(drv) && |
| 4808 | !drv->device_ap_sme) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4809 | return -1; |
| 4810 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4811 | if (drv->device_ap_sme && |
| 4812 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { |
| 4813 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " |
| 4814 | "Probe Request frame reporting in AP mode"); |
| 4815 | /* Try to survive without this */ |
| 4816 | } |
| 4817 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4818 | return 0; |
| 4819 | } |
| 4820 | |
| 4821 | |
| 4822 | static void nl80211_teardown_ap(struct i802_bss *bss) |
| 4823 | { |
| 4824 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4825 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4826 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 4827 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4828 | if (drv->device_ap_sme) { |
| 4829 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4830 | if (!drv->use_monitor) |
| 4831 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); |
| 4832 | } else if (drv->use_monitor) |
| 4833 | nl80211_remove_monitor_interface(drv); |
| 4834 | else |
| 4835 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
| 4836 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4837 | nl80211_put_wiphy_data_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4838 | bss->beacon_set = 0; |
| 4839 | } |
| 4840 | |
| 4841 | |
| 4842 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
| 4843 | const u8 *addr, const u8 *data, |
| 4844 | size_t data_len) |
| 4845 | { |
| 4846 | struct sockaddr_ll ll; |
| 4847 | int ret; |
| 4848 | |
| 4849 | if (bss->drv->eapol_tx_sock < 0) { |
| 4850 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); |
| 4851 | return -1; |
| 4852 | } |
| 4853 | |
| 4854 | os_memset(&ll, 0, sizeof(ll)); |
| 4855 | ll.sll_family = AF_PACKET; |
| 4856 | ll.sll_ifindex = bss->ifindex; |
| 4857 | ll.sll_protocol = htons(ETH_P_PAE); |
| 4858 | ll.sll_halen = ETH_ALEN; |
| 4859 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); |
| 4860 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, |
| 4861 | (struct sockaddr *) &ll, sizeof(ll)); |
| 4862 | if (ret < 0) |
| 4863 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", |
| 4864 | strerror(errno)); |
| 4865 | |
| 4866 | return ret; |
| 4867 | } |
| 4868 | |
| 4869 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4870 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 4871 | |
| 4872 | static int wpa_driver_nl80211_hapd_send_eapol( |
| 4873 | void *priv, const u8 *addr, const u8 *data, |
| 4874 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
| 4875 | { |
| 4876 | struct i802_bss *bss = priv; |
| 4877 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4878 | struct ieee80211_hdr *hdr; |
| 4879 | size_t len; |
| 4880 | u8 *pos; |
| 4881 | int res; |
| 4882 | int qos = flags & WPA_STA_WMM; |
Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 4883 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4884 | if (drv->device_ap_sme || !drv->use_monitor) |
| 4885 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
| 4886 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4887 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
| 4888 | data_len; |
| 4889 | hdr = os_zalloc(len); |
| 4890 | if (hdr == NULL) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4891 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
| 4892 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4893 | return -1; |
| 4894 | } |
| 4895 | |
| 4896 | hdr->frame_control = |
| 4897 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); |
| 4898 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 4899 | if (encrypt) |
| 4900 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); |
| 4901 | if (qos) { |
| 4902 | hdr->frame_control |= |
| 4903 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); |
| 4904 | } |
| 4905 | |
| 4906 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 4907 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 4908 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 4909 | pos = (u8 *) (hdr + 1); |
| 4910 | |
| 4911 | if (qos) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 4912 | /* Set highest priority in QoS header */ |
| 4913 | pos[0] = 7; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4914 | pos[1] = 0; |
| 4915 | pos += 2; |
| 4916 | } |
| 4917 | |
| 4918 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); |
| 4919 | pos += sizeof(rfc1042_header); |
| 4920 | WPA_PUT_BE16(pos, ETH_P_PAE); |
| 4921 | pos += 2; |
| 4922 | memcpy(pos, data, data_len); |
| 4923 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4924 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4925 | 0, 0, 0, 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4926 | if (res < 0) { |
| 4927 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " |
| 4928 | "failed: %d (%s)", |
| 4929 | (unsigned long) len, errno, strerror(errno)); |
| 4930 | } |
| 4931 | os_free(hdr); |
| 4932 | |
| 4933 | return res; |
| 4934 | } |
| 4935 | |
| 4936 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4937 | 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] | 4938 | unsigned int total_flags, |
| 4939 | unsigned int flags_or, |
| 4940 | unsigned int flags_and) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4941 | { |
| 4942 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4943 | struct nl_msg *msg; |
| 4944 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4945 | struct nl80211_sta_flag_update upd; |
| 4946 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4947 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
| 4948 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", |
| 4949 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, |
| 4950 | !!(total_flags & WPA_STA_AUTHORIZED)); |
| 4951 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4952 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 4953 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 4954 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4955 | |
| 4956 | /* |
| 4957 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This |
| 4958 | * can be removed eventually. |
| 4959 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4960 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4961 | if (!flags || |
| 4962 | ((total_flags & WPA_STA_AUTHORIZED) && |
| 4963 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || |
| 4964 | ((total_flags & WPA_STA_WMM) && |
| 4965 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || |
| 4966 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && |
| 4967 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || |
| 4968 | ((total_flags & WPA_STA_MFP) && |
| 4969 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || |
| 4970 | ((total_flags & WPA_STA_TDLS_PEER) && |
| 4971 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) |
| 4972 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4973 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4974 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4975 | |
| 4976 | os_memset(&upd, 0, sizeof(upd)); |
| 4977 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); |
| 4978 | upd.set = sta_flags_nl80211(flags_or); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4979 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 4980 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4981 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4982 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 4983 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4984 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4985 | return -ENOBUFS; |
| 4986 | } |
| 4987 | |
| 4988 | |
| 4989 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
| 4990 | struct wpa_driver_associate_params *params) |
| 4991 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4992 | enum nl80211_iftype nlmode, old_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4993 | |
| 4994 | if (params->p2p) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4995 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
| 4996 | "group (GO)"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4997 | nlmode = NL80211_IFTYPE_P2P_GO; |
| 4998 | } else |
| 4999 | nlmode = NL80211_IFTYPE_AP; |
| 5000 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5001 | old_mode = drv->nlmode; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5002 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5003 | nl80211_remove_monitor_interface(drv); |
| 5004 | return -1; |
| 5005 | } |
| 5006 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5007 | if (params->freq.freq && |
| 5008 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5009 | if (old_mode != nlmode) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5010 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5011 | nl80211_remove_monitor_interface(drv); |
| 5012 | return -1; |
| 5013 | } |
| 5014 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5015 | return 0; |
| 5016 | } |
| 5017 | |
| 5018 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5019 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 5020 | int reset_mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5021 | { |
| 5022 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5023 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5024 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5025 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5026 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5027 | if (ret) { |
| 5028 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " |
| 5029 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5030 | } else { |
| 5031 | wpa_printf(MSG_DEBUG, |
| 5032 | "nl80211: Leave IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5033 | } |
| 5034 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5035 | if (reset_mode && |
| 5036 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 5037 | NL80211_IFTYPE_STATION)) { |
| 5038 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 5039 | "station mode"); |
| 5040 | } |
| 5041 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5042 | return ret; |
| 5043 | } |
| 5044 | |
| 5045 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5046 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
| 5047 | struct wpa_driver_associate_params *params) |
| 5048 | { |
| 5049 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) |
| 5050 | return -1; |
| 5051 | |
| 5052 | if (params->htcaps && params->htcaps_mask) { |
| 5053 | int sz = sizeof(struct ieee80211_ht_capabilities); |
| 5054 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); |
| 5055 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", |
| 5056 | params->htcaps_mask, sz); |
| 5057 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, |
| 5058 | params->htcaps) || |
| 5059 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 5060 | params->htcaps_mask)) |
| 5061 | return -1; |
| 5062 | } |
| 5063 | |
| 5064 | #ifdef CONFIG_VHT_OVERRIDES |
| 5065 | if (params->disable_vht) { |
| 5066 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
| 5067 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) |
| 5068 | return -1; |
| 5069 | } |
| 5070 | |
| 5071 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 5072 | int sz = sizeof(struct ieee80211_vht_capabilities); |
| 5073 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); |
| 5074 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", |
| 5075 | params->vhtcaps_mask, sz); |
| 5076 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, |
| 5077 | params->vhtcaps) || |
| 5078 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 5079 | params->vhtcaps_mask)) |
| 5080 | return -1; |
| 5081 | } |
| 5082 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 5083 | |
| 5084 | return 0; |
| 5085 | } |
| 5086 | |
| 5087 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5088 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
| 5089 | struct wpa_driver_associate_params *params) |
| 5090 | { |
| 5091 | struct nl_msg *msg; |
| 5092 | int ret = -1; |
| 5093 | int count = 0; |
| 5094 | |
| 5095 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); |
| 5096 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5097 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5098 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 5099 | "IBSS mode"); |
| 5100 | return -1; |
| 5101 | } |
| 5102 | |
| 5103 | retry: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5104 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
| 5105 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
| 5106 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5107 | |
| 5108 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 5109 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5110 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 5111 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5112 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 5113 | drv->ssid_len = params->ssid_len; |
| 5114 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5115 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
| 5116 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5117 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5118 | |
| 5119 | ret = nl80211_set_conn_keys(params, msg); |
| 5120 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5121 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5122 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5123 | if (params->bssid && params->fixed_bssid) { |
| 5124 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, |
| 5125 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5126 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 5127 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5128 | } |
| 5129 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5130 | if (params->fixed_freq) { |
| 5131 | wpa_printf(MSG_DEBUG, " * fixed_freq"); |
| 5132 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) |
| 5133 | goto fail; |
| 5134 | } |
| 5135 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5136 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 5137 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 5138 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
| 5139 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5140 | wpa_printf(MSG_DEBUG, " * control port"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5141 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 5142 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5143 | } |
| 5144 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5145 | if (params->wpa_ie) { |
| 5146 | wpa_hexdump(MSG_DEBUG, |
| 5147 | " * Extra IEs for Beacon/Probe Response frames", |
| 5148 | params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5149 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 5150 | params->wpa_ie)) |
| 5151 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5152 | } |
| 5153 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 5154 | ret = nl80211_ht_vht_overrides(msg, params); |
| 5155 | if (ret < 0) |
| 5156 | goto fail; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5157 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5158 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5159 | msg = NULL; |
| 5160 | if (ret) { |
| 5161 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", |
| 5162 | ret, strerror(-ret)); |
| 5163 | count++; |
| 5164 | if (ret == -EALREADY && count == 1) { |
| 5165 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " |
| 5166 | "forced leave"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5167 | nl80211_leave_ibss(drv, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5168 | nlmsg_free(msg); |
| 5169 | goto retry; |
| 5170 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5171 | } else { |
| 5172 | wpa_printf(MSG_DEBUG, |
| 5173 | "nl80211: Join IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5174 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5175 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5176 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5177 | nlmsg_free(msg); |
| 5178 | return ret; |
| 5179 | } |
| 5180 | |
| 5181 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5182 | static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data *drv, |
| 5183 | struct wpa_driver_associate_params *params, |
| 5184 | struct nl_msg *msg) |
| 5185 | { |
| 5186 | if (params->fils_erp_username_len) { |
| 5187 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP EMSKname/username", |
| 5188 | params->fils_erp_username, |
| 5189 | params->fils_erp_username_len); |
| 5190 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_USERNAME, |
| 5191 | params->fils_erp_username_len, |
| 5192 | params->fils_erp_username)) |
| 5193 | return -1; |
| 5194 | } |
| 5195 | |
| 5196 | if (params->fils_erp_realm_len) { |
| 5197 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP Realm", |
| 5198 | params->fils_erp_realm, |
| 5199 | params->fils_erp_realm_len); |
| 5200 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_REALM, |
| 5201 | params->fils_erp_realm_len, params->fils_erp_realm)) |
| 5202 | return -1; |
| 5203 | } |
| 5204 | |
| 5205 | wpa_printf(MSG_DEBUG, " * FILS ERP next seq %u", |
| 5206 | params->fils_erp_next_seq_num); |
| 5207 | if (nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 5208 | params->fils_erp_next_seq_num)) |
| 5209 | return -1; |
| 5210 | |
| 5211 | if (params->fils_erp_rrk_len) { |
| 5212 | wpa_printf(MSG_DEBUG, " * FILS ERP rRK (len=%lu)", |
| 5213 | (unsigned long) params->fils_erp_rrk_len); |
| 5214 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_RRK, |
| 5215 | params->fils_erp_rrk_len, params->fils_erp_rrk)) |
| 5216 | return -1; |
| 5217 | } |
| 5218 | |
| 5219 | return 0; |
| 5220 | } |
| 5221 | |
| 5222 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5223 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
| 5224 | struct wpa_driver_associate_params *params, |
| 5225 | struct nl_msg *msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5226 | { |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5227 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 5228 | return -1; |
| 5229 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5230 | if (params->bssid) { |
| 5231 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 5232 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5233 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 5234 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5235 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5236 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5237 | if (params->bssid_hint) { |
| 5238 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, |
| 5239 | MAC2STR(params->bssid_hint)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5240 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
| 5241 | params->bssid_hint)) |
| 5242 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5243 | } |
| 5244 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5245 | if (params->freq.freq) { |
| 5246 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5247 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 5248 | params->freq.freq)) |
| 5249 | return -1; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5250 | drv->assoc_freq = params->freq.freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5251 | } else |
| 5252 | drv->assoc_freq = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5253 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5254 | if (params->freq_hint) { |
| 5255 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5256 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
| 5257 | params->freq_hint)) |
| 5258 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5259 | } |
| 5260 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5261 | if (params->bg_scan_period >= 0) { |
| 5262 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 5263 | params->bg_scan_period); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5264 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 5265 | params->bg_scan_period)) |
| 5266 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5267 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5268 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5269 | if (params->ssid) { |
| 5270 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 5271 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5272 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 5273 | params->ssid)) |
| 5274 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5275 | if (params->ssid_len > sizeof(drv->ssid)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5276 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5277 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 5278 | drv->ssid_len = params->ssid_len; |
| 5279 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5280 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5281 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5282 | if (params->wpa_ie && |
| 5283 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) |
| 5284 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5285 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5286 | if (params->wpa_proto) { |
| 5287 | enum nl80211_wpa_versions ver = 0; |
| 5288 | |
| 5289 | if (params->wpa_proto & WPA_PROTO_WPA) |
| 5290 | ver |= NL80211_WPA_VERSION_1; |
| 5291 | if (params->wpa_proto & WPA_PROTO_RSN) |
| 5292 | ver |= NL80211_WPA_VERSION_2; |
| 5293 | |
| 5294 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5295 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 5296 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5297 | } |
| 5298 | |
| 5299 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
| 5300 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
| 5301 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5302 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 5303 | cipher)) |
| 5304 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5305 | } |
| 5306 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 5307 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
| 5308 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { |
| 5309 | /* |
| 5310 | * This is likely to work even though many drivers do not |
| 5311 | * advertise support for operations without GTK. |
| 5312 | */ |
| 5313 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); |
| 5314 | } else if (params->group_suite != WPA_CIPHER_NONE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5315 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
| 5316 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5317 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
| 5318 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5319 | } |
| 5320 | |
| 5321 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 5322 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 5323 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || |
| 5324 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5325 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5326 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
| 5327 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5328 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5329 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5330 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 || |
| 5331 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA256 || |
| 5332 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA384 || |
| 5333 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA256 || |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5334 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA384 || |
| 5335 | params->key_mgmt_suite == WPA_KEY_MGMT_OWE || |
| 5336 | params->key_mgmt_suite == WPA_KEY_MGMT_DPP) { |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5337 | int mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5338 | |
| 5339 | switch (params->key_mgmt_suite) { |
| 5340 | case WPA_KEY_MGMT_CCKM: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5341 | mgmt = RSN_AUTH_KEY_MGMT_CCKM; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5342 | break; |
| 5343 | case WPA_KEY_MGMT_IEEE8021X: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5344 | mgmt = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5345 | break; |
| 5346 | case WPA_KEY_MGMT_FT_IEEE8021X: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5347 | mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5348 | break; |
| 5349 | case WPA_KEY_MGMT_FT_PSK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5350 | mgmt = RSN_AUTH_KEY_MGMT_FT_PSK; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5351 | break; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5352 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5353 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SHA256; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5354 | break; |
| 5355 | case WPA_KEY_MGMT_PSK_SHA256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5356 | mgmt = RSN_AUTH_KEY_MGMT_PSK_SHA256; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5357 | break; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5358 | case WPA_KEY_MGMT_OSEN: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5359 | mgmt = RSN_AUTH_KEY_MGMT_OSEN; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5360 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5361 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5362 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5363 | break; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5364 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5365 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5366 | break; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5367 | case WPA_KEY_MGMT_FILS_SHA256: |
| 5368 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA256; |
| 5369 | break; |
| 5370 | case WPA_KEY_MGMT_FILS_SHA384: |
| 5371 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA384; |
| 5372 | break; |
| 5373 | case WPA_KEY_MGMT_FT_FILS_SHA256: |
| 5374 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256; |
| 5375 | break; |
| 5376 | case WPA_KEY_MGMT_FT_FILS_SHA384: |
| 5377 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384; |
| 5378 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5379 | case WPA_KEY_MGMT_OWE: |
| 5380 | mgmt = RSN_AUTH_KEY_MGMT_OWE; |
| 5381 | break; |
| 5382 | case WPA_KEY_MGMT_DPP: |
| 5383 | mgmt = RSN_AUTH_KEY_MGMT_DPP; |
| 5384 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5385 | case WPA_KEY_MGMT_PSK: |
| 5386 | default: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5387 | mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5388 | break; |
| 5389 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5390 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5391 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
| 5392 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5393 | } |
| 5394 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5395 | /* Add PSK in case of 4-way handshake offload */ |
| 5396 | if (params->psk && |
| 5397 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE)) { |
| 5398 | wpa_hexdump_key(MSG_DEBUG, " * PSK", params->psk, 32); |
| 5399 | if (nla_put(msg, NL80211_ATTR_PMK, 32, params->psk)) |
| 5400 | return -1; |
| 5401 | } |
| 5402 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5403 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 5404 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5405 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 5406 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 5407 | (params->pairwise_suite == WPA_CIPHER_NONE || |
| 5408 | params->pairwise_suite == WPA_CIPHER_WEP104 || |
| 5409 | params->pairwise_suite == WPA_CIPHER_WEP40) && |
| 5410 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 5411 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
| 5412 | return -1; |
| 5413 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5414 | if (params->rrm_used) { |
| 5415 | u32 drv_rrm_flags = drv->capa.rrm_flags; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5416 | if ((!((drv_rrm_flags & |
| 5417 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && |
| 5418 | (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && |
| 5419 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5420 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
| 5421 | return -1; |
| 5422 | } |
| 5423 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5424 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5425 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5426 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5427 | if (params->p2p) |
| 5428 | wpa_printf(MSG_DEBUG, " * P2P group"); |
| 5429 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5430 | if (params->pbss) { |
| 5431 | wpa_printf(MSG_DEBUG, " * PBSS"); |
| 5432 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 5433 | return -1; |
| 5434 | } |
| 5435 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 5436 | drv->connect_reassoc = 0; |
| 5437 | if (params->prev_bssid) { |
| 5438 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, |
| 5439 | MAC2STR(params->prev_bssid)); |
| 5440 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
| 5441 | params->prev_bssid)) |
| 5442 | return -1; |
| 5443 | drv->connect_reassoc = 1; |
| 5444 | } |
| 5445 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5446 | if ((params->auth_alg & WPA_AUTH_ALG_FILS) && |
| 5447 | nl80211_put_fils_connect_params(drv, params, msg) != 0) |
| 5448 | return -1; |
| 5449 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5450 | if ((params->auth_alg & WPA_AUTH_ALG_SAE) && |
| 5451 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) && |
| 5452 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) |
| 5453 | return -1; |
| 5454 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5455 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5456 | } |
| 5457 | |
| 5458 | |
| 5459 | static int wpa_driver_nl80211_try_connect( |
| 5460 | struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5461 | struct wpa_driver_associate_params *params, |
| 5462 | struct nl_handle *nl_connect) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5463 | { |
| 5464 | struct nl_msg *msg; |
| 5465 | enum nl80211_auth_type type; |
| 5466 | int ret; |
| 5467 | int algs; |
| 5468 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5469 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5470 | if (params->req_key_mgmt_offload && params->psk && |
| 5471 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 5472 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
| 5473 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { |
| 5474 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); |
| 5475 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); |
| 5476 | if (ret) |
| 5477 | return ret; |
| 5478 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5479 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5480 | |
| 5481 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
| 5482 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5483 | if (!msg) |
| 5484 | return -1; |
| 5485 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5486 | ret = nl80211_connect_common(drv, params, msg); |
| 5487 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5488 | goto fail; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5489 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5490 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 5491 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 5492 | goto fail; |
| 5493 | |
| 5494 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_OPTIONAL && |
| 5495 | (drv->capa.flags & WPA_DRIVER_FLAGS_MFP_OPTIONAL) && |
| 5496 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_OPTIONAL)) |
| 5497 | goto fail; |
| 5498 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5499 | algs = 0; |
| 5500 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 5501 | algs++; |
| 5502 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 5503 | algs++; |
| 5504 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 5505 | algs++; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5506 | if (params->auth_alg & WPA_AUTH_ALG_FILS) |
| 5507 | algs++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5508 | if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 5509 | algs++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5510 | if (algs > 1) { |
| 5511 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " |
| 5512 | "selection"); |
| 5513 | goto skip_auth_type; |
| 5514 | } |
| 5515 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5516 | type = get_nl_auth_type(params->auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5517 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5518 | if (type == NL80211_AUTHTYPE_MAX || |
| 5519 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5520 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5521 | |
| 5522 | skip_auth_type: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5523 | ret = nl80211_set_conn_keys(params, msg); |
| 5524 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5525 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5526 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5527 | if (nl_connect) |
| 5528 | ret = send_and_recv(drv->global, nl_connect, msg, NULL, NULL); |
| 5529 | else |
| 5530 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5531 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5532 | msg = NULL; |
| 5533 | if (ret) { |
| 5534 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " |
| 5535 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5536 | } else { |
| 5537 | wpa_printf(MSG_DEBUG, |
| 5538 | "nl80211: Connect request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5539 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5540 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5541 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5542 | nlmsg_free(msg); |
| 5543 | return ret; |
| 5544 | |
| 5545 | } |
| 5546 | |
| 5547 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5548 | static int wpa_driver_nl80211_connect( |
| 5549 | struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5550 | struct wpa_driver_associate_params *params, |
| 5551 | struct nl_handle *nl_connect) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5552 | { |
Jithu Jance | a7c60b4 | 2014-12-03 18:54:40 +0530 | [diff] [blame] | 5553 | int ret; |
| 5554 | |
| 5555 | /* Store the connection attempted bssid for future use */ |
| 5556 | if (params->bssid) |
| 5557 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 5558 | else |
| 5559 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
| 5560 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5561 | ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5562 | if (ret == -EALREADY) { |
| 5563 | /* |
| 5564 | * cfg80211 does not currently accept new connections if |
| 5565 | * we are already connected. As a workaround, force |
| 5566 | * disconnection and try again. |
| 5567 | */ |
| 5568 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " |
| 5569 | "disconnecting before reassociation " |
| 5570 | "attempt"); |
| 5571 | if (wpa_driver_nl80211_disconnect( |
| 5572 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) |
| 5573 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5574 | ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5575 | } |
| 5576 | return ret; |
| 5577 | } |
| 5578 | |
| 5579 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5580 | static int wpa_driver_nl80211_associate( |
| 5581 | void *priv, struct wpa_driver_associate_params *params) |
| 5582 | { |
| 5583 | struct i802_bss *bss = priv; |
| 5584 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5585 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5586 | struct nl_msg *msg; |
| 5587 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5588 | nl80211_unmask_11b_rates(bss); |
| 5589 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5590 | if (params->mode == IEEE80211_MODE_AP) |
| 5591 | return wpa_driver_nl80211_ap(drv, params); |
| 5592 | |
| 5593 | if (params->mode == IEEE80211_MODE_IBSS) |
| 5594 | return wpa_driver_nl80211_ibss(drv, params); |
| 5595 | |
| 5596 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5597 | enum nl80211_iftype nlmode = params->p2p ? |
| 5598 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5599 | struct nl_handle *nl_connect = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5600 | |
| 5601 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5602 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5603 | if (params->auth_alg & WPA_AUTH_ALG_SAE) |
| 5604 | nl_connect = bss->nl_connect; |
| 5605 | return wpa_driver_nl80211_connect(drv, params, nl_connect); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5606 | } |
| 5607 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5608 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5609 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5610 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
| 5611 | drv->ifindex); |
| 5612 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5613 | if (!msg) |
| 5614 | return -1; |
| 5615 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5616 | ret = nl80211_connect_common(drv, params, msg); |
| 5617 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5618 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5619 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5620 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 5621 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 5622 | goto fail; |
| 5623 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5624 | if (params->fils_kek) { |
| 5625 | wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)", |
| 5626 | (unsigned int) params->fils_kek_len); |
| 5627 | if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len, |
| 5628 | params->fils_kek)) |
| 5629 | goto fail; |
| 5630 | } |
| 5631 | if (params->fils_nonces) { |
| 5632 | wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)", |
| 5633 | params->fils_nonces, |
| 5634 | params->fils_nonces_len); |
| 5635 | if (nla_put(msg, NL80211_ATTR_FILS_NONCES, |
| 5636 | params->fils_nonces_len, params->fils_nonces)) |
| 5637 | goto fail; |
| 5638 | } |
| 5639 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5640 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5641 | msg = NULL; |
| 5642 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5643 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 5644 | "nl80211: MLME command failed (assoc): ret=%d (%s)", |
| 5645 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5646 | nl80211_dump_scan(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5647 | } else { |
| 5648 | wpa_printf(MSG_DEBUG, |
| 5649 | "nl80211: Association request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5650 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5651 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5652 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5653 | nlmsg_free(msg); |
| 5654 | return ret; |
| 5655 | } |
| 5656 | |
| 5657 | |
| 5658 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5659 | int ifindex, enum nl80211_iftype mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5660 | { |
| 5661 | struct nl_msg *msg; |
| 5662 | int ret = -ENOBUFS; |
| 5663 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5664 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
| 5665 | ifindex, mode, nl80211_iftype_str(mode)); |
| 5666 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5667 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 5668 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) |
| 5669 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5670 | |
| 5671 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5672 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5673 | if (!ret) |
| 5674 | return 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5675 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5676 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5677 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
| 5678 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); |
| 5679 | return ret; |
| 5680 | } |
| 5681 | |
| 5682 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5683 | static int wpa_driver_nl80211_set_mode_impl( |
| 5684 | struct i802_bss *bss, |
| 5685 | enum nl80211_iftype nlmode, |
| 5686 | struct hostapd_freq_params *desired_freq_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5687 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5688 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5689 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5690 | int i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5691 | int was_ap = is_ap_interface(drv->nlmode); |
| 5692 | int res; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5693 | int mode_switch_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5694 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5695 | if (TEST_FAIL()) |
| 5696 | return -1; |
| 5697 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5698 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 5699 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) |
| 5700 | mode_switch_res = 0; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5701 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5702 | if (mode_switch_res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5703 | drv->nlmode = nlmode; |
| 5704 | ret = 0; |
| 5705 | goto done; |
| 5706 | } |
| 5707 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5708 | if (mode_switch_res == -ENODEV) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5709 | return -1; |
| 5710 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5711 | if (nlmode == drv->nlmode) { |
| 5712 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
| 5713 | "requested mode - ignore error"); |
| 5714 | ret = 0; |
| 5715 | goto done; /* Already in the requested mode */ |
| 5716 | } |
| 5717 | |
| 5718 | /* mac80211 doesn't allow mode changes while the device is up, so |
| 5719 | * take the device down, try to set the mode again, and bring the |
| 5720 | * device back up. |
| 5721 | */ |
| 5722 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
| 5723 | "interface down"); |
| 5724 | for (i = 0; i < 10; i++) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5725 | res = i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5726 | if (res == -EACCES || res == -ENODEV) |
| 5727 | break; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5728 | if (res != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5729 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
| 5730 | "interface down"); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5731 | os_sleep(0, 100000); |
| 5732 | continue; |
| 5733 | } |
| 5734 | |
| 5735 | /* |
| 5736 | * Setting the mode will fail for some drivers if the phy is |
| 5737 | * on a frequency that the mode is disallowed in. |
| 5738 | */ |
| 5739 | if (desired_freq_params) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5740 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5741 | if (res) { |
| 5742 | wpa_printf(MSG_DEBUG, |
| 5743 | "nl80211: Failed to set frequency on interface"); |
| 5744 | } |
| 5745 | } |
| 5746 | |
| 5747 | /* Try to set the mode again while the interface is down */ |
| 5748 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 5749 | if (mode_switch_res == -EBUSY) { |
| 5750 | wpa_printf(MSG_DEBUG, |
| 5751 | "nl80211: Delaying mode set while interface going down"); |
| 5752 | os_sleep(0, 100000); |
| 5753 | continue; |
| 5754 | } |
| 5755 | ret = mode_switch_res; |
| 5756 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5757 | } |
| 5758 | |
| 5759 | if (!ret) { |
| 5760 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " |
| 5761 | "interface is down"); |
| 5762 | drv->nlmode = nlmode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5763 | drv->ignore_if_down_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5764 | } |
| 5765 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5766 | /* Bring the interface back up */ |
| 5767 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); |
| 5768 | if (res != 0) { |
| 5769 | wpa_printf(MSG_DEBUG, |
| 5770 | "nl80211: Failed to set interface up after switching mode"); |
| 5771 | ret = -1; |
| 5772 | } |
| 5773 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5774 | done: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5775 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5776 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " |
| 5777 | "from %d failed", nlmode, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5778 | return ret; |
| 5779 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5780 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5781 | if (is_p2p_net_interface(nlmode)) { |
| 5782 | wpa_printf(MSG_DEBUG, |
| 5783 | "nl80211: Interface %s mode change to P2P - disable 11b rates", |
| 5784 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5785 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5786 | } else if (drv->disabled_11b_rates) { |
| 5787 | wpa_printf(MSG_DEBUG, |
| 5788 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", |
| 5789 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5790 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5791 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5792 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5793 | if (is_ap_interface(nlmode)) { |
| 5794 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
| 5795 | /* Setup additional AP mode functionality if needed */ |
| 5796 | if (nl80211_setup_ap(bss)) |
| 5797 | return -1; |
| 5798 | } else if (was_ap) { |
| 5799 | /* Remove additional AP mode functionality */ |
| 5800 | nl80211_teardown_ap(bss); |
| 5801 | } else { |
| 5802 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
| 5803 | } |
| 5804 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5805 | if (is_mesh_interface(nlmode) && |
| 5806 | nl80211_mgmt_subscribe_mesh(bss)) |
| 5807 | return -1; |
| 5808 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5809 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5810 | !is_mesh_interface(nlmode) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5811 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 5812 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " |
| 5813 | "frame processing - ignore for now"); |
| 5814 | |
| 5815 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5816 | } |
| 5817 | |
| 5818 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5819 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 5820 | enum nl80211_iftype nlmode) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5821 | { |
| 5822 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); |
| 5823 | } |
| 5824 | |
| 5825 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5826 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 5827 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5828 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5829 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5830 | freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5831 | } |
| 5832 | |
| 5833 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5834 | static int wpa_driver_nl80211_get_capa(void *priv, |
| 5835 | struct wpa_driver_capa *capa) |
| 5836 | { |
| 5837 | struct i802_bss *bss = priv; |
| 5838 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 5839 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5840 | if (!drv->has_capability) |
| 5841 | return -1; |
| 5842 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5843 | if (drv->extended_capa && drv->extended_capa_mask) { |
| 5844 | capa->extended_capa = drv->extended_capa; |
| 5845 | capa->extended_capa_mask = drv->extended_capa_mask; |
| 5846 | capa->extended_capa_len = drv->extended_capa_len; |
| 5847 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5848 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5849 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5850 | } |
| 5851 | |
| 5852 | |
| 5853 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) |
| 5854 | { |
| 5855 | struct i802_bss *bss = priv; |
| 5856 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5857 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5858 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
| 5859 | bss->ifname, drv->operstate, state, |
| 5860 | state ? "UP" : "DORMANT"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5861 | drv->operstate = state; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5862 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5863 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
| 5864 | } |
| 5865 | |
| 5866 | |
| 5867 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) |
| 5868 | { |
| 5869 | struct i802_bss *bss = priv; |
| 5870 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5871 | struct nl_msg *msg; |
| 5872 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5873 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5874 | |
| 5875 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { |
| 5876 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); |
| 5877 | return 0; |
| 5878 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5879 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5880 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
| 5881 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); |
| 5882 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5883 | os_memset(&upd, 0, sizeof(upd)); |
| 5884 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 5885 | if (authorized) |
| 5886 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5887 | |
| 5888 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5889 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
| 5890 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { |
| 5891 | nlmsg_free(msg); |
| 5892 | return -ENOBUFS; |
| 5893 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5894 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5895 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5896 | if (!ret) |
| 5897 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5898 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
| 5899 | ret, strerror(-ret)); |
| 5900 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5901 | } |
| 5902 | |
| 5903 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5904 | /* Set kernel driver on given frequency (MHz) */ |
| 5905 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5906 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5907 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5908 | return nl80211_set_channel(bss, freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5909 | } |
| 5910 | |
| 5911 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5912 | static inline int min_int(int a, int b) |
| 5913 | { |
| 5914 | if (a < b) |
| 5915 | return a; |
| 5916 | return b; |
| 5917 | } |
| 5918 | |
| 5919 | |
| 5920 | static int get_key_handler(struct nl_msg *msg, void *arg) |
| 5921 | { |
| 5922 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5923 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5924 | |
| 5925 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5926 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5927 | |
| 5928 | /* |
| 5929 | * TODO: validate the key index and mac address! |
| 5930 | * Otherwise, there's a race condition as soon as |
| 5931 | * the kernel starts sending key notifications. |
| 5932 | */ |
| 5933 | |
| 5934 | if (tb[NL80211_ATTR_KEY_SEQ]) |
| 5935 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 5936 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); |
| 5937 | return NL_SKIP; |
| 5938 | } |
| 5939 | |
| 5940 | |
| 5941 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, |
| 5942 | int idx, u8 *seq) |
| 5943 | { |
| 5944 | struct i802_bss *bss = priv; |
| 5945 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5946 | struct nl_msg *msg; |
| 5947 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5948 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
| 5949 | NL80211_CMD_GET_KEY); |
| 5950 | if (!msg || |
| 5951 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 5952 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
| 5953 | nlmsg_free(msg); |
| 5954 | return -ENOBUFS; |
| 5955 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5956 | |
| 5957 | memset(seq, 0, 6); |
| 5958 | |
| 5959 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5960 | } |
| 5961 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5962 | |
| 5963 | static int i802_set_rts(void *priv, int rts) |
| 5964 | { |
| 5965 | struct i802_bss *bss = priv; |
| 5966 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5967 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5968 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5969 | u32 val; |
| 5970 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5971 | if (rts >= 2347) |
| 5972 | val = (u32) -1; |
| 5973 | else |
| 5974 | val = rts; |
| 5975 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5976 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 5977 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
| 5978 | nlmsg_free(msg); |
| 5979 | return -ENOBUFS; |
| 5980 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5981 | |
| 5982 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5983 | if (!ret) |
| 5984 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5985 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
| 5986 | "%d (%s)", rts, ret, strerror(-ret)); |
| 5987 | return ret; |
| 5988 | } |
| 5989 | |
| 5990 | |
| 5991 | static int i802_set_frag(void *priv, int frag) |
| 5992 | { |
| 5993 | struct i802_bss *bss = priv; |
| 5994 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5995 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5996 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5997 | u32 val; |
| 5998 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5999 | if (frag >= 2346) |
| 6000 | val = (u32) -1; |
| 6001 | else |
| 6002 | val = frag; |
| 6003 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6004 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 6005 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
| 6006 | nlmsg_free(msg); |
| 6007 | return -ENOBUFS; |
| 6008 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6009 | |
| 6010 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6011 | if (!ret) |
| 6012 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6013 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
| 6014 | "%d: %d (%s)", frag, ret, strerror(-ret)); |
| 6015 | return ret; |
| 6016 | } |
| 6017 | |
| 6018 | |
| 6019 | static int i802_flush(void *priv) |
| 6020 | { |
| 6021 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6022 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6023 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6024 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6025 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
| 6026 | bss->ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6027 | |
| 6028 | /* |
| 6029 | * XXX: FIX! this needs to flush all VLANs too |
| 6030 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6031 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
| 6032 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6033 | if (res) { |
| 6034 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " |
| 6035 | "(%s)", res, strerror(-res)); |
| 6036 | } |
| 6037 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6038 | } |
| 6039 | |
| 6040 | |
| 6041 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
| 6042 | { |
| 6043 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6044 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6045 | struct hostap_sta_driver_data *data = arg; |
| 6046 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; |
| 6047 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
| 6048 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, |
| 6049 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, |
| 6050 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, |
| 6051 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
| 6052 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 6053 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6054 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
| 6055 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6056 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6057 | [NL80211_STA_INFO_ACK_SIGNAL] = { .type = NLA_U8 }, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6058 | }; |
| 6059 | struct nlattr *rate[NL80211_RATE_INFO_MAX + 1]; |
| 6060 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 6061 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 6062 | [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 }, |
| 6063 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 6064 | [NL80211_RATE_INFO_VHT_MCS] = { .type = NLA_U8 }, |
| 6065 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 6066 | [NL80211_RATE_INFO_VHT_NSS] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6067 | }; |
| 6068 | |
| 6069 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6070 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6071 | |
| 6072 | /* |
| 6073 | * TODO: validate the interface and mac address! |
| 6074 | * Otherwise, there's a race condition as soon as |
| 6075 | * the kernel starts sending station notifications. |
| 6076 | */ |
| 6077 | |
| 6078 | if (!tb[NL80211_ATTR_STA_INFO]) { |
| 6079 | wpa_printf(MSG_DEBUG, "sta stats missing!"); |
| 6080 | return NL_SKIP; |
| 6081 | } |
| 6082 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, |
| 6083 | tb[NL80211_ATTR_STA_INFO], |
| 6084 | stats_policy)) { |
| 6085 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); |
| 6086 | return NL_SKIP; |
| 6087 | } |
| 6088 | |
| 6089 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) |
| 6090 | data->inactive_msec = |
| 6091 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6092 | /* For backwards compatibility, fetch the 32-bit counters first. */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6093 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
| 6094 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); |
| 6095 | if (stats[NL80211_STA_INFO_TX_BYTES]) |
| 6096 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6097 | if (stats[NL80211_STA_INFO_RX_BYTES64] && |
| 6098 | stats[NL80211_STA_INFO_TX_BYTES64]) { |
| 6099 | /* |
| 6100 | * The driver supports 64-bit counters, so use them to override |
| 6101 | * the 32-bit values. |
| 6102 | */ |
| 6103 | data->rx_bytes = |
| 6104 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); |
| 6105 | data->tx_bytes = |
| 6106 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); |
| 6107 | data->bytes_64bit = 1; |
| 6108 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6109 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
| 6110 | data->rx_packets = |
| 6111 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); |
| 6112 | if (stats[NL80211_STA_INFO_TX_PACKETS]) |
| 6113 | data->tx_packets = |
| 6114 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 6115 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
| 6116 | data->tx_retry_failed = |
| 6117 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6118 | if (stats[NL80211_STA_INFO_SIGNAL]) |
| 6119 | data->signal = nla_get_u8(stats[NL80211_STA_INFO_SIGNAL]); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6120 | if (stats[NL80211_STA_INFO_ACK_SIGNAL]) { |
| 6121 | data->last_ack_rssi = |
| 6122 | nla_get_u8(stats[NL80211_STA_INFO_ACK_SIGNAL]); |
| 6123 | data->flags |= STA_DRV_DATA_LAST_ACK_RSSI; |
| 6124 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6125 | |
| 6126 | if (stats[NL80211_STA_INFO_TX_BITRATE] && |
| 6127 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, |
| 6128 | stats[NL80211_STA_INFO_TX_BITRATE], |
| 6129 | rate_policy) == 0) { |
| 6130 | if (rate[NL80211_RATE_INFO_BITRATE32]) |
| 6131 | data->current_tx_rate = |
| 6132 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); |
| 6133 | else if (rate[NL80211_RATE_INFO_BITRATE]) |
| 6134 | data->current_tx_rate = |
| 6135 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); |
| 6136 | |
| 6137 | if (rate[NL80211_RATE_INFO_MCS]) { |
| 6138 | data->tx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]); |
| 6139 | data->flags |= STA_DRV_DATA_TX_MCS; |
| 6140 | } |
| 6141 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { |
| 6142 | data->tx_vhtmcs = |
| 6143 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); |
| 6144 | data->flags |= STA_DRV_DATA_TX_VHT_MCS; |
| 6145 | } |
| 6146 | if (rate[NL80211_RATE_INFO_SHORT_GI]) |
| 6147 | data->flags |= STA_DRV_DATA_TX_SHORT_GI; |
| 6148 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { |
| 6149 | data->tx_vht_nss = |
| 6150 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); |
| 6151 | data->flags |= STA_DRV_DATA_TX_VHT_NSS; |
| 6152 | } |
| 6153 | } |
| 6154 | |
| 6155 | if (stats[NL80211_STA_INFO_RX_BITRATE] && |
| 6156 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, |
| 6157 | stats[NL80211_STA_INFO_RX_BITRATE], |
| 6158 | rate_policy) == 0) { |
| 6159 | if (rate[NL80211_RATE_INFO_BITRATE32]) |
| 6160 | data->current_rx_rate = |
| 6161 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); |
| 6162 | else if (rate[NL80211_RATE_INFO_BITRATE]) |
| 6163 | data->current_rx_rate = |
| 6164 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); |
| 6165 | |
| 6166 | if (rate[NL80211_RATE_INFO_MCS]) { |
| 6167 | data->rx_mcs = |
| 6168 | nla_get_u8(rate[NL80211_RATE_INFO_MCS]); |
| 6169 | data->flags |= STA_DRV_DATA_RX_MCS; |
| 6170 | } |
| 6171 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { |
| 6172 | data->rx_vhtmcs = |
| 6173 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); |
| 6174 | data->flags |= STA_DRV_DATA_RX_VHT_MCS; |
| 6175 | } |
| 6176 | if (rate[NL80211_RATE_INFO_SHORT_GI]) |
| 6177 | data->flags |= STA_DRV_DATA_RX_SHORT_GI; |
| 6178 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { |
| 6179 | data->rx_vht_nss = |
| 6180 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); |
| 6181 | data->flags |= STA_DRV_DATA_RX_VHT_NSS; |
| 6182 | } |
| 6183 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6184 | |
| 6185 | return NL_SKIP; |
| 6186 | } |
| 6187 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6188 | static int i802_read_sta_data(struct i802_bss *bss, |
| 6189 | struct hostap_sta_driver_data *data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6190 | const u8 *addr) |
| 6191 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6192 | struct nl_msg *msg; |
| 6193 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6194 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
| 6195 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 6196 | nlmsg_free(msg); |
| 6197 | return -ENOBUFS; |
| 6198 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6199 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6200 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6201 | } |
| 6202 | |
| 6203 | |
| 6204 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
| 6205 | int cw_min, int cw_max, int burst_time) |
| 6206 | { |
| 6207 | struct i802_bss *bss = priv; |
| 6208 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6209 | struct nl_msg *msg; |
| 6210 | struct nlattr *txq, *params; |
| 6211 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6212 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6213 | if (!msg) |
| 6214 | return -1; |
| 6215 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6216 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
| 6217 | if (!txq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6218 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6219 | |
| 6220 | /* We are only sending parameters for a single TXQ at a time */ |
| 6221 | params = nla_nest_start(msg, 1); |
| 6222 | if (!params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6223 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6224 | |
| 6225 | switch (queue) { |
| 6226 | case 0: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6227 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
| 6228 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6229 | break; |
| 6230 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6231 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
| 6232 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6233 | break; |
| 6234 | case 2: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6235 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
| 6236 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6237 | break; |
| 6238 | case 3: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6239 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
| 6240 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6241 | break; |
| 6242 | } |
| 6243 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
| 6244 | * 32 usec, so need to convert the value here. */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6245 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
| 6246 | (burst_time * 100 + 16) / 32) || |
| 6247 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || |
| 6248 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || |
| 6249 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) |
| 6250 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6251 | |
| 6252 | nla_nest_end(msg, params); |
| 6253 | |
| 6254 | nla_nest_end(msg, txq); |
| 6255 | |
| 6256 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 6257 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6258 | msg = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6259 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6260 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6261 | return -1; |
| 6262 | } |
| 6263 | |
| 6264 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6265 | 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] | 6266 | const char *ifname, int vlan_id) |
| 6267 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6268 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6269 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6270 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6271 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6272 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
| 6273 | ", ifname=%s[%d], vlan_id=%d)", |
| 6274 | bss->ifname, if_nametoindex(bss->ifname), |
| 6275 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6276 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 6277 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 6278 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { |
| 6279 | nlmsg_free(msg); |
| 6280 | return -ENOBUFS; |
| 6281 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6282 | |
| 6283 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6284 | if (ret < 0) { |
| 6285 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" |
| 6286 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", |
| 6287 | MAC2STR(addr), ifname, vlan_id, ret, |
| 6288 | strerror(-ret)); |
| 6289 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6290 | return ret; |
| 6291 | } |
| 6292 | |
| 6293 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6294 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
| 6295 | { |
| 6296 | struct hostap_sta_driver_data data; |
| 6297 | int ret; |
| 6298 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 6299 | os_memset(&data, 0, sizeof(data)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6300 | data.inactive_msec = (unsigned long) -1; |
| 6301 | ret = i802_read_sta_data(priv, &data, addr); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6302 | if (ret == -ENOENT) |
| 6303 | return -ENOENT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6304 | if (ret || data.inactive_msec == (unsigned long) -1) |
| 6305 | return -1; |
| 6306 | return data.inactive_msec / 1000; |
| 6307 | } |
| 6308 | |
| 6309 | |
| 6310 | static int i802_sta_clear_stats(void *priv, const u8 *addr) |
| 6311 | { |
| 6312 | #if 0 |
| 6313 | /* TODO */ |
| 6314 | #endif |
| 6315 | return 0; |
| 6316 | } |
| 6317 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6318 | |
| 6319 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
| 6320 | int reason) |
| 6321 | { |
| 6322 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6323 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6324 | struct ieee80211_mgmt mgmt; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 6325 | u8 channel; |
| 6326 | |
| 6327 | if (ieee80211_freq_to_chan(bss->freq, &channel) == |
| 6328 | HOSTAPD_MODE_IEEE80211AD) { |
| 6329 | /* Deauthentication is not used in DMG/IEEE 802.11ad; |
| 6330 | * disassociate the STA instead. */ |
| 6331 | return i802_sta_disassoc(priv, own_addr, addr, reason); |
| 6332 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6333 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6334 | if (is_mesh_interface(drv->nlmode)) |
| 6335 | return -1; |
| 6336 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6337 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6338 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6339 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6340 | memset(&mgmt, 0, sizeof(mgmt)); |
| 6341 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 6342 | WLAN_FC_STYPE_DEAUTH); |
| 6343 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 6344 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 6345 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 6346 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
| 6347 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 6348 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6349 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6350 | 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6351 | } |
| 6352 | |
| 6353 | |
| 6354 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
| 6355 | int reason) |
| 6356 | { |
| 6357 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6358 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6359 | struct ieee80211_mgmt mgmt; |
| 6360 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6361 | if (is_mesh_interface(drv->nlmode)) |
| 6362 | return -1; |
| 6363 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6364 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6365 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6366 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6367 | memset(&mgmt, 0, sizeof(mgmt)); |
| 6368 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 6369 | WLAN_FC_STYPE_DISASSOC); |
| 6370 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 6371 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 6372 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 6373 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
| 6374 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 6375 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6376 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6377 | 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6378 | } |
| 6379 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6380 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6381 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
| 6382 | { |
| 6383 | char buf[200], *pos, *end; |
| 6384 | int i, res; |
| 6385 | |
| 6386 | pos = buf; |
| 6387 | end = pos + sizeof(buf); |
| 6388 | |
| 6389 | for (i = 0; i < drv->num_if_indices; i++) { |
| 6390 | if (!drv->if_indices[i]) |
| 6391 | continue; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6392 | res = os_snprintf(pos, end - pos, " %d(%d)", |
| 6393 | drv->if_indices[i], |
| 6394 | drv->if_indices_reason[i]); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6395 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6396 | break; |
| 6397 | pos += res; |
| 6398 | } |
| 6399 | *pos = '\0'; |
| 6400 | |
| 6401 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", |
| 6402 | drv->num_if_indices, buf); |
| 6403 | } |
| 6404 | |
| 6405 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6406 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 6407 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6408 | { |
| 6409 | int i; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6410 | int *old, *old_reason; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6411 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6412 | wpa_printf(MSG_DEBUG, |
| 6413 | "nl80211: Add own interface ifindex %d (ifidx_reason %d)", |
| 6414 | ifidx, ifidx_reason); |
| 6415 | if (have_ifidx(drv, ifidx, ifidx_reason)) { |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6416 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
| 6417 | ifidx); |
| 6418 | return; |
| 6419 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6420 | for (i = 0; i < drv->num_if_indices; i++) { |
| 6421 | if (drv->if_indices[i] == 0) { |
| 6422 | drv->if_indices[i] = ifidx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6423 | drv->if_indices_reason[i] = ifidx_reason; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6424 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6425 | return; |
| 6426 | } |
| 6427 | } |
| 6428 | |
| 6429 | if (drv->if_indices != drv->default_if_indices) |
| 6430 | old = drv->if_indices; |
| 6431 | else |
| 6432 | old = NULL; |
| 6433 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6434 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
| 6435 | old_reason = drv->if_indices_reason; |
| 6436 | else |
| 6437 | old_reason = NULL; |
| 6438 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6439 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
| 6440 | sizeof(int)); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6441 | drv->if_indices_reason = os_realloc_array(old_reason, |
| 6442 | drv->num_if_indices + 1, |
| 6443 | sizeof(int)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6444 | if (!drv->if_indices) { |
| 6445 | if (!old) |
| 6446 | drv->if_indices = drv->default_if_indices; |
| 6447 | else |
| 6448 | drv->if_indices = old; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6449 | } |
| 6450 | if (!drv->if_indices_reason) { |
| 6451 | if (!old_reason) |
| 6452 | drv->if_indices_reason = drv->default_if_indices_reason; |
| 6453 | else |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 6454 | drv->if_indices_reason = old_reason; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6455 | } |
| 6456 | if (!drv->if_indices || !drv->if_indices_reason) { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6457 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
| 6458 | "interfaces"); |
| 6459 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); |
| 6460 | return; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6461 | } |
| 6462 | if (!old) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6463 | os_memcpy(drv->if_indices, drv->default_if_indices, |
| 6464 | sizeof(drv->default_if_indices)); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6465 | if (!old_reason) |
| 6466 | os_memcpy(drv->if_indices_reason, |
| 6467 | drv->default_if_indices_reason, |
| 6468 | sizeof(drv->default_if_indices_reason)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6469 | drv->if_indices[drv->num_if_indices] = ifidx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6470 | drv->if_indices_reason[drv->num_if_indices] = ifidx_reason; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6471 | drv->num_if_indices++; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6472 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6473 | } |
| 6474 | |
| 6475 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6476 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 6477 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6478 | { |
| 6479 | int i; |
| 6480 | |
| 6481 | for (i = 0; i < drv->num_if_indices; i++) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6482 | if ((drv->if_indices[i] == ifidx || ifidx == IFIDX_ANY) && |
| 6483 | (drv->if_indices_reason[i] == ifidx_reason || |
| 6484 | ifidx_reason == IFIDX_ANY)) { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6485 | drv->if_indices[i] = 0; |
| 6486 | break; |
| 6487 | } |
| 6488 | } |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6489 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6490 | } |
| 6491 | |
| 6492 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6493 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 6494 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6495 | { |
| 6496 | int i; |
| 6497 | |
| 6498 | for (i = 0; i < drv->num_if_indices; i++) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6499 | if (drv->if_indices[i] == ifidx && |
| 6500 | (drv->if_indices_reason[i] == ifidx_reason || |
| 6501 | ifidx_reason == IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6502 | return 1; |
| 6503 | |
| 6504 | return 0; |
| 6505 | } |
| 6506 | |
| 6507 | |
| 6508 | 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] | 6509 | const char *bridge_ifname, char *ifname_wds) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6510 | { |
| 6511 | struct i802_bss *bss = priv; |
| 6512 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6513 | char name[IFNAMSIZ + 1]; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6514 | union wpa_event_data event; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6515 | |
| 6516 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6517 | if (ifname_wds) |
| 6518 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); |
| 6519 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6520 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
| 6521 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); |
| 6522 | if (val) { |
| 6523 | if (!if_nametoindex(name)) { |
| 6524 | if (nl80211_create_iface(drv, name, |
| 6525 | NL80211_IFTYPE_AP_VLAN, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6526 | bss->addr, 1, NULL, NULL, 0) < |
| 6527 | 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6528 | return -1; |
| 6529 | if (bridge_ifname && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6530 | linux_br_add_if(drv->global->ioctl_sock, |
| 6531 | bridge_ifname, name) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6532 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6533 | |
| 6534 | os_memset(&event, 0, sizeof(event)); |
| 6535 | event.wds_sta_interface.sta_addr = addr; |
| 6536 | event.wds_sta_interface.ifname = name; |
| 6537 | event.wds_sta_interface.istatus = INTERFACE_ADDED; |
| 6538 | wpa_supplicant_event(drv->ctx, |
| 6539 | EVENT_WDS_STA_INTERFACE_STATUS, |
| 6540 | &event); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6541 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6542 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
| 6543 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " |
| 6544 | "interface %s up", name); |
| 6545 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6546 | return i802_set_sta_vlan(priv, addr, name, 0); |
| 6547 | } else { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6548 | if (bridge_ifname) |
| 6549 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, |
| 6550 | name); |
| 6551 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6552 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 6553 | nl80211_remove_iface(drv, if_nametoindex(name)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6554 | os_memset(&event, 0, sizeof(event)); |
| 6555 | event.wds_sta_interface.sta_addr = addr; |
| 6556 | event.wds_sta_interface.ifname = name; |
| 6557 | event.wds_sta_interface.istatus = INTERFACE_REMOVED; |
| 6558 | wpa_supplicant_event(drv->ctx, EVENT_WDS_STA_INTERFACE_STATUS, |
| 6559 | &event); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 6560 | return 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6561 | } |
| 6562 | } |
| 6563 | |
| 6564 | |
| 6565 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
| 6566 | { |
| 6567 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 6568 | struct sockaddr_ll lladdr; |
| 6569 | unsigned char buf[3000]; |
| 6570 | int len; |
| 6571 | socklen_t fromlen = sizeof(lladdr); |
| 6572 | |
| 6573 | len = recvfrom(sock, buf, sizeof(buf), 0, |
| 6574 | (struct sockaddr *)&lladdr, &fromlen); |
| 6575 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6576 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
| 6577 | strerror(errno)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6578 | return; |
| 6579 | } |
| 6580 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6581 | if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6582 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
| 6583 | } |
| 6584 | |
| 6585 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6586 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
| 6587 | struct i802_bss *bss, |
| 6588 | const char *brname, const char *ifname) |
| 6589 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6590 | int br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6591 | char in_br[IFNAMSIZ]; |
| 6592 | |
| 6593 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6594 | br_ifindex = if_nametoindex(brname); |
| 6595 | if (br_ifindex == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6596 | /* |
| 6597 | * Bridge was configured, but the bridge device does |
| 6598 | * not exist. Try to add it now. |
| 6599 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6600 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6601 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
| 6602 | "bridge interface %s: %s", |
| 6603 | brname, strerror(errno)); |
| 6604 | return -1; |
| 6605 | } |
| 6606 | bss->added_bridge = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6607 | br_ifindex = if_nametoindex(brname); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6608 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6609 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6610 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6611 | |
| 6612 | if (linux_br_get(in_br, ifname) == 0) { |
| 6613 | if (os_strcmp(in_br, brname) == 0) |
| 6614 | return 0; /* already in the bridge */ |
| 6615 | |
| 6616 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " |
| 6617 | "bridge %s", ifname, in_br); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6618 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
| 6619 | 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6620 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
| 6621 | "remove interface %s from bridge " |
| 6622 | "%s: %s", |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6623 | ifname, in_br, strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6624 | return -1; |
| 6625 | } |
| 6626 | } |
| 6627 | |
| 6628 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", |
| 6629 | ifname, brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6630 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6631 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
| 6632 | "into bridge %s: %s", |
| 6633 | ifname, brname, strerror(errno)); |
| 6634 | return -1; |
| 6635 | } |
| 6636 | bss->added_if_into_bridge = 1; |
| 6637 | |
| 6638 | return 0; |
| 6639 | } |
| 6640 | |
| 6641 | |
| 6642 | static void *i802_init(struct hostapd_data *hapd, |
| 6643 | struct wpa_init_params *params) |
| 6644 | { |
| 6645 | struct wpa_driver_nl80211_data *drv; |
| 6646 | struct i802_bss *bss; |
| 6647 | size_t i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6648 | char master_ifname[IFNAMSIZ]; |
| 6649 | int ifindex, br_ifindex = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6650 | int br_added = 0; |
| 6651 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 6652 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
| 6653 | params->global_priv, 1, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6654 | params->bssid, params->driver_params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6655 | if (bss == NULL) |
| 6656 | return NULL; |
| 6657 | |
| 6658 | drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6659 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6660 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6661 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6662 | params->ifname, master_ifname); |
| 6663 | br_ifindex = if_nametoindex(master_ifname); |
| 6664 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 6665 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && |
| 6666 | linux_master_get(master_ifname, params->ifname) == 0) { |
| 6667 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", |
| 6668 | params->ifname, master_ifname); |
| 6669 | /* start listening for EAPOL on the master interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6670 | add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6671 | |
| 6672 | /* check if master itself is under bridge */ |
| 6673 | if (linux_br_get(master_ifname, master_ifname) == 0) { |
| 6674 | wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s", |
| 6675 | master_ifname); |
| 6676 | br_ifindex = if_nametoindex(master_ifname); |
| 6677 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 6678 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6679 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6680 | master_ifname[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6681 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6682 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6683 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6684 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6685 | for (i = 0; i < params->num_bridge; i++) { |
| 6686 | if (params->bridge[i]) { |
| 6687 | ifindex = if_nametoindex(params->bridge[i]); |
| 6688 | if (ifindex) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6689 | add_ifidx(drv, ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6690 | if (ifindex == br_ifindex) |
| 6691 | br_added = 1; |
| 6692 | } |
| 6693 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6694 | |
| 6695 | /* start listening for EAPOL on the default AP interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6696 | add_ifidx(drv, drv->ifindex, IFIDX_ANY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6697 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6698 | if (params->num_bridge && params->bridge[0]) { |
| 6699 | if (i802_check_bridge(drv, bss, params->bridge[0], |
| 6700 | params->ifname) < 0) |
| 6701 | goto failed; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6702 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6703 | br_added = 1; |
| 6704 | } |
| 6705 | |
| 6706 | if (!br_added && br_ifindex && |
| 6707 | (params->num_bridge == 0 || !params->bridge[0])) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6708 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6709 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6710 | #ifdef CONFIG_LIBNL3_ROUTE |
| 6711 | if (bss->added_if_into_bridge) { |
| 6712 | drv->rtnl_sk = nl_socket_alloc(); |
| 6713 | if (drv->rtnl_sk == NULL) { |
| 6714 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); |
| 6715 | goto failed; |
| 6716 | } |
| 6717 | |
| 6718 | if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) { |
| 6719 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", |
| 6720 | strerror(errno)); |
| 6721 | goto failed; |
| 6722 | } |
| 6723 | } |
| 6724 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 6725 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6726 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
| 6727 | if (drv->eapol_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6728 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
| 6729 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6730 | goto failed; |
| 6731 | } |
| 6732 | |
| 6733 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) |
| 6734 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6735 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6736 | goto failed; |
| 6737 | } |
| 6738 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6739 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 6740 | params->own_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6741 | goto failed; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6742 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6743 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6744 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
| 6745 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6746 | return bss; |
| 6747 | |
| 6748 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6749 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6750 | return NULL; |
| 6751 | } |
| 6752 | |
| 6753 | |
| 6754 | static void i802_deinit(void *priv) |
| 6755 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6756 | struct i802_bss *bss = priv; |
| 6757 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6758 | } |
| 6759 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6760 | |
| 6761 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
| 6762 | enum wpa_driver_if_type type) |
| 6763 | { |
| 6764 | switch (type) { |
| 6765 | case WPA_IF_STATION: |
| 6766 | return NL80211_IFTYPE_STATION; |
| 6767 | case WPA_IF_P2P_CLIENT: |
| 6768 | case WPA_IF_P2P_GROUP: |
| 6769 | return NL80211_IFTYPE_P2P_CLIENT; |
| 6770 | case WPA_IF_AP_VLAN: |
| 6771 | return NL80211_IFTYPE_AP_VLAN; |
| 6772 | case WPA_IF_AP_BSS: |
| 6773 | return NL80211_IFTYPE_AP; |
| 6774 | case WPA_IF_P2P_GO: |
| 6775 | return NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6776 | case WPA_IF_P2P_DEVICE: |
| 6777 | return NL80211_IFTYPE_P2P_DEVICE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6778 | case WPA_IF_MESH: |
| 6779 | return NL80211_IFTYPE_MESH_POINT; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6780 | default: |
| 6781 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6782 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6783 | } |
| 6784 | |
| 6785 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6786 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
| 6787 | { |
| 6788 | struct wpa_driver_nl80211_data *drv; |
| 6789 | dl_list_for_each(drv, &global->interfaces, |
| 6790 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6791 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6792 | return 1; |
| 6793 | } |
| 6794 | return 0; |
| 6795 | } |
| 6796 | |
| 6797 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6798 | 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] | 6799 | { |
| 6800 | unsigned int idx; |
| 6801 | |
| 6802 | if (!drv->global) |
| 6803 | return -1; |
| 6804 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6805 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6806 | for (idx = 0; idx < 64; idx++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6807 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6808 | new_addr[0] ^= idx << 2; |
| 6809 | if (!nl80211_addr_in_use(drv->global, new_addr)) |
| 6810 | break; |
| 6811 | } |
| 6812 | if (idx == 64) |
| 6813 | return -1; |
| 6814 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6815 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6816 | MACSTR, MAC2STR(new_addr)); |
| 6817 | |
| 6818 | return 0; |
| 6819 | } |
| 6820 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6821 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6822 | struct wdev_info { |
| 6823 | u64 wdev_id; |
| 6824 | int wdev_id_set; |
| 6825 | u8 macaddr[ETH_ALEN]; |
| 6826 | }; |
| 6827 | |
| 6828 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) |
| 6829 | { |
| 6830 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6831 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6832 | struct wdev_info *wi = arg; |
| 6833 | |
| 6834 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6835 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6836 | if (tb[NL80211_ATTR_WDEV]) { |
| 6837 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 6838 | wi->wdev_id_set = 1; |
| 6839 | } |
| 6840 | |
| 6841 | if (tb[NL80211_ATTR_MAC]) |
| 6842 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 6843 | ETH_ALEN); |
| 6844 | |
| 6845 | return NL_SKIP; |
| 6846 | } |
| 6847 | |
| 6848 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6849 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
| 6850 | const char *ifname, const u8 *addr, |
| 6851 | void *bss_ctx, void **drv_priv, |
| 6852 | char *force_ifname, u8 *if_addr, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6853 | const char *bridge, int use_existing, |
| 6854 | int setup_ap) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6855 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6856 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6857 | struct i802_bss *bss = priv; |
| 6858 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6859 | int ifidx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6860 | int added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6861 | |
| 6862 | if (addr) |
| 6863 | os_memcpy(if_addr, addr, ETH_ALEN); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6864 | nlmode = wpa_driver_nl80211_if_type(type); |
| 6865 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 6866 | struct wdev_info p2pdev_info; |
| 6867 | |
| 6868 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); |
| 6869 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
| 6870 | 0, nl80211_wdev_handler, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6871 | &p2pdev_info, use_existing); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6872 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
| 6873 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
| 6874 | ifname); |
| 6875 | return -1; |
| 6876 | } |
| 6877 | |
| 6878 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; |
| 6879 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; |
| 6880 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) |
| 6881 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); |
| 6882 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", |
| 6883 | ifname, |
| 6884 | (long long unsigned int) p2pdev_info.wdev_id); |
| 6885 | } else { |
| 6886 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6887 | 0, NULL, NULL, use_existing); |
| 6888 | if (use_existing && ifidx == -ENFILE) { |
| 6889 | added = 0; |
| 6890 | ifidx = if_nametoindex(ifname); |
| 6891 | } else if (ifidx < 0) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6892 | return -1; |
| 6893 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6894 | } |
| 6895 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6896 | if (!addr) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6897 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6898 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
| 6899 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6900 | ifname, if_addr) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6901 | if (added) |
| 6902 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6903 | return -1; |
| 6904 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6905 | } |
| 6906 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6907 | if (!addr && |
| 6908 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6909 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
| 6910 | type == WPA_IF_STATION)) { |
| 6911 | /* Enforce unique address */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6912 | u8 new_addr[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6913 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6914 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6915 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6916 | if (added) |
| 6917 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6918 | return -1; |
| 6919 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6920 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6921 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6922 | "for interface %s type %d", ifname, type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6923 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6924 | if (added) |
| 6925 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6926 | return -1; |
| 6927 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6928 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6929 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6930 | if (added) |
| 6931 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6932 | return -1; |
| 6933 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6934 | } |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6935 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6936 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6937 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6938 | if (type == WPA_IF_AP_BSS && setup_ap) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6939 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
| 6940 | if (new_bss == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6941 | if (added) |
| 6942 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6943 | return -1; |
| 6944 | } |
| 6945 | |
| 6946 | if (bridge && |
| 6947 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { |
| 6948 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " |
| 6949 | "interface %s to a bridge %s", |
| 6950 | ifname, bridge); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6951 | if (added) |
| 6952 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6953 | os_free(new_bss); |
| 6954 | return -1; |
| 6955 | } |
| 6956 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6957 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
| 6958 | { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6959 | if (added) |
| 6960 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6961 | os_free(new_bss); |
| 6962 | return -1; |
| 6963 | } |
| 6964 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6965 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6966 | new_bss->ifindex = ifidx; |
| 6967 | new_bss->drv = drv; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6968 | new_bss->next = drv->first_bss->next; |
| 6969 | new_bss->freq = drv->first_bss->freq; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6970 | new_bss->ctx = bss_ctx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6971 | new_bss->added_if = added; |
| 6972 | drv->first_bss->next = new_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6973 | if (drv_priv) |
| 6974 | *drv_priv = new_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6975 | nl80211_init_bss(new_bss); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6976 | |
| 6977 | /* Subscribe management frames for this WPA_IF_AP_BSS */ |
| 6978 | if (nl80211_setup_ap(new_bss)) |
| 6979 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6980 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6981 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6982 | if (drv->global) |
| 6983 | drv->global->if_add_ifindex = ifidx; |
| 6984 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6985 | /* |
| 6986 | * Some virtual interfaces need to process EAPOL packets and events on |
| 6987 | * the parent interface. This is used mainly with hostapd. |
| 6988 | */ |
| 6989 | if (ifidx > 0 && |
| 6990 | (drv->hostapd || |
| 6991 | nlmode == NL80211_IFTYPE_AP_VLAN || |
| 6992 | nlmode == NL80211_IFTYPE_WDS || |
| 6993 | nlmode == NL80211_IFTYPE_MONITOR)) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6994 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6995 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6996 | return 0; |
| 6997 | } |
| 6998 | |
| 6999 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7000 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7001 | enum wpa_driver_if_type type, |
| 7002 | const char *ifname) |
| 7003 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7004 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7005 | int ifindex = if_nametoindex(ifname); |
| 7006 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7007 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
| 7008 | __func__, type, ifname, ifindex, bss->added_if); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 7009 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7010 | nl80211_remove_iface(drv, ifindex); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 7011 | else if (ifindex > 0 && !bss->added_if) { |
| 7012 | struct wpa_driver_nl80211_data *drv2; |
| 7013 | dl_list_for_each(drv2, &drv->global->interfaces, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7014 | struct wpa_driver_nl80211_data, list) { |
| 7015 | del_ifidx(drv2, ifindex, IFIDX_ANY); |
| 7016 | del_ifidx(drv2, IFIDX_ANY, ifindex); |
| 7017 | } |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 7018 | } |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7019 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7020 | if (type != WPA_IF_AP_BSS) |
| 7021 | return 0; |
| 7022 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7023 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7024 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 7025 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7026 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 7027 | "interface %s from bridge %s: %s", |
| 7028 | bss->ifname, bss->brname, strerror(errno)); |
| 7029 | } |
| 7030 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7031 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7032 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 7033 | "bridge %s: %s", |
| 7034 | bss->brname, strerror(errno)); |
| 7035 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7036 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7037 | if (bss != drv->first_bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7038 | struct i802_bss *tbss; |
| 7039 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7040 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
| 7041 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7042 | if (tbss->next == bss) { |
| 7043 | tbss->next = bss->next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7044 | /* Unsubscribe management frames */ |
| 7045 | nl80211_teardown_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7046 | nl80211_destroy_bss(bss); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7047 | if (!bss->added_if) |
| 7048 | i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7049 | os_free(bss); |
| 7050 | bss = NULL; |
| 7051 | break; |
| 7052 | } |
| 7053 | } |
| 7054 | if (bss) |
| 7055 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " |
| 7056 | "BSS %p in the list", __func__, bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7057 | } else { |
| 7058 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
| 7059 | nl80211_teardown_ap(bss); |
| 7060 | if (!bss->added_if && !drv->first_bss->next) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 7061 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7062 | nl80211_destroy_bss(bss); |
| 7063 | if (!bss->added_if) |
| 7064 | i802_set_iface_flags(bss, 0); |
| 7065 | if (drv->first_bss->next) { |
| 7066 | drv->first_bss = drv->first_bss->next; |
| 7067 | drv->ctx = drv->first_bss->ctx; |
| 7068 | os_free(bss); |
| 7069 | } else { |
| 7070 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); |
| 7071 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7072 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7073 | |
| 7074 | return 0; |
| 7075 | } |
| 7076 | |
| 7077 | |
| 7078 | static int cookie_handler(struct nl_msg *msg, void *arg) |
| 7079 | { |
| 7080 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7081 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7082 | u64 *cookie = arg; |
| 7083 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7084 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7085 | if (tb[NL80211_ATTR_COOKIE]) |
| 7086 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 7087 | return NL_SKIP; |
| 7088 | } |
| 7089 | |
| 7090 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7091 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7092 | unsigned int freq, unsigned int wait, |
| 7093 | const u8 *buf, size_t buf_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7094 | u64 *cookie_out, int no_cck, int no_ack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7095 | int offchanok, const u16 *csa_offs, |
| 7096 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7097 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7098 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7099 | struct nl_msg *msg; |
| 7100 | u64 cookie; |
| 7101 | int ret = -1; |
| 7102 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7103 | 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] | 7104 | "no_ack=%d offchanok=%d", |
| 7105 | freq, wait, no_cck, no_ack, offchanok); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7106 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7107 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7108 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
| 7109 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 7110 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || |
| 7111 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 7112 | drv->test_use_roc_tx) && |
| 7113 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || |
| 7114 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || |
| 7115 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7116 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
| 7117 | csa_offs_len * sizeof(u16), csa_offs)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7118 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
| 7119 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7120 | |
| 7121 | cookie = 0; |
| 7122 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 7123 | msg = NULL; |
| 7124 | if (ret) { |
| 7125 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 7126 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
| 7127 | freq, wait); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7128 | } else { |
| 7129 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " |
| 7130 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
| 7131 | (long long unsigned int) cookie); |
| 7132 | |
| 7133 | if (cookie_out) |
| 7134 | *cookie_out = no_ack ? (u64) -1 : cookie; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7135 | |
| 7136 | if (drv->num_send_action_cookies == MAX_SEND_ACTION_COOKIES) { |
| 7137 | wpa_printf(MSG_DEBUG, |
| 7138 | "nl80211: Drop oldest pending send action cookie 0x%llx", |
| 7139 | (long long unsigned int) |
| 7140 | drv->send_action_cookies[0]); |
| 7141 | os_memmove(&drv->send_action_cookies[0], |
| 7142 | &drv->send_action_cookies[1], |
| 7143 | (MAX_SEND_ACTION_COOKIES - 1) * |
| 7144 | sizeof(u64)); |
| 7145 | drv->num_send_action_cookies--; |
| 7146 | } |
| 7147 | drv->send_action_cookies[drv->num_send_action_cookies] = cookie; |
| 7148 | drv->num_send_action_cookies++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7149 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7150 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7151 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7152 | nlmsg_free(msg); |
| 7153 | return ret; |
| 7154 | } |
| 7155 | |
| 7156 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7157 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
| 7158 | unsigned int freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7159 | unsigned int wait_time, |
| 7160 | const u8 *dst, const u8 *src, |
| 7161 | const u8 *bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7162 | const u8 *data, size_t data_len, |
| 7163 | int no_cck) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7164 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7165 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7166 | int ret = -1; |
| 7167 | u8 *buf; |
| 7168 | struct ieee80211_hdr *hdr; |
| 7169 | |
| 7170 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7171 | "freq=%u MHz wait=%d ms no_cck=%d)", |
| 7172 | drv->ifindex, freq, wait_time, no_cck); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7173 | |
| 7174 | buf = os_zalloc(24 + data_len); |
| 7175 | if (buf == NULL) |
| 7176 | return ret; |
| 7177 | os_memcpy(buf + 24, data, data_len); |
| 7178 | hdr = (struct ieee80211_hdr *) buf; |
| 7179 | hdr->frame_control = |
| 7180 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); |
| 7181 | os_memcpy(hdr->addr1, dst, ETH_ALEN); |
| 7182 | os_memcpy(hdr->addr2, src, ETH_ALEN); |
| 7183 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); |
| 7184 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 7185 | if (os_memcmp(bss->addr, src, ETH_ALEN) != 0) { |
| 7186 | wpa_printf(MSG_DEBUG, "nl80211: Use random TA " MACSTR, |
| 7187 | MAC2STR(src)); |
| 7188 | os_memcpy(bss->rand_addr, src, ETH_ALEN); |
| 7189 | } else { |
| 7190 | os_memset(bss->rand_addr, 0, ETH_ALEN); |
| 7191 | } |
| 7192 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7193 | if (is_ap_interface(drv->nlmode) && |
| 7194 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 7195 | (int) freq == bss->freq || drv->device_ap_sme || |
| 7196 | !drv->use_monitor)) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7197 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
| 7198 | 0, freq, no_cck, 1, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7199 | wait_time, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7200 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7201 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7202 | 24 + data_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7203 | &drv->send_action_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7204 | no_cck, 0, 1, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7205 | |
| 7206 | os_free(buf); |
| 7207 | return ret; |
| 7208 | } |
| 7209 | |
| 7210 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7211 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7212 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7213 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7214 | struct nl_msg *msg; |
| 7215 | int ret; |
| 7216 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 7217 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7218 | (long long unsigned int) cookie); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7219 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7220 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7221 | nlmsg_free(msg); |
| 7222 | return; |
| 7223 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7224 | |
| 7225 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7226 | if (ret) |
| 7227 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " |
| 7228 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7229 | } |
| 7230 | |
| 7231 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7232 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
| 7233 | { |
| 7234 | struct i802_bss *bss = priv; |
| 7235 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7236 | unsigned int i; |
| 7237 | u64 cookie; |
| 7238 | |
| 7239 | /* Cancel the last pending TX cookie */ |
| 7240 | nl80211_frame_wait_cancel(bss, drv->send_action_cookie); |
| 7241 | |
| 7242 | /* |
| 7243 | * Cancel the other pending TX cookies, if any. This is needed since |
| 7244 | * the driver may keep a list of all pending offchannel TX operations |
| 7245 | * and free up the radio only once they have expired or cancelled. |
| 7246 | */ |
| 7247 | for (i = drv->num_send_action_cookies; i > 0; i--) { |
| 7248 | cookie = drv->send_action_cookies[i - 1]; |
| 7249 | if (cookie != drv->send_action_cookie) |
| 7250 | nl80211_frame_wait_cancel(bss, cookie); |
| 7251 | } |
| 7252 | drv->num_send_action_cookies = 0; |
| 7253 | } |
| 7254 | |
| 7255 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7256 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
| 7257 | unsigned int duration) |
| 7258 | { |
| 7259 | struct i802_bss *bss = priv; |
| 7260 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7261 | struct nl_msg *msg; |
| 7262 | int ret; |
| 7263 | u64 cookie; |
| 7264 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7265 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
| 7266 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 7267 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { |
| 7268 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7269 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7270 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7271 | |
| 7272 | cookie = 0; |
| 7273 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 7274 | if (ret == 0) { |
| 7275 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " |
| 7276 | "0x%llx for freq=%u MHz duration=%u", |
| 7277 | (long long unsigned int) cookie, freq, duration); |
| 7278 | drv->remain_on_chan_cookie = cookie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7279 | drv->pending_remain_on_chan = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7280 | return 0; |
| 7281 | } |
| 7282 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " |
| 7283 | "(freq=%d duration=%u): %d (%s)", |
| 7284 | freq, duration, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7285 | return -1; |
| 7286 | } |
| 7287 | |
| 7288 | |
| 7289 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) |
| 7290 | { |
| 7291 | struct i802_bss *bss = priv; |
| 7292 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7293 | struct nl_msg *msg; |
| 7294 | int ret; |
| 7295 | |
| 7296 | if (!drv->pending_remain_on_chan) { |
| 7297 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " |
| 7298 | "to cancel"); |
| 7299 | return -1; |
| 7300 | } |
| 7301 | |
| 7302 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " |
| 7303 | "0x%llx", |
| 7304 | (long long unsigned int) drv->remain_on_chan_cookie); |
| 7305 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7306 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
| 7307 | if (!msg || |
| 7308 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
| 7309 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7310 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7311 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7312 | |
| 7313 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7314 | if (ret == 0) |
| 7315 | return 0; |
| 7316 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " |
| 7317 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7318 | return -1; |
| 7319 | } |
| 7320 | |
| 7321 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7322 | 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] | 7323 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7324 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 7325 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7326 | if (!report) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7327 | if (bss->nl_preq && drv->device_ap_sme && |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 7328 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
| 7329 | !bss->static_ap) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7330 | /* |
| 7331 | * Do not disable Probe Request reporting that was |
| 7332 | * enabled in nl80211_setup_ap(). |
| 7333 | */ |
| 7334 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " |
| 7335 | "Probe Request reporting nl_preq=%p while " |
| 7336 | "in AP mode", bss->nl_preq); |
| 7337 | } else if (bss->nl_preq) { |
| 7338 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
| 7339 | "reporting nl_preq=%p", bss->nl_preq); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7340 | nl80211_destroy_eloop_handle(&bss->nl_preq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7341 | } |
| 7342 | return 0; |
| 7343 | } |
| 7344 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7345 | if (bss->nl_preq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7346 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7347 | "already on! nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7348 | return 0; |
| 7349 | } |
| 7350 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7351 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
| 7352 | if (bss->nl_preq == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7353 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7354 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
| 7355 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7356 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7357 | if (nl80211_register_frame(bss, bss->nl_preq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7358 | (WLAN_FC_TYPE_MGMT << 2) | |
| 7359 | (WLAN_FC_STYPE_PROBE_REQ << 4), |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7360 | NULL, 0) < 0) |
| 7361 | goto out_err; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 7362 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7363 | nl80211_register_eloop_read(&bss->nl_preq, |
| 7364 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7365 | bss->nl_cb, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7366 | |
| 7367 | return 0; |
| 7368 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7369 | out_err: |
| 7370 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7371 | return -1; |
| 7372 | } |
| 7373 | |
| 7374 | |
| 7375 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 7376 | int ifindex, int disabled) |
| 7377 | { |
| 7378 | struct nl_msg *msg; |
| 7379 | struct nlattr *bands, *band; |
| 7380 | int ret; |
| 7381 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7382 | wpa_printf(MSG_DEBUG, |
| 7383 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", |
| 7384 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : |
| 7385 | "no NL80211_TXRATE_LEGACY constraint"); |
| 7386 | |
| 7387 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
| 7388 | NL80211_CMD_SET_TX_BITRATE_MASK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7389 | if (!msg) |
| 7390 | return -1; |
| 7391 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7392 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 7393 | if (!bands) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7394 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7395 | |
| 7396 | /* |
| 7397 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything |
| 7398 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS |
| 7399 | * rates. All 5 GHz rates are left enabled. |
| 7400 | */ |
| 7401 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7402 | if (!band || |
| 7403 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, |
| 7404 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) |
| 7405 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7406 | nla_nest_end(msg, band); |
| 7407 | |
| 7408 | nla_nest_end(msg, bands); |
| 7409 | |
| 7410 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7411 | if (ret) { |
| 7412 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " |
| 7413 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7414 | } else |
| 7415 | drv->disabled_11b_rates = disabled; |
| 7416 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7417 | return ret; |
| 7418 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7419 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7420 | nlmsg_free(msg); |
| 7421 | return -1; |
| 7422 | } |
| 7423 | |
| 7424 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7425 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
| 7426 | { |
| 7427 | struct i802_bss *bss = priv; |
| 7428 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7429 | if (!is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7430 | return -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 7431 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7432 | bss->beacon_set = 0; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7433 | |
| 7434 | /* |
| 7435 | * If the P2P GO interface was dynamically added, then it is |
| 7436 | * possible that the interface change to station is not possible. |
| 7437 | */ |
| 7438 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) |
| 7439 | return 0; |
| 7440 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7441 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7442 | } |
| 7443 | |
| 7444 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7445 | static int wpa_driver_nl80211_stop_ap(void *priv) |
| 7446 | { |
| 7447 | struct i802_bss *bss = priv; |
| 7448 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7449 | if (!is_ap_interface(drv->nlmode)) |
| 7450 | return -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 7451 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7452 | bss->beacon_set = 0; |
| 7453 | return 0; |
| 7454 | } |
| 7455 | |
| 7456 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7457 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
| 7458 | { |
| 7459 | struct i802_bss *bss = priv; |
| 7460 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7461 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) |
| 7462 | return -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7463 | |
| 7464 | /* |
| 7465 | * If the P2P Client interface was dynamically added, then it is |
| 7466 | * possible that the interface change to station is not possible. |
| 7467 | */ |
| 7468 | if (bss->if_dynamic) |
| 7469 | return 0; |
| 7470 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7471 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
| 7472 | } |
| 7473 | |
| 7474 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7475 | static void wpa_driver_nl80211_resume(void *priv) |
| 7476 | { |
| 7477 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7478 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7479 | |
| 7480 | if (i802_set_iface_flags(bss, 1)) |
| 7481 | 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] | 7482 | |
| 7483 | if (is_p2p_net_interface(nlmode)) |
| 7484 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7485 | } |
| 7486 | |
| 7487 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7488 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
| 7489 | { |
| 7490 | struct i802_bss *bss = priv; |
| 7491 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7492 | struct nl_msg *msg; |
| 7493 | struct nlattr *cqm; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7494 | |
| 7495 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " |
| 7496 | "hysteresis=%d", threshold, hysteresis); |
| 7497 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7498 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
| 7499 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
| 7500 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || |
| 7501 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { |
| 7502 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7503 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7504 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7505 | nla_nest_end(msg, cqm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7506 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7507 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7508 | } |
| 7509 | |
| 7510 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7511 | static int get_channel_width(struct nl_msg *msg, void *arg) |
| 7512 | { |
| 7513 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7514 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7515 | struct wpa_signal_info *sig_change = arg; |
| 7516 | |
| 7517 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7518 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7519 | |
| 7520 | sig_change->center_frq1 = -1; |
| 7521 | sig_change->center_frq2 = -1; |
| 7522 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 7523 | |
| 7524 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 7525 | sig_change->chanwidth = convert2width( |
| 7526 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 7527 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 7528 | sig_change->center_frq1 = |
| 7529 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 7530 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 7531 | sig_change->center_frq2 = |
| 7532 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 7533 | } |
| 7534 | |
| 7535 | return NL_SKIP; |
| 7536 | } |
| 7537 | |
| 7538 | |
| 7539 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, |
| 7540 | struct wpa_signal_info *sig) |
| 7541 | { |
| 7542 | struct nl_msg *msg; |
| 7543 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7544 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7545 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7546 | } |
| 7547 | |
| 7548 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7549 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
| 7550 | { |
| 7551 | struct i802_bss *bss = priv; |
| 7552 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7553 | int res; |
| 7554 | |
| 7555 | os_memset(si, 0, sizeof(*si)); |
| 7556 | res = nl80211_get_link_signal(drv, si); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7557 | if (res) { |
| 7558 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && |
| 7559 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
| 7560 | return res; |
| 7561 | si->current_signal = 0; |
| 7562 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7563 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7564 | res = nl80211_get_channel_width(drv, si); |
| 7565 | if (res != 0) |
| 7566 | return res; |
| 7567 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7568 | return nl80211_get_link_noise(drv, si); |
| 7569 | } |
| 7570 | |
| 7571 | |
| 7572 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
| 7573 | int encrypt) |
| 7574 | { |
| 7575 | struct i802_bss *bss = priv; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7576 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7577 | 0, 0, 0, 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7578 | } |
| 7579 | |
| 7580 | |
| 7581 | static int nl80211_set_param(void *priv, const char *param) |
| 7582 | { |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 7583 | struct i802_bss *bss = priv; |
| 7584 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7585 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7586 | if (param == NULL) |
| 7587 | return 0; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7588 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7589 | |
| 7590 | #ifdef CONFIG_P2P |
| 7591 | if (os_strstr(param, "use_p2p_group_interface=1")) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7592 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 7593 | "interface"); |
| 7594 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 7595 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 7596 | } |
| 7597 | #endif /* CONFIG_P2P */ |
| 7598 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 7599 | if (os_strstr(param, "use_monitor=1")) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7600 | drv->use_monitor = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7601 | |
| 7602 | if (os_strstr(param, "force_connect_cmd=1")) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7603 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7604 | drv->force_connect_cmd = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7605 | } |
| 7606 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 7607 | if (os_strstr(param, "force_bss_selection=1")) |
| 7608 | drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
| 7609 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 7610 | if (os_strstr(param, "no_offchannel_tx=1")) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 7611 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 7612 | drv->test_use_roc_tx = 1; |
| 7613 | } |
| 7614 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7615 | return 0; |
| 7616 | } |
| 7617 | |
| 7618 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7619 | static void * nl80211_global_init(void *ctx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7620 | { |
| 7621 | struct nl80211_global *global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7622 | struct netlink_config *cfg; |
| 7623 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7624 | global = os_zalloc(sizeof(*global)); |
| 7625 | if (global == NULL) |
| 7626 | return NULL; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7627 | global->ctx = ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7628 | global->ioctl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7629 | dl_list_init(&global->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7630 | global->if_add_ifindex = -1; |
| 7631 | |
| 7632 | cfg = os_zalloc(sizeof(*cfg)); |
| 7633 | if (cfg == NULL) |
| 7634 | goto err; |
| 7635 | |
| 7636 | cfg->ctx = global; |
| 7637 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; |
| 7638 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; |
| 7639 | global->netlink = netlink_init(cfg); |
| 7640 | if (global->netlink == NULL) { |
| 7641 | os_free(cfg); |
| 7642 | goto err; |
| 7643 | } |
| 7644 | |
| 7645 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
| 7646 | goto err; |
| 7647 | |
| 7648 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 7649 | if (global->ioctl_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7650 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
| 7651 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7652 | goto err; |
| 7653 | } |
| 7654 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7655 | return global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7656 | |
| 7657 | err: |
| 7658 | nl80211_global_deinit(global); |
| 7659 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7660 | } |
| 7661 | |
| 7662 | |
| 7663 | static void nl80211_global_deinit(void *priv) |
| 7664 | { |
| 7665 | struct nl80211_global *global = priv; |
| 7666 | if (global == NULL) |
| 7667 | return; |
| 7668 | if (!dl_list_empty(&global->interfaces)) { |
| 7669 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " |
| 7670 | "nl80211_global_deinit", |
| 7671 | dl_list_len(&global->interfaces)); |
| 7672 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7673 | |
| 7674 | if (global->netlink) |
| 7675 | netlink_deinit(global->netlink); |
| 7676 | |
| 7677 | nl_destroy_handles(&global->nl); |
| 7678 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7679 | if (global->nl_event) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7680 | nl80211_destroy_eloop_handle(&global->nl_event, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7681 | |
| 7682 | nl_cb_put(global->nl_cb); |
| 7683 | |
| 7684 | if (global->ioctl_sock >= 0) |
| 7685 | close(global->ioctl_sock); |
| 7686 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7687 | os_free(global); |
| 7688 | } |
| 7689 | |
| 7690 | |
| 7691 | static const char * nl80211_get_radio_name(void *priv) |
| 7692 | { |
| 7693 | struct i802_bss *bss = priv; |
| 7694 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7695 | return drv->phyname; |
| 7696 | } |
| 7697 | |
| 7698 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7699 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, |
| 7700 | struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7701 | { |
| 7702 | struct nl_msg *msg; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7703 | const size_t PMK_MAX_LEN = 48; /* current cfg80211 limit */ |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7704 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7705 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7706 | (params->pmkid && |
| 7707 | nla_put(msg, NL80211_ATTR_PMKID, 16, params->pmkid)) || |
| 7708 | (params->bssid && |
| 7709 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) || |
| 7710 | (params->ssid_len && |
| 7711 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || |
| 7712 | (params->fils_cache_id && |
| 7713 | nla_put(msg, NL80211_ATTR_FILS_CACHE_ID, 2, |
| 7714 | params->fils_cache_id)) || |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7715 | (params->pmk_len && params->pmk_len <= PMK_MAX_LEN && |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7716 | nla_put(msg, NL80211_ATTR_PMK, params->pmk_len, params->pmk))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7717 | nlmsg_free(msg); |
| 7718 | return -ENOBUFS; |
| 7719 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7720 | |
| 7721 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7722 | } |
| 7723 | |
| 7724 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7725 | static int nl80211_add_pmkid(void *priv, struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7726 | { |
| 7727 | struct i802_bss *bss = priv; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7728 | int ret; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7729 | |
| 7730 | if (params->bssid) |
| 7731 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, |
| 7732 | MAC2STR(params->bssid)); |
| 7733 | else if (params->fils_cache_id && params->ssid_len) { |
| 7734 | wpa_printf(MSG_DEBUG, |
| 7735 | "nl80211: Add PMKSA for cache id %02x%02x SSID %s", |
| 7736 | params->fils_cache_id[0], params->fils_cache_id[1], |
| 7737 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
| 7738 | } |
| 7739 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7740 | ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params); |
| 7741 | if (ret < 0) { |
| 7742 | wpa_printf(MSG_DEBUG, |
| 7743 | "nl80211: NL80211_CMD_SET_PMKSA failed: %d (%s)", |
| 7744 | ret, strerror(-ret)); |
| 7745 | } |
| 7746 | |
| 7747 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7748 | } |
| 7749 | |
| 7750 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7751 | static int nl80211_remove_pmkid(void *priv, struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7752 | { |
| 7753 | struct i802_bss *bss = priv; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7754 | int ret; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7755 | |
| 7756 | if (params->bssid) |
| 7757 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, |
| 7758 | MAC2STR(params->bssid)); |
| 7759 | else if (params->fils_cache_id && params->ssid_len) { |
| 7760 | wpa_printf(MSG_DEBUG, |
| 7761 | "nl80211: Delete PMKSA for cache id %02x%02x SSID %s", |
| 7762 | params->fils_cache_id[0], params->fils_cache_id[1], |
| 7763 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
| 7764 | } |
| 7765 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7766 | ret = nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, params); |
| 7767 | if (ret < 0) { |
| 7768 | wpa_printf(MSG_DEBUG, |
| 7769 | "nl80211: NL80211_CMD_DEL_PMKSA failed: %d (%s)", |
| 7770 | ret, strerror(-ret)); |
| 7771 | } |
| 7772 | |
| 7773 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7774 | } |
| 7775 | |
| 7776 | |
| 7777 | static int nl80211_flush_pmkid(void *priv) |
| 7778 | { |
| 7779 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7780 | struct nl_msg *msg; |
| 7781 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7782 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7783 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_FLUSH_PMKSA); |
| 7784 | if (!msg) |
| 7785 | return -ENOBUFS; |
| 7786 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7787 | } |
| 7788 | |
| 7789 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7790 | static void clean_survey_results(struct survey_results *survey_results) |
| 7791 | { |
| 7792 | struct freq_survey *survey, *tmp; |
| 7793 | |
| 7794 | if (dl_list_empty(&survey_results->survey_list)) |
| 7795 | return; |
| 7796 | |
| 7797 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 7798 | struct freq_survey, list) { |
| 7799 | dl_list_del(&survey->list); |
| 7800 | os_free(survey); |
| 7801 | } |
| 7802 | } |
| 7803 | |
| 7804 | |
| 7805 | static void add_survey(struct nlattr **sinfo, u32 ifidx, |
| 7806 | struct dl_list *survey_list) |
| 7807 | { |
| 7808 | struct freq_survey *survey; |
| 7809 | |
| 7810 | survey = os_zalloc(sizeof(struct freq_survey)); |
| 7811 | if (!survey) |
| 7812 | return; |
| 7813 | |
| 7814 | survey->ifidx = ifidx; |
| 7815 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 7816 | survey->filled = 0; |
| 7817 | |
| 7818 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { |
| 7819 | survey->nf = (int8_t) |
| 7820 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 7821 | survey->filled |= SURVEY_HAS_NF; |
| 7822 | } |
| 7823 | |
| 7824 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { |
| 7825 | survey->channel_time = |
| 7826 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); |
| 7827 | survey->filled |= SURVEY_HAS_CHAN_TIME; |
| 7828 | } |
| 7829 | |
| 7830 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { |
| 7831 | survey->channel_time_busy = |
| 7832 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); |
| 7833 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; |
| 7834 | } |
| 7835 | |
| 7836 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { |
| 7837 | survey->channel_time_rx = |
| 7838 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); |
| 7839 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; |
| 7840 | } |
| 7841 | |
| 7842 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { |
| 7843 | survey->channel_time_tx = |
| 7844 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); |
| 7845 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; |
| 7846 | } |
| 7847 | |
| 7848 | 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)", |
| 7849 | survey->freq, |
| 7850 | survey->nf, |
| 7851 | (unsigned long int) survey->channel_time, |
| 7852 | (unsigned long int) survey->channel_time_busy, |
| 7853 | (unsigned long int) survey->channel_time_tx, |
| 7854 | (unsigned long int) survey->channel_time_rx, |
| 7855 | survey->filled); |
| 7856 | |
| 7857 | dl_list_add_tail(survey_list, &survey->list); |
| 7858 | } |
| 7859 | |
| 7860 | |
| 7861 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, |
| 7862 | unsigned int freq_filter) |
| 7863 | { |
| 7864 | if (!freq_filter) |
| 7865 | return 1; |
| 7866 | |
| 7867 | return freq_filter == surveyed_freq; |
| 7868 | } |
| 7869 | |
| 7870 | |
| 7871 | static int survey_handler(struct nl_msg *msg, void *arg) |
| 7872 | { |
| 7873 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7874 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7875 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 7876 | struct survey_results *survey_results; |
| 7877 | u32 surveyed_freq = 0; |
| 7878 | u32 ifidx; |
| 7879 | |
| 7880 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 7881 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 7882 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 7883 | }; |
| 7884 | |
| 7885 | survey_results = (struct survey_results *) arg; |
| 7886 | |
| 7887 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7888 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7889 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 7890 | if (!tb[NL80211_ATTR_IFINDEX]) |
| 7891 | return NL_SKIP; |
| 7892 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7893 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 7894 | |
| 7895 | if (!tb[NL80211_ATTR_SURVEY_INFO]) |
| 7896 | return NL_SKIP; |
| 7897 | |
| 7898 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 7899 | tb[NL80211_ATTR_SURVEY_INFO], |
| 7900 | survey_policy)) |
| 7901 | return NL_SKIP; |
| 7902 | |
| 7903 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { |
| 7904 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); |
| 7905 | return NL_SKIP; |
| 7906 | } |
| 7907 | |
| 7908 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 7909 | |
| 7910 | if (!check_survey_ok(sinfo, surveyed_freq, |
| 7911 | survey_results->freq_filter)) |
| 7912 | return NL_SKIP; |
| 7913 | |
| 7914 | if (survey_results->freq_filter && |
| 7915 | survey_results->freq_filter != surveyed_freq) { |
| 7916 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", |
| 7917 | surveyed_freq); |
| 7918 | return NL_SKIP; |
| 7919 | } |
| 7920 | |
| 7921 | add_survey(sinfo, ifidx, &survey_results->survey_list); |
| 7922 | |
| 7923 | return NL_SKIP; |
| 7924 | } |
| 7925 | |
| 7926 | |
| 7927 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) |
| 7928 | { |
| 7929 | struct i802_bss *bss = priv; |
| 7930 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7931 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7932 | int err; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7933 | union wpa_event_data data; |
| 7934 | struct survey_results *survey_results; |
| 7935 | |
| 7936 | os_memset(&data, 0, sizeof(data)); |
| 7937 | survey_results = &data.survey_results; |
| 7938 | |
| 7939 | dl_list_init(&survey_results->survey_list); |
| 7940 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7941 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7942 | if (!msg) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7943 | return -ENOBUFS; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7944 | |
| 7945 | if (freq) |
| 7946 | data.survey_results.freq_filter = freq; |
| 7947 | |
| 7948 | do { |
| 7949 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); |
| 7950 | err = send_and_recv_msgs(drv, msg, survey_handler, |
| 7951 | survey_results); |
| 7952 | } while (err > 0); |
| 7953 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7954 | if (err) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7955 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7956 | else |
| 7957 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7958 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7959 | clean_survey_results(survey_results); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7960 | return err; |
| 7961 | } |
| 7962 | |
| 7963 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 7964 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
| 7965 | const u8 *kck, size_t kck_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7966 | const u8 *replay_ctr) |
| 7967 | { |
| 7968 | struct i802_bss *bss = priv; |
| 7969 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7970 | struct nlattr *replay_nested; |
| 7971 | struct nl_msg *msg; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 7972 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7973 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 7974 | if (!drv->set_rekey_offload) |
| 7975 | return; |
| 7976 | |
| 7977 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7978 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
| 7979 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 7980 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7981 | (kck_len && nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7982 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
| 7983 | replay_ctr)) { |
| 7984 | nl80211_nlmsg_clear(msg); |
| 7985 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7986 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7987 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7988 | |
| 7989 | nla_nest_end(msg, replay_nested); |
| 7990 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 7991 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 7992 | if (ret == -EOPNOTSUPP) { |
| 7993 | wpa_printf(MSG_DEBUG, |
| 7994 | "nl80211: Driver does not support rekey offload"); |
| 7995 | drv->set_rekey_offload = 0; |
| 7996 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7997 | } |
| 7998 | |
| 7999 | |
| 8000 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
| 8001 | const u8 *addr, int qos) |
| 8002 | { |
| 8003 | /* send data frame to poll STA and check whether |
| 8004 | * this frame is ACKed */ |
| 8005 | struct { |
| 8006 | struct ieee80211_hdr hdr; |
| 8007 | u16 qos_ctl; |
| 8008 | } STRUCT_PACKED nulldata; |
| 8009 | size_t size; |
| 8010 | |
| 8011 | /* Send data frame to poll STA and check whether this frame is ACKed */ |
| 8012 | |
| 8013 | os_memset(&nulldata, 0, sizeof(nulldata)); |
| 8014 | |
| 8015 | if (qos) { |
| 8016 | nulldata.hdr.frame_control = |
| 8017 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 8018 | WLAN_FC_STYPE_QOS_NULL); |
| 8019 | size = sizeof(nulldata); |
| 8020 | } else { |
| 8021 | nulldata.hdr.frame_control = |
| 8022 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 8023 | WLAN_FC_STYPE_NULLFUNC); |
| 8024 | size = sizeof(struct ieee80211_hdr); |
| 8025 | } |
| 8026 | |
| 8027 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 8028 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 8029 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 8030 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 8031 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8032 | 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] | 8033 | 0, 0, NULL, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8034 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
| 8035 | "send poll frame"); |
| 8036 | } |
| 8037 | |
| 8038 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
| 8039 | int qos) |
| 8040 | { |
| 8041 | struct i802_bss *bss = priv; |
| 8042 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8043 | struct nl_msg *msg; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8044 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8045 | |
| 8046 | if (!drv->poll_command_supported) { |
| 8047 | nl80211_send_null_frame(bss, own_addr, addr, qos); |
| 8048 | return; |
| 8049 | } |
| 8050 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8051 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
| 8052 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 8053 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8054 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8055 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8056 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8057 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8058 | if (ret < 0) { |
| 8059 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " |
| 8060 | MACSTR " failed: ret=%d (%s)", |
| 8061 | MAC2STR(addr), ret, strerror(-ret)); |
| 8062 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8063 | } |
| 8064 | |
| 8065 | |
| 8066 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
| 8067 | { |
| 8068 | struct nl_msg *msg; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8069 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8070 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8071 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
| 8072 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
| 8073 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { |
| 8074 | nlmsg_free(msg); |
| 8075 | return -ENOBUFS; |
| 8076 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8077 | |
| 8078 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 8079 | if (ret < 0) { |
| 8080 | wpa_printf(MSG_DEBUG, |
| 8081 | "nl80211: Setting PS state %s failed: %d (%s)", |
| 8082 | enabled ? "enabled" : "disabled", |
| 8083 | ret, strerror(-ret)); |
| 8084 | } |
| 8085 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8086 | } |
| 8087 | |
| 8088 | |
| 8089 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, |
| 8090 | int ctwindow) |
| 8091 | { |
| 8092 | struct i802_bss *bss = priv; |
| 8093 | |
| 8094 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " |
| 8095 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); |
| 8096 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8097 | if (opp_ps != -1 || ctwindow != -1) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8098 | #ifdef ANDROID_P2P |
| 8099 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8100 | #else /* ANDROID_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8101 | return -1; /* Not yet supported */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8102 | #endif /* ANDROID_P2P */ |
| 8103 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8104 | |
| 8105 | if (legacy_ps == -1) |
| 8106 | return 0; |
| 8107 | if (legacy_ps != 0 && legacy_ps != 1) |
| 8108 | return -1; /* Not yet supported */ |
| 8109 | |
| 8110 | return nl80211_set_power_save(bss, legacy_ps); |
| 8111 | } |
| 8112 | |
| 8113 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8114 | static int nl80211_start_radar_detection(void *priv, |
| 8115 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8116 | { |
| 8117 | struct i802_bss *bss = priv; |
| 8118 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8119 | struct nl_msg *msg; |
| 8120 | int ret; |
| 8121 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8122 | wpa_printf(MSG_DEBUG, "nl80211: Start radar detection (CAC) %d MHz (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
| 8123 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 8124 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 8125 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8126 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
| 8127 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " |
| 8128 | "detection"); |
| 8129 | return -1; |
| 8130 | } |
| 8131 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8132 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
| 8133 | nl80211_put_freq_params(msg, freq) < 0) { |
| 8134 | nlmsg_free(msg); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8135 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8136 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8137 | |
| 8138 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8139 | if (ret == 0) |
| 8140 | return 0; |
| 8141 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " |
| 8142 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8143 | return -1; |
| 8144 | } |
| 8145 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8146 | #ifdef CONFIG_TDLS |
| 8147 | |
| 8148 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, |
| 8149 | u8 dialog_token, u16 status_code, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 8150 | u32 peer_capab, int initiator, const u8 *buf, |
| 8151 | size_t len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8152 | { |
| 8153 | struct i802_bss *bss = priv; |
| 8154 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8155 | struct nl_msg *msg; |
| 8156 | |
| 8157 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 8158 | return -EOPNOTSUPP; |
| 8159 | |
| 8160 | if (!dst) |
| 8161 | return -EINVAL; |
| 8162 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8163 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
| 8164 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 8165 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || |
| 8166 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || |
| 8167 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) |
| 8168 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8169 | if (peer_capab) { |
| 8170 | /* |
| 8171 | * The internal enum tdls_peer_capability definition is |
| 8172 | * currently identical with the nl80211 enum |
| 8173 | * nl80211_tdls_peer_capability, so no conversion is needed |
| 8174 | * here. |
| 8175 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8176 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
| 8177 | peer_capab)) |
| 8178 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8179 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8180 | if ((initiator && |
| 8181 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || |
| 8182 | nla_put(msg, NL80211_ATTR_IE, len, buf)) |
| 8183 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8184 | |
| 8185 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8186 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8187 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8188 | nlmsg_free(msg); |
| 8189 | return -ENOBUFS; |
| 8190 | } |
| 8191 | |
| 8192 | |
| 8193 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) |
| 8194 | { |
| 8195 | struct i802_bss *bss = priv; |
| 8196 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8197 | struct nl_msg *msg; |
| 8198 | enum nl80211_tdls_operation nl80211_oper; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8199 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8200 | |
| 8201 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 8202 | return -EOPNOTSUPP; |
| 8203 | |
| 8204 | switch (oper) { |
| 8205 | case TDLS_DISCOVERY_REQ: |
| 8206 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; |
| 8207 | break; |
| 8208 | case TDLS_SETUP: |
| 8209 | nl80211_oper = NL80211_TDLS_SETUP; |
| 8210 | break; |
| 8211 | case TDLS_TEARDOWN: |
| 8212 | nl80211_oper = NL80211_TDLS_TEARDOWN; |
| 8213 | break; |
| 8214 | case TDLS_ENABLE_LINK: |
| 8215 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; |
| 8216 | break; |
| 8217 | case TDLS_DISABLE_LINK: |
| 8218 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; |
| 8219 | break; |
| 8220 | case TDLS_ENABLE: |
| 8221 | return 0; |
| 8222 | case TDLS_DISABLE: |
| 8223 | return 0; |
| 8224 | default: |
| 8225 | return -EINVAL; |
| 8226 | } |
| 8227 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8228 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
| 8229 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
| 8230 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
| 8231 | nlmsg_free(msg); |
| 8232 | return -ENOBUFS; |
| 8233 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8234 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8235 | res = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8236 | wpa_printf(MSG_DEBUG, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR |
| 8237 | " --> res=%d (%s)", nl80211_oper, MAC2STR(peer), res, |
| 8238 | strerror(-res)); |
| 8239 | return res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8240 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8241 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8242 | |
| 8243 | static int |
| 8244 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, |
| 8245 | const struct hostapd_freq_params *params) |
| 8246 | { |
| 8247 | struct i802_bss *bss = priv; |
| 8248 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8249 | struct nl_msg *msg; |
| 8250 | int ret = -ENOBUFS; |
| 8251 | |
| 8252 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 8253 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 8254 | return -EOPNOTSUPP; |
| 8255 | |
| 8256 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR |
| 8257 | " oper_class=%u freq=%u", |
| 8258 | MAC2STR(addr), oper_class, params->freq); |
| 8259 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); |
| 8260 | if (!msg || |
| 8261 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 8262 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || |
| 8263 | (ret = nl80211_put_freq_params(msg, params))) { |
| 8264 | nlmsg_free(msg); |
| 8265 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); |
| 8266 | return ret; |
| 8267 | } |
| 8268 | |
| 8269 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8270 | } |
| 8271 | |
| 8272 | |
| 8273 | static int |
| 8274 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) |
| 8275 | { |
| 8276 | struct i802_bss *bss = priv; |
| 8277 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8278 | struct nl_msg *msg; |
| 8279 | |
| 8280 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 8281 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 8282 | return -EOPNOTSUPP; |
| 8283 | |
| 8284 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, |
| 8285 | MAC2STR(addr)); |
| 8286 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); |
| 8287 | if (!msg || |
| 8288 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 8289 | nlmsg_free(msg); |
| 8290 | wpa_printf(MSG_DEBUG, |
| 8291 | "nl80211: Could not build TDLS cancel chan switch"); |
| 8292 | return -ENOBUFS; |
| 8293 | } |
| 8294 | |
| 8295 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8296 | } |
| 8297 | |
| 8298 | #endif /* CONFIG TDLS */ |
| 8299 | |
| 8300 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8301 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
| 8302 | enum wpa_alg alg, const u8 *addr, |
| 8303 | int key_idx, int set_tx, |
| 8304 | const u8 *seq, size_t seq_len, |
| 8305 | const u8 *key, size_t key_len) |
| 8306 | { |
| 8307 | struct i802_bss *bss = priv; |
| 8308 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, |
| 8309 | set_tx, seq, seq_len, key, key_len); |
| 8310 | } |
| 8311 | |
| 8312 | |
| 8313 | static int driver_nl80211_scan2(void *priv, |
| 8314 | struct wpa_driver_scan_params *params) |
| 8315 | { |
| 8316 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8317 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 8318 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8319 | |
| 8320 | /* |
| 8321 | * Do a vendor specific scan if possible. If only_new_results is |
| 8322 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush |
| 8323 | * cannot be achieved through a vendor scan. The below condition may |
| 8324 | * need to be modified if new scan flags are added in the future whose |
| 8325 | * functionality can only be achieved through a normal scan. |
| 8326 | */ |
| 8327 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) |
| 8328 | return wpa_driver_nl80211_vendor_scan(bss, params); |
| 8329 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8330 | return wpa_driver_nl80211_scan(bss, params); |
| 8331 | } |
| 8332 | |
| 8333 | |
| 8334 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
| 8335 | int reason_code) |
| 8336 | { |
| 8337 | struct i802_bss *bss = priv; |
| 8338 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); |
| 8339 | } |
| 8340 | |
| 8341 | |
| 8342 | static int driver_nl80211_authenticate(void *priv, |
| 8343 | struct wpa_driver_auth_params *params) |
| 8344 | { |
| 8345 | struct i802_bss *bss = priv; |
| 8346 | return wpa_driver_nl80211_authenticate(bss, params); |
| 8347 | } |
| 8348 | |
| 8349 | |
| 8350 | static void driver_nl80211_deinit(void *priv) |
| 8351 | { |
| 8352 | struct i802_bss *bss = priv; |
| 8353 | wpa_driver_nl80211_deinit(bss); |
| 8354 | } |
| 8355 | |
| 8356 | |
| 8357 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, |
| 8358 | const char *ifname) |
| 8359 | { |
| 8360 | struct i802_bss *bss = priv; |
| 8361 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 8362 | } |
| 8363 | |
| 8364 | |
| 8365 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8366 | size_t data_len, int noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8367 | unsigned int freq, |
| 8368 | const u16 *csa_offs, size_t csa_offs_len) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8369 | { |
| 8370 | struct i802_bss *bss = priv; |
| 8371 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8372 | freq, 0, 0, 0, csa_offs, |
| 8373 | csa_offs_len); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8374 | } |
| 8375 | |
| 8376 | |
| 8377 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) |
| 8378 | { |
| 8379 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8380 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8381 | } |
| 8382 | |
| 8383 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8384 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
| 8385 | const char *ifname, int vlan_id) |
| 8386 | { |
| 8387 | struct i802_bss *bss = priv; |
| 8388 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); |
| 8389 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8390 | |
| 8391 | |
| 8392 | static int driver_nl80211_read_sta_data(void *priv, |
| 8393 | struct hostap_sta_driver_data *data, |
| 8394 | const u8 *addr) |
| 8395 | { |
| 8396 | struct i802_bss *bss = priv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 8397 | |
| 8398 | os_memset(data, 0, sizeof(*data)); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8399 | return i802_read_sta_data(bss, data, addr); |
| 8400 | } |
| 8401 | |
| 8402 | |
| 8403 | static int driver_nl80211_send_action(void *priv, unsigned int freq, |
| 8404 | unsigned int wait_time, |
| 8405 | const u8 *dst, const u8 *src, |
| 8406 | const u8 *bssid, |
| 8407 | const u8 *data, size_t data_len, |
| 8408 | int no_cck) |
| 8409 | { |
| 8410 | struct i802_bss *bss = priv; |
| 8411 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, |
| 8412 | bssid, data, data_len, no_cck); |
| 8413 | } |
| 8414 | |
| 8415 | |
| 8416 | static int driver_nl80211_probe_req_report(void *priv, int report) |
| 8417 | { |
| 8418 | struct i802_bss *bss = priv; |
| 8419 | return wpa_driver_nl80211_probe_req_report(bss, report); |
| 8420 | } |
| 8421 | |
| 8422 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8423 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
| 8424 | const u8 *ies, size_t ies_len) |
| 8425 | { |
| 8426 | int ret; |
| 8427 | struct nl_msg *msg; |
| 8428 | struct i802_bss *bss = priv; |
| 8429 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8430 | u16 mdid = WPA_GET_LE16(md); |
| 8431 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8432 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8433 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
| 8434 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
| 8435 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { |
| 8436 | nlmsg_free(msg); |
| 8437 | return -ENOBUFS; |
| 8438 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8439 | |
| 8440 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8441 | if (ret) { |
| 8442 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " |
| 8443 | "err=%d (%s)", ret, strerror(-ret)); |
| 8444 | } |
| 8445 | |
| 8446 | return ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8447 | } |
| 8448 | |
| 8449 | |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 8450 | static const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8451 | { |
| 8452 | struct i802_bss *bss = priv; |
| 8453 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8454 | |
| 8455 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 8456 | return NULL; |
| 8457 | |
| 8458 | return bss->addr; |
| 8459 | } |
| 8460 | |
| 8461 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8462 | static const char * scan_state_str(enum scan_states scan_state) |
| 8463 | { |
| 8464 | switch (scan_state) { |
| 8465 | case NO_SCAN: |
| 8466 | return "NO_SCAN"; |
| 8467 | case SCAN_REQUESTED: |
| 8468 | return "SCAN_REQUESTED"; |
| 8469 | case SCAN_STARTED: |
| 8470 | return "SCAN_STARTED"; |
| 8471 | case SCAN_COMPLETED: |
| 8472 | return "SCAN_COMPLETED"; |
| 8473 | case SCAN_ABORTED: |
| 8474 | return "SCAN_ABORTED"; |
| 8475 | case SCHED_SCAN_STARTED: |
| 8476 | return "SCHED_SCAN_STARTED"; |
| 8477 | case SCHED_SCAN_STOPPED: |
| 8478 | return "SCHED_SCAN_STOPPED"; |
| 8479 | case SCHED_SCAN_RESULTS: |
| 8480 | return "SCHED_SCAN_RESULTS"; |
| 8481 | } |
| 8482 | |
| 8483 | return "??"; |
| 8484 | } |
| 8485 | |
| 8486 | |
| 8487 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) |
| 8488 | { |
| 8489 | struct i802_bss *bss = priv; |
| 8490 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8491 | int res; |
| 8492 | char *pos, *end; |
| 8493 | |
| 8494 | pos = buf; |
| 8495 | end = buf + buflen; |
| 8496 | |
| 8497 | res = os_snprintf(pos, end - pos, |
| 8498 | "ifindex=%d\n" |
| 8499 | "ifname=%s\n" |
| 8500 | "brname=%s\n" |
| 8501 | "addr=" MACSTR "\n" |
| 8502 | "freq=%d\n" |
| 8503 | "%s%s%s%s%s", |
| 8504 | bss->ifindex, |
| 8505 | bss->ifname, |
| 8506 | bss->brname, |
| 8507 | MAC2STR(bss->addr), |
| 8508 | bss->freq, |
| 8509 | bss->beacon_set ? "beacon_set=1\n" : "", |
| 8510 | bss->added_if_into_bridge ? |
| 8511 | "added_if_into_bridge=1\n" : "", |
| 8512 | bss->added_bridge ? "added_bridge=1\n" : "", |
| 8513 | bss->in_deinit ? "in_deinit=1\n" : "", |
| 8514 | bss->if_dynamic ? "if_dynamic=1\n" : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8515 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8516 | return pos - buf; |
| 8517 | pos += res; |
| 8518 | |
| 8519 | if (bss->wdev_id_set) { |
| 8520 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", |
| 8521 | (unsigned long long) bss->wdev_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8522 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8523 | return pos - buf; |
| 8524 | pos += res; |
| 8525 | } |
| 8526 | |
| 8527 | res = os_snprintf(pos, end - pos, |
| 8528 | "phyname=%s\n" |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8529 | "perm_addr=" MACSTR "\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8530 | "drv_ifindex=%d\n" |
| 8531 | "operstate=%d\n" |
| 8532 | "scan_state=%s\n" |
| 8533 | "auth_bssid=" MACSTR "\n" |
| 8534 | "auth_attempt_bssid=" MACSTR "\n" |
| 8535 | "bssid=" MACSTR "\n" |
| 8536 | "prev_bssid=" MACSTR "\n" |
| 8537 | "associated=%d\n" |
| 8538 | "assoc_freq=%u\n" |
| 8539 | "monitor_sock=%d\n" |
| 8540 | "monitor_ifidx=%d\n" |
| 8541 | "monitor_refcount=%d\n" |
| 8542 | "last_mgmt_freq=%u\n" |
| 8543 | "eapol_tx_sock=%d\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8544 | "%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] | 8545 | drv->phyname, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8546 | MAC2STR(drv->perm_addr), |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8547 | drv->ifindex, |
| 8548 | drv->operstate, |
| 8549 | scan_state_str(drv->scan_state), |
| 8550 | MAC2STR(drv->auth_bssid), |
| 8551 | MAC2STR(drv->auth_attempt_bssid), |
| 8552 | MAC2STR(drv->bssid), |
| 8553 | MAC2STR(drv->prev_bssid), |
| 8554 | drv->associated, |
| 8555 | drv->assoc_freq, |
| 8556 | drv->monitor_sock, |
| 8557 | drv->monitor_ifidx, |
| 8558 | drv->monitor_refcount, |
| 8559 | drv->last_mgmt_freq, |
| 8560 | drv->eapol_tx_sock, |
| 8561 | drv->ignore_if_down_event ? |
| 8562 | "ignore_if_down_event=1\n" : "", |
| 8563 | drv->scan_complete_events ? |
| 8564 | "scan_complete_events=1\n" : "", |
| 8565 | drv->disabled_11b_rates ? |
| 8566 | "disabled_11b_rates=1\n" : "", |
| 8567 | drv->pending_remain_on_chan ? |
| 8568 | "pending_remain_on_chan=1\n" : "", |
| 8569 | drv->in_interface_list ? "in_interface_list=1\n" : "", |
| 8570 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", |
| 8571 | drv->poll_command_supported ? |
| 8572 | "poll_command_supported=1\n" : "", |
| 8573 | drv->data_tx_status ? "data_tx_status=1\n" : "", |
| 8574 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", |
| 8575 | drv->retry_auth ? "retry_auth=1\n" : "", |
| 8576 | drv->use_monitor ? "use_monitor=1\n" : "", |
| 8577 | drv->ignore_next_local_disconnect ? |
| 8578 | "ignore_next_local_disconnect=1\n" : "", |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 8579 | drv->ignore_next_local_deauth ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8580 | "ignore_next_local_deauth=1\n" : ""); |
| 8581 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8582 | return pos - buf; |
| 8583 | pos += res; |
| 8584 | |
| 8585 | if (drv->has_capability) { |
| 8586 | res = os_snprintf(pos, end - pos, |
| 8587 | "capa.key_mgmt=0x%x\n" |
| 8588 | "capa.enc=0x%x\n" |
| 8589 | "capa.auth=0x%x\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8590 | "capa.flags=0x%llx\n" |
| 8591 | "capa.rrm_flags=0x%x\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8592 | "capa.max_scan_ssids=%d\n" |
| 8593 | "capa.max_sched_scan_ssids=%d\n" |
| 8594 | "capa.sched_scan_supported=%d\n" |
| 8595 | "capa.max_match_sets=%d\n" |
| 8596 | "capa.max_remain_on_chan=%u\n" |
| 8597 | "capa.max_stations=%u\n" |
| 8598 | "capa.probe_resp_offloads=0x%x\n" |
| 8599 | "capa.max_acl_mac_addrs=%u\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8600 | "capa.num_multichan_concurrent=%u\n" |
| 8601 | "capa.mac_addr_rand_sched_scan_supported=%d\n" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8602 | "capa.mac_addr_rand_scan_supported=%d\n" |
| 8603 | "capa.conc_capab=%u\n" |
| 8604 | "capa.max_conc_chan_2_4=%u\n" |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8605 | "capa.max_conc_chan_5_0=%u\n" |
| 8606 | "capa.max_sched_scan_plans=%u\n" |
| 8607 | "capa.max_sched_scan_plan_interval=%u\n" |
| 8608 | "capa.max_sched_scan_plan_iterations=%u\n", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8609 | drv->capa.key_mgmt, |
| 8610 | drv->capa.enc, |
| 8611 | drv->capa.auth, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8612 | (unsigned long long) drv->capa.flags, |
| 8613 | drv->capa.rrm_flags, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8614 | drv->capa.max_scan_ssids, |
| 8615 | drv->capa.max_sched_scan_ssids, |
| 8616 | drv->capa.sched_scan_supported, |
| 8617 | drv->capa.max_match_sets, |
| 8618 | drv->capa.max_remain_on_chan, |
| 8619 | drv->capa.max_stations, |
| 8620 | drv->capa.probe_resp_offloads, |
| 8621 | drv->capa.max_acl_mac_addrs, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8622 | drv->capa.num_multichan_concurrent, |
| 8623 | drv->capa.mac_addr_rand_sched_scan_supported, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8624 | drv->capa.mac_addr_rand_scan_supported, |
| 8625 | drv->capa.conc_capab, |
| 8626 | drv->capa.max_conc_chan_2_4, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8627 | drv->capa.max_conc_chan_5_0, |
| 8628 | drv->capa.max_sched_scan_plans, |
| 8629 | drv->capa.max_sched_scan_plan_interval, |
| 8630 | drv->capa.max_sched_scan_plan_iterations); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8631 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8632 | return pos - buf; |
| 8633 | pos += res; |
| 8634 | } |
| 8635 | |
| 8636 | return pos - buf; |
| 8637 | } |
| 8638 | |
| 8639 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8640 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
| 8641 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8642 | if ((settings->head && |
| 8643 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, |
| 8644 | settings->head_len, settings->head)) || |
| 8645 | (settings->tail && |
| 8646 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, |
| 8647 | settings->tail_len, settings->tail)) || |
| 8648 | (settings->beacon_ies && |
| 8649 | nla_put(msg, NL80211_ATTR_IE, |
| 8650 | settings->beacon_ies_len, settings->beacon_ies)) || |
| 8651 | (settings->proberesp_ies && |
| 8652 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 8653 | settings->proberesp_ies_len, settings->proberesp_ies)) || |
| 8654 | (settings->assocresp_ies && |
| 8655 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 8656 | settings->assocresp_ies_len, settings->assocresp_ies)) || |
| 8657 | (settings->probe_resp && |
| 8658 | nla_put(msg, NL80211_ATTR_PROBE_RESP, |
| 8659 | settings->probe_resp_len, settings->probe_resp))) |
| 8660 | return -ENOBUFS; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8661 | |
| 8662 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8663 | } |
| 8664 | |
| 8665 | |
| 8666 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) |
| 8667 | { |
| 8668 | struct nl_msg *msg; |
| 8669 | struct i802_bss *bss = priv; |
| 8670 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8671 | struct nlattr *beacon_csa; |
| 8672 | int ret = -ENOBUFS; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8673 | int csa_off_len = 0; |
| 8674 | int i; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8675 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 8676 | 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] | 8677 | settings->cs_count, settings->block_tx, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 8678 | settings->freq_params.freq, settings->freq_params.bandwidth, |
| 8679 | settings->freq_params.center_freq1, |
| 8680 | settings->freq_params.center_freq2); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8681 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8682 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8683 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
| 8684 | return -EOPNOTSUPP; |
| 8685 | } |
| 8686 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8687 | if (drv->nlmode != NL80211_IFTYPE_AP && |
| 8688 | drv->nlmode != NL80211_IFTYPE_P2P_GO && |
| 8689 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8690 | return -EOPNOTSUPP; |
| 8691 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8692 | /* |
| 8693 | * Remove empty counters, assuming Probe Response and Beacon frame |
| 8694 | * counters match. This implementation assumes that there are only two |
| 8695 | * counters. |
| 8696 | */ |
| 8697 | if (settings->counter_offset_beacon[0] && |
| 8698 | !settings->counter_offset_beacon[1]) { |
| 8699 | csa_off_len = 1; |
| 8700 | } else if (settings->counter_offset_beacon[1] && |
| 8701 | !settings->counter_offset_beacon[0]) { |
| 8702 | csa_off_len = 1; |
| 8703 | settings->counter_offset_beacon[0] = |
| 8704 | settings->counter_offset_beacon[1]; |
| 8705 | settings->counter_offset_presp[0] = |
| 8706 | settings->counter_offset_presp[1]; |
| 8707 | } else if (settings->counter_offset_beacon[1] && |
| 8708 | settings->counter_offset_beacon[0]) { |
| 8709 | csa_off_len = 2; |
| 8710 | } else { |
| 8711 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); |
| 8712 | return -EINVAL; |
| 8713 | } |
| 8714 | |
| 8715 | /* Check CSA counters validity */ |
| 8716 | if (drv->capa.max_csa_counters && |
| 8717 | csa_off_len > drv->capa.max_csa_counters) { |
| 8718 | wpa_printf(MSG_ERROR, |
| 8719 | "nl80211: Too many CSA counters provided"); |
| 8720 | return -EINVAL; |
| 8721 | } |
| 8722 | |
| 8723 | if (!settings->beacon_csa.tail) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8724 | return -EINVAL; |
| 8725 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8726 | for (i = 0; i < csa_off_len; i++) { |
| 8727 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; |
| 8728 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; |
| 8729 | |
| 8730 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || |
| 8731 | (settings->beacon_csa.tail[csa_c_off_bcn] != |
| 8732 | settings->cs_count)) |
| 8733 | return -EINVAL; |
| 8734 | |
| 8735 | if (settings->beacon_csa.probe_resp && |
| 8736 | ((settings->beacon_csa.probe_resp_len <= |
| 8737 | csa_c_off_presp) || |
| 8738 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != |
| 8739 | settings->cs_count))) |
| 8740 | return -EINVAL; |
| 8741 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8742 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8743 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
| 8744 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
| 8745 | settings->cs_count) || |
| 8746 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || |
| 8747 | (settings->block_tx && |
| 8748 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8749 | goto error; |
| 8750 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8751 | /* beacon_after params */ |
| 8752 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 8753 | if (ret) |
| 8754 | goto error; |
| 8755 | |
| 8756 | /* beacon_csa params */ |
| 8757 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); |
| 8758 | if (!beacon_csa) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8759 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8760 | |
| 8761 | ret = set_beacon_data(msg, &settings->beacon_csa); |
| 8762 | if (ret) |
| 8763 | goto error; |
| 8764 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8765 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
| 8766 | csa_off_len * sizeof(u16), |
| 8767 | settings->counter_offset_beacon) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8768 | (settings->beacon_csa.probe_resp && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8769 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
| 8770 | csa_off_len * sizeof(u16), |
| 8771 | settings->counter_offset_presp))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8772 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8773 | |
| 8774 | nla_nest_end(msg, beacon_csa); |
| 8775 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8776 | if (ret) { |
| 8777 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", |
| 8778 | ret, strerror(-ret)); |
| 8779 | } |
| 8780 | return ret; |
| 8781 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8782 | fail: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8783 | ret = -ENOBUFS; |
| 8784 | error: |
| 8785 | nlmsg_free(msg); |
| 8786 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); |
| 8787 | return ret; |
| 8788 | } |
| 8789 | |
| 8790 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8791 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
| 8792 | u8 user_priority, u16 admitted_time) |
| 8793 | { |
| 8794 | struct i802_bss *bss = priv; |
| 8795 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8796 | struct nl_msg *msg; |
| 8797 | int ret; |
| 8798 | |
| 8799 | wpa_printf(MSG_DEBUG, |
| 8800 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", |
| 8801 | tsid, admitted_time, user_priority); |
| 8802 | |
| 8803 | if (!is_sta_interface(drv->nlmode)) |
| 8804 | return -ENOTSUP; |
| 8805 | |
| 8806 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
| 8807 | if (!msg || |
| 8808 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 8809 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 8810 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || |
| 8811 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { |
| 8812 | nlmsg_free(msg); |
| 8813 | return -ENOBUFS; |
| 8814 | } |
| 8815 | |
| 8816 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8817 | if (ret) |
| 8818 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", |
| 8819 | ret, strerror(-ret)); |
| 8820 | return ret; |
| 8821 | } |
| 8822 | |
| 8823 | |
| 8824 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) |
| 8825 | { |
| 8826 | struct i802_bss *bss = priv; |
| 8827 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8828 | struct nl_msg *msg; |
| 8829 | int ret; |
| 8830 | |
| 8831 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); |
| 8832 | |
| 8833 | if (!is_sta_interface(drv->nlmode)) |
| 8834 | return -ENOTSUP; |
| 8835 | |
| 8836 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
| 8837 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 8838 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 8839 | nlmsg_free(msg); |
| 8840 | return -ENOBUFS; |
| 8841 | } |
| 8842 | |
| 8843 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8844 | if (ret) |
| 8845 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", |
| 8846 | ret, strerror(-ret)); |
| 8847 | return ret; |
| 8848 | } |
| 8849 | |
| 8850 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8851 | #ifdef CONFIG_TESTING_OPTIONS |
| 8852 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) |
| 8853 | { |
| 8854 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8855 | struct wpabuf *buf = arg; |
| 8856 | |
| 8857 | if (!buf) |
| 8858 | return NL_SKIP; |
| 8859 | |
| 8860 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { |
| 8861 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); |
| 8862 | return NL_SKIP; |
| 8863 | } |
| 8864 | |
| 8865 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), |
| 8866 | genlmsg_attrlen(gnlh, 0)); |
| 8867 | |
| 8868 | return NL_SKIP; |
| 8869 | } |
| 8870 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 8871 | |
| 8872 | |
| 8873 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
| 8874 | { |
| 8875 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8876 | struct nlattr *nl_vendor_reply, *nl; |
| 8877 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8878 | struct wpabuf *buf = arg; |
| 8879 | int rem; |
| 8880 | |
| 8881 | if (!buf) |
| 8882 | return NL_SKIP; |
| 8883 | |
| 8884 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8885 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8886 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; |
| 8887 | |
| 8888 | if (!nl_vendor_reply) |
| 8889 | return NL_SKIP; |
| 8890 | |
| 8891 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { |
| 8892 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); |
| 8893 | return NL_SKIP; |
| 8894 | } |
| 8895 | |
| 8896 | nla_for_each_nested(nl, nl_vendor_reply, rem) { |
| 8897 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); |
| 8898 | } |
| 8899 | |
| 8900 | return NL_SKIP; |
| 8901 | } |
| 8902 | |
| 8903 | |
| 8904 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, |
| 8905 | unsigned int subcmd, const u8 *data, |
| 8906 | size_t data_len, struct wpabuf *buf) |
| 8907 | { |
| 8908 | struct i802_bss *bss = priv; |
| 8909 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8910 | struct nl_msg *msg; |
| 8911 | int ret; |
| 8912 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8913 | #ifdef CONFIG_TESTING_OPTIONS |
| 8914 | if (vendor_id == 0xffffffff) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8915 | msg = nlmsg_alloc(); |
| 8916 | if (!msg) |
| 8917 | return -ENOMEM; |
| 8918 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8919 | nl80211_cmd(drv, msg, 0, subcmd); |
| 8920 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < |
| 8921 | 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8922 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8923 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
| 8924 | if (ret) |
| 8925 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", |
| 8926 | ret); |
| 8927 | return ret; |
| 8928 | } |
| 8929 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 8930 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8931 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 8932 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
| 8933 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || |
| 8934 | (data && |
| 8935 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) |
| 8936 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8937 | |
| 8938 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); |
| 8939 | if (ret) |
| 8940 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", |
| 8941 | ret); |
| 8942 | return ret; |
| 8943 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8944 | fail: |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8945 | nlmsg_free(msg); |
| 8946 | return -ENOBUFS; |
| 8947 | } |
| 8948 | |
| 8949 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8950 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
| 8951 | u8 qos_map_set_len) |
| 8952 | { |
| 8953 | struct i802_bss *bss = priv; |
| 8954 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8955 | struct nl_msg *msg; |
| 8956 | int ret; |
| 8957 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8958 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
| 8959 | qos_map_set, qos_map_set_len); |
| 8960 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8961 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
| 8962 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
| 8963 | nlmsg_free(msg); |
| 8964 | return -ENOBUFS; |
| 8965 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8966 | |
| 8967 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8968 | if (ret) |
| 8969 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); |
| 8970 | |
| 8971 | return ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8972 | } |
| 8973 | |
| 8974 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8975 | static int nl80211_set_wowlan(void *priv, |
| 8976 | const struct wowlan_triggers *triggers) |
| 8977 | { |
| 8978 | struct i802_bss *bss = priv; |
| 8979 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8980 | struct nl_msg *msg; |
| 8981 | struct nlattr *wowlan_triggers; |
| 8982 | int ret; |
| 8983 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8984 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
| 8985 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8986 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8987 | !(wowlan_triggers = nla_nest_start(msg, |
| 8988 | NL80211_ATTR_WOWLAN_TRIGGERS)) || |
| 8989 | (triggers->any && |
| 8990 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 8991 | (triggers->disconnect && |
| 8992 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 8993 | (triggers->magic_pkt && |
| 8994 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 8995 | (triggers->gtk_rekey_failure && |
| 8996 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 8997 | (triggers->eap_identity_req && |
| 8998 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 8999 | (triggers->four_way_handshake && |
| 9000 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 9001 | (triggers->rfkill_release && |
| 9002 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { |
| 9003 | nlmsg_free(msg); |
| 9004 | return -ENOBUFS; |
| 9005 | } |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9006 | |
| 9007 | nla_nest_end(msg, wowlan_triggers); |
| 9008 | |
| 9009 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9010 | if (ret) |
| 9011 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); |
| 9012 | |
| 9013 | return ret; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9014 | } |
| 9015 | |
| 9016 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9017 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9018 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
| 9019 | { |
| 9020 | struct i802_bss *bss = priv; |
| 9021 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9022 | struct nl_msg *msg; |
| 9023 | struct nlattr *params; |
| 9024 | |
| 9025 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); |
| 9026 | |
| 9027 | if (!drv->roaming_vendor_cmd_avail) { |
| 9028 | wpa_printf(MSG_DEBUG, |
| 9029 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); |
| 9030 | return -1; |
| 9031 | } |
| 9032 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9033 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9034 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9035 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9036 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || |
| 9037 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9038 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, |
| 9039 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : |
| 9040 | QCA_ROAMING_NOT_ALLOWED) || |
| 9041 | (bssid && |
| 9042 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { |
| 9043 | nlmsg_free(msg); |
| 9044 | return -1; |
| 9045 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9046 | nla_nest_end(msg, params); |
| 9047 | |
| 9048 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9049 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9050 | |
| 9051 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9052 | static int nl80211_disable_fils(void *priv, int disable) |
| 9053 | { |
| 9054 | struct i802_bss *bss = priv; |
| 9055 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9056 | struct nl_msg *msg; |
| 9057 | struct nlattr *params; |
| 9058 | |
| 9059 | wpa_printf(MSG_DEBUG, "nl80211: Disable FILS=%d", disable); |
| 9060 | |
| 9061 | if (!drv->set_wifi_conf_vendor_cmd_avail) |
| 9062 | return -1; |
| 9063 | |
| 9064 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9065 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9066 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9067 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) || |
| 9068 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9069 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS, |
| 9070 | disable)) { |
| 9071 | nlmsg_free(msg); |
| 9072 | return -1; |
| 9073 | } |
| 9074 | nla_nest_end(msg, params); |
| 9075 | |
| 9076 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9077 | } |
| 9078 | |
| 9079 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9080 | /* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */ |
| 9081 | #define WPA_SUPPLICANT_CLIENT_ID 1 |
| 9082 | |
| 9083 | static int nl80211_set_bssid_blacklist(void *priv, unsigned int num_bssid, |
| 9084 | const u8 *bssid) |
| 9085 | { |
| 9086 | struct i802_bss *bss = priv; |
| 9087 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9088 | struct nl_msg *msg; |
| 9089 | struct nlattr *params, *nlbssids, *attr; |
| 9090 | unsigned int i; |
| 9091 | |
| 9092 | wpa_printf(MSG_DEBUG, "nl80211: Set blacklist BSSID (num=%u)", |
| 9093 | num_bssid); |
| 9094 | |
| 9095 | if (!drv->roam_vendor_cmd_avail) |
| 9096 | return -1; |
| 9097 | |
| 9098 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9099 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9100 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9101 | QCA_NL80211_VENDOR_SUBCMD_ROAM) || |
| 9102 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9103 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD, |
| 9104 | QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_SET_BLACKLIST_BSSID) || |
| 9105 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID, |
| 9106 | WPA_SUPPLICANT_CLIENT_ID) || |
| 9107 | nla_put_u32(msg, |
| 9108 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID, |
| 9109 | num_bssid)) |
| 9110 | goto fail; |
| 9111 | |
| 9112 | nlbssids = nla_nest_start( |
| 9113 | msg, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS); |
| 9114 | if (!nlbssids) |
| 9115 | goto fail; |
| 9116 | |
| 9117 | for (i = 0; i < num_bssid; i++) { |
| 9118 | attr = nla_nest_start(msg, i); |
| 9119 | if (!attr) |
| 9120 | goto fail; |
| 9121 | if (nla_put(msg, |
| 9122 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID, |
| 9123 | ETH_ALEN, &bssid[i * ETH_ALEN])) |
| 9124 | goto fail; |
| 9125 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%u]: " MACSTR, i, |
| 9126 | MAC2STR(&bssid[i * ETH_ALEN])); |
| 9127 | nla_nest_end(msg, attr); |
| 9128 | } |
| 9129 | nla_nest_end(msg, nlbssids); |
| 9130 | nla_nest_end(msg, params); |
| 9131 | |
| 9132 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9133 | |
| 9134 | fail: |
| 9135 | nlmsg_free(msg); |
| 9136 | return -1; |
| 9137 | } |
| 9138 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9139 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9140 | |
| 9141 | |
| 9142 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
| 9143 | { |
| 9144 | struct i802_bss *bss = priv; |
| 9145 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9146 | int new_addr = addr != NULL; |
| 9147 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9148 | if (TEST_FAIL()) |
| 9149 | return -1; |
| 9150 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9151 | if (!addr) |
| 9152 | addr = drv->perm_addr; |
| 9153 | |
| 9154 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) |
| 9155 | return -1; |
| 9156 | |
| 9157 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) |
| 9158 | { |
| 9159 | wpa_printf(MSG_DEBUG, |
| 9160 | "nl80211: failed to set_mac_addr for %s to " MACSTR, |
| 9161 | bss->ifname, MAC2STR(addr)); |
| 9162 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 9163 | 1) < 0) { |
| 9164 | wpa_printf(MSG_DEBUG, |
| 9165 | "nl80211: Could not restore interface UP after failed set_mac_addr"); |
| 9166 | } |
| 9167 | return -1; |
| 9168 | } |
| 9169 | |
| 9170 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, |
| 9171 | bss->ifname, MAC2STR(addr)); |
| 9172 | drv->addr_changed = new_addr; |
| 9173 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 9174 | |
| 9175 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) |
| 9176 | { |
| 9177 | wpa_printf(MSG_DEBUG, |
| 9178 | "nl80211: Could not restore interface UP after set_mac_addr"); |
| 9179 | } |
| 9180 | |
| 9181 | return 0; |
| 9182 | } |
| 9183 | |
| 9184 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9185 | #ifdef CONFIG_MESH |
| 9186 | |
| 9187 | static int wpa_driver_nl80211_init_mesh(void *priv) |
| 9188 | { |
| 9189 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { |
| 9190 | wpa_printf(MSG_INFO, |
| 9191 | "nl80211: Failed to set interface into mesh mode"); |
| 9192 | return -1; |
| 9193 | } |
| 9194 | return 0; |
| 9195 | } |
| 9196 | |
| 9197 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9198 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
| 9199 | size_t mesh_id_len) |
| 9200 | { |
| 9201 | if (mesh_id) { |
| 9202 | wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)", |
| 9203 | mesh_id, mesh_id_len); |
| 9204 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); |
| 9205 | } |
| 9206 | |
| 9207 | return 0; |
| 9208 | } |
| 9209 | |
| 9210 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9211 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
| 9212 | struct wpa_driver_mesh_bss_params *params) |
| 9213 | { |
| 9214 | struct nlattr *container; |
| 9215 | |
| 9216 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
| 9217 | if (!container) |
| 9218 | return -1; |
| 9219 | |
| 9220 | if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9221 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 9222 | params->auto_plinks)) || |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9223 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) && |
| 9224 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9225 | params->max_peer_links)) || |
| 9226 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD) && |
| 9227 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 9228 | params->rssi_threshold))) |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9229 | return -1; |
| 9230 | |
| 9231 | /* |
| 9232 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because |
| 9233 | * the timer could disconnect stations even in that case. |
| 9234 | */ |
| 9235 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) && |
| 9236 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 9237 | params->peer_link_timeout)) { |
| 9238 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); |
| 9239 | return -1; |
| 9240 | } |
| 9241 | |
| 9242 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) && |
| 9243 | nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) { |
| 9244 | wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE"); |
| 9245 | return -1; |
| 9246 | } |
| 9247 | |
| 9248 | nla_nest_end(msg, container); |
| 9249 | |
| 9250 | return 0; |
| 9251 | } |
| 9252 | |
| 9253 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9254 | static int nl80211_join_mesh(struct i802_bss *bss, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9255 | struct wpa_driver_mesh_join_params *params) |
| 9256 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9257 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9258 | struct nl_msg *msg; |
| 9259 | struct nlattr *container; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 9260 | int ret = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9261 | |
| 9262 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
| 9263 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9264 | if (!msg || |
| 9265 | nl80211_put_freq_params(msg, ¶ms->freq) || |
| 9266 | nl80211_put_basic_rates(msg, params->basic_rates) || |
| 9267 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 9268 | nl80211_put_beacon_int(msg, params->beacon_int) || |
| 9269 | nl80211_put_dtim_period(msg, params->dtim_period)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9270 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9271 | |
| 9272 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
| 9273 | |
| 9274 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); |
| 9275 | if (!container) |
| 9276 | goto fail; |
| 9277 | |
| 9278 | if (params->ies) { |
| 9279 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); |
| 9280 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
| 9281 | params->ies)) |
| 9282 | goto fail; |
| 9283 | } |
| 9284 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ |
| 9285 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { |
| 9286 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
| 9287 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) |
| 9288 | goto fail; |
| 9289 | } |
| 9290 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
| 9291 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) |
| 9292 | goto fail; |
| 9293 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && |
| 9294 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) |
| 9295 | goto fail; |
| 9296 | nla_nest_end(msg, container); |
| 9297 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9298 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS; |
| 9299 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT; |
| 9300 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS; |
| 9301 | if (nl80211_put_mesh_config(msg, ¶ms->conf) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9302 | goto fail; |
| 9303 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9304 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9305 | msg = NULL; |
| 9306 | if (ret) { |
| 9307 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", |
| 9308 | ret, strerror(-ret)); |
| 9309 | goto fail; |
| 9310 | } |
| 9311 | ret = 0; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 9312 | drv->assoc_freq = bss->freq = params->freq.freq; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9313 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
| 9314 | |
| 9315 | fail: |
| 9316 | nlmsg_free(msg); |
| 9317 | return ret; |
| 9318 | } |
| 9319 | |
| 9320 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9321 | static int |
| 9322 | wpa_driver_nl80211_join_mesh(void *priv, |
| 9323 | struct wpa_driver_mesh_join_params *params) |
| 9324 | { |
| 9325 | struct i802_bss *bss = priv; |
| 9326 | int ret, timeout; |
| 9327 | |
| 9328 | timeout = params->conf.peer_link_timeout; |
| 9329 | |
| 9330 | /* Disable kernel inactivity timer */ |
| 9331 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) |
| 9332 | params->conf.peer_link_timeout = 0; |
| 9333 | |
| 9334 | ret = nl80211_join_mesh(bss, params); |
| 9335 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { |
| 9336 | wpa_printf(MSG_DEBUG, |
| 9337 | "nl80211: Mesh join retry for peer_link_timeout"); |
| 9338 | /* |
| 9339 | * Old kernel does not support setting |
| 9340 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds |
| 9341 | * into future from peer_link_timeout. |
| 9342 | */ |
| 9343 | params->conf.peer_link_timeout = timeout + 60; |
| 9344 | ret = nl80211_join_mesh(priv, params); |
| 9345 | } |
| 9346 | |
| 9347 | params->conf.peer_link_timeout = timeout; |
| 9348 | return ret; |
| 9349 | } |
| 9350 | |
| 9351 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9352 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
| 9353 | { |
| 9354 | struct i802_bss *bss = priv; |
| 9355 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9356 | struct nl_msg *msg; |
| 9357 | int ret; |
| 9358 | |
| 9359 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); |
| 9360 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
| 9361 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9362 | if (ret) { |
| 9363 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", |
| 9364 | ret, strerror(-ret)); |
| 9365 | } else { |
| 9366 | wpa_printf(MSG_DEBUG, |
| 9367 | "nl80211: mesh leave request send successfully"); |
| 9368 | } |
| 9369 | |
| 9370 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
| 9371 | NL80211_IFTYPE_STATION)) { |
| 9372 | wpa_printf(MSG_INFO, |
| 9373 | "nl80211: Failed to set interface into station mode"); |
| 9374 | } |
| 9375 | return ret; |
| 9376 | } |
| 9377 | |
| 9378 | #endif /* CONFIG_MESH */ |
| 9379 | |
| 9380 | |
| 9381 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
| 9382 | const u8 *ipaddr, int prefixlen, |
| 9383 | const u8 *addr) |
| 9384 | { |
| 9385 | #ifdef CONFIG_LIBNL3_ROUTE |
| 9386 | struct i802_bss *bss = priv; |
| 9387 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9388 | struct rtnl_neigh *rn; |
| 9389 | struct nl_addr *nl_ipaddr = NULL; |
| 9390 | struct nl_addr *nl_lladdr = NULL; |
| 9391 | int family, addrsize; |
| 9392 | int res; |
| 9393 | |
| 9394 | if (!ipaddr || prefixlen == 0 || !addr) |
| 9395 | return -EINVAL; |
| 9396 | |
| 9397 | if (bss->br_ifindex == 0) { |
| 9398 | wpa_printf(MSG_DEBUG, |
| 9399 | "nl80211: bridge must be set before adding an ip neigh to it"); |
| 9400 | return -1; |
| 9401 | } |
| 9402 | |
| 9403 | if (!drv->rtnl_sk) { |
| 9404 | wpa_printf(MSG_DEBUG, |
| 9405 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 9406 | return -1; |
| 9407 | } |
| 9408 | |
| 9409 | if (version == 4) { |
| 9410 | family = AF_INET; |
| 9411 | addrsize = 4; |
| 9412 | } else if (version == 6) { |
| 9413 | family = AF_INET6; |
| 9414 | addrsize = 16; |
| 9415 | } else { |
| 9416 | return -EINVAL; |
| 9417 | } |
| 9418 | |
| 9419 | rn = rtnl_neigh_alloc(); |
| 9420 | if (rn == NULL) |
| 9421 | return -ENOMEM; |
| 9422 | |
| 9423 | /* set the destination ip address for neigh */ |
| 9424 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 9425 | if (nl_ipaddr == NULL) { |
| 9426 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 9427 | res = -ENOMEM; |
| 9428 | goto errout; |
| 9429 | } |
| 9430 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); |
| 9431 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 9432 | if (res) { |
| 9433 | wpa_printf(MSG_DEBUG, |
| 9434 | "nl80211: neigh set destination addr failed"); |
| 9435 | goto errout; |
| 9436 | } |
| 9437 | |
| 9438 | /* set the corresponding lladdr for neigh */ |
| 9439 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); |
| 9440 | if (nl_lladdr == NULL) { |
| 9441 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); |
| 9442 | res = -ENOMEM; |
| 9443 | goto errout; |
| 9444 | } |
| 9445 | rtnl_neigh_set_lladdr(rn, nl_lladdr); |
| 9446 | |
| 9447 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 9448 | rtnl_neigh_set_state(rn, NUD_PERMANENT); |
| 9449 | |
| 9450 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); |
| 9451 | if (res) { |
| 9452 | wpa_printf(MSG_DEBUG, |
| 9453 | "nl80211: Adding bridge ip neigh failed: %s", |
| 9454 | strerror(errno)); |
| 9455 | } |
| 9456 | errout: |
| 9457 | if (nl_lladdr) |
| 9458 | nl_addr_put(nl_lladdr); |
| 9459 | if (nl_ipaddr) |
| 9460 | nl_addr_put(nl_ipaddr); |
| 9461 | if (rn) |
| 9462 | rtnl_neigh_put(rn); |
| 9463 | return res; |
| 9464 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 9465 | return -1; |
| 9466 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 9467 | } |
| 9468 | |
| 9469 | |
| 9470 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
| 9471 | const u8 *ipaddr) |
| 9472 | { |
| 9473 | #ifdef CONFIG_LIBNL3_ROUTE |
| 9474 | struct i802_bss *bss = priv; |
| 9475 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9476 | struct rtnl_neigh *rn; |
| 9477 | struct nl_addr *nl_ipaddr; |
| 9478 | int family, addrsize; |
| 9479 | int res; |
| 9480 | |
| 9481 | if (!ipaddr) |
| 9482 | return -EINVAL; |
| 9483 | |
| 9484 | if (version == 4) { |
| 9485 | family = AF_INET; |
| 9486 | addrsize = 4; |
| 9487 | } else if (version == 6) { |
| 9488 | family = AF_INET6; |
| 9489 | addrsize = 16; |
| 9490 | } else { |
| 9491 | return -EINVAL; |
| 9492 | } |
| 9493 | |
| 9494 | if (bss->br_ifindex == 0) { |
| 9495 | wpa_printf(MSG_DEBUG, |
| 9496 | "nl80211: bridge must be set to delete an ip neigh"); |
| 9497 | return -1; |
| 9498 | } |
| 9499 | |
| 9500 | if (!drv->rtnl_sk) { |
| 9501 | wpa_printf(MSG_DEBUG, |
| 9502 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 9503 | return -1; |
| 9504 | } |
| 9505 | |
| 9506 | rn = rtnl_neigh_alloc(); |
| 9507 | if (rn == NULL) |
| 9508 | return -ENOMEM; |
| 9509 | |
| 9510 | /* set the destination ip address for neigh */ |
| 9511 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 9512 | if (nl_ipaddr == NULL) { |
| 9513 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 9514 | res = -ENOMEM; |
| 9515 | goto errout; |
| 9516 | } |
| 9517 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 9518 | if (res) { |
| 9519 | wpa_printf(MSG_DEBUG, |
| 9520 | "nl80211: neigh set destination addr failed"); |
| 9521 | goto errout; |
| 9522 | } |
| 9523 | |
| 9524 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 9525 | |
| 9526 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 9527 | if (res) { |
| 9528 | wpa_printf(MSG_DEBUG, |
| 9529 | "nl80211: Deleting bridge ip neigh failed: %s", |
| 9530 | strerror(errno)); |
| 9531 | } |
| 9532 | errout: |
| 9533 | if (nl_ipaddr) |
| 9534 | nl_addr_put(nl_ipaddr); |
| 9535 | if (rn) |
| 9536 | rtnl_neigh_put(rn); |
| 9537 | return res; |
| 9538 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 9539 | return -1; |
| 9540 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 9541 | } |
| 9542 | |
| 9543 | |
| 9544 | static int linux_write_system_file(const char *path, unsigned int val) |
| 9545 | { |
| 9546 | char buf[50]; |
| 9547 | int fd, len; |
| 9548 | |
| 9549 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); |
| 9550 | if (os_snprintf_error(sizeof(buf), len)) |
| 9551 | return -1; |
| 9552 | |
| 9553 | fd = open(path, O_WRONLY); |
| 9554 | if (fd < 0) |
| 9555 | return -1; |
| 9556 | |
| 9557 | if (write(fd, buf, len) < 0) { |
| 9558 | wpa_printf(MSG_DEBUG, |
| 9559 | "nl80211: Failed to write Linux system file: %s with the value of %d", |
| 9560 | path, val); |
| 9561 | close(fd); |
| 9562 | return -1; |
| 9563 | } |
| 9564 | close(fd); |
| 9565 | |
| 9566 | return 0; |
| 9567 | } |
| 9568 | |
| 9569 | |
| 9570 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) |
| 9571 | { |
| 9572 | switch (attr) { |
| 9573 | case DRV_BR_PORT_ATTR_PROXYARP: |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 9574 | return "proxyarp_wifi"; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9575 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
| 9576 | return "hairpin_mode"; |
| 9577 | } |
| 9578 | |
| 9579 | return NULL; |
| 9580 | } |
| 9581 | |
| 9582 | |
| 9583 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, |
| 9584 | unsigned int val) |
| 9585 | { |
| 9586 | struct i802_bss *bss = priv; |
| 9587 | char path[128]; |
| 9588 | const char *attr_txt; |
| 9589 | |
| 9590 | attr_txt = drv_br_port_attr_str(attr); |
| 9591 | if (attr_txt == NULL) |
| 9592 | return -EINVAL; |
| 9593 | |
| 9594 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", |
| 9595 | bss->ifname, attr_txt); |
| 9596 | |
| 9597 | if (linux_write_system_file(path, val)) |
| 9598 | return -1; |
| 9599 | |
| 9600 | return 0; |
| 9601 | } |
| 9602 | |
| 9603 | |
| 9604 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
| 9605 | { |
| 9606 | switch (param) { |
| 9607 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 9608 | return "arp_accept"; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 9609 | default: |
| 9610 | return NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9611 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9612 | } |
| 9613 | |
| 9614 | |
| 9615 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, |
| 9616 | unsigned int val) |
| 9617 | { |
| 9618 | struct i802_bss *bss = priv; |
| 9619 | char path[128]; |
| 9620 | const char *param_txt; |
| 9621 | int ip_version = 4; |
| 9622 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 9623 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
| 9624 | os_snprintf(path, sizeof(path), |
| 9625 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", |
| 9626 | bss->brname); |
| 9627 | goto set_val; |
| 9628 | } |
| 9629 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9630 | param_txt = drv_br_net_param_str(param); |
| 9631 | if (param_txt == NULL) |
| 9632 | return -EINVAL; |
| 9633 | |
| 9634 | switch (param) { |
| 9635 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 9636 | ip_version = 4; |
| 9637 | break; |
| 9638 | default: |
| 9639 | return -EINVAL; |
| 9640 | } |
| 9641 | |
| 9642 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", |
| 9643 | ip_version, bss->brname, param_txt); |
| 9644 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 9645 | set_val: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9646 | if (linux_write_system_file(path, val)) |
| 9647 | return -1; |
| 9648 | |
| 9649 | return 0; |
| 9650 | } |
| 9651 | |
| 9652 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9653 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 9654 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9655 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
| 9656 | { |
| 9657 | switch (hw_mode) { |
| 9658 | case HOSTAPD_MODE_IEEE80211B: |
| 9659 | return QCA_ACS_MODE_IEEE80211B; |
| 9660 | case HOSTAPD_MODE_IEEE80211G: |
| 9661 | return QCA_ACS_MODE_IEEE80211G; |
| 9662 | case HOSTAPD_MODE_IEEE80211A: |
| 9663 | return QCA_ACS_MODE_IEEE80211A; |
| 9664 | case HOSTAPD_MODE_IEEE80211AD: |
| 9665 | return QCA_ACS_MODE_IEEE80211AD; |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 9666 | case HOSTAPD_MODE_IEEE80211ANY: |
| 9667 | return QCA_ACS_MODE_IEEE80211ANY; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9668 | default: |
| 9669 | return -1; |
| 9670 | } |
| 9671 | } |
| 9672 | |
| 9673 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9674 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
| 9675 | { |
| 9676 | int i, len, ret; |
| 9677 | u32 *freqs; |
| 9678 | |
| 9679 | if (!freq_list) |
| 9680 | return 0; |
| 9681 | len = int_array_len(freq_list); |
| 9682 | freqs = os_malloc(sizeof(u32) * len); |
| 9683 | if (!freqs) |
| 9684 | return -1; |
| 9685 | for (i = 0; i < len; i++) |
| 9686 | freqs[i] = freq_list[i]; |
| 9687 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, |
| 9688 | sizeof(u32) * len, freqs); |
| 9689 | os_free(freqs); |
| 9690 | return ret; |
| 9691 | } |
| 9692 | |
| 9693 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9694 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
| 9695 | { |
| 9696 | struct i802_bss *bss = priv; |
| 9697 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9698 | struct nl_msg *msg; |
| 9699 | struct nlattr *data; |
| 9700 | int ret; |
| 9701 | int mode; |
| 9702 | |
| 9703 | mode = hw_mode_to_qca_acs(params->hw_mode); |
| 9704 | if (mode < 0) |
| 9705 | return -1; |
| 9706 | |
| 9707 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9708 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9709 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9710 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || |
| 9711 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9712 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || |
| 9713 | (params->ht_enabled && |
| 9714 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || |
| 9715 | (params->ht40_enabled && |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 9716 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
| 9717 | (params->vht_enabled && |
| 9718 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || |
| 9719 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, |
| 9720 | params->ch_width) || |
| 9721 | (params->ch_list_len && |
| 9722 | 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] | 9723 | params->ch_list)) || |
| 9724 | add_acs_freq_list(msg, params->freq_list)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9725 | nlmsg_free(msg); |
| 9726 | return -ENOBUFS; |
| 9727 | } |
| 9728 | nla_nest_end(msg, data); |
| 9729 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 9730 | wpa_printf(MSG_DEBUG, |
| 9731 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u", |
| 9732 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
| 9733 | params->vht_enabled, params->ch_width, params->ch_list_len); |
| 9734 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9735 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9736 | if (ret) { |
| 9737 | wpa_printf(MSG_DEBUG, |
| 9738 | "nl80211: Failed to invoke driver ACS function: %s", |
| 9739 | strerror(errno)); |
| 9740 | } |
| 9741 | return ret; |
| 9742 | } |
| 9743 | |
| 9744 | |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 9745 | static int nl80211_set_band(void *priv, enum set_band band) |
| 9746 | { |
| 9747 | struct i802_bss *bss = priv; |
| 9748 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9749 | struct nl_msg *msg; |
| 9750 | struct nlattr *data; |
| 9751 | int ret; |
| 9752 | enum qca_set_band qca_band; |
| 9753 | |
| 9754 | if (!drv->setband_vendor_cmd_avail) |
| 9755 | return -1; |
| 9756 | |
| 9757 | switch (band) { |
| 9758 | case WPA_SETBAND_AUTO: |
| 9759 | qca_band = QCA_SETBAND_AUTO; |
| 9760 | break; |
| 9761 | case WPA_SETBAND_5G: |
| 9762 | qca_band = QCA_SETBAND_5G; |
| 9763 | break; |
| 9764 | case WPA_SETBAND_2G: |
| 9765 | qca_band = QCA_SETBAND_2G; |
| 9766 | break; |
| 9767 | default: |
| 9768 | return -1; |
| 9769 | } |
| 9770 | |
| 9771 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9772 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9773 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9774 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || |
| 9775 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9776 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) { |
| 9777 | nlmsg_free(msg); |
| 9778 | return -ENOBUFS; |
| 9779 | } |
| 9780 | nla_nest_end(msg, data); |
| 9781 | |
| 9782 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9783 | if (ret) { |
| 9784 | wpa_printf(MSG_DEBUG, |
| 9785 | "nl80211: Driver setband function failed: %s", |
| 9786 | strerror(errno)); |
| 9787 | } |
| 9788 | return ret; |
| 9789 | } |
| 9790 | |
| 9791 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9792 | struct nl80211_pcl { |
| 9793 | unsigned int num; |
| 9794 | unsigned int *freq_list; |
| 9795 | }; |
| 9796 | |
| 9797 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) |
| 9798 | { |
| 9799 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9800 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9801 | struct nl80211_pcl *param = arg; |
| 9802 | struct nlattr *nl_vend, *attr; |
| 9803 | enum qca_iface_type iface_type; |
| 9804 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 9805 | unsigned int num, max_num; |
| 9806 | u32 *freqs; |
| 9807 | |
| 9808 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9809 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9810 | |
| 9811 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; |
| 9812 | if (!nl_vend) |
| 9813 | return NL_SKIP; |
| 9814 | |
| 9815 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 9816 | nla_data(nl_vend), nla_len(nl_vend), NULL); |
| 9817 | |
| 9818 | attr = tb_vendor[ |
| 9819 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; |
| 9820 | if (!attr) { |
| 9821 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); |
| 9822 | param->num = 0; |
| 9823 | return NL_SKIP; |
| 9824 | } |
| 9825 | |
| 9826 | iface_type = (enum qca_iface_type) nla_get_u32(attr); |
| 9827 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", |
| 9828 | iface_type); |
| 9829 | |
| 9830 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; |
| 9831 | if (!attr) { |
| 9832 | wpa_printf(MSG_ERROR, |
| 9833 | "nl80211: preferred_freq_list couldn't be found"); |
| 9834 | param->num = 0; |
| 9835 | return NL_SKIP; |
| 9836 | } |
| 9837 | |
| 9838 | /* |
| 9839 | * param->num has the maximum number of entries for which there |
| 9840 | * is room in the freq_list provided by the caller. |
| 9841 | */ |
| 9842 | freqs = nla_data(attr); |
| 9843 | max_num = nla_len(attr) / sizeof(u32); |
| 9844 | if (max_num > param->num) |
| 9845 | max_num = param->num; |
| 9846 | for (num = 0; num < max_num; num++) |
| 9847 | param->freq_list[num] = freqs[num]; |
| 9848 | param->num = num; |
| 9849 | |
| 9850 | return NL_SKIP; |
| 9851 | } |
| 9852 | |
| 9853 | |
| 9854 | static int nl80211_get_pref_freq_list(void *priv, |
| 9855 | enum wpa_driver_if_type if_type, |
| 9856 | unsigned int *num, |
| 9857 | unsigned int *freq_list) |
| 9858 | { |
| 9859 | struct i802_bss *bss = priv; |
| 9860 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9861 | struct nl_msg *msg; |
| 9862 | int ret; |
| 9863 | unsigned int i; |
| 9864 | struct nlattr *params; |
| 9865 | struct nl80211_pcl param; |
| 9866 | enum qca_iface_type iface_type; |
| 9867 | |
| 9868 | if (!drv->get_pref_freq_list) |
| 9869 | return -1; |
| 9870 | |
| 9871 | switch (if_type) { |
| 9872 | case WPA_IF_STATION: |
| 9873 | iface_type = QCA_IFACE_TYPE_STA; |
| 9874 | break; |
| 9875 | case WPA_IF_AP_BSS: |
| 9876 | iface_type = QCA_IFACE_TYPE_AP; |
| 9877 | break; |
| 9878 | case WPA_IF_P2P_GO: |
| 9879 | iface_type = QCA_IFACE_TYPE_P2P_GO; |
| 9880 | break; |
| 9881 | case WPA_IF_P2P_CLIENT: |
| 9882 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; |
| 9883 | break; |
| 9884 | case WPA_IF_IBSS: |
| 9885 | iface_type = QCA_IFACE_TYPE_IBSS; |
| 9886 | break; |
| 9887 | case WPA_IF_TDLS: |
| 9888 | iface_type = QCA_IFACE_TYPE_TDLS; |
| 9889 | break; |
| 9890 | default: |
| 9891 | return -1; |
| 9892 | } |
| 9893 | |
| 9894 | param.num = *num; |
| 9895 | param.freq_list = freq_list; |
| 9896 | |
| 9897 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9898 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || |
| 9899 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9900 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9901 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || |
| 9902 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9903 | nla_put_u32(msg, |
| 9904 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, |
| 9905 | iface_type)) { |
| 9906 | wpa_printf(MSG_ERROR, |
| 9907 | "%s: err in adding vendor_cmd and vendor_data", |
| 9908 | __func__); |
| 9909 | nlmsg_free(msg); |
| 9910 | return -1; |
| 9911 | } |
| 9912 | nla_nest_end(msg, params); |
| 9913 | |
| 9914 | os_memset(freq_list, 0, *num * sizeof(freq_list[0])); |
| 9915 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m); |
| 9916 | if (ret) { |
| 9917 | wpa_printf(MSG_ERROR, |
| 9918 | "%s: err in send_and_recv_msgs", __func__); |
| 9919 | return ret; |
| 9920 | } |
| 9921 | |
| 9922 | *num = param.num; |
| 9923 | |
| 9924 | for (i = 0; i < *num; i++) { |
| 9925 | wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d", |
| 9926 | i, freq_list[i]); |
| 9927 | } |
| 9928 | |
| 9929 | return 0; |
| 9930 | } |
| 9931 | |
| 9932 | |
| 9933 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
| 9934 | { |
| 9935 | struct i802_bss *bss = priv; |
| 9936 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9937 | struct nl_msg *msg; |
| 9938 | int ret; |
| 9939 | struct nlattr *params; |
| 9940 | |
| 9941 | if (!drv->set_prob_oper_freq) |
| 9942 | return -1; |
| 9943 | |
| 9944 | wpa_printf(MSG_DEBUG, |
| 9945 | "nl80211: Set P2P probable operating freq %u for ifindex %d", |
| 9946 | freq, bss->ifindex); |
| 9947 | |
| 9948 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9949 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9950 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9951 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || |
| 9952 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9953 | nla_put_u32(msg, |
| 9954 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, |
| 9955 | QCA_IFACE_TYPE_P2P_CLIENT) || |
| 9956 | nla_put_u32(msg, |
| 9957 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, |
| 9958 | freq)) { |
| 9959 | wpa_printf(MSG_ERROR, |
| 9960 | "%s: err in adding vendor_cmd and vendor_data", |
| 9961 | __func__); |
| 9962 | nlmsg_free(msg); |
| 9963 | return -1; |
| 9964 | } |
| 9965 | nla_nest_end(msg, params); |
| 9966 | |
| 9967 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9968 | msg = NULL; |
| 9969 | if (ret) { |
| 9970 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", |
| 9971 | __func__); |
| 9972 | return ret; |
| 9973 | } |
| 9974 | nlmsg_free(msg); |
| 9975 | return 0; |
| 9976 | } |
| 9977 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 9978 | |
| 9979 | static int nl80211_p2p_lo_start(void *priv, unsigned int freq, |
| 9980 | unsigned int period, unsigned int interval, |
| 9981 | unsigned int count, const u8 *device_types, |
| 9982 | size_t dev_types_len, |
| 9983 | const u8 *ies, size_t ies_len) |
| 9984 | { |
| 9985 | struct i802_bss *bss = priv; |
| 9986 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9987 | struct nl_msg *msg; |
| 9988 | struct nlattr *container; |
| 9989 | int ret; |
| 9990 | |
| 9991 | wpa_printf(MSG_DEBUG, |
| 9992 | "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u", |
| 9993 | freq, period, interval, count); |
| 9994 | |
| 9995 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 9996 | return -1; |
| 9997 | |
| 9998 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9999 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10000 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10001 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START)) |
| 10002 | goto fail; |
| 10003 | |
| 10004 | container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 10005 | if (!container) |
| 10006 | goto fail; |
| 10007 | |
| 10008 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL, |
| 10009 | freq) || |
| 10010 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD, |
| 10011 | period) || |
| 10012 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL, |
| 10013 | interval) || |
| 10014 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT, |
| 10015 | count) || |
| 10016 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES, |
| 10017 | dev_types_len, device_types) || |
| 10018 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE, |
| 10019 | ies_len, ies)) |
| 10020 | goto fail; |
| 10021 | |
| 10022 | nla_nest_end(msg, container); |
| 10023 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10024 | msg = NULL; |
| 10025 | if (ret) { |
| 10026 | wpa_printf(MSG_DEBUG, |
| 10027 | "nl80211: Failed to send P2P Listen offload vendor command"); |
| 10028 | goto fail; |
| 10029 | } |
| 10030 | |
| 10031 | return 0; |
| 10032 | |
| 10033 | fail: |
| 10034 | nlmsg_free(msg); |
| 10035 | return -1; |
| 10036 | } |
| 10037 | |
| 10038 | |
| 10039 | static int nl80211_p2p_lo_stop(void *priv) |
| 10040 | { |
| 10041 | struct i802_bss *bss = priv; |
| 10042 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10043 | struct nl_msg *msg; |
| 10044 | |
| 10045 | wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload"); |
| 10046 | |
| 10047 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 10048 | return -1; |
| 10049 | |
| 10050 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10051 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10052 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10053 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) { |
| 10054 | nlmsg_free(msg); |
| 10055 | return -1; |
| 10056 | } |
| 10057 | |
| 10058 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10059 | } |
| 10060 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 10061 | |
| 10062 | static int nl80211_set_tdls_mode(void *priv, int tdls_external_control) |
| 10063 | { |
| 10064 | struct i802_bss *bss = priv; |
| 10065 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10066 | struct nl_msg *msg; |
| 10067 | struct nlattr *params; |
| 10068 | int ret; |
| 10069 | u32 tdls_mode; |
| 10070 | |
| 10071 | wpa_printf(MSG_DEBUG, |
| 10072 | "nl80211: Set TDKS mode: tdls_external_control=%d", |
| 10073 | tdls_external_control); |
| 10074 | |
| 10075 | if (tdls_external_control == 1) |
| 10076 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT | |
| 10077 | QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL; |
| 10078 | else |
| 10079 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT; |
| 10080 | |
| 10081 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10082 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10083 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10084 | QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS)) |
| 10085 | goto fail; |
| 10086 | |
| 10087 | params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 10088 | if (!params) |
| 10089 | goto fail; |
| 10090 | |
| 10091 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE, |
| 10092 | tdls_mode)) |
| 10093 | goto fail; |
| 10094 | |
| 10095 | nla_nest_end(msg, params); |
| 10096 | |
| 10097 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10098 | msg = NULL; |
| 10099 | if (ret) { |
| 10100 | wpa_printf(MSG_ERROR, |
| 10101 | "nl80211: Set TDLS mode failed: ret=%d (%s)", |
| 10102 | ret, strerror(-ret)); |
| 10103 | goto fail; |
| 10104 | } |
| 10105 | return 0; |
| 10106 | fail: |
| 10107 | nlmsg_free(msg); |
| 10108 | return -1; |
| 10109 | } |
| 10110 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10111 | |
| 10112 | #ifdef CONFIG_MBO |
| 10113 | |
| 10114 | static enum mbo_transition_reject_reason |
| 10115 | nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status) |
| 10116 | { |
| 10117 | switch (status) { |
| 10118 | case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED: |
| 10119 | return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS; |
| 10120 | case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED: |
| 10121 | return MBO_TRANSITION_REJECT_REASON_DELAY; |
| 10122 | case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY: |
| 10123 | return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY; |
| 10124 | case QCA_STATUS_REJECT_LOW_RSSI: |
| 10125 | return MBO_TRANSITION_REJECT_REASON_RSSI; |
| 10126 | case QCA_STATUS_REJECT_HIGH_INTERFERENCE: |
| 10127 | return MBO_TRANSITION_REJECT_REASON_INTERFERENCE; |
| 10128 | case QCA_STATUS_REJECT_UNKNOWN: |
| 10129 | default: |
| 10130 | return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED; |
| 10131 | } |
| 10132 | } |
| 10133 | |
| 10134 | |
| 10135 | static void nl80211_parse_btm_candidate_info(struct candidate_list *candidate, |
| 10136 | struct nlattr *tb[], int num) |
| 10137 | { |
| 10138 | enum qca_wlan_btm_candidate_status status; |
| 10139 | char buf[50]; |
| 10140 | |
| 10141 | os_memcpy(candidate->bssid, |
| 10142 | nla_data(tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID]), |
| 10143 | ETH_ALEN); |
| 10144 | |
| 10145 | status = nla_get_u32( |
| 10146 | tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]); |
| 10147 | candidate->is_accept = status == QCA_STATUS_ACCEPT; |
| 10148 | candidate->reject_reason = nl80211_mbo_reject_reason_mapping(status); |
| 10149 | |
| 10150 | if (candidate->is_accept) |
| 10151 | os_snprintf(buf, sizeof(buf), "Accepted"); |
| 10152 | else |
| 10153 | os_snprintf(buf, sizeof(buf), |
| 10154 | "Rejected, Reject_reason: %d", |
| 10155 | candidate->reject_reason); |
| 10156 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR " %s", |
| 10157 | num, MAC2STR(candidate->bssid), buf); |
| 10158 | } |
| 10159 | |
| 10160 | |
| 10161 | static int |
| 10162 | nl80211_get_bss_transition_status_handler(struct nl_msg *msg, void *arg) |
| 10163 | { |
| 10164 | struct wpa_bss_candidate_info *info = arg; |
| 10165 | struct candidate_list *candidate = info->candidates; |
| 10166 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 10167 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 10168 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1]; |
| 10169 | static struct nla_policy policy[ |
| 10170 | QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1] = { |
| 10171 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] = { |
| 10172 | .minlen = ETH_ALEN |
| 10173 | }, |
| 10174 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS] = { |
| 10175 | .type = NLA_U32, |
| 10176 | }, |
| 10177 | }; |
| 10178 | struct nlattr *attr; |
| 10179 | int rem; |
| 10180 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 10181 | u8 num; |
| 10182 | |
| 10183 | num = info->num; /* number of candidates sent to driver */ |
| 10184 | info->num = 0; |
| 10185 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 10186 | genlmsg_attrlen(gnlh, 0), NULL); |
| 10187 | |
| 10188 | if (!tb_msg[NL80211_ATTR_VENDOR_DATA] || |
| 10189 | nla_parse_nested(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 10190 | tb_msg[NL80211_ATTR_VENDOR_DATA], NULL) || |
| 10191 | !tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO]) |
| 10192 | return NL_SKIP; |
| 10193 | |
| 10194 | wpa_printf(MSG_DEBUG, |
| 10195 | "nl80211: WNM Candidate list received from driver"); |
| 10196 | nla_for_each_nested(attr, |
| 10197 | tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO], |
| 10198 | rem) { |
| 10199 | if (info->num >= num || |
| 10200 | nla_parse_nested( |
| 10201 | tb, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX, |
| 10202 | attr, policy) || |
| 10203 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] || |
| 10204 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]) |
| 10205 | break; |
| 10206 | |
| 10207 | nl80211_parse_btm_candidate_info(candidate, tb, info->num); |
| 10208 | |
| 10209 | candidate++; |
| 10210 | info->num++; |
| 10211 | } |
| 10212 | |
| 10213 | return NL_SKIP; |
| 10214 | } |
| 10215 | |
| 10216 | |
| 10217 | static struct wpa_bss_candidate_info * |
| 10218 | nl80211_get_bss_transition_status(void *priv, struct wpa_bss_trans_info *params) |
| 10219 | { |
| 10220 | struct i802_bss *bss = priv; |
| 10221 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10222 | struct nl_msg *msg; |
| 10223 | struct nlattr *attr, *attr1, *attr2; |
| 10224 | struct wpa_bss_candidate_info *info; |
| 10225 | u8 i; |
| 10226 | int ret; |
| 10227 | u8 *pos; |
| 10228 | |
| 10229 | if (!drv->fetch_bss_trans_status) |
| 10230 | return NULL; |
| 10231 | |
| 10232 | info = os_zalloc(sizeof(*info)); |
| 10233 | if (!info) |
| 10234 | return NULL; |
| 10235 | /* Allocate memory for number of candidates sent to driver */ |
| 10236 | info->candidates = os_calloc(params->n_candidates, |
| 10237 | sizeof(*info->candidates)); |
| 10238 | if (!info->candidates) { |
| 10239 | os_free(info); |
| 10240 | return NULL; |
| 10241 | } |
| 10242 | |
| 10243 | /* Copy the number of candidates being sent to driver. This is used in |
| 10244 | * nl80211_get_bss_transition_status_handler() to limit the number of |
| 10245 | * candidates that can be populated in info->candidates and will be |
| 10246 | * later overwritten with the actual number of candidates received from |
| 10247 | * the driver. |
| 10248 | */ |
| 10249 | info->num = params->n_candidates; |
| 10250 | |
| 10251 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10252 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10253 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10254 | QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS)) |
| 10255 | goto fail; |
| 10256 | |
| 10257 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 10258 | if (!attr) |
| 10259 | goto fail; |
| 10260 | |
| 10261 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON, |
| 10262 | params->mbo_transition_reason)) |
| 10263 | goto fail; |
| 10264 | |
| 10265 | attr1 = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO); |
| 10266 | if (!attr1) |
| 10267 | goto fail; |
| 10268 | |
| 10269 | wpa_printf(MSG_DEBUG, |
| 10270 | "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d", |
| 10271 | params->mbo_transition_reason, params->n_candidates); |
| 10272 | pos = params->bssid; |
| 10273 | for (i = 0; i < params->n_candidates; i++) { |
| 10274 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR, i, |
| 10275 | MAC2STR(pos)); |
| 10276 | attr2 = nla_nest_start(msg, i); |
| 10277 | if (!attr2 || |
| 10278 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID, |
| 10279 | ETH_ALEN, pos)) |
| 10280 | goto fail; |
| 10281 | pos += ETH_ALEN; |
| 10282 | nla_nest_end(msg, attr2); |
| 10283 | } |
| 10284 | |
| 10285 | nla_nest_end(msg, attr1); |
| 10286 | nla_nest_end(msg, attr); |
| 10287 | |
| 10288 | ret = send_and_recv_msgs(drv, msg, |
| 10289 | nl80211_get_bss_transition_status_handler, |
| 10290 | info); |
| 10291 | msg = NULL; |
| 10292 | if (ret) { |
| 10293 | wpa_printf(MSG_ERROR, |
| 10294 | "nl80211: WNM Get BSS transition status failed: ret=%d (%s)", |
| 10295 | ret, strerror(-ret)); |
| 10296 | goto fail; |
| 10297 | } |
| 10298 | return info; |
| 10299 | |
| 10300 | fail: |
| 10301 | nlmsg_free(msg); |
| 10302 | os_free(info->candidates); |
| 10303 | os_free(info); |
| 10304 | return NULL; |
| 10305 | } |
| 10306 | |
| 10307 | |
| 10308 | /** |
| 10309 | * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow |
| 10310 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() |
| 10311 | * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore |
| 10312 | * Returns: 0 on success, -1 on failure |
| 10313 | */ |
| 10314 | static int nl80211_ignore_assoc_disallow(void *priv, int ignore_disallow) |
| 10315 | { |
| 10316 | struct i802_bss *bss = priv; |
| 10317 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10318 | struct nl_msg *msg; |
| 10319 | struct nlattr *attr; |
| 10320 | int ret = -1; |
| 10321 | |
| 10322 | if (!drv->set_wifi_conf_vendor_cmd_avail) |
| 10323 | return -1; |
| 10324 | |
| 10325 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10326 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10327 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10328 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) |
| 10329 | goto fail; |
| 10330 | |
| 10331 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 10332 | if (!attr) |
| 10333 | goto fail; |
| 10334 | |
| 10335 | wpa_printf(MSG_DEBUG, "nl80211: Set ignore_assoc_disallow %d", |
| 10336 | ignore_disallow); |
| 10337 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED, |
| 10338 | ignore_disallow)) |
| 10339 | goto fail; |
| 10340 | |
| 10341 | nla_nest_end(msg, attr); |
| 10342 | |
| 10343 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10344 | msg = NULL; |
| 10345 | if (ret) { |
| 10346 | wpa_printf(MSG_ERROR, |
| 10347 | "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)", |
| 10348 | ret, strerror(-ret)); |
| 10349 | goto fail; |
| 10350 | } |
| 10351 | |
| 10352 | fail: |
| 10353 | nlmsg_free(msg); |
| 10354 | return ret; |
| 10355 | } |
| 10356 | |
| 10357 | #endif /* CONFIG_MBO */ |
| 10358 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10359 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 10360 | |
| 10361 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10362 | static int nl80211_write_to_file(const char *name, unsigned int val) |
| 10363 | { |
| 10364 | int fd, len; |
| 10365 | char tmp[128]; |
| 10366 | |
| 10367 | fd = open(name, O_RDWR); |
| 10368 | if (fd < 0) { |
| 10369 | wpa_printf(MSG_ERROR, "nl80211: Failed to open %s: %s", |
| 10370 | name, strerror(errno)); |
| 10371 | return fd; |
| 10372 | } |
| 10373 | |
| 10374 | len = os_snprintf(tmp, sizeof(tmp), "%u\n", val); |
| 10375 | len = write(fd, tmp, len); |
| 10376 | if (len < 0) |
| 10377 | wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s", |
| 10378 | name, strerror(errno)); |
| 10379 | close(fd); |
| 10380 | |
| 10381 | return 0; |
| 10382 | } |
| 10383 | |
| 10384 | |
| 10385 | static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags) |
| 10386 | { |
| 10387 | struct i802_bss *bss = priv; |
| 10388 | char path[128]; |
| 10389 | int ret; |
| 10390 | |
| 10391 | wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x", |
| 10392 | filter_flags); |
| 10393 | |
| 10394 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 10395 | ret = os_snprintf(path, sizeof(path), |
| 10396 | "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast", |
| 10397 | bss->ifname); |
| 10398 | if (os_snprintf_error(sizeof(path), ret)) |
| 10399 | return -1; |
| 10400 | |
| 10401 | ret = nl80211_write_to_file(path, |
| 10402 | !!(filter_flags & |
| 10403 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 10404 | if (ret) { |
| 10405 | wpa_printf(MSG_ERROR, |
| 10406 | "nl80211: Failed to set IPv4 unicast in multicast filter"); |
| 10407 | return ret; |
| 10408 | } |
| 10409 | |
| 10410 | os_snprintf(path, sizeof(path), |
| 10411 | "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast", |
| 10412 | bss->ifname); |
| 10413 | ret = nl80211_write_to_file(path, |
| 10414 | !!(filter_flags & |
| 10415 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 10416 | |
| 10417 | if (ret) { |
| 10418 | wpa_printf(MSG_ERROR, |
| 10419 | "nl80211: Failed to set IPv6 unicast in multicast filter"); |
| 10420 | return ret; |
| 10421 | } |
| 10422 | |
| 10423 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 10424 | os_snprintf(path, sizeof(path), |
| 10425 | "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp", |
| 10426 | bss->ifname); |
| 10427 | ret = nl80211_write_to_file(path, |
| 10428 | !!(filter_flags & |
| 10429 | WPA_DATA_FRAME_FILTER_FLAG_ARP)); |
| 10430 | if (ret) { |
| 10431 | wpa_printf(MSG_ERROR, |
| 10432 | "nl80211: Failed set gratuitous ARP filter"); |
| 10433 | return ret; |
| 10434 | } |
| 10435 | |
| 10436 | /* Configure filtering of IPv6 NA frames */ |
| 10437 | os_snprintf(path, sizeof(path), |
| 10438 | "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na", |
| 10439 | bss->ifname); |
| 10440 | ret = nl80211_write_to_file(path, |
| 10441 | !!(filter_flags & |
| 10442 | WPA_DATA_FRAME_FILTER_FLAG_NA)); |
| 10443 | if (ret) { |
| 10444 | wpa_printf(MSG_ERROR, |
| 10445 | "nl80211: Failed to set unsolicited NA filter"); |
| 10446 | return ret; |
| 10447 | } |
| 10448 | |
| 10449 | return 0; |
| 10450 | } |
| 10451 | |
| 10452 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 10453 | static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type, |
| 10454 | const u8 **ext_capa, const u8 **ext_capa_mask, |
| 10455 | unsigned int *ext_capa_len) |
| 10456 | { |
| 10457 | struct i802_bss *bss = priv; |
| 10458 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10459 | enum nl80211_iftype nlmode; |
| 10460 | unsigned int i; |
| 10461 | |
| 10462 | if (!ext_capa || !ext_capa_mask || !ext_capa_len) |
| 10463 | return -1; |
| 10464 | |
| 10465 | nlmode = wpa_driver_nl80211_if_type(type); |
| 10466 | |
| 10467 | /* By default, use the per-radio values */ |
| 10468 | *ext_capa = drv->extended_capa; |
| 10469 | *ext_capa_mask = drv->extended_capa_mask; |
| 10470 | *ext_capa_len = drv->extended_capa_len; |
| 10471 | |
| 10472 | /* Replace the default value if a per-interface type value exists */ |
| 10473 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 10474 | if (nlmode == drv->iface_ext_capa[i].iftype) { |
| 10475 | *ext_capa = drv->iface_ext_capa[i].ext_capa; |
| 10476 | *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask; |
| 10477 | *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len; |
| 10478 | break; |
| 10479 | } |
| 10480 | } |
| 10481 | |
| 10482 | return 0; |
| 10483 | } |
| 10484 | |
| 10485 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10486 | static int nl80211_update_connection_params( |
| 10487 | void *priv, struct wpa_driver_associate_params *params, |
| 10488 | enum wpa_drv_update_connect_params_mask mask) |
| 10489 | { |
| 10490 | struct i802_bss *bss = priv; |
| 10491 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10492 | struct nl_msg *msg; |
| 10493 | int ret = -1; |
| 10494 | enum nl80211_auth_type type; |
| 10495 | |
| 10496 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS); |
| 10497 | if (!msg) |
| 10498 | goto fail; |
| 10499 | |
| 10500 | wpa_printf(MSG_DEBUG, "nl80211: Update connection params (ifindex=%d)", |
| 10501 | drv->ifindex); |
| 10502 | |
| 10503 | if ((mask & WPA_DRV_UPDATE_ASSOC_IES) && params->wpa_ie) { |
| 10504 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 10505 | params->wpa_ie)) |
| 10506 | goto fail; |
| 10507 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, |
| 10508 | params->wpa_ie_len); |
| 10509 | } |
| 10510 | |
| 10511 | if (mask & WPA_DRV_UPDATE_AUTH_TYPE) { |
| 10512 | type = get_nl_auth_type(params->auth_alg); |
| 10513 | if (type == NL80211_AUTHTYPE_MAX || |
| 10514 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 10515 | goto fail; |
| 10516 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
| 10517 | } |
| 10518 | |
| 10519 | if ((mask & WPA_DRV_UPDATE_FILS_ERP_INFO) && |
| 10520 | nl80211_put_fils_connect_params(drv, params, msg)) |
| 10521 | goto fail; |
| 10522 | |
| 10523 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10524 | msg = NULL; |
| 10525 | if (ret) |
| 10526 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 10527 | "nl80211: Update connect params command failed: ret=%d (%s)", |
| 10528 | ret, strerror(-ret)); |
| 10529 | |
| 10530 | fail: |
| 10531 | nlmsg_free(msg); |
| 10532 | return ret; |
| 10533 | } |
| 10534 | |
| 10535 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10536 | static int nl80211_send_external_auth_status(void *priv, |
| 10537 | struct external_auth *params) |
| 10538 | { |
| 10539 | struct i802_bss *bss = priv; |
| 10540 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10541 | struct nl_msg *msg = NULL; |
| 10542 | int ret = -1; |
| 10543 | |
| 10544 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 10545 | "nl80211: External auth status: %u", params->status); |
| 10546 | |
| 10547 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_EXTERNAL_AUTH); |
| 10548 | if (!msg || |
| 10549 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, params->status) || |
| 10550 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 10551 | params->ssid) || |
| 10552 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid)) |
| 10553 | goto fail; |
| 10554 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10555 | msg = NULL; |
| 10556 | if (ret) { |
| 10557 | wpa_printf(MSG_DEBUG, |
| 10558 | "nl80211: External Auth status update failed: ret=%d (%s)", |
| 10559 | ret, strerror(-ret)); |
| 10560 | goto fail; |
| 10561 | } |
| 10562 | fail: |
| 10563 | nlmsg_free(msg); |
| 10564 | return ret; |
| 10565 | } |
| 10566 | |
| 10567 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10568 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 10569 | .name = "nl80211", |
| 10570 | .desc = "Linux nl80211/cfg80211", |
| 10571 | .get_bssid = wpa_driver_nl80211_get_bssid, |
| 10572 | .get_ssid = wpa_driver_nl80211_get_ssid, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10573 | .set_key = driver_nl80211_set_key, |
| 10574 | .scan2 = driver_nl80211_scan2, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10575 | .sched_scan = wpa_driver_nl80211_sched_scan, |
| 10576 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10577 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 10578 | .abort_scan = wpa_driver_nl80211_abort_scan, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10579 | .deauthenticate = driver_nl80211_deauthenticate, |
| 10580 | .authenticate = driver_nl80211_authenticate, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10581 | .associate = wpa_driver_nl80211_associate, |
| 10582 | .global_init = nl80211_global_init, |
| 10583 | .global_deinit = nl80211_global_deinit, |
| 10584 | .init2 = wpa_driver_nl80211_init, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10585 | .deinit = driver_nl80211_deinit, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10586 | .get_capa = wpa_driver_nl80211_get_capa, |
| 10587 | .set_operstate = wpa_driver_nl80211_set_operstate, |
| 10588 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
| 10589 | .set_country = wpa_driver_nl80211_set_country, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 10590 | .get_country = wpa_driver_nl80211_get_country, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10591 | .set_ap = wpa_driver_nl80211_set_ap, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 10592 | .set_acl = wpa_driver_nl80211_set_acl, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10593 | .if_add = wpa_driver_nl80211_if_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10594 | .if_remove = driver_nl80211_if_remove, |
| 10595 | .send_mlme = driver_nl80211_send_mlme, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10596 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10597 | .sta_add = wpa_driver_nl80211_sta_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10598 | .sta_remove = driver_nl80211_sta_remove, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10599 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
| 10600 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10601 | .hapd_init = i802_init, |
| 10602 | .hapd_deinit = i802_deinit, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10603 | .set_wds_sta = i802_set_wds_sta, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10604 | .get_seqnum = i802_get_seqnum, |
| 10605 | .flush = i802_flush, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10606 | .get_inact_sec = i802_get_inact_sec, |
| 10607 | .sta_clear_stats = i802_sta_clear_stats, |
| 10608 | .set_rts = i802_set_rts, |
| 10609 | .set_frag = i802_set_frag, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10610 | .set_tx_queue_params = i802_set_tx_queue_params, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10611 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10612 | .sta_deauth = i802_sta_deauth, |
| 10613 | .sta_disassoc = i802_sta_disassoc, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10614 | .read_sta_data = driver_nl80211_read_sta_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10615 | .set_freq = i802_set_freq, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10616 | .send_action = driver_nl80211_send_action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10617 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
| 10618 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
| 10619 | .cancel_remain_on_channel = |
| 10620 | wpa_driver_nl80211_cancel_remain_on_channel, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10621 | .probe_req_report = driver_nl80211_probe_req_report, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10622 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 10623 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10624 | .resume = wpa_driver_nl80211_resume, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10625 | .signal_monitor = nl80211_signal_monitor, |
| 10626 | .signal_poll = nl80211_signal_poll, |
| 10627 | .send_frame = nl80211_send_frame, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10628 | .set_param = nl80211_set_param, |
| 10629 | .get_radio_name = nl80211_get_radio_name, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10630 | .add_pmkid = nl80211_add_pmkid, |
| 10631 | .remove_pmkid = nl80211_remove_pmkid, |
| 10632 | .flush_pmkid = nl80211_flush_pmkid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10633 | .set_rekey_info = nl80211_set_rekey_info, |
| 10634 | .poll_client = nl80211_poll_client, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10635 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 10636 | .start_dfs_cac = nl80211_start_radar_detection, |
| 10637 | .stop_ap = wpa_driver_nl80211_stop_ap, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10638 | #ifdef CONFIG_TDLS |
| 10639 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, |
| 10640 | .tdls_oper = nl80211_tdls_oper, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10641 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
| 10642 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10643 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 10644 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 10645 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10646 | .get_survey = wpa_driver_nl80211_get_survey, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10647 | .status = wpa_driver_nl80211_status, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10648 | .switch_channel = nl80211_switch_channel, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10649 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 10650 | .set_noa = wpa_driver_set_p2p_noa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10651 | .get_noa = wpa_driver_get_p2p_noa, |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 10652 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 10653 | #endif /* ANDROID_P2P */ |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 10654 | #ifdef ANDROID |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 10655 | #ifndef ANDROID_LIB_STUB |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 10656 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 10657 | #endif /* !ANDROID_LIB_STUB */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 10658 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10659 | .vendor_cmd = nl80211_vendor_cmd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10660 | .set_qos_map = nl80211_set_qos_map, |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 10661 | .set_wowlan = nl80211_set_wowlan, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10662 | .set_mac_addr = nl80211_set_mac_addr, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10663 | #ifdef CONFIG_MESH |
| 10664 | .init_mesh = wpa_driver_nl80211_init_mesh, |
| 10665 | .join_mesh = wpa_driver_nl80211_join_mesh, |
| 10666 | .leave_mesh = wpa_driver_nl80211_leave_mesh, |
| 10667 | #endif /* CONFIG_MESH */ |
| 10668 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
| 10669 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, |
| 10670 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
| 10671 | .br_set_net_param = wpa_driver_br_set_net_param, |
| 10672 | .add_tx_ts = nl80211_add_ts, |
| 10673 | .del_tx_ts = nl80211_del_ts, |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 10674 | .get_ifindex = nl80211_get_ifindex, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10675 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 10676 | .roaming = nl80211_roaming, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10677 | .disable_fils = nl80211_disable_fils, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10678 | .do_acs = wpa_driver_do_acs, |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 10679 | .set_band = nl80211_set_band, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10680 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
| 10681 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 10682 | .p2p_lo_start = nl80211_p2p_lo_start, |
| 10683 | .p2p_lo_stop = nl80211_p2p_lo_stop, |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 10684 | .set_default_scan_ies = nl80211_set_default_scan_ies, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 10685 | .set_tdls_mode = nl80211_set_tdls_mode, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10686 | #ifdef CONFIG_MBO |
| 10687 | .get_bss_transition_status = nl80211_get_bss_transition_status, |
| 10688 | .ignore_assoc_disallow = nl80211_ignore_assoc_disallow, |
| 10689 | #endif /* CONFIG_MBO */ |
| 10690 | .set_bssid_blacklist = nl80211_set_bssid_blacklist, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10691 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10692 | .configure_data_frame_filters = nl80211_configure_data_frame_filters, |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 10693 | .get_ext_capab = nl80211_get_ext_capab, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10694 | .update_connect_params = nl80211_update_connection_params, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10695 | .send_external_auth_status = nl80211_send_external_auth_status, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10696 | }; |