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)) { |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 1082 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1083 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1084 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1085 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1086 | "event since interface %s is down", |
| 1087 | namebuf); |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 1088 | return; |
| 1089 | } |
| 1090 | wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)", |
| 1091 | namebuf, ifname); |
| 1092 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 1093 | wpa_printf(MSG_DEBUG, |
| 1094 | "nl80211: Not the main interface (%s) - do not indicate interface up", |
| 1095 | drv->first_bss->ifname); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1096 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1097 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1098 | "event since interface %s does not exist", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1099 | drv->first_bss->ifname); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1100 | } else if (drv->if_removed) { |
| 1101 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1102 | "event since interface %s is marked " |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1103 | "removed", drv->first_bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1104 | } else { |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1105 | /* Re-read MAC address as it may have changed */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1106 | nl80211_refresh_mac(drv, ifi->ifi_index, 0); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1107 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1108 | drv->if_disabled = 0; |
| 1109 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, |
| 1110 | NULL); |
| 1111 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
| 1114 | /* |
| 1115 | * Some drivers send the association event before the operup event--in |
| 1116 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() |
| 1117 | * fails. This will hit us when wpa_supplicant does not need to do |
| 1118 | * IEEE 802.1X authentication |
| 1119 | */ |
| 1120 | if (drv->operstate == 1 && |
| 1121 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1122 | !(ifi->ifi_flags & IFF_RUNNING)) { |
| 1123 | 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] | 1124 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1125 | -1, IF_OPER_UP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1128 | event_newlink: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1129 | if (ifname[0]) |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1130 | wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index, |
| 1131 | ifname); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1132 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1133 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1134 | struct i802_bss *bss; |
| 1135 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1136 | /* device has been added to bridge */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1137 | if (!if_indextoname(brid, namebuf)) { |
| 1138 | wpa_printf(MSG_DEBUG, |
| 1139 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1140 | brid); |
| 1141 | return; |
| 1142 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1143 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
| 1144 | brid, namebuf); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1145 | add_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1146 | |
| 1147 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 1148 | if (os_strcmp(ifname, bss->ifname) == 0) { |
| 1149 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); |
| 1150 | break; |
| 1151 | } |
| 1152 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1153 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | |
| 1157 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
| 1158 | struct ifinfomsg *ifi, |
| 1159 | u8 *buf, size_t len) |
| 1160 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1161 | struct nl80211_global *global = ctx; |
| 1162 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1163 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1164 | struct rtattr *attr; |
| 1165 | u32 brid = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1166 | char ifname[IFNAMSIZ + 1]; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1167 | char extra[100], *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1168 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1169 | extra[0] = '\0'; |
| 1170 | pos = extra; |
| 1171 | end = pos + sizeof(extra); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1172 | ifname[0] = '\0'; |
| 1173 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1174 | attrlen = len; |
| 1175 | attr = (struct rtattr *) buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1176 | while (RTA_OK(attr, attrlen)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1177 | switch (attr->rta_type) { |
| 1178 | case IFLA_IFNAME: |
| 1179 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) |
| 1180 | break; |
| 1181 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1182 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1183 | break; |
| 1184 | case IFLA_MASTER: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1185 | brid = nla_get_u32((struct nlattr *) attr); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1186 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1187 | break; |
| 1188 | case IFLA_OPERSTATE: |
| 1189 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1190 | nla_get_u32((struct nlattr *) attr)); |
| 1191 | break; |
| 1192 | case IFLA_LINKMODE: |
| 1193 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1194 | nla_get_u32((struct nlattr *) attr)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1195 | break; |
| 1196 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1197 | attr = RTA_NEXT(attr, attrlen); |
| 1198 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1199 | extra[sizeof(extra) - 1] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1200 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1201 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1202 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1203 | ifi->ifi_flags, |
| 1204 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1205 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1206 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1207 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1208 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1209 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1210 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1211 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1212 | /* device has been removed from bridge */ |
| 1213 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1214 | |
| 1215 | if (!if_indextoname(brid, namebuf)) { |
| 1216 | wpa_printf(MSG_DEBUG, |
| 1217 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1218 | brid); |
| 1219 | } else { |
| 1220 | wpa_printf(MSG_DEBUG, |
| 1221 | "nl80211: Remove ifindex %u for bridge %s", |
| 1222 | brid, namebuf); |
| 1223 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1224 | del_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1225 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1226 | |
| 1227 | if (ifi->ifi_family != AF_BRIDGE || !brid) |
| 1228 | wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index, |
| 1229 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1233 | struct nl80211_get_assoc_freq_arg { |
| 1234 | struct wpa_driver_nl80211_data *drv; |
| 1235 | unsigned int assoc_freq; |
| 1236 | unsigned int ibss_freq; |
| 1237 | u8 assoc_bssid[ETH_ALEN]; |
| 1238 | u8 assoc_ssid[SSID_MAX_LEN]; |
| 1239 | u8 assoc_ssid_len; |
| 1240 | }; |
| 1241 | |
| 1242 | static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg) |
| 1243 | { |
| 1244 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1245 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1246 | struct nlattr *bss[NL80211_BSS_MAX + 1]; |
| 1247 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { |
| 1248 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, |
| 1249 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, |
| 1250 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, |
| 1251 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
| 1252 | }; |
| 1253 | struct nl80211_get_assoc_freq_arg *ctx = arg; |
| 1254 | enum nl80211_bss_status status; |
| 1255 | |
| 1256 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1257 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1258 | if (!tb[NL80211_ATTR_BSS] || |
| 1259 | nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], |
| 1260 | bss_policy) || |
| 1261 | !bss[NL80211_BSS_STATUS]) |
| 1262 | return NL_SKIP; |
| 1263 | |
| 1264 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); |
| 1265 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1266 | bss[NL80211_BSS_FREQUENCY]) { |
| 1267 | ctx->assoc_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1268 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", |
| 1269 | ctx->assoc_freq); |
| 1270 | } |
| 1271 | if (status == NL80211_BSS_STATUS_IBSS_JOINED && |
| 1272 | bss[NL80211_BSS_FREQUENCY]) { |
| 1273 | ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1274 | wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz", |
| 1275 | ctx->ibss_freq); |
| 1276 | } |
| 1277 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1278 | bss[NL80211_BSS_BSSID]) { |
| 1279 | os_memcpy(ctx->assoc_bssid, |
| 1280 | nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN); |
| 1281 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " |
| 1282 | MACSTR, MAC2STR(ctx->assoc_bssid)); |
| 1283 | } |
| 1284 | |
| 1285 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1286 | bss[NL80211_BSS_INFORMATION_ELEMENTS]) { |
| 1287 | const u8 *ie, *ssid; |
| 1288 | size_t ie_len; |
| 1289 | |
| 1290 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1291 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1292 | ssid = get_ie(ie, ie_len, WLAN_EID_SSID); |
| 1293 | if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) { |
| 1294 | ctx->assoc_ssid_len = ssid[1]; |
| 1295 | os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]); |
| 1296 | } |
| 1297 | } |
| 1298 | |
| 1299 | return NL_SKIP; |
| 1300 | } |
| 1301 | |
| 1302 | |
| 1303 | 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] | 1304 | { |
| 1305 | struct nl_msg *msg; |
| 1306 | int ret; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1307 | struct nl80211_get_assoc_freq_arg arg; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1308 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1309 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1310 | os_memset(&arg, 0, sizeof(arg)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1311 | arg.drv = drv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1312 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
| 1313 | &arg); |
| 1314 | if (ret == 0) { |
| 1315 | os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len); |
| 1316 | return arg.assoc_ssid_len; |
| 1317 | } |
| 1318 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)", |
| 1319 | ret, strerror(-ret)); |
| 1320 | return ret; |
| 1321 | } |
| 1322 | |
| 1323 | |
| 1324 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
| 1325 | { |
| 1326 | struct nl_msg *msg; |
| 1327 | int ret; |
| 1328 | struct nl80211_get_assoc_freq_arg arg; |
| 1329 | |
| 1330 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
| 1331 | os_memset(&arg, 0, sizeof(arg)); |
| 1332 | arg.drv = drv; |
| 1333 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
| 1334 | &arg); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1335 | if (ret == 0) { |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1336 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
| 1337 | arg.ibss_freq : arg.assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1338 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1339 | "associated BSS from scan results: %u MHz", freq); |
| 1340 | if (freq) |
| 1341 | drv->assoc_freq = freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1342 | return drv->assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1343 | } |
| 1344 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
| 1345 | "(%s)", ret, strerror(-ret)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1346 | return drv->assoc_freq; |
| 1347 | } |
| 1348 | |
| 1349 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1350 | static int get_link_signal(struct nl_msg *msg, void *arg) |
| 1351 | { |
| 1352 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1353 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1354 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; |
| 1355 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { |
| 1356 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1357 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1358 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1359 | }; |
| 1360 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
| 1361 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 1362 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 1363 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 1364 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, |
| 1365 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 1366 | }; |
| 1367 | struct wpa_signal_info *sig_change = arg; |
| 1368 | |
| 1369 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1370 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1371 | if (!tb[NL80211_ATTR_STA_INFO] || |
| 1372 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, |
| 1373 | tb[NL80211_ATTR_STA_INFO], policy)) |
| 1374 | return NL_SKIP; |
| 1375 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) |
| 1376 | return NL_SKIP; |
| 1377 | |
| 1378 | sig_change->current_signal = |
| 1379 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); |
| 1380 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1381 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
| 1382 | sig_change->avg_signal = |
| 1383 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); |
| 1384 | else |
| 1385 | sig_change->avg_signal = 0; |
| 1386 | |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1387 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
| 1388 | sig_change->avg_beacon_signal = |
| 1389 | (s8) |
| 1390 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); |
| 1391 | else |
| 1392 | sig_change->avg_beacon_signal = 0; |
| 1393 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1394 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
| 1395 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, |
| 1396 | sinfo[NL80211_STA_INFO_TX_BITRATE], |
| 1397 | rate_policy)) { |
| 1398 | sig_change->current_txrate = 0; |
| 1399 | } else { |
| 1400 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { |
| 1401 | sig_change->current_txrate = |
| 1402 | nla_get_u16(rinfo[ |
| 1403 | NL80211_RATE_INFO_BITRATE]) * 100; |
| 1404 | } |
| 1405 | } |
| 1406 | } |
| 1407 | |
| 1408 | return NL_SKIP; |
| 1409 | } |
| 1410 | |
| 1411 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1412 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
| 1413 | struct wpa_signal_info *sig) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1414 | { |
| 1415 | struct nl_msg *msg; |
| 1416 | |
| 1417 | sig->current_signal = -9999; |
| 1418 | sig->current_txrate = 0; |
| 1419 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1420 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
| 1421 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) { |
| 1422 | nlmsg_free(msg); |
| 1423 | return -ENOBUFS; |
| 1424 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1425 | |
| 1426 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1427 | } |
| 1428 | |
| 1429 | |
| 1430 | static int get_link_noise(struct nl_msg *msg, void *arg) |
| 1431 | { |
| 1432 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1433 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1434 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 1435 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 1436 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 1437 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 1438 | }; |
| 1439 | struct wpa_signal_info *sig_change = arg; |
| 1440 | |
| 1441 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1442 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1443 | |
| 1444 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 1445 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); |
| 1446 | return NL_SKIP; |
| 1447 | } |
| 1448 | |
| 1449 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 1450 | tb[NL80211_ATTR_SURVEY_INFO], |
| 1451 | survey_policy)) { |
| 1452 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " |
| 1453 | "attributes!"); |
| 1454 | return NL_SKIP; |
| 1455 | } |
| 1456 | |
| 1457 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 1458 | return NL_SKIP; |
| 1459 | |
| 1460 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 1461 | sig_change->frequency) |
| 1462 | return NL_SKIP; |
| 1463 | |
| 1464 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 1465 | return NL_SKIP; |
| 1466 | |
| 1467 | sig_change->current_noise = |
| 1468 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 1469 | |
| 1470 | return NL_SKIP; |
| 1471 | } |
| 1472 | |
| 1473 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1474 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
| 1475 | struct wpa_signal_info *sig_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1476 | { |
| 1477 | struct nl_msg *msg; |
| 1478 | |
| 1479 | sig_change->current_noise = 9999; |
| 1480 | sig_change->frequency = drv->assoc_freq; |
| 1481 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1482 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1483 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | |
| 1487 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
| 1488 | void *handle) |
| 1489 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1490 | struct nl_cb *cb = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1491 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1492 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1493 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1494 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1495 | res = nl_recvmsgs(handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 1496 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1497 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 1498 | __func__, res); |
| 1499 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | |
| 1503 | /** |
| 1504 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain |
| 1505 | * @priv: driver_nl80211 private data |
| 1506 | * @alpha2_arg: country to which to switch to |
| 1507 | * Returns: 0 on success, -1 on failure |
| 1508 | * |
| 1509 | * This asks nl80211 to set the regulatory domain for given |
| 1510 | * country ISO / IEC alpha2. |
| 1511 | */ |
| 1512 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) |
| 1513 | { |
| 1514 | struct i802_bss *bss = priv; |
| 1515 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1516 | char alpha2[3]; |
| 1517 | struct nl_msg *msg; |
| 1518 | |
| 1519 | msg = nlmsg_alloc(); |
| 1520 | if (!msg) |
| 1521 | return -ENOMEM; |
| 1522 | |
| 1523 | alpha2[0] = alpha2_arg[0]; |
| 1524 | alpha2[1] = alpha2_arg[1]; |
| 1525 | alpha2[2] = '\0'; |
| 1526 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1527 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
| 1528 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { |
| 1529 | nlmsg_free(msg); |
| 1530 | return -EINVAL; |
| 1531 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1532 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) |
| 1533 | return -EINVAL; |
| 1534 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1538 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
| 1539 | { |
| 1540 | char *alpha2 = arg; |
| 1541 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 1542 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1543 | |
| 1544 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1545 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1546 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { |
| 1547 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); |
| 1548 | return NL_SKIP; |
| 1549 | } |
| 1550 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); |
| 1551 | return NL_SKIP; |
| 1552 | } |
| 1553 | |
| 1554 | |
| 1555 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) |
| 1556 | { |
| 1557 | struct i802_bss *bss = priv; |
| 1558 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1559 | struct nl_msg *msg; |
| 1560 | int ret; |
| 1561 | |
| 1562 | msg = nlmsg_alloc(); |
| 1563 | if (!msg) |
| 1564 | return -ENOMEM; |
| 1565 | |
| 1566 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
| 1567 | alpha2[0] = '\0'; |
| 1568 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2); |
| 1569 | if (!alpha2[0]) |
| 1570 | ret = -1; |
| 1571 | |
| 1572 | return ret; |
| 1573 | } |
| 1574 | |
| 1575 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1576 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1577 | { |
| 1578 | int ret; |
| 1579 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1580 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1581 | if (global->nl_cb == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1582 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 1583 | "callbacks"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1584 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1585 | } |
| 1586 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1587 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
| 1588 | if (global->nl == NULL) |
| 1589 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1590 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1591 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
| 1592 | if (global->nl80211_id < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1593 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
| 1594 | "found"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1595 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1596 | } |
| 1597 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1598 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
| 1599 | if (global->nl_event == NULL) |
| 1600 | goto err; |
| 1601 | |
| 1602 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1603 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1604 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1605 | if (ret < 0) { |
| 1606 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1607 | "membership for scan events: %d (%s)", |
| 1608 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1609 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1610 | } |
| 1611 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1612 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1613 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1614 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1615 | if (ret < 0) { |
| 1616 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1617 | "membership for mlme events: %d (%s)", |
| 1618 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1619 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1620 | } |
| 1621 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1622 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1623 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1624 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1625 | if (ret < 0) { |
| 1626 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1627 | "membership for regulatory events: %d (%s)", |
| 1628 | ret, strerror(-ret)); |
| 1629 | /* Continue without regulatory events */ |
| 1630 | } |
| 1631 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1632 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
| 1633 | if (ret >= 0) |
| 1634 | ret = nl_socket_add_membership(global->nl_event, ret); |
| 1635 | if (ret < 0) { |
| 1636 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1637 | "membership for vendor events: %d (%s)", |
| 1638 | ret, strerror(-ret)); |
| 1639 | /* Continue without vendor events */ |
| 1640 | } |
| 1641 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1642 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1643 | no_seq_check, NULL); |
| 1644 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1645 | process_global_event, global); |
| 1646 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1647 | nl80211_register_eloop_read(&global->nl_event, |
| 1648 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1649 | global->nl_cb, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1650 | |
| 1651 | return 0; |
| 1652 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1653 | err: |
| 1654 | nl_destroy_handles(&global->nl_event); |
| 1655 | nl_destroy_handles(&global->nl); |
| 1656 | nl_cb_put(global->nl_cb); |
| 1657 | global->nl_cb = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1658 | return -1; |
| 1659 | } |
| 1660 | |
| 1661 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1662 | static void nl80211_check_global(struct nl80211_global *global) |
| 1663 | { |
| 1664 | struct nl_handle *handle; |
| 1665 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; |
| 1666 | int ret; |
| 1667 | unsigned int i; |
| 1668 | |
| 1669 | /* |
| 1670 | * Try to re-add memberships to handle case of cfg80211 getting reloaded |
| 1671 | * and all registration having been cleared. |
| 1672 | */ |
| 1673 | handle = (void *) (((intptr_t) global->nl_event) ^ |
| 1674 | ELOOP_SOCKET_INVALID); |
| 1675 | |
| 1676 | for (i = 0; groups[i]; i++) { |
| 1677 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); |
| 1678 | if (ret >= 0) |
| 1679 | ret = nl_socket_add_membership(handle, ret); |
| 1680 | if (ret < 0) { |
| 1681 | wpa_printf(MSG_INFO, |
| 1682 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", |
| 1683 | groups[i], ret, strerror(-ret)); |
| 1684 | } |
| 1685 | } |
| 1686 | } |
| 1687 | |
| 1688 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1689 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
| 1690 | { |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1691 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1692 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1693 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1694 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1695 | /* |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1696 | * rtnetlink ifdown handler will report interfaces other than the P2P |
| 1697 | * Device interface as disabled. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1698 | */ |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1699 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 1700 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1701 | } |
| 1702 | |
| 1703 | |
| 1704 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) |
| 1705 | { |
| 1706 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1707 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1708 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1709 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
| 1710 | "after rfkill unblock"); |
| 1711 | return; |
| 1712 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1713 | |
| 1714 | if (is_p2p_net_interface(drv->nlmode)) |
| 1715 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
| 1716 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1717 | /* |
| 1718 | * rtnetlink ifup handler will report interfaces other than the P2P |
| 1719 | * Device interface as enabled. |
| 1720 | */ |
| 1721 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 1722 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1726 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
| 1727 | void *eloop_ctx, |
| 1728 | void *handle) |
| 1729 | { |
| 1730 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 1731 | u8 data[2048]; |
| 1732 | struct msghdr msg; |
| 1733 | struct iovec entry; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1734 | u8 control[512]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1735 | struct cmsghdr *cmsg; |
| 1736 | int res, found_ee = 0, found_wifi = 0, acked = 0; |
| 1737 | union wpa_event_data event; |
| 1738 | |
| 1739 | memset(&msg, 0, sizeof(msg)); |
| 1740 | msg.msg_iov = &entry; |
| 1741 | msg.msg_iovlen = 1; |
| 1742 | entry.iov_base = data; |
| 1743 | entry.iov_len = sizeof(data); |
| 1744 | msg.msg_control = &control; |
| 1745 | msg.msg_controllen = sizeof(control); |
| 1746 | |
| 1747 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); |
| 1748 | /* if error or not fitting 802.3 header, return */ |
| 1749 | if (res < 14) |
| 1750 | return; |
| 1751 | |
| 1752 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
| 1753 | { |
| 1754 | if (cmsg->cmsg_level == SOL_SOCKET && |
| 1755 | cmsg->cmsg_type == SCM_WIFI_STATUS) { |
| 1756 | int *ack; |
| 1757 | |
| 1758 | found_wifi = 1; |
| 1759 | ack = (void *)CMSG_DATA(cmsg); |
| 1760 | acked = *ack; |
| 1761 | } |
| 1762 | |
| 1763 | if (cmsg->cmsg_level == SOL_PACKET && |
| 1764 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { |
| 1765 | struct sock_extended_err *err = |
| 1766 | (struct sock_extended_err *)CMSG_DATA(cmsg); |
| 1767 | |
| 1768 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) |
| 1769 | found_ee = 1; |
| 1770 | } |
| 1771 | } |
| 1772 | |
| 1773 | if (!found_ee || !found_wifi) |
| 1774 | return; |
| 1775 | |
| 1776 | memset(&event, 0, sizeof(event)); |
| 1777 | event.eapol_tx_status.dst = data; |
| 1778 | event.eapol_tx_status.data = data + 14; |
| 1779 | event.eapol_tx_status.data_len = res - 14; |
| 1780 | event.eapol_tx_status.ack = acked; |
| 1781 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); |
| 1782 | } |
| 1783 | |
| 1784 | |
| 1785 | static int nl80211_init_bss(struct i802_bss *bss) |
| 1786 | { |
| 1787 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1788 | if (!bss->nl_cb) |
| 1789 | return -1; |
| 1790 | |
| 1791 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1792 | no_seq_check, NULL); |
| 1793 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1794 | process_bss_event, bss); |
| 1795 | |
| 1796 | return 0; |
| 1797 | } |
| 1798 | |
| 1799 | |
| 1800 | static void nl80211_destroy_bss(struct i802_bss *bss) |
| 1801 | { |
| 1802 | nl_cb_put(bss->nl_cb); |
| 1803 | bss->nl_cb = NULL; |
| 1804 | } |
| 1805 | |
| 1806 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1807 | static void |
| 1808 | wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv) |
| 1809 | { |
| 1810 | struct rfkill_config *rcfg; |
| 1811 | |
| 1812 | if (drv->rfkill) |
| 1813 | return; |
| 1814 | |
| 1815 | rcfg = os_zalloc(sizeof(*rcfg)); |
| 1816 | if (!rcfg) |
| 1817 | return; |
| 1818 | |
| 1819 | rcfg->ctx = drv; |
| 1820 | |
| 1821 | /* rfkill uses netdev sysfs for initialization. However, P2P Device is |
| 1822 | * not associated with a netdev, so use the name of some other interface |
| 1823 | * sharing the same wiphy as the P2P Device interface. |
| 1824 | * |
| 1825 | * Note: This is valid, as a P2P Device interface is always dynamically |
| 1826 | * created and is created only once another wpa_s interface was added. |
| 1827 | */ |
| 1828 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 1829 | struct nl80211_global *global = drv->global; |
| 1830 | struct wpa_driver_nl80211_data *tmp1; |
| 1831 | |
| 1832 | dl_list_for_each(tmp1, &global->interfaces, |
| 1833 | struct wpa_driver_nl80211_data, list) { |
| 1834 | if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx || |
| 1835 | !tmp1->rfkill) |
| 1836 | continue; |
| 1837 | |
| 1838 | wpa_printf(MSG_DEBUG, |
| 1839 | "nl80211: Use (%s) to initialize P2P Device rfkill", |
| 1840 | tmp1->first_bss->ifname); |
| 1841 | os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname, |
| 1842 | sizeof(rcfg->ifname)); |
| 1843 | break; |
| 1844 | } |
| 1845 | } else { |
| 1846 | os_strlcpy(rcfg->ifname, drv->first_bss->ifname, |
| 1847 | sizeof(rcfg->ifname)); |
| 1848 | } |
| 1849 | |
| 1850 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; |
| 1851 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; |
| 1852 | drv->rfkill = rfkill_init(rcfg); |
| 1853 | if (!drv->rfkill) { |
| 1854 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
| 1855 | os_free(rcfg); |
| 1856 | } |
| 1857 | } |
| 1858 | |
| 1859 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1860 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
| 1861 | void *global_priv, int hostapd, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1862 | const u8 *set_addr, |
| 1863 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1864 | { |
| 1865 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1866 | struct i802_bss *bss; |
| 1867 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1868 | if (global_priv == NULL) |
| 1869 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1870 | drv = os_zalloc(sizeof(*drv)); |
| 1871 | if (drv == NULL) |
| 1872 | return NULL; |
| 1873 | drv->global = global_priv; |
| 1874 | drv->ctx = ctx; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1875 | drv->hostapd = !!hostapd; |
| 1876 | drv->eapol_sock = -1; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1877 | |
| 1878 | /* |
| 1879 | * There is no driver capability flag for this, so assume it is |
| 1880 | * supported and disable this on first attempt to use if the driver |
| 1881 | * rejects the command due to missing support. |
| 1882 | */ |
| 1883 | drv->set_rekey_offload = 1; |
| 1884 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1885 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
| 1886 | drv->if_indices = drv->default_if_indices; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1887 | drv->if_indices_reason = drv->default_if_indices_reason; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1888 | |
| 1889 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); |
| 1890 | if (!drv->first_bss) { |
| 1891 | os_free(drv); |
| 1892 | return NULL; |
| 1893 | } |
| 1894 | bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1895 | bss->drv = drv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1896 | bss->ctx = ctx; |
| 1897 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1898 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
| 1899 | drv->monitor_ifidx = -1; |
| 1900 | drv->monitor_sock = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1901 | drv->eapol_tx_sock = -1; |
| 1902 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1903 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1904 | if (nl80211_init_bss(bss)) |
| 1905 | goto failed; |
| 1906 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1907 | 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] | 1908 | goto failed; |
| 1909 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1910 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
| 1911 | if (drv->eapol_tx_sock < 0) |
| 1912 | goto failed; |
| 1913 | |
| 1914 | if (drv->data_tx_status) { |
| 1915 | int enabled = 1; |
| 1916 | |
| 1917 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, |
| 1918 | &enabled, sizeof(enabled)) < 0) { |
| 1919 | wpa_printf(MSG_DEBUG, |
| 1920 | "nl80211: wifi status sockopt failed\n"); |
| 1921 | drv->data_tx_status = 0; |
| 1922 | if (!drv->use_monitor) |
| 1923 | drv->capa.flags &= |
| 1924 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
| 1925 | } else { |
| 1926 | eloop_register_read_sock(drv->eapol_tx_sock, |
| 1927 | wpa_driver_nl80211_handle_eapol_tx_status, |
| 1928 | drv, NULL); |
| 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | if (drv->global) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1933 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1934 | dl_list_add(&drv->global->interfaces, &drv->list); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1935 | drv->in_interface_list = 1; |
| 1936 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1937 | |
| 1938 | return bss; |
| 1939 | |
| 1940 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1941 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1942 | return NULL; |
| 1943 | } |
| 1944 | |
| 1945 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1946 | /** |
| 1947 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface |
| 1948 | * @ctx: context to be used when calling wpa_supplicant functions, |
| 1949 | * e.g., wpa_supplicant_event() |
| 1950 | * @ifname: interface name, e.g., wlan0 |
| 1951 | * @global_priv: private driver global data from global_init() |
| 1952 | * Returns: Pointer to private data, %NULL on failure |
| 1953 | */ |
| 1954 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
| 1955 | void *global_priv) |
| 1956 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1957 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
| 1958 | NULL); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1962 | static int nl80211_register_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1963 | struct nl_handle *nl_handle, |
| 1964 | u16 type, const u8 *match, size_t match_len) |
| 1965 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1966 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1967 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1968 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1969 | char buf[30]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1970 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1971 | buf[0] = '\0'; |
| 1972 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 1973 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s", |
| 1974 | type, fc2str(type), nl_handle, buf); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1975 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1976 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) || |
| 1977 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
| 1978 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { |
| 1979 | nlmsg_free(msg); |
| 1980 | return -1; |
| 1981 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1982 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1983 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1984 | if (ret) { |
| 1985 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
| 1986 | "failed (type=%u): ret=%d (%s)", |
| 1987 | type, ret, strerror(-ret)); |
| 1988 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", |
| 1989 | match, match_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1990 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1991 | return ret; |
| 1992 | } |
| 1993 | |
| 1994 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1995 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
| 1996 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1997 | if (bss->nl_mgmt) { |
| 1998 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
| 1999 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
| 2000 | return -1; |
| 2001 | } |
| 2002 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2003 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2004 | if (bss->nl_mgmt == NULL) |
| 2005 | return -1; |
| 2006 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2007 | return 0; |
| 2008 | } |
| 2009 | |
| 2010 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2011 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
| 2012 | { |
| 2013 | nl80211_register_eloop_read(&bss->nl_mgmt, |
| 2014 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2015 | bss->nl_cb, 0); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2019 | static int nl80211_register_action_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2020 | const u8 *match, size_t match_len) |
| 2021 | { |
| 2022 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2023 | return nl80211_register_frame(bss, bss->nl_mgmt, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2024 | type, match, match_len); |
| 2025 | } |
| 2026 | |
| 2027 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2028 | static int nl80211_init_connect_handle(struct i802_bss *bss) |
| 2029 | { |
| 2030 | if (bss->nl_connect) { |
| 2031 | wpa_printf(MSG_DEBUG, |
| 2032 | "nl80211: Connect handle already created (nl_connect=%p)", |
| 2033 | bss->nl_connect); |
| 2034 | return -1; |
| 2035 | } |
| 2036 | |
| 2037 | bss->nl_connect = nl_create_handle(bss->nl_cb, "connect"); |
| 2038 | if (!bss->nl_connect) |
| 2039 | return -1; |
| 2040 | nl80211_register_eloop_read(&bss->nl_connect, |
| 2041 | wpa_driver_nl80211_event_receive, |
| 2042 | bss->nl_cb, 1); |
| 2043 | return 0; |
| 2044 | } |
| 2045 | |
| 2046 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2047 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2048 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2049 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2050 | int ret = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2051 | |
| 2052 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2053 | return -1; |
| 2054 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
| 2055 | "handle %p", bss->nl_mgmt); |
| 2056 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2057 | if (drv->nlmode == NL80211_IFTYPE_ADHOC || |
| 2058 | ((drv->capa.flags & WPA_DRIVER_FLAGS_SAE) && |
| 2059 | !(drv->capa.flags & WPA_DRIVER_FLAGS_SME))) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2060 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
| 2061 | |
| 2062 | /* register for any AUTH message */ |
| 2063 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); |
| 2064 | } |
| 2065 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2066 | #ifdef CONFIG_INTERWORKING |
| 2067 | /* QoS Map Configure */ |
| 2068 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2069 | ret = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2070 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2071 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2072 | /* GAS Initial Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2073 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2074 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2075 | /* GAS Initial Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2076 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2077 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2078 | /* GAS Comeback Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2079 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2080 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2081 | /* GAS Comeback Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2082 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2083 | ret = -1; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2084 | /* Protected GAS Initial Request */ |
| 2085 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) |
| 2086 | ret = -1; |
| 2087 | /* Protected GAS Initial Response */ |
| 2088 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) |
| 2089 | ret = -1; |
| 2090 | /* Protected GAS Comeback Request */ |
| 2091 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) |
| 2092 | ret = -1; |
| 2093 | /* Protected GAS Comeback Response */ |
| 2094 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) |
| 2095 | ret = -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2096 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2097 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2098 | /* P2P Public Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2099 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2100 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
| 2101 | 6) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2102 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2103 | /* P2P Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2104 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2105 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
| 2106 | 5) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2107 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2108 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2109 | #ifdef CONFIG_DPP |
| 2110 | /* DPP Public Action */ |
| 2111 | if (nl80211_register_action_frame(bss, |
| 2112 | (u8 *) "\x04\x09\x50\x6f\x9a\x1a", |
| 2113 | 6) < 0) |
| 2114 | ret = -1; |
| 2115 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2116 | #ifdef CONFIG_IEEE80211W |
| 2117 | /* SA Query Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2118 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2119 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2120 | #endif /* CONFIG_IEEE80211W */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2121 | #ifdef CONFIG_TDLS |
| 2122 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { |
| 2123 | /* TDLS Discovery Response */ |
| 2124 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
| 2125 | 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2126 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2127 | } |
| 2128 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2129 | #ifdef CONFIG_FST |
| 2130 | /* FST Action frames */ |
| 2131 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2132 | ret = -1; |
| 2133 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2134 | |
| 2135 | /* FT Action frames */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2136 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2137 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2138 | else |
| 2139 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | |
| 2140 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; |
| 2141 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2142 | /* WNM - BSS Transition Management Request */ |
| 2143 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2144 | ret = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2145 | /* WNM-Sleep Mode Response */ |
| 2146 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2147 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2148 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2149 | #ifdef CONFIG_HS20 |
| 2150 | /* WNM-Notification */ |
| 2151 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2152 | ret = -1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2153 | #endif /* CONFIG_HS20 */ |
| 2154 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2155 | /* WMM-AC ADDTS Response */ |
| 2156 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) |
| 2157 | ret = -1; |
| 2158 | |
| 2159 | /* WMM-AC DELTS */ |
| 2160 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) |
| 2161 | ret = -1; |
| 2162 | |
| 2163 | /* Radio Measurement - Neighbor Report Response */ |
| 2164 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) |
| 2165 | ret = -1; |
| 2166 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2167 | /* Radio Measurement - Radio Measurement Request */ |
| 2168 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0) |
| 2169 | ret = -1; |
| 2170 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2171 | /* Radio Measurement - Link Measurement Request */ |
| 2172 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && |
| 2173 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) |
| 2174 | ret = -1; |
| 2175 | |
| 2176 | nl80211_mgmt_handle_register_eloop(bss); |
| 2177 | |
| 2178 | return ret; |
| 2179 | } |
| 2180 | |
| 2181 | |
| 2182 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
| 2183 | { |
| 2184 | int ret = 0; |
| 2185 | |
| 2186 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2187 | return -1; |
| 2188 | |
| 2189 | wpa_printf(MSG_DEBUG, |
| 2190 | "nl80211: Subscribe to mgmt frames with mesh handle %p", |
| 2191 | bss->nl_mgmt); |
| 2192 | |
| 2193 | /* Auth frames for mesh SAE */ |
| 2194 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2195 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2196 | (WLAN_FC_STYPE_AUTH << 4), |
| 2197 | NULL, 0) < 0) |
| 2198 | ret = -1; |
| 2199 | |
| 2200 | /* Mesh peering open */ |
| 2201 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) |
| 2202 | ret = -1; |
| 2203 | /* Mesh peering confirm */ |
| 2204 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) |
| 2205 | ret = -1; |
| 2206 | /* Mesh peering close */ |
| 2207 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) |
| 2208 | ret = -1; |
| 2209 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2210 | nl80211_mgmt_handle_register_eloop(bss); |
| 2211 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2212 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2213 | } |
| 2214 | |
| 2215 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2216 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
| 2217 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2218 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2219 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2220 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2221 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
| 2222 | 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] | 2223 | if (ret) { |
| 2224 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " |
| 2225 | "failed: ret=%d (%s)", |
| 2226 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2227 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2228 | return ret; |
| 2229 | } |
| 2230 | |
| 2231 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2232 | static int nl80211_action_subscribe_ap(struct i802_bss *bss) |
| 2233 | { |
| 2234 | int ret = 0; |
| 2235 | |
| 2236 | /* Public Action frames */ |
| 2237 | if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0) |
| 2238 | ret = -1; |
| 2239 | /* RRM Measurement Report */ |
| 2240 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0) |
| 2241 | ret = -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2242 | /* RRM Link Measurement Report */ |
| 2243 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0) |
| 2244 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2245 | /* RRM Neighbor Report Request */ |
| 2246 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0) |
| 2247 | ret = -1; |
| 2248 | /* FT Action frames */ |
| 2249 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
| 2250 | ret = -1; |
| 2251 | #ifdef CONFIG_IEEE80211W |
| 2252 | /* SA Query */ |
| 2253 | if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0) |
| 2254 | ret = -1; |
| 2255 | #endif /* CONFIG_IEEE80211W */ |
| 2256 | /* Protected Dual of Public Action */ |
| 2257 | if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0) |
| 2258 | ret = -1; |
| 2259 | /* WNM */ |
| 2260 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0) |
| 2261 | ret = -1; |
| 2262 | /* WMM */ |
| 2263 | if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0) |
| 2264 | ret = -1; |
| 2265 | #ifdef CONFIG_FST |
| 2266 | /* FST Action frames */ |
| 2267 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2268 | ret = -1; |
| 2269 | #endif /* CONFIG_FST */ |
| 2270 | /* Vendor-specific */ |
| 2271 | if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0) |
| 2272 | ret = -1; |
| 2273 | |
| 2274 | return ret; |
| 2275 | } |
| 2276 | |
| 2277 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2278 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
| 2279 | { |
| 2280 | static const int stypes[] = { |
| 2281 | WLAN_FC_STYPE_AUTH, |
| 2282 | WLAN_FC_STYPE_ASSOC_REQ, |
| 2283 | WLAN_FC_STYPE_REASSOC_REQ, |
| 2284 | WLAN_FC_STYPE_DISASSOC, |
| 2285 | WLAN_FC_STYPE_DEAUTH, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2286 | WLAN_FC_STYPE_PROBE_REQ, |
| 2287 | /* Beacon doesn't work as mac80211 doesn't currently allow |
| 2288 | * it, but it wouldn't really be the right thing anyway as |
| 2289 | * it isn't per interface ... maybe just dump the scan |
| 2290 | * results periodically for OLBC? |
| 2291 | */ |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2292 | /* WLAN_FC_STYPE_BEACON, */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2293 | }; |
| 2294 | unsigned int i; |
| 2295 | |
| 2296 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2297 | return -1; |
| 2298 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2299 | "handle %p", bss->nl_mgmt); |
| 2300 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2301 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2302 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2303 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2304 | (stypes[i] << 4), |
| 2305 | NULL, 0) < 0) { |
| 2306 | goto out_err; |
| 2307 | } |
| 2308 | } |
| 2309 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2310 | if (nl80211_action_subscribe_ap(bss)) |
| 2311 | goto out_err; |
| 2312 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2313 | if (nl80211_register_spurious_class3(bss)) |
| 2314 | goto out_err; |
| 2315 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2316 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2317 | return 0; |
| 2318 | |
| 2319 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2320 | nl_destroy_handles(&bss->nl_mgmt); |
| 2321 | return -1; |
| 2322 | } |
| 2323 | |
| 2324 | |
| 2325 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
| 2326 | { |
| 2327 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2328 | return -1; |
| 2329 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2330 | "handle %p (device SME)", bss->nl_mgmt); |
| 2331 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2332 | if (nl80211_action_subscribe_ap(bss)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2333 | goto out_err; |
| 2334 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2335 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2336 | return 0; |
| 2337 | |
| 2338 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2339 | nl_destroy_handles(&bss->nl_mgmt); |
| 2340 | return -1; |
| 2341 | } |
| 2342 | |
| 2343 | |
| 2344 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
| 2345 | { |
| 2346 | if (bss->nl_mgmt == NULL) |
| 2347 | return; |
| 2348 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
| 2349 | "(%s)", bss->nl_mgmt, reason); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2350 | nl80211_destroy_eloop_handle(&bss->nl_mgmt, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2351 | |
| 2352 | nl80211_put_wiphy_data_ap(bss); |
| 2353 | } |
| 2354 | |
| 2355 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2356 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
| 2357 | { |
| 2358 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); |
| 2359 | } |
| 2360 | |
| 2361 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2362 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
| 2363 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2364 | struct nl_msg *msg; |
| 2365 | int ret; |
| 2366 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2367 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
| 2368 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2369 | |
| 2370 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", |
| 2371 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2372 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2373 | } |
| 2374 | |
| 2375 | |
| 2376 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
| 2377 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2378 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2379 | int ret; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2380 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2381 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
| 2382 | NL80211_CMD_STOP_P2P_DEVICE); |
| 2383 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2384 | |
| 2385 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
| 2386 | start ? "Start" : "Stop", |
| 2387 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2388 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2389 | return ret; |
| 2390 | } |
| 2391 | |
| 2392 | |
| 2393 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
| 2394 | { |
| 2395 | enum nl80211_iftype nlmode; |
| 2396 | |
| 2397 | nlmode = nl80211_get_ifmode(bss); |
| 2398 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2399 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, |
| 2400 | bss->ifname, up); |
| 2401 | } |
| 2402 | |
| 2403 | /* P2P Device has start/stop which is equivalent */ |
| 2404 | return nl80211_set_p2pdev(bss, up); |
| 2405 | } |
| 2406 | |
| 2407 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2408 | #ifdef CONFIG_TESTING_OPTIONS |
| 2409 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) |
| 2410 | { |
| 2411 | /* struct wpa_driver_nl80211_data *drv = arg; */ |
| 2412 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 2413 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2414 | |
| 2415 | |
| 2416 | wpa_printf(MSG_DEBUG, |
| 2417 | "nl80211: QCA vendor test command response received"); |
| 2418 | |
| 2419 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2420 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2421 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { |
| 2422 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); |
| 2423 | return NL_SKIP; |
| 2424 | } |
| 2425 | |
| 2426 | wpa_hexdump(MSG_DEBUG, |
| 2427 | "nl80211: Received QCA vendor test command response", |
| 2428 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), |
| 2429 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); |
| 2430 | |
| 2431 | return NL_SKIP; |
| 2432 | } |
| 2433 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2434 | |
| 2435 | |
| 2436 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) |
| 2437 | { |
| 2438 | #ifdef CONFIG_TESTING_OPTIONS |
| 2439 | struct nl_msg *msg; |
| 2440 | struct nlattr *params; |
| 2441 | int ret; |
| 2442 | |
| 2443 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2444 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2445 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2446 | QCA_NL80211_VENDOR_SUBCMD_TEST) || |
| 2447 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 2448 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { |
| 2449 | nlmsg_free(msg); |
| 2450 | return; |
| 2451 | } |
| 2452 | nla_nest_end(msg, params); |
| 2453 | |
| 2454 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv); |
| 2455 | wpa_printf(MSG_DEBUG, |
| 2456 | "nl80211: QCA vendor test command returned %d (%s)", |
| 2457 | ret, strerror(-ret)); |
| 2458 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2459 | } |
| 2460 | |
| 2461 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2462 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2463 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2464 | const u8 *set_addr, int first, |
| 2465 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2466 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2467 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2468 | int send_rfkill_event = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2469 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2470 | |
| 2471 | drv->ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2472 | bss->ifindex = drv->ifindex; |
| 2473 | bss->wdev_id = drv->global->if_add_wdevid; |
| 2474 | bss->wdev_id_set = drv->global->if_add_wdevid_set; |
| 2475 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2476 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
| 2477 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2478 | drv->global->if_add_wdevid_set = 0; |
| 2479 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2480 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2481 | bss->static_ap = 1; |
| 2482 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 2483 | if (first && |
| 2484 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && |
| 2485 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) |
| 2486 | drv->start_iface_up = 1; |
| 2487 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2488 | if (wpa_driver_nl80211_capa(drv)) |
| 2489 | return -1; |
| 2490 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2491 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
| 2492 | return -1; |
| 2493 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2494 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
| 2495 | bss->ifname, drv->phyname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2496 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2497 | if (set_addr && |
| 2498 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || |
| 2499 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2500 | set_addr))) |
| 2501 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2502 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2503 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2504 | drv->start_mode_ap = 1; |
| 2505 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2506 | if (drv->hostapd || bss->static_ap) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2507 | nlmode = NL80211_IFTYPE_AP; |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 2508 | else if (bss->if_dynamic || |
| 2509 | nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2510 | nlmode = nl80211_get_ifmode(bss); |
| 2511 | else |
| 2512 | nlmode = NL80211_IFTYPE_STATION; |
| 2513 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2514 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2515 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2516 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2517 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2518 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2519 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2520 | nl80211_get_macaddr(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2521 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2522 | wpa_driver_nl80211_drv_init_rfkill(drv); |
| 2523 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2524 | if (!rfkill_is_blocked(drv->rfkill)) { |
| 2525 | int ret = i802_set_iface_flags(bss, 1); |
| 2526 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2527 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
| 2528 | "interface '%s' UP", bss->ifname); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2529 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2530 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2531 | |
| 2532 | if (is_p2p_net_interface(nlmode)) |
| 2533 | nl80211_disable_11b_rates(bss->drv, |
| 2534 | bss->drv->ifindex, 1); |
| 2535 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2536 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2537 | return ret; |
| 2538 | } else { |
| 2539 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " |
| 2540 | "interface '%s' due to rfkill", bss->ifname); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2541 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 2542 | drv->if_disabled = 1; |
| 2543 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2544 | send_rfkill_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2545 | } |
| 2546 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2547 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2548 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
| 2549 | 1, IF_OPER_DORMANT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2550 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2551 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2552 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2553 | bss->addr)) |
| 2554 | return -1; |
| 2555 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); |
| 2556 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2557 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2558 | if (send_rfkill_event) { |
| 2559 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, |
| 2560 | drv, drv->ctx); |
| 2561 | } |
| 2562 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2563 | if (drv->vendor_cmd_test_avail) |
| 2564 | qca_vendor_test(drv); |
| 2565 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2566 | nl80211_init_connect_handle(bss); |
| 2567 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2568 | return 0; |
| 2569 | } |
| 2570 | |
| 2571 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2572 | static int wpa_driver_nl80211_del_beacon(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2573 | { |
| 2574 | struct nl_msg *msg; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2575 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2576 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2577 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
| 2578 | drv->ifindex); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2579 | nl80211_put_wiphy_data_ap(bss); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2580 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2581 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2582 | } |
| 2583 | |
| 2584 | |
| 2585 | /** |
| 2586 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2587 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2588 | * |
| 2589 | * Shut down driver interface and processing of driver events. Free |
| 2590 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). |
| 2591 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2592 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2593 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2594 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2595 | unsigned int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2596 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2597 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
| 2598 | bss->ifname, drv->disabled_11b_rates); |
| 2599 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2600 | bss->in_deinit = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2601 | if (drv->data_tx_status) |
| 2602 | eloop_unregister_read_sock(drv->eapol_tx_sock); |
| 2603 | if (drv->eapol_tx_sock >= 0) |
| 2604 | close(drv->eapol_tx_sock); |
| 2605 | |
| 2606 | if (bss->nl_preq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2607 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 2608 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2609 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 2610 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2611 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2612 | "interface %s from bridge %s: %s", |
| 2613 | bss->ifname, bss->brname, strerror(errno)); |
| 2614 | } |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 2615 | |
| 2616 | if (drv->rtnl_sk) |
| 2617 | nl80211_handle_destroy(drv->rtnl_sk); |
| 2618 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2619 | if (bss->added_bridge) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2620 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
| 2621 | 0) < 0) |
| 2622 | wpa_printf(MSG_INFO, |
| 2623 | "nl80211: Could not set bridge %s down", |
| 2624 | bss->brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2625 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2626 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2627 | "bridge %s: %s", |
| 2628 | bss->brname, strerror(errno)); |
| 2629 | } |
| 2630 | |
| 2631 | nl80211_remove_monitor_interface(drv); |
| 2632 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2633 | if (is_ap_interface(drv->nlmode)) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2634 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2635 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2636 | if (drv->eapol_sock >= 0) { |
| 2637 | eloop_unregister_read_sock(drv->eapol_sock); |
| 2638 | close(drv->eapol_sock); |
| 2639 | } |
| 2640 | |
| 2641 | if (drv->if_indices != drv->default_if_indices) |
| 2642 | os_free(drv->if_indices); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2643 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2644 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
| 2645 | os_free(drv->if_indices_reason); |
| 2646 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2647 | if (drv->disabled_11b_rates) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2648 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 2649 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2650 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
| 2651 | IF_OPER_UP); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 2652 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2653 | rfkill_deinit(drv->rfkill); |
| 2654 | |
| 2655 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 2656 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2657 | if (!drv->start_iface_up) |
| 2658 | (void) i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2659 | |
| 2660 | if (drv->addr_changed) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2661 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 2662 | 0) < 0) { |
| 2663 | wpa_printf(MSG_DEBUG, |
| 2664 | "nl80211: Could not set interface down to restore permanent MAC address"); |
| 2665 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2666 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2667 | drv->perm_addr) < 0) { |
| 2668 | wpa_printf(MSG_DEBUG, |
| 2669 | "nl80211: Could not restore permanent MAC address"); |
| 2670 | } |
| 2671 | } |
| 2672 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2673 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2674 | if (!drv->hostapd || !drv->start_mode_ap) |
| 2675 | wpa_driver_nl80211_set_mode(bss, |
| 2676 | NL80211_IFTYPE_STATION); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2677 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2678 | } else { |
| 2679 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
| 2680 | nl80211_del_p2pdev(bss); |
| 2681 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2682 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2683 | if (bss->nl_connect) |
| 2684 | nl80211_destroy_eloop_handle(&bss->nl_connect, 1); |
| 2685 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2686 | nl80211_destroy_bss(drv->first_bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2687 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2688 | os_free(drv->filter_ssids); |
| 2689 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2690 | os_free(drv->auth_ie); |
| 2691 | |
| 2692 | if (drv->in_interface_list) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2693 | dl_list_del(&drv->list); |
| 2694 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2695 | os_free(drv->extended_capa); |
| 2696 | os_free(drv->extended_capa_mask); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2697 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 2698 | os_free(drv->iface_ext_capa[i].ext_capa); |
| 2699 | os_free(drv->iface_ext_capa[i].ext_capa_mask); |
| 2700 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2701 | os_free(drv->first_bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2702 | os_free(drv); |
| 2703 | } |
| 2704 | |
| 2705 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2706 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
| 2707 | { |
| 2708 | switch (alg) { |
| 2709 | case WPA_ALG_WEP: |
| 2710 | if (key_len == 5) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2711 | return RSN_CIPHER_SUITE_WEP40; |
| 2712 | return RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2713 | case WPA_ALG_TKIP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2714 | return RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2715 | case WPA_ALG_CCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2716 | return RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2717 | case WPA_ALG_GCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2718 | return RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2719 | case WPA_ALG_CCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2720 | return RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2721 | case WPA_ALG_GCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2722 | return RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2723 | case WPA_ALG_IGTK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2724 | return RSN_CIPHER_SUITE_AES_128_CMAC; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2725 | case WPA_ALG_BIP_GMAC_128: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2726 | return RSN_CIPHER_SUITE_BIP_GMAC_128; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2727 | case WPA_ALG_BIP_GMAC_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2728 | return RSN_CIPHER_SUITE_BIP_GMAC_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2729 | case WPA_ALG_BIP_CMAC_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2730 | return RSN_CIPHER_SUITE_BIP_CMAC_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2731 | case WPA_ALG_SMS4: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2732 | return RSN_CIPHER_SUITE_SMS4; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2733 | case WPA_ALG_KRK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2734 | return RSN_CIPHER_SUITE_KRK; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2735 | case WPA_ALG_NONE: |
| 2736 | case WPA_ALG_PMK: |
| 2737 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", |
| 2738 | alg); |
| 2739 | return 0; |
| 2740 | } |
| 2741 | |
| 2742 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", |
| 2743 | alg); |
| 2744 | return 0; |
| 2745 | } |
| 2746 | |
| 2747 | |
| 2748 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) |
| 2749 | { |
| 2750 | switch (cipher) { |
| 2751 | case WPA_CIPHER_CCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2752 | return RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2753 | case WPA_CIPHER_GCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2754 | return RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2755 | case WPA_CIPHER_CCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2756 | return RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2757 | case WPA_CIPHER_GCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2758 | return RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2759 | case WPA_CIPHER_TKIP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2760 | return RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2761 | case WPA_CIPHER_WEP104: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2762 | return RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2763 | case WPA_CIPHER_WEP40: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2764 | return RSN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2765 | case WPA_CIPHER_GTK_NOT_USED: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2766 | return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2767 | } |
| 2768 | |
| 2769 | return 0; |
| 2770 | } |
| 2771 | |
| 2772 | |
| 2773 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], |
| 2774 | int max_suites) |
| 2775 | { |
| 2776 | int num_suites = 0; |
| 2777 | |
| 2778 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2779 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2780 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2781 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2782 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2783 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2784 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2785 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2786 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2787 | suites[num_suites++] = RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2788 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2789 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2790 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2791 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2792 | |
| 2793 | return num_suites; |
| 2794 | } |
| 2795 | |
| 2796 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2797 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2798 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 2799 | const u8 *key, size_t key_len) |
| 2800 | { |
| 2801 | struct nl_msg *msg; |
| 2802 | int ret; |
| 2803 | |
| 2804 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
| 2805 | return 0; |
| 2806 | |
| 2807 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2808 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2809 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2810 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || |
| 2811 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { |
| 2812 | nl80211_nlmsg_clear(msg); |
| 2813 | nlmsg_free(msg); |
| 2814 | return -1; |
| 2815 | } |
| 2816 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 2817 | if (ret) { |
| 2818 | wpa_printf(MSG_DEBUG, |
| 2819 | "nl80211: Key management set key failed: ret=%d (%s)", |
| 2820 | ret, strerror(-ret)); |
| 2821 | } |
| 2822 | |
| 2823 | return ret; |
| 2824 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2825 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2826 | |
| 2827 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2828 | static int nl80211_set_pmk(struct wpa_driver_nl80211_data *drv, |
| 2829 | const u8 *key, size_t key_len, |
| 2830 | const u8 *addr) |
| 2831 | { |
| 2832 | struct nl_msg *msg = NULL; |
| 2833 | int ret; |
| 2834 | |
| 2835 | /* |
| 2836 | * If the authenticator address is not set, assume it is |
| 2837 | * the current BSSID. |
| 2838 | */ |
| 2839 | if (!addr && drv->associated) |
| 2840 | addr = drv->bssid; |
| 2841 | else if (!addr) |
| 2842 | return -1; |
| 2843 | |
| 2844 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK to the driver for " MACSTR, |
| 2845 | MAC2STR(addr)); |
| 2846 | wpa_hexdump_key(MSG_DEBUG, "nl80211: PMK", key, key_len); |
| 2847 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_PMK); |
| 2848 | if (!msg || |
| 2849 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 2850 | nla_put(msg, NL80211_ATTR_PMK, key_len, key)) { |
| 2851 | nl80211_nlmsg_clear(msg); |
| 2852 | nlmsg_free(msg); |
| 2853 | return -ENOBUFS; |
| 2854 | } |
| 2855 | |
| 2856 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 2857 | if (ret) { |
| 2858 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK failed: ret=%d (%s)", |
| 2859 | ret, strerror(-ret)); |
| 2860 | } |
| 2861 | |
| 2862 | return ret; |
| 2863 | } |
| 2864 | |
| 2865 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2866 | 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] | 2867 | enum wpa_alg alg, const u8 *addr, |
| 2868 | int key_idx, int set_tx, |
| 2869 | const u8 *seq, size_t seq_len, |
| 2870 | const u8 *key, size_t key_len) |
| 2871 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2872 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2873 | int ifindex; |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2874 | struct nl_msg *msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2875 | int ret; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2876 | int tdls = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2877 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2878 | /* Ignore for P2P Device */ |
| 2879 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2880 | return 0; |
| 2881 | |
| 2882 | ifindex = if_nametoindex(ifname); |
| 2883 | 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] | 2884 | "set_tx=%d seq_len=%lu key_len=%lu", |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2885 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2886 | (unsigned long) seq_len, (unsigned long) key_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2887 | #ifdef CONFIG_TDLS |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2888 | if (key_idx == -1) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2889 | key_idx = 0; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2890 | tdls = 1; |
| 2891 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2892 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2893 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2894 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2895 | if (alg == WPA_ALG_PMK && |
| 2896 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { |
| 2897 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
| 2898 | __func__); |
| 2899 | ret = issue_key_mgmt_set_key(drv, key, key_len); |
| 2900 | return ret; |
| 2901 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2902 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2903 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2904 | if (alg == WPA_ALG_PMK && |
| 2905 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE)) |
| 2906 | return nl80211_set_pmk(drv, key, key_len, addr); |
| 2907 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2908 | if (alg == WPA_ALG_NONE) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2909 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
| 2910 | if (!msg) |
| 2911 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2912 | } else { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2913 | u32 suite; |
| 2914 | |
| 2915 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 2916 | if (!suite) |
| 2917 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2918 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
| 2919 | if (!msg || |
| 2920 | nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2921 | nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, suite)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2922 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2923 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2924 | } |
| 2925 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2926 | if (seq && seq_len) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2927 | if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq)) |
| 2928 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2929 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
| 2930 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2931 | |
| 2932 | if (addr && !is_broadcast_ether_addr(addr)) { |
| 2933 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2934 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 2935 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2936 | |
| 2937 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { |
| 2938 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2939 | if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, |
| 2940 | NL80211_KEYTYPE_GROUP)) |
| 2941 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2942 | } |
| 2943 | } else if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2944 | struct nlattr *types; |
| 2945 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2946 | wpa_printf(MSG_DEBUG, " broadcast key"); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2947 | |
| 2948 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2949 | if (!types || |
| 2950 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 2951 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2952 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2953 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2954 | if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2955 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2956 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2957 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2958 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
| 2959 | ret = 0; |
| 2960 | if (ret) |
| 2961 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", |
| 2962 | ret, strerror(-ret)); |
| 2963 | |
| 2964 | /* |
| 2965 | * If we failed or don't need to set the default TX key (below), |
| 2966 | * we're done here. |
| 2967 | */ |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2968 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2969 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2970 | if (is_ap_interface(drv->nlmode) && addr && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2971 | !is_broadcast_ether_addr(addr)) |
| 2972 | return ret; |
| 2973 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2974 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
| 2975 | if (!msg || |
| 2976 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2977 | nla_put_flag(msg, (alg == WPA_ALG_IGTK || |
| 2978 | alg == WPA_ALG_BIP_GMAC_128 || |
| 2979 | alg == WPA_ALG_BIP_GMAC_256 || |
| 2980 | alg == WPA_ALG_BIP_CMAC_256) ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2981 | NL80211_ATTR_KEY_DEFAULT_MGMT : |
| 2982 | NL80211_ATTR_KEY_DEFAULT)) |
| 2983 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2984 | if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2985 | struct nlattr *types; |
| 2986 | |
| 2987 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2988 | if (!types || |
| 2989 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 2990 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2991 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2992 | } else if (addr) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2993 | struct nlattr *types; |
| 2994 | |
| 2995 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2996 | if (!types || |
| 2997 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) |
| 2998 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2999 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3000 | } |
| 3001 | |
| 3002 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3003 | if (ret == -ENOENT) |
| 3004 | ret = 0; |
| 3005 | if (ret) |
| 3006 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " |
| 3007 | "err=%d %s)", ret, strerror(-ret)); |
| 3008 | return ret; |
| 3009 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3010 | fail: |
| 3011 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3012 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3013 | return -ENOBUFS; |
| 3014 | } |
| 3015 | |
| 3016 | |
| 3017 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
| 3018 | int key_idx, int defkey, |
| 3019 | const u8 *seq, size_t seq_len, |
| 3020 | const u8 *key, size_t key_len) |
| 3021 | { |
| 3022 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3023 | u32 suite; |
| 3024 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3025 | if (!key_attr) |
| 3026 | return -1; |
| 3027 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3028 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 3029 | if (!suite) |
| 3030 | return -1; |
| 3031 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3032 | if (defkey && alg == WPA_ALG_IGTK) { |
| 3033 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) |
| 3034 | return -1; |
| 3035 | } else if (defkey) { |
| 3036 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) |
| 3037 | return -1; |
| 3038 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3039 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3040 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3041 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3042 | (seq && seq_len && |
| 3043 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || |
| 3044 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) |
| 3045 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3046 | |
| 3047 | nla_nest_end(msg, key_attr); |
| 3048 | |
| 3049 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3050 | } |
| 3051 | |
| 3052 | |
| 3053 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
| 3054 | struct nl_msg *msg) |
| 3055 | { |
| 3056 | int i, privacy = 0; |
| 3057 | struct nlattr *nl_keys, *nl_key; |
| 3058 | |
| 3059 | for (i = 0; i < 4; i++) { |
| 3060 | if (!params->wep_key[i]) |
| 3061 | continue; |
| 3062 | privacy = 1; |
| 3063 | break; |
| 3064 | } |
| 3065 | if (params->wps == WPS_MODE_PRIVACY) |
| 3066 | privacy = 1; |
| 3067 | if (params->pairwise_suite && |
| 3068 | params->pairwise_suite != WPA_CIPHER_NONE) |
| 3069 | privacy = 1; |
| 3070 | |
| 3071 | if (!privacy) |
| 3072 | return 0; |
| 3073 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3074 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 3075 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3076 | |
| 3077 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); |
| 3078 | if (!nl_keys) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3079 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3080 | |
| 3081 | for (i = 0; i < 4; i++) { |
| 3082 | if (!params->wep_key[i]) |
| 3083 | continue; |
| 3084 | |
| 3085 | nl_key = nla_nest_start(msg, i); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3086 | if (!nl_key || |
| 3087 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], |
| 3088 | params->wep_key[i]) || |
| 3089 | nla_put_u32(msg, NL80211_KEY_CIPHER, |
| 3090 | params->wep_key_len[i] == 5 ? |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3091 | RSN_CIPHER_SUITE_WEP40 : |
| 3092 | RSN_CIPHER_SUITE_WEP104) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3093 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
| 3094 | (i == params->wep_tx_keyidx && |
| 3095 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) |
| 3096 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3097 | |
| 3098 | nla_nest_end(msg, nl_key); |
| 3099 | } |
| 3100 | nla_nest_end(msg, nl_keys); |
| 3101 | |
| 3102 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3103 | } |
| 3104 | |
| 3105 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3106 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 3107 | const u8 *addr, int cmd, u16 reason_code, |
| 3108 | int local_state_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3109 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3110 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3111 | struct nl_msg *msg; |
| 3112 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3113 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
| 3114 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
| 3115 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 3116 | (local_state_change && |
| 3117 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { |
| 3118 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3119 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3120 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3121 | |
| 3122 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3123 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3124 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 3125 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", |
| 3126 | reason_code, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3127 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3128 | return ret; |
| 3129 | } |
| 3130 | |
| 3131 | |
| 3132 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3133 | int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3134 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3135 | int ret; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3136 | int drv_associated = drv->associated; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3137 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3138 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3139 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3140 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3141 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
| 3142 | reason_code, 0); |
| 3143 | /* |
| 3144 | * For locally generated disconnect, supplicant already generates a |
| 3145 | * DEAUTH event, so ignore the event from NL80211. |
| 3146 | */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3147 | drv->ignore_next_local_disconnect = drv_associated && (ret == 0); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3148 | |
| 3149 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3150 | } |
| 3151 | |
| 3152 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3153 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
| 3154 | const u8 *addr, int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3155 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3156 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3157 | int ret; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3158 | int drv_associated = drv->associated; |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3159 | |
| 3160 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3161 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3162 | return nl80211_leave_ibss(drv, 1); |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3163 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3164 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3165 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3166 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
| 3167 | __func__, MAC2STR(addr), reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3168 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3169 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
| 3170 | reason_code, 0); |
| 3171 | /* |
| 3172 | * For locally generated deauthenticate, supplicant already generates a |
| 3173 | * DEAUTH event, so ignore the event from NL80211. |
| 3174 | */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3175 | drv->ignore_next_local_deauth = drv_associated && (ret == 0); |
| 3176 | |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3177 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3178 | } |
| 3179 | |
| 3180 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3181 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
| 3182 | struct wpa_driver_auth_params *params) |
| 3183 | { |
| 3184 | int i; |
| 3185 | |
| 3186 | drv->auth_freq = params->freq; |
| 3187 | drv->auth_alg = params->auth_alg; |
| 3188 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; |
| 3189 | drv->auth_local_state_change = params->local_state_change; |
| 3190 | drv->auth_p2p = params->p2p; |
| 3191 | |
| 3192 | if (params->bssid) |
| 3193 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); |
| 3194 | else |
| 3195 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); |
| 3196 | |
| 3197 | if (params->ssid) { |
| 3198 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); |
| 3199 | drv->auth_ssid_len = params->ssid_len; |
| 3200 | } else |
| 3201 | drv->auth_ssid_len = 0; |
| 3202 | |
| 3203 | |
| 3204 | os_free(drv->auth_ie); |
| 3205 | drv->auth_ie = NULL; |
| 3206 | drv->auth_ie_len = 0; |
| 3207 | if (params->ie) { |
| 3208 | drv->auth_ie = os_malloc(params->ie_len); |
| 3209 | if (drv->auth_ie) { |
| 3210 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); |
| 3211 | drv->auth_ie_len = params->ie_len; |
| 3212 | } |
| 3213 | } |
| 3214 | |
| 3215 | for (i = 0; i < 4; i++) { |
| 3216 | if (params->wep_key[i] && params->wep_key_len[i] && |
| 3217 | params->wep_key_len[i] <= 16) { |
| 3218 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], |
| 3219 | params->wep_key_len[i]); |
| 3220 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; |
| 3221 | } else |
| 3222 | drv->auth_wep_key_len[i] = 0; |
| 3223 | } |
| 3224 | } |
| 3225 | |
| 3226 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3227 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
| 3228 | { |
| 3229 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3230 | |
| 3231 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) |
| 3232 | return; |
| 3233 | |
| 3234 | /* |
| 3235 | * Looks like we failed to unmask 11b rates previously. This could |
| 3236 | * happen, e.g., if the interface was down at the point in time when a |
| 3237 | * P2P group was terminated. |
| 3238 | */ |
| 3239 | wpa_printf(MSG_DEBUG, |
| 3240 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", |
| 3241 | bss->ifname); |
| 3242 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 3243 | } |
| 3244 | |
| 3245 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3246 | static enum nl80211_auth_type get_nl_auth_type(int wpa_auth_alg) |
| 3247 | { |
| 3248 | if (wpa_auth_alg & WPA_AUTH_ALG_OPEN) |
| 3249 | return NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 3250 | if (wpa_auth_alg & WPA_AUTH_ALG_SHARED) |
| 3251 | return NL80211_AUTHTYPE_SHARED_KEY; |
| 3252 | if (wpa_auth_alg & WPA_AUTH_ALG_LEAP) |
| 3253 | return NL80211_AUTHTYPE_NETWORK_EAP; |
| 3254 | if (wpa_auth_alg & WPA_AUTH_ALG_FT) |
| 3255 | return NL80211_AUTHTYPE_FT; |
| 3256 | if (wpa_auth_alg & WPA_AUTH_ALG_SAE) |
| 3257 | return NL80211_AUTHTYPE_SAE; |
| 3258 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS) |
| 3259 | return NL80211_AUTHTYPE_FILS_SK; |
| 3260 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS_SK_PFS) |
| 3261 | return NL80211_AUTHTYPE_FILS_SK_PFS; |
| 3262 | |
| 3263 | return NL80211_AUTHTYPE_MAX; |
| 3264 | } |
| 3265 | |
| 3266 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3267 | static int wpa_driver_nl80211_authenticate( |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3268 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3269 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3270 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3271 | int ret = -1, i; |
| 3272 | struct nl_msg *msg; |
| 3273 | enum nl80211_auth_type type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3274 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3275 | int count = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3276 | int is_retry; |
| 3277 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3278 | nl80211_unmask_11b_rates(bss); |
| 3279 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3280 | is_retry = drv->retry_auth; |
| 3281 | drv->retry_auth = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3282 | drv->ignore_deauth_event = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3283 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3284 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3285 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3286 | if (params->bssid) |
| 3287 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 3288 | else |
| 3289 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3290 | /* FIX: IBSS mode */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3291 | nlmode = params->p2p ? |
| 3292 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 3293 | if (drv->nlmode != nlmode && |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3294 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3295 | return -1; |
| 3296 | |
| 3297 | retry: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3298 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
| 3299 | drv->ifindex); |
| 3300 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3301 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
| 3302 | if (!msg) |
| 3303 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3304 | |
| 3305 | for (i = 0; i < 4; i++) { |
| 3306 | if (!params->wep_key[i]) |
| 3307 | continue; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3308 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3309 | NULL, i, |
| 3310 | i == params->wep_tx_keyidx, NULL, 0, |
| 3311 | params->wep_key[i], |
| 3312 | params->wep_key_len[i]); |
| 3313 | if (params->wep_tx_keyidx != i) |
| 3314 | continue; |
| 3315 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3316 | params->wep_key[i], params->wep_key_len[i])) |
| 3317 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3318 | } |
| 3319 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3320 | if (params->bssid) { |
| 3321 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 3322 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3323 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 3324 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3325 | } |
| 3326 | if (params->freq) { |
| 3327 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3328 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
| 3329 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3330 | } |
| 3331 | if (params->ssid) { |
| 3332 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 3333 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3334 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 3335 | params->ssid)) |
| 3336 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3337 | } |
| 3338 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3339 | if (params->ie && |
| 3340 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) |
| 3341 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3342 | if (params->auth_data) { |
| 3343 | wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data, |
| 3344 | params->auth_data_len); |
| 3345 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len, |
| 3346 | params->auth_data)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3347 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3348 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3349 | type = get_nl_auth_type(params->auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3350 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3351 | if (type == NL80211_AUTHTYPE_MAX || |
| 3352 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3353 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3354 | if (params->local_state_change) { |
| 3355 | wpa_printf(MSG_DEBUG, " * Local state change only"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3356 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
| 3357 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3358 | } |
| 3359 | |
| 3360 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3361 | msg = NULL; |
| 3362 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3363 | wpa_dbg(drv->ctx, MSG_DEBUG, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3364 | "nl80211: MLME command failed (auth): count=%d ret=%d (%s)", |
| 3365 | count, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3366 | count++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3367 | if ((ret == -EALREADY || ret == -EEXIST) && count == 1 && |
| 3368 | params->bssid && !params->local_state_change) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3369 | /* |
| 3370 | * mac80211 does not currently accept new |
| 3371 | * authentication if we are already authenticated. As a |
| 3372 | * workaround, force deauthentication and try again. |
| 3373 | */ |
| 3374 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " |
| 3375 | "after forced deauthentication"); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3376 | drv->ignore_deauth_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3377 | wpa_driver_nl80211_deauthenticate( |
| 3378 | bss, params->bssid, |
| 3379 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 3380 | nlmsg_free(msg); |
| 3381 | goto retry; |
| 3382 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3383 | |
| 3384 | if (ret == -ENOENT && params->freq && !is_retry) { |
| 3385 | /* |
| 3386 | * cfg80211 has likely expired the BSS entry even |
| 3387 | * though it was previously available in our internal |
| 3388 | * BSS table. To recover quickly, start a single |
| 3389 | * channel scan on the specified channel. |
| 3390 | */ |
| 3391 | struct wpa_driver_scan_params scan; |
| 3392 | int freqs[2]; |
| 3393 | |
| 3394 | os_memset(&scan, 0, sizeof(scan)); |
| 3395 | scan.num_ssids = 1; |
| 3396 | if (params->ssid) { |
| 3397 | scan.ssids[0].ssid = params->ssid; |
| 3398 | scan.ssids[0].ssid_len = params->ssid_len; |
| 3399 | } |
| 3400 | freqs[0] = params->freq; |
| 3401 | freqs[1] = 0; |
| 3402 | scan.freqs = freqs; |
| 3403 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " |
| 3404 | "channel scan to refresh cfg80211 BSS " |
| 3405 | "entry"); |
| 3406 | ret = wpa_driver_nl80211_scan(bss, &scan); |
| 3407 | if (ret == 0) { |
| 3408 | nl80211_copy_auth_params(drv, params); |
| 3409 | drv->scan_for_auth = 1; |
| 3410 | } |
| 3411 | } else if (is_retry) { |
| 3412 | /* |
| 3413 | * Need to indicate this with an event since the return |
| 3414 | * value from the retry is not delivered to core code. |
| 3415 | */ |
| 3416 | union wpa_event_data event; |
| 3417 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " |
| 3418 | "failed"); |
| 3419 | os_memset(&event, 0, sizeof(event)); |
| 3420 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, |
| 3421 | ETH_ALEN); |
| 3422 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, |
| 3423 | &event); |
| 3424 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3425 | } else { |
| 3426 | wpa_printf(MSG_DEBUG, |
| 3427 | "nl80211: Authentication request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3428 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3429 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3430 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3431 | nlmsg_free(msg); |
| 3432 | return ret; |
| 3433 | } |
| 3434 | |
| 3435 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3436 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3437 | { |
| 3438 | struct wpa_driver_auth_params params; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3439 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3440 | int i; |
| 3441 | |
| 3442 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); |
| 3443 | |
| 3444 | os_memset(¶ms, 0, sizeof(params)); |
| 3445 | params.freq = drv->auth_freq; |
| 3446 | params.auth_alg = drv->auth_alg; |
| 3447 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; |
| 3448 | params.local_state_change = drv->auth_local_state_change; |
| 3449 | params.p2p = drv->auth_p2p; |
| 3450 | |
| 3451 | if (!is_zero_ether_addr(drv->auth_bssid_)) |
| 3452 | params.bssid = drv->auth_bssid_; |
| 3453 | |
| 3454 | if (drv->auth_ssid_len) { |
| 3455 | params.ssid = drv->auth_ssid; |
| 3456 | params.ssid_len = drv->auth_ssid_len; |
| 3457 | } |
| 3458 | |
| 3459 | params.ie = drv->auth_ie; |
| 3460 | params.ie_len = drv->auth_ie_len; |
| 3461 | |
| 3462 | for (i = 0; i < 4; i++) { |
| 3463 | if (drv->auth_wep_key_len[i]) { |
| 3464 | params.wep_key[i] = drv->auth_wep_key[i]; |
| 3465 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; |
| 3466 | } |
| 3467 | } |
| 3468 | |
| 3469 | drv->retry_auth = 1; |
| 3470 | return wpa_driver_nl80211_authenticate(bss, ¶ms); |
| 3471 | } |
| 3472 | |
| 3473 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3474 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
| 3475 | const void *data, size_t len, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3476 | int encrypt, int noack, |
| 3477 | unsigned int freq, int no_cck, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3478 | int offchanok, unsigned int wait_time, |
| 3479 | const u16 *csa_offs, |
| 3480 | size_t csa_offs_len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3481 | { |
| 3482 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3483 | u64 cookie; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3484 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3485 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 3486 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3487 | freq = nl80211_get_assoc_freq(drv); |
| 3488 | wpa_printf(MSG_DEBUG, |
| 3489 | "nl80211: send_frame - Use assoc_freq=%u for IBSS", |
| 3490 | freq); |
| 3491 | } |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3492 | if (freq == 0) { |
| 3493 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", |
| 3494 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3495 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3496 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3497 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3498 | if (drv->use_monitor) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3499 | 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] | 3500 | freq, bss->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3501 | return nl80211_send_monitor(drv, data, len, encrypt, noack); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3502 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3503 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3504 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3505 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3506 | &cookie, no_cck, noack, offchanok, |
| 3507 | csa_offs, csa_offs_len); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3508 | if (res == 0 && !noack) { |
| 3509 | const struct ieee80211_mgmt *mgmt; |
| 3510 | u16 fc; |
| 3511 | |
| 3512 | mgmt = (const struct ieee80211_mgmt *) data; |
| 3513 | fc = le_to_host16(mgmt->frame_control); |
| 3514 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3515 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { |
| 3516 | wpa_printf(MSG_MSGDUMP, |
| 3517 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", |
| 3518 | (long long unsigned int) |
| 3519 | drv->send_action_cookie, |
| 3520 | (long long unsigned int) cookie); |
| 3521 | drv->send_action_cookie = cookie; |
| 3522 | } |
| 3523 | } |
| 3524 | |
| 3525 | return res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3526 | } |
| 3527 | |
| 3528 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3529 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
| 3530 | size_t data_len, int noack, |
| 3531 | unsigned int freq, int no_cck, |
| 3532 | int offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3533 | unsigned int wait_time, |
| 3534 | const u16 *csa_offs, |
| 3535 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3536 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3537 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3538 | struct ieee80211_mgmt *mgmt; |
| 3539 | int encrypt = 1; |
| 3540 | u16 fc; |
| 3541 | |
| 3542 | mgmt = (struct ieee80211_mgmt *) data; |
| 3543 | fc = le_to_host16(mgmt->frame_control); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 3544 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR |
| 3545 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d", |
| 3546 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, |
| 3547 | fc, fc2str(fc), drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3548 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3549 | if ((is_sta_interface(drv->nlmode) || |
| 3550 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3551 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3552 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { |
| 3553 | /* |
| 3554 | * The use of last_mgmt_freq is a bit of a hack, |
| 3555 | * but it works due to the single-threaded nature |
| 3556 | * of wpa_supplicant. |
| 3557 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3558 | if (freq == 0) { |
| 3559 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", |
| 3560 | drv->last_mgmt_freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3561 | freq = drv->last_mgmt_freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3562 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3563 | return nl80211_send_frame_cmd(bss, freq, 0, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3564 | data, data_len, NULL, 1, noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3565 | 1, csa_offs, csa_offs_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3566 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3567 | |
| 3568 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3569 | if (freq == 0) { |
| 3570 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", |
| 3571 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3572 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3573 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3574 | return nl80211_send_frame_cmd(bss, freq, |
| 3575 | (int) freq == bss->freq ? 0 : |
| 3576 | wait_time, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3577 | data, data_len, |
| 3578 | &drv->send_action_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3579 | no_cck, noack, offchanok, |
| 3580 | csa_offs, csa_offs_len); |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 3581 | } |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 3582 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3583 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3584 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 3585 | /* |
| 3586 | * Only one of the authentication frame types is encrypted. |
| 3587 | * In order for static WEP encryption to work properly (i.e., |
| 3588 | * to not encrypt the frame), we need to tell mac80211 about |
| 3589 | * the frames that must not be encrypted. |
| 3590 | */ |
| 3591 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 3592 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); |
| 3593 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
| 3594 | encrypt = 0; |
| 3595 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3596 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3597 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3598 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3599 | noack, freq, no_cck, offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3600 | wait_time, csa_offs, |
| 3601 | csa_offs_len); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3602 | } |
| 3603 | |
| 3604 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3605 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
| 3606 | { |
| 3607 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 3608 | u8 rates_len = 0; |
| 3609 | int i; |
| 3610 | |
| 3611 | if (!basic_rates) |
| 3612 | return 0; |
| 3613 | |
| 3614 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) |
| 3615 | rates[rates_len++] = basic_rates[i] / 5; |
| 3616 | |
| 3617 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); |
| 3618 | } |
| 3619 | |
| 3620 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3621 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
| 3622 | int slot, int ht_opmode, int ap_isolate, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3623 | const int *basic_rates) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3624 | { |
| 3625 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3626 | struct nl_msg *msg; |
| 3627 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3628 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
| 3629 | (cts >= 0 && |
| 3630 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || |
| 3631 | (preamble >= 0 && |
| 3632 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || |
| 3633 | (slot >= 0 && |
| 3634 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || |
| 3635 | (ht_opmode >= 0 && |
| 3636 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || |
| 3637 | (ap_isolate >= 0 && |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3638 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
| 3639 | nl80211_put_basic_rates(msg, basic_rates)) { |
| 3640 | nlmsg_free(msg); |
| 3641 | return -ENOBUFS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3642 | } |
| 3643 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3644 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3645 | } |
| 3646 | |
| 3647 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3648 | static int wpa_driver_nl80211_set_acl(void *priv, |
| 3649 | struct hostapd_acl_params *params) |
| 3650 | { |
| 3651 | struct i802_bss *bss = priv; |
| 3652 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3653 | struct nl_msg *msg; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3654 | struct nl_msg *acl; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3655 | unsigned int i; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3656 | int ret; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3657 | |
| 3658 | if (!(drv->capa.max_acl_mac_addrs)) |
| 3659 | return -ENOTSUP; |
| 3660 | |
| 3661 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) |
| 3662 | return -ENOTSUP; |
| 3663 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3664 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
| 3665 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); |
| 3666 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3667 | acl = nlmsg_alloc(); |
| 3668 | if (!acl) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3669 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3670 | for (i = 0; i < params->num_mac_acl; i++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3671 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { |
| 3672 | nlmsg_free(acl); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3673 | return -ENOMEM; |
| 3674 | } |
| 3675 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3676 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3677 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
| 3678 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
| 3679 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : |
| 3680 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || |
| 3681 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
| 3682 | nlmsg_free(msg); |
| 3683 | nlmsg_free(acl); |
| 3684 | return -ENOMEM; |
| 3685 | } |
| 3686 | nlmsg_free(acl); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3687 | |
| 3688 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3689 | if (ret) { |
| 3690 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", |
| 3691 | ret, strerror(-ret)); |
| 3692 | } |
| 3693 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3694 | return ret; |
| 3695 | } |
| 3696 | |
| 3697 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3698 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
| 3699 | { |
| 3700 | if (beacon_int > 0) { |
| 3701 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); |
| 3702 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 3703 | beacon_int); |
| 3704 | } |
| 3705 | |
| 3706 | return 0; |
| 3707 | } |
| 3708 | |
| 3709 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3710 | static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period) |
| 3711 | { |
| 3712 | if (dtim_period > 0) { |
| 3713 | wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period); |
| 3714 | return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); |
| 3715 | } |
| 3716 | |
| 3717 | return 0; |
| 3718 | } |
| 3719 | |
| 3720 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3721 | #ifdef CONFIG_MESH |
| 3722 | static int nl80211_set_mesh_config(void *priv, |
| 3723 | struct wpa_driver_mesh_bss_params *params) |
| 3724 | { |
| 3725 | struct i802_bss *bss = priv; |
| 3726 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3727 | struct nl_msg *msg; |
| 3728 | int ret; |
| 3729 | |
| 3730 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG); |
| 3731 | if (!msg) |
| 3732 | return -1; |
| 3733 | |
| 3734 | ret = nl80211_put_mesh_config(msg, params); |
| 3735 | if (ret < 0) { |
| 3736 | nlmsg_free(msg); |
| 3737 | return ret; |
| 3738 | } |
| 3739 | |
| 3740 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3741 | if (ret) { |
| 3742 | wpa_printf(MSG_ERROR, |
| 3743 | "nl80211: Mesh config set failed: %d (%s)", |
| 3744 | ret, strerror(-ret)); |
| 3745 | return ret; |
| 3746 | } |
| 3747 | return 0; |
| 3748 | } |
| 3749 | #endif /* CONFIG_MESH */ |
| 3750 | |
| 3751 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3752 | static int nl80211_put_beacon_rate(struct nl_msg *msg, const u64 flags, |
| 3753 | struct wpa_driver_ap_params *params) |
| 3754 | { |
| 3755 | struct nlattr *bands, *band; |
| 3756 | struct nl80211_txrate_vht vht_rate; |
| 3757 | |
| 3758 | if (!params->freq || |
| 3759 | (params->beacon_rate == 0 && |
| 3760 | params->rate_type == BEACON_RATE_LEGACY)) |
| 3761 | return 0; |
| 3762 | |
| 3763 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 3764 | if (!bands) |
| 3765 | return -1; |
| 3766 | |
| 3767 | switch (params->freq->mode) { |
| 3768 | case HOSTAPD_MODE_IEEE80211B: |
| 3769 | case HOSTAPD_MODE_IEEE80211G: |
| 3770 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
| 3771 | break; |
| 3772 | case HOSTAPD_MODE_IEEE80211A: |
| 3773 | band = nla_nest_start(msg, NL80211_BAND_5GHZ); |
| 3774 | break; |
| 3775 | case HOSTAPD_MODE_IEEE80211AD: |
| 3776 | band = nla_nest_start(msg, NL80211_BAND_60GHZ); |
| 3777 | break; |
| 3778 | default: |
| 3779 | return 0; |
| 3780 | } |
| 3781 | |
| 3782 | if (!band) |
| 3783 | return -1; |
| 3784 | |
| 3785 | os_memset(&vht_rate, 0, sizeof(vht_rate)); |
| 3786 | |
| 3787 | switch (params->rate_type) { |
| 3788 | case BEACON_RATE_LEGACY: |
| 3789 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) { |
| 3790 | wpa_printf(MSG_INFO, |
| 3791 | "nl80211: Driver does not support setting Beacon frame rate (legacy)"); |
| 3792 | return -1; |
| 3793 | } |
| 3794 | |
| 3795 | if (nla_put_u8(msg, NL80211_TXRATE_LEGACY, |
| 3796 | (u8) params->beacon_rate / 5) || |
| 3797 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || |
| 3798 | (params->freq->vht_enabled && |
| 3799 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 3800 | &vht_rate))) |
| 3801 | return -1; |
| 3802 | |
| 3803 | wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)", |
| 3804 | params->beacon_rate); |
| 3805 | break; |
| 3806 | case BEACON_RATE_HT: |
| 3807 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) { |
| 3808 | wpa_printf(MSG_INFO, |
| 3809 | "nl80211: Driver does not support setting Beacon frame rate (HT)"); |
| 3810 | return -1; |
| 3811 | } |
| 3812 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || |
| 3813 | nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) || |
| 3814 | (params->freq->vht_enabled && |
| 3815 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 3816 | &vht_rate))) |
| 3817 | return -1; |
| 3818 | wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u", |
| 3819 | params->beacon_rate); |
| 3820 | break; |
| 3821 | case BEACON_RATE_VHT: |
| 3822 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) { |
| 3823 | wpa_printf(MSG_INFO, |
| 3824 | "nl80211: Driver does not support setting Beacon frame rate (VHT)"); |
| 3825 | return -1; |
| 3826 | } |
| 3827 | vht_rate.mcs[0] = BIT(params->beacon_rate); |
| 3828 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL)) |
| 3829 | return -1; |
| 3830 | if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL)) |
| 3831 | return -1; |
| 3832 | if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 3833 | &vht_rate)) |
| 3834 | return -1; |
| 3835 | wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u", |
| 3836 | params->beacon_rate); |
| 3837 | break; |
| 3838 | } |
| 3839 | |
| 3840 | nla_nest_end(msg, band); |
| 3841 | nla_nest_end(msg, bands); |
| 3842 | |
| 3843 | return 0; |
| 3844 | } |
| 3845 | |
| 3846 | |
| 3847 | static int nl80211_set_multicast_to_unicast(struct i802_bss *bss, |
| 3848 | int multicast_to_unicast) |
| 3849 | { |
| 3850 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3851 | struct nl_msg *msg; |
| 3852 | int ret; |
| 3853 | |
| 3854 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST); |
| 3855 | if (!msg || |
| 3856 | (multicast_to_unicast && |
| 3857 | nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) { |
| 3858 | wpa_printf(MSG_ERROR, |
| 3859 | "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s", |
| 3860 | bss->ifname); |
| 3861 | nlmsg_free(msg); |
| 3862 | return -ENOBUFS; |
| 3863 | } |
| 3864 | |
| 3865 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3866 | |
| 3867 | switch (ret) { |
| 3868 | case 0: |
| 3869 | wpa_printf(MSG_DEBUG, |
| 3870 | "nl80211: multicast to unicast %s on interface %s", |
| 3871 | multicast_to_unicast ? "enabled" : "disabled", |
| 3872 | bss->ifname); |
| 3873 | break; |
| 3874 | case -EOPNOTSUPP: |
| 3875 | if (!multicast_to_unicast) |
| 3876 | break; |
| 3877 | wpa_printf(MSG_INFO, |
| 3878 | "nl80211: multicast to unicast not supported on interface %s", |
| 3879 | bss->ifname); |
| 3880 | break; |
| 3881 | default: |
| 3882 | wpa_printf(MSG_ERROR, |
| 3883 | "nl80211: %s multicast to unicast failed with %d (%s) on interface %s", |
| 3884 | multicast_to_unicast ? "enabling" : "disabling", |
| 3885 | ret, strerror(-ret), bss->ifname); |
| 3886 | break; |
| 3887 | } |
| 3888 | |
| 3889 | return ret; |
| 3890 | } |
| 3891 | |
| 3892 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3893 | static int wpa_driver_nl80211_set_ap(void *priv, |
| 3894 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3895 | { |
| 3896 | struct i802_bss *bss = priv; |
| 3897 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3898 | struct nl_msg *msg; |
| 3899 | u8 cmd = NL80211_CMD_NEW_BEACON; |
| 3900 | int ret; |
| 3901 | int beacon_set; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3902 | int num_suites; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3903 | int smps_mode; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3904 | u32 suites[10], suite; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3905 | u32 ver; |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3906 | #ifdef CONFIG_MESH |
| 3907 | struct wpa_driver_mesh_bss_params mesh_params; |
| 3908 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3909 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3910 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3911 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3912 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
| 3913 | beacon_set); |
| 3914 | if (beacon_set) |
| 3915 | cmd = NL80211_CMD_SET_BEACON; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3916 | else if (!drv->device_ap_sme && !drv->use_monitor && |
| 3917 | !nl80211_get_wiphy_data_ap(bss)) |
| 3918 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3919 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3920 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
| 3921 | params->head, params->head_len); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3922 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
| 3923 | params->tail, params->tail_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3924 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3925 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3926 | wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate); |
| 3927 | wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3928 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3929 | wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid", |
| 3930 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3931 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 3932 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
| 3933 | params->head) || |
| 3934 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, |
| 3935 | params->tail) || |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3936 | nl80211_put_beacon_int(msg, params->beacon_int) || |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3937 | nl80211_put_beacon_rate(msg, drv->capa.flags, params) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3938 | nl80211_put_dtim_period(msg, params->dtim_period) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3939 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 3940 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3941 | if (params->proberesp && params->proberesp_len) { |
| 3942 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", |
| 3943 | params->proberesp, params->proberesp_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3944 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
| 3945 | params->proberesp)) |
| 3946 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3947 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3948 | switch (params->hide_ssid) { |
| 3949 | case NO_SSID_HIDING: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3950 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3951 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3952 | NL80211_HIDDEN_SSID_NOT_IN_USE)) |
| 3953 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3954 | break; |
| 3955 | case HIDDEN_SSID_ZERO_LEN: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3956 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3957 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3958 | NL80211_HIDDEN_SSID_ZERO_LEN)) |
| 3959 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3960 | break; |
| 3961 | case HIDDEN_SSID_ZERO_CONTENTS: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3962 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3963 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3964 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) |
| 3965 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3966 | break; |
| 3967 | } |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3968 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3969 | if (params->privacy && |
| 3970 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 3971 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3972 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3973 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
| 3974 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { |
| 3975 | /* Leave out the attribute */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3976 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
| 3977 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 3978 | NL80211_AUTHTYPE_SHARED_KEY)) |
| 3979 | goto fail; |
| 3980 | } else { |
| 3981 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 3982 | NL80211_AUTHTYPE_OPEN_SYSTEM)) |
| 3983 | goto fail; |
| 3984 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3985 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3986 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3987 | ver = 0; |
| 3988 | if (params->wpa_version & WPA_PROTO_WPA) |
| 3989 | ver |= NL80211_WPA_VERSION_1; |
| 3990 | if (params->wpa_version & WPA_PROTO_RSN) |
| 3991 | ver |= NL80211_WPA_VERSION_2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3992 | if (ver && |
| 3993 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 3994 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3995 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3996 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
| 3997 | params->key_mgmt_suites); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3998 | num_suites = 0; |
| 3999 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4000 | suites[num_suites++] = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4001 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4002 | suites[num_suites++] = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4003 | if (num_suites && |
| 4004 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), |
| 4005 | suites)) |
| 4006 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4007 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4008 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4009 | (!params->pairwise_ciphers || |
| 4010 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) && |
| 4011 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 4012 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4013 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4014 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4015 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
| 4016 | params->pairwise_ciphers); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4017 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
| 4018 | suites, ARRAY_SIZE(suites)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4019 | if (num_suites && |
| 4020 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 4021 | num_suites * sizeof(u32), suites)) |
| 4022 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4023 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4024 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
| 4025 | params->group_cipher); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4026 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4027 | if (suite && |
| 4028 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) |
| 4029 | goto fail; |
| 4030 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 4031 | if (params->ht_opmode != -1) { |
| 4032 | switch (params->smps_mode) { |
| 4033 | case HT_CAP_INFO_SMPS_DYNAMIC: |
| 4034 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic"); |
| 4035 | smps_mode = NL80211_SMPS_DYNAMIC; |
| 4036 | break; |
| 4037 | case HT_CAP_INFO_SMPS_STATIC: |
| 4038 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static"); |
| 4039 | smps_mode = NL80211_SMPS_STATIC; |
| 4040 | break; |
| 4041 | default: |
| 4042 | /* invalid - fallback to smps off */ |
| 4043 | case HT_CAP_INFO_SMPS_DISABLED: |
| 4044 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off"); |
| 4045 | smps_mode = NL80211_SMPS_OFF; |
| 4046 | break; |
| 4047 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4048 | if (nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, smps_mode)) |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 4049 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4050 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4051 | |
| 4052 | if (params->beacon_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4053 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
| 4054 | params->beacon_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4055 | if (nla_put(msg, NL80211_ATTR_IE, |
| 4056 | wpabuf_len(params->beacon_ies), |
| 4057 | wpabuf_head(params->beacon_ies))) |
| 4058 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4059 | } |
| 4060 | if (params->proberesp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4061 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
| 4062 | params->proberesp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4063 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 4064 | wpabuf_len(params->proberesp_ies), |
| 4065 | wpabuf_head(params->proberesp_ies))) |
| 4066 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4067 | } |
| 4068 | if (params->assocresp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4069 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
| 4070 | params->assocresp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4071 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 4072 | wpabuf_len(params->assocresp_ies), |
| 4073 | wpabuf_head(params->assocresp_ies))) |
| 4074 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4075 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4076 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4077 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4078 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
| 4079 | params->ap_max_inactivity); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4080 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
| 4081 | params->ap_max_inactivity)) |
| 4082 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4083 | } |
| 4084 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4085 | #ifdef CONFIG_P2P |
| 4086 | if (params->p2p_go_ctwindow > 0) { |
| 4087 | if (drv->p2p_go_ctwindow_supported) { |
| 4088 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", |
| 4089 | params->p2p_go_ctwindow); |
| 4090 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, |
| 4091 | params->p2p_go_ctwindow)) |
| 4092 | goto fail; |
| 4093 | } else { |
| 4094 | wpa_printf(MSG_INFO, |
| 4095 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); |
| 4096 | } |
| 4097 | } |
| 4098 | #endif /* CONFIG_P2P */ |
| 4099 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4100 | if (params->pbss) { |
| 4101 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); |
| 4102 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 4103 | goto fail; |
| 4104 | } |
| 4105 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4106 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4107 | if (ret) { |
| 4108 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", |
| 4109 | ret, strerror(-ret)); |
| 4110 | } else { |
| 4111 | bss->beacon_set = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4112 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
| 4113 | params->short_slot_time, params->ht_opmode, |
| 4114 | params->isolate, params->basic_rates); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4115 | nl80211_set_multicast_to_unicast(bss, |
| 4116 | params->multicast_to_unicast); |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4117 | if (beacon_set && params->freq && |
| 4118 | params->freq->bandwidth != bss->bandwidth) { |
| 4119 | wpa_printf(MSG_DEBUG, |
| 4120 | "nl80211: Update BSS %s bandwidth: %d -> %d", |
| 4121 | bss->ifname, bss->bandwidth, |
| 4122 | params->freq->bandwidth); |
| 4123 | ret = nl80211_set_channel(bss, params->freq, 1); |
| 4124 | if (ret) { |
| 4125 | wpa_printf(MSG_DEBUG, |
| 4126 | "nl80211: Frequency set failed: %d (%s)", |
| 4127 | ret, strerror(-ret)); |
| 4128 | } else { |
| 4129 | wpa_printf(MSG_DEBUG, |
| 4130 | "nl80211: Frequency set succeeded for ht2040 coex"); |
| 4131 | bss->bandwidth = params->freq->bandwidth; |
| 4132 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4133 | } else if (!beacon_set && params->freq) { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4134 | /* |
| 4135 | * cfg80211 updates the driver on frequence change in AP |
| 4136 | * mode only at the point when beaconing is started, so |
| 4137 | * set the initial value here. |
| 4138 | */ |
| 4139 | bss->bandwidth = params->freq->bandwidth; |
| 4140 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4141 | } |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4142 | |
| 4143 | #ifdef CONFIG_MESH |
| 4144 | if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) { |
| 4145 | os_memset(&mesh_params, 0, sizeof(mesh_params)); |
| 4146 | mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE; |
| 4147 | mesh_params.ht_opmode = params->ht_opmode; |
| 4148 | ret = nl80211_set_mesh_config(priv, &mesh_params); |
| 4149 | if (ret < 0) |
| 4150 | return ret; |
| 4151 | } |
| 4152 | #endif /* CONFIG_MESH */ |
| 4153 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4154 | return ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4155 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4156 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4157 | return -ENOBUFS; |
| 4158 | } |
| 4159 | |
| 4160 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4161 | static int nl80211_put_freq_params(struct nl_msg *msg, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4162 | const struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4163 | { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4164 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4165 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
| 4166 | return -ENOBUFS; |
| 4167 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4168 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
| 4169 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); |
| 4170 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4171 | if (freq->vht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4172 | enum nl80211_chan_width cw; |
| 4173 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4174 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4175 | switch (freq->bandwidth) { |
| 4176 | case 20: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4177 | cw = NL80211_CHAN_WIDTH_20; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4178 | break; |
| 4179 | case 40: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4180 | cw = NL80211_CHAN_WIDTH_40; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4181 | break; |
| 4182 | case 80: |
| 4183 | if (freq->center_freq2) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4184 | cw = NL80211_CHAN_WIDTH_80P80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4185 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4186 | cw = NL80211_CHAN_WIDTH_80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4187 | break; |
| 4188 | case 160: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4189 | cw = NL80211_CHAN_WIDTH_160; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4190 | break; |
| 4191 | default: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4192 | return -EINVAL; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4193 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4194 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4195 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
| 4196 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", |
| 4197 | freq->center_freq1); |
| 4198 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", |
| 4199 | freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4200 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
| 4201 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, |
| 4202 | freq->center_freq1) || |
| 4203 | (freq->center_freq2 && |
| 4204 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 4205 | freq->center_freq2))) |
| 4206 | return -ENOBUFS; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4207 | } else if (freq->ht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4208 | enum nl80211_channel_type ct; |
| 4209 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4210 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
| 4211 | freq->sec_channel_offset); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4212 | switch (freq->sec_channel_offset) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4213 | case -1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4214 | ct = NL80211_CHAN_HT40MINUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4215 | break; |
| 4216 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4217 | ct = NL80211_CHAN_HT40PLUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4218 | break; |
| 4219 | default: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4220 | ct = NL80211_CHAN_HT20; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4221 | break; |
| 4222 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4223 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4224 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4225 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
| 4226 | return -ENOBUFS; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4227 | } else { |
| 4228 | wpa_printf(MSG_DEBUG, " * channel_type=%d", |
| 4229 | NL80211_CHAN_NO_HT); |
| 4230 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 4231 | NL80211_CHAN_NO_HT)) |
| 4232 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4233 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4234 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4235 | } |
| 4236 | |
| 4237 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4238 | static int nl80211_set_channel(struct i802_bss *bss, |
| 4239 | struct hostapd_freq_params *freq, int set_chan) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4240 | { |
| 4241 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4242 | struct nl_msg *msg; |
| 4243 | int ret; |
| 4244 | |
| 4245 | wpa_printf(MSG_DEBUG, |
| 4246 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
| 4247 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 4248 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4249 | |
| 4250 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
| 4251 | NL80211_CMD_SET_WIPHY); |
| 4252 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { |
| 4253 | nlmsg_free(msg); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4254 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4255 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4256 | |
| 4257 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4258 | if (ret == 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4259 | bss->freq = freq->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4260 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4261 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4262 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4263 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4264 | return -1; |
| 4265 | } |
| 4266 | |
| 4267 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4268 | static u32 sta_flags_nl80211(int flags) |
| 4269 | { |
| 4270 | u32 f = 0; |
| 4271 | |
| 4272 | if (flags & WPA_STA_AUTHORIZED) |
| 4273 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 4274 | if (flags & WPA_STA_WMM) |
| 4275 | f |= BIT(NL80211_STA_FLAG_WME); |
| 4276 | if (flags & WPA_STA_SHORT_PREAMBLE) |
| 4277 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
| 4278 | if (flags & WPA_STA_MFP) |
| 4279 | f |= BIT(NL80211_STA_FLAG_MFP); |
| 4280 | if (flags & WPA_STA_TDLS_PEER) |
| 4281 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4282 | if (flags & WPA_STA_AUTHENTICATED) |
| 4283 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4284 | if (flags & WPA_STA_ASSOCIATED) |
| 4285 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4286 | |
| 4287 | return f; |
| 4288 | } |
| 4289 | |
| 4290 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4291 | #ifdef CONFIG_MESH |
| 4292 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) |
| 4293 | { |
| 4294 | switch (state) { |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4295 | case PLINK_IDLE: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4296 | return NL80211_PLINK_LISTEN; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4297 | case PLINK_OPN_SNT: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4298 | return NL80211_PLINK_OPN_SNT; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4299 | case PLINK_OPN_RCVD: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4300 | return NL80211_PLINK_OPN_RCVD; |
| 4301 | case PLINK_CNF_RCVD: |
| 4302 | return NL80211_PLINK_CNF_RCVD; |
| 4303 | case PLINK_ESTAB: |
| 4304 | return NL80211_PLINK_ESTAB; |
| 4305 | case PLINK_HOLDING: |
| 4306 | return NL80211_PLINK_HOLDING; |
| 4307 | case PLINK_BLOCKED: |
| 4308 | return NL80211_PLINK_BLOCKED; |
| 4309 | default: |
| 4310 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", |
| 4311 | state); |
| 4312 | } |
| 4313 | return -1; |
| 4314 | } |
| 4315 | #endif /* CONFIG_MESH */ |
| 4316 | |
| 4317 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4318 | static int wpa_driver_nl80211_sta_add(void *priv, |
| 4319 | struct hostapd_sta_add_params *params) |
| 4320 | { |
| 4321 | struct i802_bss *bss = priv; |
| 4322 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4323 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4324 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4325 | int ret = -ENOBUFS; |
| 4326 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4327 | if ((params->flags & WPA_STA_TDLS_PEER) && |
| 4328 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 4329 | return -EOPNOTSUPP; |
| 4330 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4331 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
| 4332 | params->set ? "Set" : "Add", MAC2STR(params->addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4333 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
| 4334 | NL80211_CMD_NEW_STATION); |
| 4335 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) |
| 4336 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4337 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4338 | /* |
| 4339 | * Set the below properties only in one of the following cases: |
| 4340 | * 1. New station is added, already associated. |
| 4341 | * 2. Set WPA_STA_TDLS_PEER station. |
| 4342 | * 3. Set an already added unassociated station, if driver supports |
| 4343 | * full AP client state. (Set these properties after station became |
| 4344 | * associated will be rejected by the driver). |
| 4345 | */ |
| 4346 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
| 4347 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 4348 | (params->flags & WPA_STA_ASSOCIATED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4349 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
| 4350 | params->supp_rates, params->supp_rates_len); |
| 4351 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
| 4352 | params->capability); |
| 4353 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, |
| 4354 | params->supp_rates_len, params->supp_rates) || |
| 4355 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, |
| 4356 | params->capability)) |
| 4357 | goto fail; |
| 4358 | |
| 4359 | if (params->ht_capabilities) { |
| 4360 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
| 4361 | (u8 *) params->ht_capabilities, |
| 4362 | sizeof(*params->ht_capabilities)); |
| 4363 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
| 4364 | sizeof(*params->ht_capabilities), |
| 4365 | params->ht_capabilities)) |
| 4366 | goto fail; |
| 4367 | } |
| 4368 | |
| 4369 | if (params->vht_capabilities) { |
| 4370 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
| 4371 | (u8 *) params->vht_capabilities, |
| 4372 | sizeof(*params->vht_capabilities)); |
| 4373 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
| 4374 | sizeof(*params->vht_capabilities), |
| 4375 | params->vht_capabilities)) |
| 4376 | goto fail; |
| 4377 | } |
| 4378 | |
| 4379 | if (params->ext_capab) { |
| 4380 | wpa_hexdump(MSG_DEBUG, " * ext_capab", |
| 4381 | params->ext_capab, params->ext_capab_len); |
| 4382 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
| 4383 | params->ext_capab_len, params->ext_capab)) |
| 4384 | goto fail; |
| 4385 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4386 | |
| 4387 | if (is_ap_interface(drv->nlmode) && |
| 4388 | nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS, |
| 4389 | params->support_p2p_ps ? |
| 4390 | NL80211_P2P_PS_SUPPORTED : |
| 4391 | NL80211_P2P_PS_UNSUPPORTED)) |
| 4392 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4393 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4394 | if (!params->set) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4395 | if (params->aid) { |
| 4396 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4397 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
| 4398 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4399 | } else { |
| 4400 | /* |
| 4401 | * cfg80211 validates that AID is non-zero, so we have |
| 4402 | * to make this a non-zero value for the TDLS case where |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4403 | * a dummy STA entry is used for now and for a station |
| 4404 | * that is still not associated. |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4405 | */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4406 | wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)", |
| 4407 | (params->flags & WPA_STA_TDLS_PEER) ? |
| 4408 | "TDLS" : "UNASSOC_STA"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4409 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
| 4410 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4411 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4412 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 4413 | params->listen_interval); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4414 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 4415 | params->listen_interval)) |
| 4416 | goto fail; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4417 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
| 4418 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4419 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
| 4420 | goto fail; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4421 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 4422 | (params->flags & WPA_STA_ASSOCIATED)) { |
| 4423 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
| 4424 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 4425 | params->listen_interval); |
| 4426 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || |
| 4427 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 4428 | params->listen_interval)) |
| 4429 | goto fail; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4430 | } |
| 4431 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 4432 | if (params->vht_opmode_enabled) { |
| 4433 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4434 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
| 4435 | params->vht_opmode)) |
| 4436 | goto fail; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4437 | } |
| 4438 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4439 | if (params->supp_channels) { |
| 4440 | wpa_hexdump(MSG_DEBUG, " * supported channels", |
| 4441 | params->supp_channels, params->supp_channels_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4442 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
| 4443 | params->supp_channels_len, params->supp_channels)) |
| 4444 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4445 | } |
| 4446 | |
| 4447 | if (params->supp_oper_classes) { |
| 4448 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", |
| 4449 | params->supp_oper_classes, |
| 4450 | params->supp_oper_classes_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4451 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
| 4452 | params->supp_oper_classes_len, |
| 4453 | params->supp_oper_classes)) |
| 4454 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4455 | } |
| 4456 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4457 | os_memset(&upd, 0, sizeof(upd)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4458 | upd.set = sta_flags_nl80211(params->flags); |
| 4459 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4460 | |
| 4461 | /* |
| 4462 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH |
| 4463 | * flags, as nl80211 driver moves a new station, by default, into |
| 4464 | * associated state. |
| 4465 | * |
| 4466 | * On the other hand, if the driver supports that feature and the |
| 4467 | * station is added in unauthenticated state, set the |
| 4468 | * authenticated/associated bits in the mask to prevent moving this |
| 4469 | * station to associated state before it is actually associated. |
| 4470 | * |
| 4471 | * This is irrelevant for mesh mode where the station is added to the |
| 4472 | * driver as authenticated already, and ASSOCIATED isn't part of the |
| 4473 | * nl80211 API. |
| 4474 | */ |
| 4475 | if (!is_mesh_interface(drv->nlmode)) { |
| 4476 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { |
| 4477 | wpa_printf(MSG_DEBUG, |
| 4478 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); |
| 4479 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4480 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); |
| 4481 | } else if (!params->set && |
| 4482 | !(params->flags & WPA_STA_TDLS_PEER)) { |
| 4483 | if (!(params->flags & WPA_STA_AUTHENTICATED)) |
| 4484 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
| 4485 | if (!(params->flags & WPA_STA_ASSOCIATED)) |
| 4486 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 4487 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4488 | #ifdef CONFIG_MESH |
| 4489 | } else { |
| 4490 | if (params->plink_state == PLINK_ESTAB && params->peer_aid) { |
| 4491 | ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID, |
| 4492 | params->peer_aid); |
| 4493 | if (ret) |
| 4494 | goto fail; |
| 4495 | } |
| 4496 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4497 | } |
| 4498 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4499 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
| 4500 | upd.set, upd.mask); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4501 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 4502 | goto fail; |
| 4503 | |
| 4504 | #ifdef CONFIG_MESH |
| 4505 | if (params->plink_state && |
| 4506 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, |
| 4507 | sta_plink_state_nl80211(params->plink_state))) |
| 4508 | goto fail; |
| 4509 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4510 | |
| 4511 | if (params->flags & WPA_STA_WMM) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4512 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 4513 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4514 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4515 | if (!wme || |
| 4516 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 4517 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || |
| 4518 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, |
| 4519 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
| 4520 | WMM_QOSINFO_STA_SP_MASK)) |
| 4521 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4522 | nla_nest_end(msg, wme); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4523 | } |
| 4524 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4525 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4526 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4527 | if (ret) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4528 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
| 4529 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, |
| 4530 | strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4531 | if (ret == -EEXIST) |
| 4532 | ret = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4533 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4534 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4535 | return ret; |
| 4536 | } |
| 4537 | |
| 4538 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4539 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
| 4540 | { |
| 4541 | #ifdef CONFIG_LIBNL3_ROUTE |
| 4542 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4543 | struct rtnl_neigh *rn; |
| 4544 | struct nl_addr *nl_addr; |
| 4545 | int err; |
| 4546 | |
| 4547 | rn = rtnl_neigh_alloc(); |
| 4548 | if (!rn) |
| 4549 | return; |
| 4550 | |
| 4551 | rtnl_neigh_set_family(rn, AF_BRIDGE); |
| 4552 | rtnl_neigh_set_ifindex(rn, bss->ifindex); |
| 4553 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); |
| 4554 | if (!nl_addr) { |
| 4555 | rtnl_neigh_put(rn); |
| 4556 | return; |
| 4557 | } |
| 4558 | rtnl_neigh_set_lladdr(rn, nl_addr); |
| 4559 | |
| 4560 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 4561 | if (err < 0) { |
| 4562 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " |
| 4563 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), |
| 4564 | bss->ifindex, nl_geterror(err)); |
| 4565 | } else { |
| 4566 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " |
| 4567 | MACSTR, MAC2STR(addr)); |
| 4568 | } |
| 4569 | |
| 4570 | nl_addr_put(nl_addr); |
| 4571 | rtnl_neigh_put(rn); |
| 4572 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 4573 | } |
| 4574 | |
| 4575 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4576 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
| 4577 | int deauth, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4578 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4579 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4580 | struct nl_msg *msg; |
| 4581 | int ret; |
| 4582 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4583 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
| 4584 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 4585 | (deauth == 0 && |
| 4586 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 4587 | WLAN_FC_STYPE_DISASSOC)) || |
| 4588 | (deauth == 1 && |
| 4589 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 4590 | WLAN_FC_STYPE_DEAUTH)) || |
| 4591 | (reason_code && |
| 4592 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { |
| 4593 | nlmsg_free(msg); |
| 4594 | return -ENOBUFS; |
| 4595 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4596 | |
| 4597 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 4598 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
| 4599 | " --> %d (%s)", |
| 4600 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4601 | |
| 4602 | if (drv->rtnl_sk) |
| 4603 | rtnl_neigh_delete_fdb_entry(bss, addr); |
| 4604 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4605 | if (ret == -ENOENT) |
| 4606 | return 0; |
| 4607 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4608 | } |
| 4609 | |
| 4610 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4611 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4612 | { |
| 4613 | struct nl_msg *msg; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4614 | struct wpa_driver_nl80211_data *drv2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4615 | |
| 4616 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
| 4617 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4618 | /* stop listening for EAPOL on this interface */ |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4619 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 4620 | struct wpa_driver_nl80211_data, list) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4621 | { |
| 4622 | del_ifidx(drv2, ifidx, IFIDX_ANY); |
| 4623 | /* Remove all bridges learned for this iface */ |
| 4624 | del_ifidx(drv2, IFIDX_ANY, ifidx); |
| 4625 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4626 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4627 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4628 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 4629 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4630 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
| 4631 | } |
| 4632 | |
| 4633 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 4634 | const char * nl80211_iftype_str(enum nl80211_iftype mode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4635 | { |
| 4636 | switch (mode) { |
| 4637 | case NL80211_IFTYPE_ADHOC: |
| 4638 | return "ADHOC"; |
| 4639 | case NL80211_IFTYPE_STATION: |
| 4640 | return "STATION"; |
| 4641 | case NL80211_IFTYPE_AP: |
| 4642 | return "AP"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 4643 | case NL80211_IFTYPE_AP_VLAN: |
| 4644 | return "AP_VLAN"; |
| 4645 | case NL80211_IFTYPE_WDS: |
| 4646 | return "WDS"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4647 | case NL80211_IFTYPE_MONITOR: |
| 4648 | return "MONITOR"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 4649 | case NL80211_IFTYPE_MESH_POINT: |
| 4650 | return "MESH_POINT"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4651 | case NL80211_IFTYPE_P2P_CLIENT: |
| 4652 | return "P2P_CLIENT"; |
| 4653 | case NL80211_IFTYPE_P2P_GO: |
| 4654 | return "P2P_GO"; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4655 | case NL80211_IFTYPE_P2P_DEVICE: |
| 4656 | return "P2P_DEVICE"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4657 | default: |
| 4658 | return "unknown"; |
| 4659 | } |
| 4660 | } |
| 4661 | |
| 4662 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4663 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
| 4664 | const char *ifname, |
| 4665 | enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4666 | const u8 *addr, int wds, |
| 4667 | int (*handler)(struct nl_msg *, void *), |
| 4668 | void *arg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4669 | { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4670 | struct nl_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4671 | int ifidx; |
| 4672 | int ret = -ENOBUFS; |
| 4673 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4674 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
| 4675 | iftype, nl80211_iftype_str(iftype)); |
| 4676 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4677 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
| 4678 | if (!msg || |
| 4679 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
| 4680 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) |
| 4681 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4682 | |
| 4683 | if (iftype == NL80211_IFTYPE_MONITOR) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4684 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4685 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4686 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4687 | if (!flags || |
| 4688 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) |
| 4689 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4690 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4691 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4692 | } else if (wds) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4693 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
| 4694 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4695 | } |
| 4696 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4697 | /* |
| 4698 | * Tell cfg80211 that the interface belongs to the socket that created |
| 4699 | * it, and the interface should be deleted when the socket is closed. |
| 4700 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4701 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 4702 | goto fail; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4703 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4704 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4705 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4706 | if (ret) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4707 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4708 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4709 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
| 4710 | ifname, ret, strerror(-ret)); |
| 4711 | return ret; |
| 4712 | } |
| 4713 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4714 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
| 4715 | return 0; |
| 4716 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4717 | ifidx = if_nametoindex(ifname); |
| 4718 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
| 4719 | ifname, ifidx); |
| 4720 | |
| 4721 | if (ifidx <= 0) |
| 4722 | return -1; |
| 4723 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4724 | /* |
| 4725 | * Some virtual interfaces need to process EAPOL packets and events on |
| 4726 | * the parent interface. This is used mainly with hostapd. |
| 4727 | */ |
| 4728 | if (drv->hostapd || |
| 4729 | iftype == NL80211_IFTYPE_AP_VLAN || |
| 4730 | iftype == NL80211_IFTYPE_WDS || |
| 4731 | iftype == NL80211_IFTYPE_MONITOR) { |
| 4732 | /* start listening for EAPOL on this interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4733 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4734 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4735 | |
| 4736 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4737 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4738 | nl80211_remove_iface(drv, ifidx); |
| 4739 | return -1; |
| 4740 | } |
| 4741 | |
| 4742 | return ifidx; |
| 4743 | } |
| 4744 | |
| 4745 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4746 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
| 4747 | const char *ifname, enum nl80211_iftype iftype, |
| 4748 | const u8 *addr, int wds, |
| 4749 | int (*handler)(struct nl_msg *, void *), |
| 4750 | void *arg, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4751 | { |
| 4752 | int ret; |
| 4753 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4754 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
| 4755 | arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4756 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4757 | /* if error occurred and interface exists already */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4758 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4759 | if (use_existing) { |
| 4760 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", |
| 4761 | ifname); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 4762 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
| 4763 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4764 | addr) < 0 && |
| 4765 | (linux_set_iface_flags(drv->global->ioctl_sock, |
| 4766 | ifname, 0) < 0 || |
| 4767 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4768 | addr) < 0 || |
| 4769 | linux_set_iface_flags(drv->global->ioctl_sock, |
| 4770 | ifname, 1) < 0)) |
| 4771 | return -1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4772 | return -ENFILE; |
| 4773 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4774 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
| 4775 | |
| 4776 | /* Try to remove the interface that was already there. */ |
| 4777 | nl80211_remove_iface(drv, if_nametoindex(ifname)); |
| 4778 | |
| 4779 | /* Try to create the interface again */ |
| 4780 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4781 | wds, handler, arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4782 | } |
| 4783 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4784 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
| 4785 | wpa_printf(MSG_DEBUG, |
| 4786 | "nl80211: Interface %s created for P2P - disable 11b rates", |
| 4787 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4788 | nl80211_disable_11b_rates(drv, ret, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4789 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4790 | |
| 4791 | return ret; |
| 4792 | } |
| 4793 | |
| 4794 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4795 | static int nl80211_setup_ap(struct i802_bss *bss) |
| 4796 | { |
| 4797 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4798 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4799 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 4800 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4801 | |
| 4802 | /* |
| 4803 | * Disable Probe Request reporting unless we need it in this way for |
| 4804 | * devices that include the AP SME, in the other case (unless using |
| 4805 | * monitor iface) we'll get it through the nl_mgmt socket instead. |
| 4806 | */ |
| 4807 | if (!drv->device_ap_sme) |
| 4808 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4809 | |
| 4810 | if (!drv->device_ap_sme && !drv->use_monitor) |
| 4811 | if (nl80211_mgmt_subscribe_ap(bss)) |
| 4812 | return -1; |
| 4813 | |
| 4814 | if (drv->device_ap_sme && !drv->use_monitor) |
| 4815 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4816 | wpa_printf(MSG_DEBUG, |
| 4817 | "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] | 4818 | |
| 4819 | if (!drv->device_ap_sme && drv->use_monitor && |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 4820 | nl80211_create_monitor_interface(drv) && |
| 4821 | !drv->device_ap_sme) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4822 | return -1; |
| 4823 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4824 | if (drv->device_ap_sme && |
| 4825 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { |
| 4826 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " |
| 4827 | "Probe Request frame reporting in AP mode"); |
| 4828 | /* Try to survive without this */ |
| 4829 | } |
| 4830 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4831 | return 0; |
| 4832 | } |
| 4833 | |
| 4834 | |
| 4835 | static void nl80211_teardown_ap(struct i802_bss *bss) |
| 4836 | { |
| 4837 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4838 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4839 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 4840 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4841 | if (drv->device_ap_sme) { |
| 4842 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4843 | if (!drv->use_monitor) |
| 4844 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); |
| 4845 | } else if (drv->use_monitor) |
| 4846 | nl80211_remove_monitor_interface(drv); |
| 4847 | else |
| 4848 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
| 4849 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4850 | nl80211_put_wiphy_data_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4851 | bss->beacon_set = 0; |
| 4852 | } |
| 4853 | |
| 4854 | |
| 4855 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
| 4856 | const u8 *addr, const u8 *data, |
| 4857 | size_t data_len) |
| 4858 | { |
| 4859 | struct sockaddr_ll ll; |
| 4860 | int ret; |
| 4861 | |
| 4862 | if (bss->drv->eapol_tx_sock < 0) { |
| 4863 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); |
| 4864 | return -1; |
| 4865 | } |
| 4866 | |
| 4867 | os_memset(&ll, 0, sizeof(ll)); |
| 4868 | ll.sll_family = AF_PACKET; |
| 4869 | ll.sll_ifindex = bss->ifindex; |
| 4870 | ll.sll_protocol = htons(ETH_P_PAE); |
| 4871 | ll.sll_halen = ETH_ALEN; |
| 4872 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); |
| 4873 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, |
| 4874 | (struct sockaddr *) &ll, sizeof(ll)); |
| 4875 | if (ret < 0) |
| 4876 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", |
| 4877 | strerror(errno)); |
| 4878 | |
| 4879 | return ret; |
| 4880 | } |
| 4881 | |
| 4882 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4883 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 4884 | |
| 4885 | static int wpa_driver_nl80211_hapd_send_eapol( |
| 4886 | void *priv, const u8 *addr, const u8 *data, |
| 4887 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
| 4888 | { |
| 4889 | struct i802_bss *bss = priv; |
| 4890 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4891 | struct ieee80211_hdr *hdr; |
| 4892 | size_t len; |
| 4893 | u8 *pos; |
| 4894 | int res; |
| 4895 | int qos = flags & WPA_STA_WMM; |
Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 4896 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4897 | if (drv->device_ap_sme || !drv->use_monitor) |
| 4898 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
| 4899 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4900 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
| 4901 | data_len; |
| 4902 | hdr = os_zalloc(len); |
| 4903 | if (hdr == NULL) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4904 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
| 4905 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4906 | return -1; |
| 4907 | } |
| 4908 | |
| 4909 | hdr->frame_control = |
| 4910 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); |
| 4911 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 4912 | if (encrypt) |
| 4913 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); |
| 4914 | if (qos) { |
| 4915 | hdr->frame_control |= |
| 4916 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); |
| 4917 | } |
| 4918 | |
| 4919 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 4920 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 4921 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 4922 | pos = (u8 *) (hdr + 1); |
| 4923 | |
| 4924 | if (qos) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 4925 | /* Set highest priority in QoS header */ |
| 4926 | pos[0] = 7; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4927 | pos[1] = 0; |
| 4928 | pos += 2; |
| 4929 | } |
| 4930 | |
| 4931 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); |
| 4932 | pos += sizeof(rfc1042_header); |
| 4933 | WPA_PUT_BE16(pos, ETH_P_PAE); |
| 4934 | pos += 2; |
| 4935 | memcpy(pos, data, data_len); |
| 4936 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4937 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4938 | 0, 0, 0, 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4939 | if (res < 0) { |
| 4940 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " |
| 4941 | "failed: %d (%s)", |
| 4942 | (unsigned long) len, errno, strerror(errno)); |
| 4943 | } |
| 4944 | os_free(hdr); |
| 4945 | |
| 4946 | return res; |
| 4947 | } |
| 4948 | |
| 4949 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4950 | 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] | 4951 | unsigned int total_flags, |
| 4952 | unsigned int flags_or, |
| 4953 | unsigned int flags_and) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4954 | { |
| 4955 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4956 | struct nl_msg *msg; |
| 4957 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4958 | struct nl80211_sta_flag_update upd; |
| 4959 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4960 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
| 4961 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", |
| 4962 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, |
| 4963 | !!(total_flags & WPA_STA_AUTHORIZED)); |
| 4964 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4965 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 4966 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 4967 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4968 | |
| 4969 | /* |
| 4970 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This |
| 4971 | * can be removed eventually. |
| 4972 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4973 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4974 | if (!flags || |
| 4975 | ((total_flags & WPA_STA_AUTHORIZED) && |
| 4976 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || |
| 4977 | ((total_flags & WPA_STA_WMM) && |
| 4978 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || |
| 4979 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && |
| 4980 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || |
| 4981 | ((total_flags & WPA_STA_MFP) && |
| 4982 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || |
| 4983 | ((total_flags & WPA_STA_TDLS_PEER) && |
| 4984 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) |
| 4985 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4986 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4987 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4988 | |
| 4989 | os_memset(&upd, 0, sizeof(upd)); |
| 4990 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); |
| 4991 | upd.set = sta_flags_nl80211(flags_or); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4992 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 4993 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4994 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4995 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 4996 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4997 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4998 | return -ENOBUFS; |
| 4999 | } |
| 5000 | |
| 5001 | |
| 5002 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
| 5003 | struct wpa_driver_associate_params *params) |
| 5004 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5005 | enum nl80211_iftype nlmode, old_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5006 | |
| 5007 | if (params->p2p) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5008 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
| 5009 | "group (GO)"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5010 | nlmode = NL80211_IFTYPE_P2P_GO; |
| 5011 | } else |
| 5012 | nlmode = NL80211_IFTYPE_AP; |
| 5013 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5014 | old_mode = drv->nlmode; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5015 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5016 | nl80211_remove_monitor_interface(drv); |
| 5017 | return -1; |
| 5018 | } |
| 5019 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5020 | if (params->freq.freq && |
| 5021 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5022 | if (old_mode != nlmode) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5023 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5024 | nl80211_remove_monitor_interface(drv); |
| 5025 | return -1; |
| 5026 | } |
| 5027 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5028 | return 0; |
| 5029 | } |
| 5030 | |
| 5031 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5032 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 5033 | int reset_mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5034 | { |
| 5035 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5036 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5037 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5038 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5039 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5040 | if (ret) { |
| 5041 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " |
| 5042 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5043 | } else { |
| 5044 | wpa_printf(MSG_DEBUG, |
| 5045 | "nl80211: Leave IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5046 | } |
| 5047 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5048 | if (reset_mode && |
| 5049 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 5050 | NL80211_IFTYPE_STATION)) { |
| 5051 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 5052 | "station mode"); |
| 5053 | } |
| 5054 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5055 | return ret; |
| 5056 | } |
| 5057 | |
| 5058 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5059 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
| 5060 | struct wpa_driver_associate_params *params) |
| 5061 | { |
| 5062 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) |
| 5063 | return -1; |
| 5064 | |
| 5065 | if (params->htcaps && params->htcaps_mask) { |
| 5066 | int sz = sizeof(struct ieee80211_ht_capabilities); |
| 5067 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); |
| 5068 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", |
| 5069 | params->htcaps_mask, sz); |
| 5070 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, |
| 5071 | params->htcaps) || |
| 5072 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 5073 | params->htcaps_mask)) |
| 5074 | return -1; |
| 5075 | } |
| 5076 | |
| 5077 | #ifdef CONFIG_VHT_OVERRIDES |
| 5078 | if (params->disable_vht) { |
| 5079 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
| 5080 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) |
| 5081 | return -1; |
| 5082 | } |
| 5083 | |
| 5084 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 5085 | int sz = sizeof(struct ieee80211_vht_capabilities); |
| 5086 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); |
| 5087 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", |
| 5088 | params->vhtcaps_mask, sz); |
| 5089 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, |
| 5090 | params->vhtcaps) || |
| 5091 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 5092 | params->vhtcaps_mask)) |
| 5093 | return -1; |
| 5094 | } |
| 5095 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 5096 | |
| 5097 | return 0; |
| 5098 | } |
| 5099 | |
| 5100 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5101 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
| 5102 | struct wpa_driver_associate_params *params) |
| 5103 | { |
| 5104 | struct nl_msg *msg; |
| 5105 | int ret = -1; |
| 5106 | int count = 0; |
| 5107 | |
| 5108 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); |
| 5109 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5110 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5111 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 5112 | "IBSS mode"); |
| 5113 | return -1; |
| 5114 | } |
| 5115 | |
| 5116 | retry: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5117 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
| 5118 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
| 5119 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5120 | |
| 5121 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 5122 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5123 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 5124 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5125 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 5126 | drv->ssid_len = params->ssid_len; |
| 5127 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5128 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
| 5129 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5130 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5131 | |
| 5132 | ret = nl80211_set_conn_keys(params, msg); |
| 5133 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5134 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5135 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5136 | if (params->bssid && params->fixed_bssid) { |
| 5137 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, |
| 5138 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5139 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 5140 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5141 | } |
| 5142 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5143 | if (params->fixed_freq) { |
| 5144 | wpa_printf(MSG_DEBUG, " * fixed_freq"); |
| 5145 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) |
| 5146 | goto fail; |
| 5147 | } |
| 5148 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5149 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 5150 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 5151 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
| 5152 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5153 | wpa_printf(MSG_DEBUG, " * control port"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5154 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 5155 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5156 | } |
| 5157 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5158 | if (params->wpa_ie) { |
| 5159 | wpa_hexdump(MSG_DEBUG, |
| 5160 | " * Extra IEs for Beacon/Probe Response frames", |
| 5161 | params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5162 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 5163 | params->wpa_ie)) |
| 5164 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5165 | } |
| 5166 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 5167 | ret = nl80211_ht_vht_overrides(msg, params); |
| 5168 | if (ret < 0) |
| 5169 | goto fail; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5170 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5171 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5172 | msg = NULL; |
| 5173 | if (ret) { |
| 5174 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", |
| 5175 | ret, strerror(-ret)); |
| 5176 | count++; |
| 5177 | if (ret == -EALREADY && count == 1) { |
| 5178 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " |
| 5179 | "forced leave"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5180 | nl80211_leave_ibss(drv, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5181 | nlmsg_free(msg); |
| 5182 | goto retry; |
| 5183 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5184 | } else { |
| 5185 | wpa_printf(MSG_DEBUG, |
| 5186 | "nl80211: Join IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5187 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5188 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5189 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5190 | nlmsg_free(msg); |
| 5191 | return ret; |
| 5192 | } |
| 5193 | |
| 5194 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5195 | static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data *drv, |
| 5196 | struct wpa_driver_associate_params *params, |
| 5197 | struct nl_msg *msg) |
| 5198 | { |
| 5199 | if (params->fils_erp_username_len) { |
| 5200 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP EMSKname/username", |
| 5201 | params->fils_erp_username, |
| 5202 | params->fils_erp_username_len); |
| 5203 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_USERNAME, |
| 5204 | params->fils_erp_username_len, |
| 5205 | params->fils_erp_username)) |
| 5206 | return -1; |
| 5207 | } |
| 5208 | |
| 5209 | if (params->fils_erp_realm_len) { |
| 5210 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP Realm", |
| 5211 | params->fils_erp_realm, |
| 5212 | params->fils_erp_realm_len); |
| 5213 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_REALM, |
| 5214 | params->fils_erp_realm_len, params->fils_erp_realm)) |
| 5215 | return -1; |
| 5216 | } |
| 5217 | |
| 5218 | wpa_printf(MSG_DEBUG, " * FILS ERP next seq %u", |
| 5219 | params->fils_erp_next_seq_num); |
| 5220 | if (nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 5221 | params->fils_erp_next_seq_num)) |
| 5222 | return -1; |
| 5223 | |
| 5224 | if (params->fils_erp_rrk_len) { |
| 5225 | wpa_printf(MSG_DEBUG, " * FILS ERP rRK (len=%lu)", |
| 5226 | (unsigned long) params->fils_erp_rrk_len); |
| 5227 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_RRK, |
| 5228 | params->fils_erp_rrk_len, params->fils_erp_rrk)) |
| 5229 | return -1; |
| 5230 | } |
| 5231 | |
| 5232 | return 0; |
| 5233 | } |
| 5234 | |
| 5235 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5236 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
| 5237 | struct wpa_driver_associate_params *params, |
| 5238 | struct nl_msg *msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5239 | { |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5240 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 5241 | return -1; |
| 5242 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5243 | if (params->bssid) { |
| 5244 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 5245 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5246 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 5247 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5248 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5249 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5250 | if (params->bssid_hint) { |
| 5251 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, |
| 5252 | MAC2STR(params->bssid_hint)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5253 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
| 5254 | params->bssid_hint)) |
| 5255 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5256 | } |
| 5257 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5258 | if (params->freq.freq) { |
| 5259 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5260 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 5261 | params->freq.freq)) |
| 5262 | return -1; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5263 | drv->assoc_freq = params->freq.freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5264 | } else |
| 5265 | drv->assoc_freq = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5266 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5267 | if (params->freq_hint) { |
| 5268 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5269 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
| 5270 | params->freq_hint)) |
| 5271 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5272 | } |
| 5273 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5274 | if (params->bg_scan_period >= 0) { |
| 5275 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 5276 | params->bg_scan_period); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5277 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 5278 | params->bg_scan_period)) |
| 5279 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5280 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5281 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5282 | if (params->ssid) { |
| 5283 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 5284 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5285 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 5286 | params->ssid)) |
| 5287 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5288 | if (params->ssid_len > sizeof(drv->ssid)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5289 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5290 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 5291 | drv->ssid_len = params->ssid_len; |
| 5292 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5293 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5294 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5295 | if (params->wpa_ie && |
| 5296 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) |
| 5297 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5298 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5299 | if (params->wpa_proto) { |
| 5300 | enum nl80211_wpa_versions ver = 0; |
| 5301 | |
| 5302 | if (params->wpa_proto & WPA_PROTO_WPA) |
| 5303 | ver |= NL80211_WPA_VERSION_1; |
| 5304 | if (params->wpa_proto & WPA_PROTO_RSN) |
| 5305 | ver |= NL80211_WPA_VERSION_2; |
| 5306 | |
| 5307 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5308 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 5309 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5310 | } |
| 5311 | |
| 5312 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
| 5313 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
| 5314 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5315 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 5316 | cipher)) |
| 5317 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5318 | } |
| 5319 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 5320 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
| 5321 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { |
| 5322 | /* |
| 5323 | * This is likely to work even though many drivers do not |
| 5324 | * advertise support for operations without GTK. |
| 5325 | */ |
| 5326 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); |
| 5327 | } else if (params->group_suite != WPA_CIPHER_NONE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5328 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
| 5329 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5330 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
| 5331 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5332 | } |
| 5333 | |
| 5334 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 5335 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 5336 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || |
| 5337 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5338 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5339 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
| 5340 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5341 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5342 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5343 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 || |
| 5344 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA256 || |
| 5345 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA384 || |
| 5346 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA256 || |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5347 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA384 || |
| 5348 | params->key_mgmt_suite == WPA_KEY_MGMT_OWE || |
| 5349 | params->key_mgmt_suite == WPA_KEY_MGMT_DPP) { |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5350 | int mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5351 | |
| 5352 | switch (params->key_mgmt_suite) { |
| 5353 | case WPA_KEY_MGMT_CCKM: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5354 | mgmt = RSN_AUTH_KEY_MGMT_CCKM; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5355 | break; |
| 5356 | case WPA_KEY_MGMT_IEEE8021X: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5357 | mgmt = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5358 | break; |
| 5359 | case WPA_KEY_MGMT_FT_IEEE8021X: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5360 | mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5361 | break; |
| 5362 | case WPA_KEY_MGMT_FT_PSK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5363 | mgmt = RSN_AUTH_KEY_MGMT_FT_PSK; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5364 | break; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5365 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5366 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SHA256; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5367 | break; |
| 5368 | case WPA_KEY_MGMT_PSK_SHA256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5369 | mgmt = RSN_AUTH_KEY_MGMT_PSK_SHA256; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5370 | break; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5371 | case WPA_KEY_MGMT_OSEN: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5372 | mgmt = RSN_AUTH_KEY_MGMT_OSEN; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5373 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5374 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5375 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5376 | break; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5377 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5378 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5379 | break; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5380 | case WPA_KEY_MGMT_FILS_SHA256: |
| 5381 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA256; |
| 5382 | break; |
| 5383 | case WPA_KEY_MGMT_FILS_SHA384: |
| 5384 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA384; |
| 5385 | break; |
| 5386 | case WPA_KEY_MGMT_FT_FILS_SHA256: |
| 5387 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256; |
| 5388 | break; |
| 5389 | case WPA_KEY_MGMT_FT_FILS_SHA384: |
| 5390 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384; |
| 5391 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5392 | case WPA_KEY_MGMT_OWE: |
| 5393 | mgmt = RSN_AUTH_KEY_MGMT_OWE; |
| 5394 | break; |
| 5395 | case WPA_KEY_MGMT_DPP: |
| 5396 | mgmt = RSN_AUTH_KEY_MGMT_DPP; |
| 5397 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5398 | case WPA_KEY_MGMT_PSK: |
| 5399 | default: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5400 | mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5401 | break; |
| 5402 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5403 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5404 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
| 5405 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5406 | } |
| 5407 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5408 | /* Add PSK in case of 4-way handshake offload */ |
| 5409 | if (params->psk && |
| 5410 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE)) { |
| 5411 | wpa_hexdump_key(MSG_DEBUG, " * PSK", params->psk, 32); |
| 5412 | if (nla_put(msg, NL80211_ATTR_PMK, 32, params->psk)) |
| 5413 | return -1; |
| 5414 | } |
| 5415 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5416 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 5417 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5418 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 5419 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 5420 | (params->pairwise_suite == WPA_CIPHER_NONE || |
| 5421 | params->pairwise_suite == WPA_CIPHER_WEP104 || |
| 5422 | params->pairwise_suite == WPA_CIPHER_WEP40) && |
| 5423 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 5424 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
| 5425 | return -1; |
| 5426 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5427 | if (params->rrm_used) { |
| 5428 | u32 drv_rrm_flags = drv->capa.rrm_flags; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5429 | if ((!((drv_rrm_flags & |
| 5430 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && |
| 5431 | (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && |
| 5432 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5433 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
| 5434 | return -1; |
| 5435 | } |
| 5436 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5437 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5438 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5439 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5440 | if (params->p2p) |
| 5441 | wpa_printf(MSG_DEBUG, " * P2P group"); |
| 5442 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5443 | if (params->pbss) { |
| 5444 | wpa_printf(MSG_DEBUG, " * PBSS"); |
| 5445 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 5446 | return -1; |
| 5447 | } |
| 5448 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 5449 | drv->connect_reassoc = 0; |
| 5450 | if (params->prev_bssid) { |
| 5451 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, |
| 5452 | MAC2STR(params->prev_bssid)); |
| 5453 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
| 5454 | params->prev_bssid)) |
| 5455 | return -1; |
| 5456 | drv->connect_reassoc = 1; |
| 5457 | } |
| 5458 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5459 | if ((params->auth_alg & WPA_AUTH_ALG_FILS) && |
| 5460 | nl80211_put_fils_connect_params(drv, params, msg) != 0) |
| 5461 | return -1; |
| 5462 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5463 | if ((params->auth_alg & WPA_AUTH_ALG_SAE) && |
| 5464 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) && |
| 5465 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) |
| 5466 | return -1; |
| 5467 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5468 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5469 | } |
| 5470 | |
| 5471 | |
| 5472 | static int wpa_driver_nl80211_try_connect( |
| 5473 | struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5474 | struct wpa_driver_associate_params *params, |
| 5475 | struct nl_handle *nl_connect) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5476 | { |
| 5477 | struct nl_msg *msg; |
| 5478 | enum nl80211_auth_type type; |
| 5479 | int ret; |
| 5480 | int algs; |
| 5481 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5482 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5483 | if (params->req_key_mgmt_offload && params->psk && |
| 5484 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 5485 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
| 5486 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { |
| 5487 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); |
| 5488 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); |
| 5489 | if (ret) |
| 5490 | return ret; |
| 5491 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5492 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5493 | |
| 5494 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
| 5495 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5496 | if (!msg) |
| 5497 | return -1; |
| 5498 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5499 | ret = nl80211_connect_common(drv, params, msg); |
| 5500 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5501 | goto fail; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5502 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5503 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 5504 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 5505 | goto fail; |
| 5506 | |
| 5507 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_OPTIONAL && |
| 5508 | (drv->capa.flags & WPA_DRIVER_FLAGS_MFP_OPTIONAL) && |
| 5509 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_OPTIONAL)) |
| 5510 | goto fail; |
| 5511 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5512 | algs = 0; |
| 5513 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 5514 | algs++; |
| 5515 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 5516 | algs++; |
| 5517 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 5518 | algs++; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5519 | if (params->auth_alg & WPA_AUTH_ALG_FILS) |
| 5520 | algs++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5521 | if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 5522 | algs++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5523 | if (algs > 1) { |
| 5524 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " |
| 5525 | "selection"); |
| 5526 | goto skip_auth_type; |
| 5527 | } |
| 5528 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5529 | type = get_nl_auth_type(params->auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5530 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5531 | if (type == NL80211_AUTHTYPE_MAX || |
| 5532 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5533 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5534 | |
| 5535 | skip_auth_type: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5536 | ret = nl80211_set_conn_keys(params, msg); |
| 5537 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5538 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5539 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5540 | if (nl_connect) |
| 5541 | ret = send_and_recv(drv->global, nl_connect, msg, NULL, NULL); |
| 5542 | else |
| 5543 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5544 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5545 | msg = NULL; |
| 5546 | if (ret) { |
| 5547 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " |
| 5548 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5549 | } else { |
| 5550 | wpa_printf(MSG_DEBUG, |
| 5551 | "nl80211: Connect request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5552 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5553 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5554 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5555 | nlmsg_free(msg); |
| 5556 | return ret; |
| 5557 | |
| 5558 | } |
| 5559 | |
| 5560 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5561 | static int wpa_driver_nl80211_connect( |
| 5562 | struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5563 | struct wpa_driver_associate_params *params, |
| 5564 | struct nl_handle *nl_connect) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5565 | { |
Jithu Jance | a7c60b4 | 2014-12-03 18:54:40 +0530 | [diff] [blame] | 5566 | int ret; |
| 5567 | |
| 5568 | /* Store the connection attempted bssid for future use */ |
| 5569 | if (params->bssid) |
| 5570 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 5571 | else |
| 5572 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
| 5573 | |
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 | if (ret == -EALREADY) { |
| 5576 | /* |
| 5577 | * cfg80211 does not currently accept new connections if |
| 5578 | * we are already connected. As a workaround, force |
| 5579 | * disconnection and try again. |
| 5580 | */ |
| 5581 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " |
| 5582 | "disconnecting before reassociation " |
| 5583 | "attempt"); |
| 5584 | if (wpa_driver_nl80211_disconnect( |
| 5585 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) |
| 5586 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5587 | ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5588 | } |
| 5589 | return ret; |
| 5590 | } |
| 5591 | |
| 5592 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5593 | static int wpa_driver_nl80211_associate( |
| 5594 | void *priv, struct wpa_driver_associate_params *params) |
| 5595 | { |
| 5596 | struct i802_bss *bss = priv; |
| 5597 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5598 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5599 | struct nl_msg *msg; |
| 5600 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5601 | nl80211_unmask_11b_rates(bss); |
| 5602 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5603 | if (params->mode == IEEE80211_MODE_AP) |
| 5604 | return wpa_driver_nl80211_ap(drv, params); |
| 5605 | |
| 5606 | if (params->mode == IEEE80211_MODE_IBSS) |
| 5607 | return wpa_driver_nl80211_ibss(drv, params); |
| 5608 | |
| 5609 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5610 | enum nl80211_iftype nlmode = params->p2p ? |
| 5611 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5612 | struct nl_handle *nl_connect = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5613 | |
| 5614 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5615 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5616 | if (params->auth_alg & WPA_AUTH_ALG_SAE) |
| 5617 | nl_connect = bss->nl_connect; |
| 5618 | return wpa_driver_nl80211_connect(drv, params, nl_connect); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5619 | } |
| 5620 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5621 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5622 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5623 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
| 5624 | drv->ifindex); |
| 5625 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5626 | if (!msg) |
| 5627 | return -1; |
| 5628 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5629 | ret = nl80211_connect_common(drv, params, msg); |
| 5630 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5631 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5632 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5633 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 5634 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 5635 | goto fail; |
| 5636 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5637 | if (params->fils_kek) { |
| 5638 | wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)", |
| 5639 | (unsigned int) params->fils_kek_len); |
| 5640 | if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len, |
| 5641 | params->fils_kek)) |
| 5642 | goto fail; |
| 5643 | } |
| 5644 | if (params->fils_nonces) { |
| 5645 | wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)", |
| 5646 | params->fils_nonces, |
| 5647 | params->fils_nonces_len); |
| 5648 | if (nla_put(msg, NL80211_ATTR_FILS_NONCES, |
| 5649 | params->fils_nonces_len, params->fils_nonces)) |
| 5650 | goto fail; |
| 5651 | } |
| 5652 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5653 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5654 | msg = NULL; |
| 5655 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5656 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 5657 | "nl80211: MLME command failed (assoc): ret=%d (%s)", |
| 5658 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5659 | nl80211_dump_scan(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5660 | } else { |
| 5661 | wpa_printf(MSG_DEBUG, |
| 5662 | "nl80211: Association request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5663 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5664 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5665 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5666 | nlmsg_free(msg); |
| 5667 | return ret; |
| 5668 | } |
| 5669 | |
| 5670 | |
| 5671 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5672 | int ifindex, enum nl80211_iftype mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5673 | { |
| 5674 | struct nl_msg *msg; |
| 5675 | int ret = -ENOBUFS; |
| 5676 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5677 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
| 5678 | ifindex, mode, nl80211_iftype_str(mode)); |
| 5679 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5680 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 5681 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) |
| 5682 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5683 | |
| 5684 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5685 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5686 | if (!ret) |
| 5687 | return 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5688 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5689 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5690 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
| 5691 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); |
| 5692 | return ret; |
| 5693 | } |
| 5694 | |
| 5695 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5696 | static int wpa_driver_nl80211_set_mode_impl( |
| 5697 | struct i802_bss *bss, |
| 5698 | enum nl80211_iftype nlmode, |
| 5699 | struct hostapd_freq_params *desired_freq_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5700 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5701 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5702 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5703 | int i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5704 | int was_ap = is_ap_interface(drv->nlmode); |
| 5705 | int res; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5706 | int mode_switch_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5707 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5708 | if (TEST_FAIL()) |
| 5709 | return -1; |
| 5710 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5711 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 5712 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) |
| 5713 | mode_switch_res = 0; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5714 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5715 | if (mode_switch_res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5716 | drv->nlmode = nlmode; |
| 5717 | ret = 0; |
| 5718 | goto done; |
| 5719 | } |
| 5720 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5721 | if (mode_switch_res == -ENODEV) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5722 | return -1; |
| 5723 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5724 | if (nlmode == drv->nlmode) { |
| 5725 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
| 5726 | "requested mode - ignore error"); |
| 5727 | ret = 0; |
| 5728 | goto done; /* Already in the requested mode */ |
| 5729 | } |
| 5730 | |
| 5731 | /* mac80211 doesn't allow mode changes while the device is up, so |
| 5732 | * take the device down, try to set the mode again, and bring the |
| 5733 | * device back up. |
| 5734 | */ |
| 5735 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
| 5736 | "interface down"); |
| 5737 | for (i = 0; i < 10; i++) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5738 | res = i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5739 | if (res == -EACCES || res == -ENODEV) |
| 5740 | break; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5741 | if (res != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5742 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
| 5743 | "interface down"); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5744 | os_sleep(0, 100000); |
| 5745 | continue; |
| 5746 | } |
| 5747 | |
| 5748 | /* |
| 5749 | * Setting the mode will fail for some drivers if the phy is |
| 5750 | * on a frequency that the mode is disallowed in. |
| 5751 | */ |
| 5752 | if (desired_freq_params) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5753 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5754 | if (res) { |
| 5755 | wpa_printf(MSG_DEBUG, |
| 5756 | "nl80211: Failed to set frequency on interface"); |
| 5757 | } |
| 5758 | } |
| 5759 | |
| 5760 | /* Try to set the mode again while the interface is down */ |
| 5761 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 5762 | if (mode_switch_res == -EBUSY) { |
| 5763 | wpa_printf(MSG_DEBUG, |
| 5764 | "nl80211: Delaying mode set while interface going down"); |
| 5765 | os_sleep(0, 100000); |
| 5766 | continue; |
| 5767 | } |
| 5768 | ret = mode_switch_res; |
| 5769 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5770 | } |
| 5771 | |
| 5772 | if (!ret) { |
| 5773 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " |
| 5774 | "interface is down"); |
| 5775 | drv->nlmode = nlmode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5776 | drv->ignore_if_down_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5777 | } |
| 5778 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5779 | /* Bring the interface back up */ |
| 5780 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); |
| 5781 | if (res != 0) { |
| 5782 | wpa_printf(MSG_DEBUG, |
| 5783 | "nl80211: Failed to set interface up after switching mode"); |
| 5784 | ret = -1; |
| 5785 | } |
| 5786 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5787 | done: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5788 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5789 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " |
| 5790 | "from %d failed", nlmode, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5791 | return ret; |
| 5792 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5793 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5794 | if (is_p2p_net_interface(nlmode)) { |
| 5795 | wpa_printf(MSG_DEBUG, |
| 5796 | "nl80211: Interface %s mode change to P2P - disable 11b rates", |
| 5797 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5798 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5799 | } else if (drv->disabled_11b_rates) { |
| 5800 | wpa_printf(MSG_DEBUG, |
| 5801 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", |
| 5802 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5803 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5804 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5805 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5806 | if (is_ap_interface(nlmode)) { |
| 5807 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
| 5808 | /* Setup additional AP mode functionality if needed */ |
| 5809 | if (nl80211_setup_ap(bss)) |
| 5810 | return -1; |
| 5811 | } else if (was_ap) { |
| 5812 | /* Remove additional AP mode functionality */ |
| 5813 | nl80211_teardown_ap(bss); |
| 5814 | } else { |
| 5815 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
| 5816 | } |
| 5817 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5818 | if (is_mesh_interface(nlmode) && |
| 5819 | nl80211_mgmt_subscribe_mesh(bss)) |
| 5820 | return -1; |
| 5821 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5822 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5823 | !is_mesh_interface(nlmode) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5824 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 5825 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " |
| 5826 | "frame processing - ignore for now"); |
| 5827 | |
| 5828 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5829 | } |
| 5830 | |
| 5831 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5832 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 5833 | enum nl80211_iftype nlmode) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5834 | { |
| 5835 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); |
| 5836 | } |
| 5837 | |
| 5838 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5839 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 5840 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5841 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5842 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5843 | freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5844 | } |
| 5845 | |
| 5846 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5847 | static int wpa_driver_nl80211_get_capa(void *priv, |
| 5848 | struct wpa_driver_capa *capa) |
| 5849 | { |
| 5850 | struct i802_bss *bss = priv; |
| 5851 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 5852 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5853 | if (!drv->has_capability) |
| 5854 | return -1; |
| 5855 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5856 | if (drv->extended_capa && drv->extended_capa_mask) { |
| 5857 | capa->extended_capa = drv->extended_capa; |
| 5858 | capa->extended_capa_mask = drv->extended_capa_mask; |
| 5859 | capa->extended_capa_len = drv->extended_capa_len; |
| 5860 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5861 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5862 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5863 | } |
| 5864 | |
| 5865 | |
| 5866 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) |
| 5867 | { |
| 5868 | struct i802_bss *bss = priv; |
| 5869 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5870 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5871 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
| 5872 | bss->ifname, drv->operstate, state, |
| 5873 | state ? "UP" : "DORMANT"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5874 | drv->operstate = state; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5875 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5876 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
| 5877 | } |
| 5878 | |
| 5879 | |
| 5880 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) |
| 5881 | { |
| 5882 | struct i802_bss *bss = priv; |
| 5883 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5884 | struct nl_msg *msg; |
| 5885 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5886 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5887 | |
| 5888 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { |
| 5889 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); |
| 5890 | return 0; |
| 5891 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5892 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5893 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
| 5894 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); |
| 5895 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5896 | os_memset(&upd, 0, sizeof(upd)); |
| 5897 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 5898 | if (authorized) |
| 5899 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5900 | |
| 5901 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5902 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
| 5903 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { |
| 5904 | nlmsg_free(msg); |
| 5905 | return -ENOBUFS; |
| 5906 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5907 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5908 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5909 | if (!ret) |
| 5910 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5911 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
| 5912 | ret, strerror(-ret)); |
| 5913 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5914 | } |
| 5915 | |
| 5916 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5917 | /* Set kernel driver on given frequency (MHz) */ |
| 5918 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5919 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5920 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5921 | return nl80211_set_channel(bss, freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5922 | } |
| 5923 | |
| 5924 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5925 | static inline int min_int(int a, int b) |
| 5926 | { |
| 5927 | if (a < b) |
| 5928 | return a; |
| 5929 | return b; |
| 5930 | } |
| 5931 | |
| 5932 | |
| 5933 | static int get_key_handler(struct nl_msg *msg, void *arg) |
| 5934 | { |
| 5935 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5936 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5937 | |
| 5938 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5939 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5940 | |
| 5941 | /* |
| 5942 | * TODO: validate the key index and mac address! |
| 5943 | * Otherwise, there's a race condition as soon as |
| 5944 | * the kernel starts sending key notifications. |
| 5945 | */ |
| 5946 | |
| 5947 | if (tb[NL80211_ATTR_KEY_SEQ]) |
| 5948 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 5949 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); |
| 5950 | return NL_SKIP; |
| 5951 | } |
| 5952 | |
| 5953 | |
| 5954 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, |
| 5955 | int idx, u8 *seq) |
| 5956 | { |
| 5957 | struct i802_bss *bss = priv; |
| 5958 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5959 | struct nl_msg *msg; |
| 5960 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5961 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
| 5962 | NL80211_CMD_GET_KEY); |
| 5963 | if (!msg || |
| 5964 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 5965 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
| 5966 | nlmsg_free(msg); |
| 5967 | return -ENOBUFS; |
| 5968 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5969 | |
| 5970 | memset(seq, 0, 6); |
| 5971 | |
| 5972 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5973 | } |
| 5974 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5975 | |
| 5976 | static int i802_set_rts(void *priv, int rts) |
| 5977 | { |
| 5978 | struct i802_bss *bss = priv; |
| 5979 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5980 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5981 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5982 | u32 val; |
| 5983 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5984 | if (rts >= 2347) |
| 5985 | val = (u32) -1; |
| 5986 | else |
| 5987 | val = rts; |
| 5988 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5989 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 5990 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
| 5991 | nlmsg_free(msg); |
| 5992 | return -ENOBUFS; |
| 5993 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5994 | |
| 5995 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5996 | if (!ret) |
| 5997 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5998 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
| 5999 | "%d (%s)", rts, ret, strerror(-ret)); |
| 6000 | return ret; |
| 6001 | } |
| 6002 | |
| 6003 | |
| 6004 | static int i802_set_frag(void *priv, int frag) |
| 6005 | { |
| 6006 | struct i802_bss *bss = priv; |
| 6007 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6008 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6009 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6010 | u32 val; |
| 6011 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6012 | if (frag >= 2346) |
| 6013 | val = (u32) -1; |
| 6014 | else |
| 6015 | val = frag; |
| 6016 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6017 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 6018 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
| 6019 | nlmsg_free(msg); |
| 6020 | return -ENOBUFS; |
| 6021 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6022 | |
| 6023 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6024 | if (!ret) |
| 6025 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6026 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
| 6027 | "%d: %d (%s)", frag, ret, strerror(-ret)); |
| 6028 | return ret; |
| 6029 | } |
| 6030 | |
| 6031 | |
| 6032 | static int i802_flush(void *priv) |
| 6033 | { |
| 6034 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6035 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6036 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6037 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6038 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
| 6039 | bss->ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6040 | |
| 6041 | /* |
| 6042 | * XXX: FIX! this needs to flush all VLANs too |
| 6043 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6044 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
| 6045 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6046 | if (res) { |
| 6047 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " |
| 6048 | "(%s)", res, strerror(-res)); |
| 6049 | } |
| 6050 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6051 | } |
| 6052 | |
| 6053 | |
| 6054 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
| 6055 | { |
| 6056 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6057 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6058 | struct hostap_sta_driver_data *data = arg; |
| 6059 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; |
| 6060 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
| 6061 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, |
| 6062 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, |
| 6063 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, |
| 6064 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
| 6065 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 6066 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6067 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
| 6068 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6069 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6070 | [NL80211_STA_INFO_ACK_SIGNAL] = { .type = NLA_U8 }, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6071 | }; |
| 6072 | struct nlattr *rate[NL80211_RATE_INFO_MAX + 1]; |
| 6073 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 6074 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 6075 | [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 }, |
| 6076 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 6077 | [NL80211_RATE_INFO_VHT_MCS] = { .type = NLA_U8 }, |
| 6078 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 6079 | [NL80211_RATE_INFO_VHT_NSS] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6080 | }; |
| 6081 | |
| 6082 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6083 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6084 | |
| 6085 | /* |
| 6086 | * TODO: validate the interface and mac address! |
| 6087 | * Otherwise, there's a race condition as soon as |
| 6088 | * the kernel starts sending station notifications. |
| 6089 | */ |
| 6090 | |
| 6091 | if (!tb[NL80211_ATTR_STA_INFO]) { |
| 6092 | wpa_printf(MSG_DEBUG, "sta stats missing!"); |
| 6093 | return NL_SKIP; |
| 6094 | } |
| 6095 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, |
| 6096 | tb[NL80211_ATTR_STA_INFO], |
| 6097 | stats_policy)) { |
| 6098 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); |
| 6099 | return NL_SKIP; |
| 6100 | } |
| 6101 | |
| 6102 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) |
| 6103 | data->inactive_msec = |
| 6104 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6105 | /* For backwards compatibility, fetch the 32-bit counters first. */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6106 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
| 6107 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); |
| 6108 | if (stats[NL80211_STA_INFO_TX_BYTES]) |
| 6109 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6110 | if (stats[NL80211_STA_INFO_RX_BYTES64] && |
| 6111 | stats[NL80211_STA_INFO_TX_BYTES64]) { |
| 6112 | /* |
| 6113 | * The driver supports 64-bit counters, so use them to override |
| 6114 | * the 32-bit values. |
| 6115 | */ |
| 6116 | data->rx_bytes = |
| 6117 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); |
| 6118 | data->tx_bytes = |
| 6119 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); |
| 6120 | data->bytes_64bit = 1; |
| 6121 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6122 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
| 6123 | data->rx_packets = |
| 6124 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); |
| 6125 | if (stats[NL80211_STA_INFO_TX_PACKETS]) |
| 6126 | data->tx_packets = |
| 6127 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 6128 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
| 6129 | data->tx_retry_failed = |
| 6130 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6131 | if (stats[NL80211_STA_INFO_SIGNAL]) |
| 6132 | data->signal = nla_get_u8(stats[NL80211_STA_INFO_SIGNAL]); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6133 | if (stats[NL80211_STA_INFO_ACK_SIGNAL]) { |
| 6134 | data->last_ack_rssi = |
| 6135 | nla_get_u8(stats[NL80211_STA_INFO_ACK_SIGNAL]); |
| 6136 | data->flags |= STA_DRV_DATA_LAST_ACK_RSSI; |
| 6137 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6138 | |
| 6139 | if (stats[NL80211_STA_INFO_TX_BITRATE] && |
| 6140 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, |
| 6141 | stats[NL80211_STA_INFO_TX_BITRATE], |
| 6142 | rate_policy) == 0) { |
| 6143 | if (rate[NL80211_RATE_INFO_BITRATE32]) |
| 6144 | data->current_tx_rate = |
| 6145 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); |
| 6146 | else if (rate[NL80211_RATE_INFO_BITRATE]) |
| 6147 | data->current_tx_rate = |
| 6148 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); |
| 6149 | |
| 6150 | if (rate[NL80211_RATE_INFO_MCS]) { |
| 6151 | data->tx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]); |
| 6152 | data->flags |= STA_DRV_DATA_TX_MCS; |
| 6153 | } |
| 6154 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { |
| 6155 | data->tx_vhtmcs = |
| 6156 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); |
| 6157 | data->flags |= STA_DRV_DATA_TX_VHT_MCS; |
| 6158 | } |
| 6159 | if (rate[NL80211_RATE_INFO_SHORT_GI]) |
| 6160 | data->flags |= STA_DRV_DATA_TX_SHORT_GI; |
| 6161 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { |
| 6162 | data->tx_vht_nss = |
| 6163 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); |
| 6164 | data->flags |= STA_DRV_DATA_TX_VHT_NSS; |
| 6165 | } |
| 6166 | } |
| 6167 | |
| 6168 | if (stats[NL80211_STA_INFO_RX_BITRATE] && |
| 6169 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, |
| 6170 | stats[NL80211_STA_INFO_RX_BITRATE], |
| 6171 | rate_policy) == 0) { |
| 6172 | if (rate[NL80211_RATE_INFO_BITRATE32]) |
| 6173 | data->current_rx_rate = |
| 6174 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); |
| 6175 | else if (rate[NL80211_RATE_INFO_BITRATE]) |
| 6176 | data->current_rx_rate = |
| 6177 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); |
| 6178 | |
| 6179 | if (rate[NL80211_RATE_INFO_MCS]) { |
| 6180 | data->rx_mcs = |
| 6181 | nla_get_u8(rate[NL80211_RATE_INFO_MCS]); |
| 6182 | data->flags |= STA_DRV_DATA_RX_MCS; |
| 6183 | } |
| 6184 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { |
| 6185 | data->rx_vhtmcs = |
| 6186 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); |
| 6187 | data->flags |= STA_DRV_DATA_RX_VHT_MCS; |
| 6188 | } |
| 6189 | if (rate[NL80211_RATE_INFO_SHORT_GI]) |
| 6190 | data->flags |= STA_DRV_DATA_RX_SHORT_GI; |
| 6191 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { |
| 6192 | data->rx_vht_nss = |
| 6193 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); |
| 6194 | data->flags |= STA_DRV_DATA_RX_VHT_NSS; |
| 6195 | } |
| 6196 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6197 | |
| 6198 | return NL_SKIP; |
| 6199 | } |
| 6200 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6201 | static int i802_read_sta_data(struct i802_bss *bss, |
| 6202 | struct hostap_sta_driver_data *data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6203 | const u8 *addr) |
| 6204 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6205 | struct nl_msg *msg; |
| 6206 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6207 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
| 6208 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 6209 | nlmsg_free(msg); |
| 6210 | return -ENOBUFS; |
| 6211 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6212 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6213 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6214 | } |
| 6215 | |
| 6216 | |
| 6217 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
| 6218 | int cw_min, int cw_max, int burst_time) |
| 6219 | { |
| 6220 | struct i802_bss *bss = priv; |
| 6221 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6222 | struct nl_msg *msg; |
| 6223 | struct nlattr *txq, *params; |
| 6224 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6225 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6226 | if (!msg) |
| 6227 | return -1; |
| 6228 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6229 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
| 6230 | if (!txq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6231 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6232 | |
| 6233 | /* We are only sending parameters for a single TXQ at a time */ |
| 6234 | params = nla_nest_start(msg, 1); |
| 6235 | if (!params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6236 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6237 | |
| 6238 | switch (queue) { |
| 6239 | case 0: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6240 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
| 6241 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6242 | break; |
| 6243 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6244 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
| 6245 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6246 | break; |
| 6247 | case 2: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6248 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
| 6249 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6250 | break; |
| 6251 | case 3: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6252 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
| 6253 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6254 | break; |
| 6255 | } |
| 6256 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
| 6257 | * 32 usec, so need to convert the value here. */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6258 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
| 6259 | (burst_time * 100 + 16) / 32) || |
| 6260 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || |
| 6261 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || |
| 6262 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) |
| 6263 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6264 | |
| 6265 | nla_nest_end(msg, params); |
| 6266 | |
| 6267 | nla_nest_end(msg, txq); |
| 6268 | |
| 6269 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 6270 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6271 | msg = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6272 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6273 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6274 | return -1; |
| 6275 | } |
| 6276 | |
| 6277 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6278 | 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] | 6279 | const char *ifname, int vlan_id) |
| 6280 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6281 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6282 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6283 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6284 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6285 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
| 6286 | ", ifname=%s[%d], vlan_id=%d)", |
| 6287 | bss->ifname, if_nametoindex(bss->ifname), |
| 6288 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6289 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 6290 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 6291 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { |
| 6292 | nlmsg_free(msg); |
| 6293 | return -ENOBUFS; |
| 6294 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6295 | |
| 6296 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6297 | if (ret < 0) { |
| 6298 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" |
| 6299 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", |
| 6300 | MAC2STR(addr), ifname, vlan_id, ret, |
| 6301 | strerror(-ret)); |
| 6302 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6303 | return ret; |
| 6304 | } |
| 6305 | |
| 6306 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6307 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
| 6308 | { |
| 6309 | struct hostap_sta_driver_data data; |
| 6310 | int ret; |
| 6311 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 6312 | os_memset(&data, 0, sizeof(data)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6313 | data.inactive_msec = (unsigned long) -1; |
| 6314 | ret = i802_read_sta_data(priv, &data, addr); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6315 | if (ret == -ENOENT) |
| 6316 | return -ENOENT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6317 | if (ret || data.inactive_msec == (unsigned long) -1) |
| 6318 | return -1; |
| 6319 | return data.inactive_msec / 1000; |
| 6320 | } |
| 6321 | |
| 6322 | |
| 6323 | static int i802_sta_clear_stats(void *priv, const u8 *addr) |
| 6324 | { |
| 6325 | #if 0 |
| 6326 | /* TODO */ |
| 6327 | #endif |
| 6328 | return 0; |
| 6329 | } |
| 6330 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6331 | |
| 6332 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
| 6333 | int reason) |
| 6334 | { |
| 6335 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6336 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6337 | struct ieee80211_mgmt mgmt; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 6338 | u8 channel; |
| 6339 | |
| 6340 | if (ieee80211_freq_to_chan(bss->freq, &channel) == |
| 6341 | HOSTAPD_MODE_IEEE80211AD) { |
| 6342 | /* Deauthentication is not used in DMG/IEEE 802.11ad; |
| 6343 | * disassociate the STA instead. */ |
| 6344 | return i802_sta_disassoc(priv, own_addr, addr, reason); |
| 6345 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6346 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6347 | if (is_mesh_interface(drv->nlmode)) |
| 6348 | return -1; |
| 6349 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6350 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6351 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6352 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6353 | memset(&mgmt, 0, sizeof(mgmt)); |
| 6354 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 6355 | WLAN_FC_STYPE_DEAUTH); |
| 6356 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 6357 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 6358 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 6359 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
| 6360 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 6361 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6362 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6363 | 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6364 | } |
| 6365 | |
| 6366 | |
| 6367 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
| 6368 | int reason) |
| 6369 | { |
| 6370 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6371 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6372 | struct ieee80211_mgmt mgmt; |
| 6373 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6374 | if (is_mesh_interface(drv->nlmode)) |
| 6375 | return -1; |
| 6376 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6377 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6378 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6379 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6380 | memset(&mgmt, 0, sizeof(mgmt)); |
| 6381 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 6382 | WLAN_FC_STYPE_DISASSOC); |
| 6383 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 6384 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 6385 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 6386 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
| 6387 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 6388 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6389 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6390 | 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6391 | } |
| 6392 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6393 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6394 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
| 6395 | { |
| 6396 | char buf[200], *pos, *end; |
| 6397 | int i, res; |
| 6398 | |
| 6399 | pos = buf; |
| 6400 | end = pos + sizeof(buf); |
| 6401 | |
| 6402 | for (i = 0; i < drv->num_if_indices; i++) { |
| 6403 | if (!drv->if_indices[i]) |
| 6404 | continue; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6405 | res = os_snprintf(pos, end - pos, " %d(%d)", |
| 6406 | drv->if_indices[i], |
| 6407 | drv->if_indices_reason[i]); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6408 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6409 | break; |
| 6410 | pos += res; |
| 6411 | } |
| 6412 | *pos = '\0'; |
| 6413 | |
| 6414 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", |
| 6415 | drv->num_if_indices, buf); |
| 6416 | } |
| 6417 | |
| 6418 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6419 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 6420 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6421 | { |
| 6422 | int i; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6423 | int *old, *old_reason; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6424 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6425 | wpa_printf(MSG_DEBUG, |
| 6426 | "nl80211: Add own interface ifindex %d (ifidx_reason %d)", |
| 6427 | ifidx, ifidx_reason); |
| 6428 | if (have_ifidx(drv, ifidx, ifidx_reason)) { |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6429 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
| 6430 | ifidx); |
| 6431 | return; |
| 6432 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6433 | for (i = 0; i < drv->num_if_indices; i++) { |
| 6434 | if (drv->if_indices[i] == 0) { |
| 6435 | drv->if_indices[i] = ifidx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6436 | drv->if_indices_reason[i] = ifidx_reason; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6437 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6438 | return; |
| 6439 | } |
| 6440 | } |
| 6441 | |
| 6442 | if (drv->if_indices != drv->default_if_indices) |
| 6443 | old = drv->if_indices; |
| 6444 | else |
| 6445 | old = NULL; |
| 6446 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6447 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
| 6448 | old_reason = drv->if_indices_reason; |
| 6449 | else |
| 6450 | old_reason = NULL; |
| 6451 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6452 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
| 6453 | sizeof(int)); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6454 | drv->if_indices_reason = os_realloc_array(old_reason, |
| 6455 | drv->num_if_indices + 1, |
| 6456 | sizeof(int)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6457 | if (!drv->if_indices) { |
| 6458 | if (!old) |
| 6459 | drv->if_indices = drv->default_if_indices; |
| 6460 | else |
| 6461 | drv->if_indices = old; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6462 | } |
| 6463 | if (!drv->if_indices_reason) { |
| 6464 | if (!old_reason) |
| 6465 | drv->if_indices_reason = drv->default_if_indices_reason; |
| 6466 | else |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 6467 | drv->if_indices_reason = old_reason; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6468 | } |
| 6469 | if (!drv->if_indices || !drv->if_indices_reason) { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6470 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
| 6471 | "interfaces"); |
| 6472 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); |
| 6473 | return; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6474 | } |
| 6475 | if (!old) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6476 | os_memcpy(drv->if_indices, drv->default_if_indices, |
| 6477 | sizeof(drv->default_if_indices)); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6478 | if (!old_reason) |
| 6479 | os_memcpy(drv->if_indices_reason, |
| 6480 | drv->default_if_indices_reason, |
| 6481 | sizeof(drv->default_if_indices_reason)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6482 | drv->if_indices[drv->num_if_indices] = ifidx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6483 | drv->if_indices_reason[drv->num_if_indices] = ifidx_reason; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6484 | drv->num_if_indices++; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6485 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6486 | } |
| 6487 | |
| 6488 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6489 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 6490 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6491 | { |
| 6492 | int i; |
| 6493 | |
| 6494 | for (i = 0; i < drv->num_if_indices; i++) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6495 | if ((drv->if_indices[i] == ifidx || ifidx == IFIDX_ANY) && |
| 6496 | (drv->if_indices_reason[i] == ifidx_reason || |
| 6497 | ifidx_reason == IFIDX_ANY)) { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6498 | drv->if_indices[i] = 0; |
| 6499 | break; |
| 6500 | } |
| 6501 | } |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6502 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6503 | } |
| 6504 | |
| 6505 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6506 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 6507 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6508 | { |
| 6509 | int i; |
| 6510 | |
| 6511 | for (i = 0; i < drv->num_if_indices; i++) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6512 | if (drv->if_indices[i] == ifidx && |
| 6513 | (drv->if_indices_reason[i] == ifidx_reason || |
| 6514 | ifidx_reason == IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6515 | return 1; |
| 6516 | |
| 6517 | return 0; |
| 6518 | } |
| 6519 | |
| 6520 | |
| 6521 | 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] | 6522 | const char *bridge_ifname, char *ifname_wds) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6523 | { |
| 6524 | struct i802_bss *bss = priv; |
| 6525 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6526 | char name[IFNAMSIZ + 1]; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6527 | union wpa_event_data event; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6528 | |
| 6529 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6530 | if (ifname_wds) |
| 6531 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); |
| 6532 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6533 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
| 6534 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); |
| 6535 | if (val) { |
| 6536 | if (!if_nametoindex(name)) { |
| 6537 | if (nl80211_create_iface(drv, name, |
| 6538 | NL80211_IFTYPE_AP_VLAN, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6539 | bss->addr, 1, NULL, NULL, 0) < |
| 6540 | 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6541 | return -1; |
| 6542 | if (bridge_ifname && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6543 | linux_br_add_if(drv->global->ioctl_sock, |
| 6544 | bridge_ifname, name) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6545 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6546 | |
| 6547 | os_memset(&event, 0, sizeof(event)); |
| 6548 | event.wds_sta_interface.sta_addr = addr; |
| 6549 | event.wds_sta_interface.ifname = name; |
| 6550 | event.wds_sta_interface.istatus = INTERFACE_ADDED; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 6551 | wpa_supplicant_event(bss->ctx, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6552 | EVENT_WDS_STA_INTERFACE_STATUS, |
| 6553 | &event); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6554 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6555 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
| 6556 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " |
| 6557 | "interface %s up", name); |
| 6558 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6559 | return i802_set_sta_vlan(priv, addr, name, 0); |
| 6560 | } else { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6561 | if (bridge_ifname) |
| 6562 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, |
| 6563 | name); |
| 6564 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6565 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 6566 | nl80211_remove_iface(drv, if_nametoindex(name)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6567 | os_memset(&event, 0, sizeof(event)); |
| 6568 | event.wds_sta_interface.sta_addr = addr; |
| 6569 | event.wds_sta_interface.ifname = name; |
| 6570 | event.wds_sta_interface.istatus = INTERFACE_REMOVED; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 6571 | wpa_supplicant_event(bss->ctx, EVENT_WDS_STA_INTERFACE_STATUS, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6572 | &event); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 6573 | return 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6574 | } |
| 6575 | } |
| 6576 | |
| 6577 | |
| 6578 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
| 6579 | { |
| 6580 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 6581 | struct sockaddr_ll lladdr; |
| 6582 | unsigned char buf[3000]; |
| 6583 | int len; |
| 6584 | socklen_t fromlen = sizeof(lladdr); |
| 6585 | |
| 6586 | len = recvfrom(sock, buf, sizeof(buf), 0, |
| 6587 | (struct sockaddr *)&lladdr, &fromlen); |
| 6588 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6589 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
| 6590 | strerror(errno)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6591 | return; |
| 6592 | } |
| 6593 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6594 | if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6595 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
| 6596 | } |
| 6597 | |
| 6598 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6599 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
| 6600 | struct i802_bss *bss, |
| 6601 | const char *brname, const char *ifname) |
| 6602 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6603 | int br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6604 | char in_br[IFNAMSIZ]; |
| 6605 | |
| 6606 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6607 | br_ifindex = if_nametoindex(brname); |
| 6608 | if (br_ifindex == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6609 | /* |
| 6610 | * Bridge was configured, but the bridge device does |
| 6611 | * not exist. Try to add it now. |
| 6612 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6613 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6614 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
| 6615 | "bridge interface %s: %s", |
| 6616 | brname, strerror(errno)); |
| 6617 | return -1; |
| 6618 | } |
| 6619 | bss->added_bridge = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6620 | br_ifindex = if_nametoindex(brname); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6621 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6622 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6623 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6624 | |
| 6625 | if (linux_br_get(in_br, ifname) == 0) { |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 6626 | if (os_strcmp(in_br, brname) == 0) { |
| 6627 | bss->already_in_bridge = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6628 | return 0; /* already in the bridge */ |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 6629 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6630 | |
| 6631 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " |
| 6632 | "bridge %s", ifname, in_br); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6633 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
| 6634 | 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6635 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
| 6636 | "remove interface %s from bridge " |
| 6637 | "%s: %s", |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6638 | ifname, in_br, strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6639 | return -1; |
| 6640 | } |
| 6641 | } |
| 6642 | |
| 6643 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", |
| 6644 | ifname, brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6645 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6646 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
| 6647 | "into bridge %s: %s", |
| 6648 | ifname, brname, strerror(errno)); |
| 6649 | return -1; |
| 6650 | } |
| 6651 | bss->added_if_into_bridge = 1; |
| 6652 | |
| 6653 | return 0; |
| 6654 | } |
| 6655 | |
| 6656 | |
| 6657 | static void *i802_init(struct hostapd_data *hapd, |
| 6658 | struct wpa_init_params *params) |
| 6659 | { |
| 6660 | struct wpa_driver_nl80211_data *drv; |
| 6661 | struct i802_bss *bss; |
| 6662 | size_t i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6663 | char master_ifname[IFNAMSIZ]; |
| 6664 | int ifindex, br_ifindex = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6665 | int br_added = 0; |
| 6666 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 6667 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
| 6668 | params->global_priv, 1, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6669 | params->bssid, params->driver_params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6670 | if (bss == NULL) |
| 6671 | return NULL; |
| 6672 | |
| 6673 | drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6674 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6675 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6676 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6677 | params->ifname, master_ifname); |
| 6678 | br_ifindex = if_nametoindex(master_ifname); |
| 6679 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 6680 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && |
| 6681 | linux_master_get(master_ifname, params->ifname) == 0) { |
| 6682 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", |
| 6683 | params->ifname, master_ifname); |
| 6684 | /* start listening for EAPOL on the master interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6685 | add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6686 | |
| 6687 | /* check if master itself is under bridge */ |
| 6688 | if (linux_br_get(master_ifname, master_ifname) == 0) { |
| 6689 | wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s", |
| 6690 | master_ifname); |
| 6691 | br_ifindex = if_nametoindex(master_ifname); |
| 6692 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 6693 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6694 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6695 | master_ifname[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6696 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6697 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6698 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6699 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6700 | for (i = 0; i < params->num_bridge; i++) { |
| 6701 | if (params->bridge[i]) { |
| 6702 | ifindex = if_nametoindex(params->bridge[i]); |
| 6703 | if (ifindex) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6704 | add_ifidx(drv, ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6705 | if (ifindex == br_ifindex) |
| 6706 | br_added = 1; |
| 6707 | } |
| 6708 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6709 | |
| 6710 | /* start listening for EAPOL on the default AP interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6711 | add_ifidx(drv, drv->ifindex, IFIDX_ANY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6712 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6713 | if (params->num_bridge && params->bridge[0]) { |
| 6714 | if (i802_check_bridge(drv, bss, params->bridge[0], |
| 6715 | params->ifname) < 0) |
| 6716 | goto failed; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6717 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6718 | br_added = 1; |
| 6719 | } |
| 6720 | |
| 6721 | if (!br_added && br_ifindex && |
| 6722 | (params->num_bridge == 0 || !params->bridge[0])) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6723 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6724 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6725 | #ifdef CONFIG_LIBNL3_ROUTE |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 6726 | if (bss->added_if_into_bridge || bss->already_in_bridge) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6727 | drv->rtnl_sk = nl_socket_alloc(); |
| 6728 | if (drv->rtnl_sk == NULL) { |
| 6729 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); |
| 6730 | goto failed; |
| 6731 | } |
| 6732 | |
| 6733 | if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) { |
| 6734 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", |
| 6735 | strerror(errno)); |
| 6736 | goto failed; |
| 6737 | } |
| 6738 | } |
| 6739 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 6740 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6741 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
| 6742 | if (drv->eapol_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6743 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
| 6744 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6745 | goto failed; |
| 6746 | } |
| 6747 | |
| 6748 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) |
| 6749 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6750 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6751 | goto failed; |
| 6752 | } |
| 6753 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6754 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 6755 | params->own_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6756 | goto failed; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6757 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6758 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6759 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
| 6760 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6761 | return bss; |
| 6762 | |
| 6763 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6764 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6765 | return NULL; |
| 6766 | } |
| 6767 | |
| 6768 | |
| 6769 | static void i802_deinit(void *priv) |
| 6770 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6771 | struct i802_bss *bss = priv; |
| 6772 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6773 | } |
| 6774 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6775 | |
| 6776 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
| 6777 | enum wpa_driver_if_type type) |
| 6778 | { |
| 6779 | switch (type) { |
| 6780 | case WPA_IF_STATION: |
| 6781 | return NL80211_IFTYPE_STATION; |
| 6782 | case WPA_IF_P2P_CLIENT: |
| 6783 | case WPA_IF_P2P_GROUP: |
| 6784 | return NL80211_IFTYPE_P2P_CLIENT; |
| 6785 | case WPA_IF_AP_VLAN: |
| 6786 | return NL80211_IFTYPE_AP_VLAN; |
| 6787 | case WPA_IF_AP_BSS: |
| 6788 | return NL80211_IFTYPE_AP; |
| 6789 | case WPA_IF_P2P_GO: |
| 6790 | return NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6791 | case WPA_IF_P2P_DEVICE: |
| 6792 | return NL80211_IFTYPE_P2P_DEVICE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6793 | case WPA_IF_MESH: |
| 6794 | return NL80211_IFTYPE_MESH_POINT; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6795 | default: |
| 6796 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6797 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6798 | } |
| 6799 | |
| 6800 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6801 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
| 6802 | { |
| 6803 | struct wpa_driver_nl80211_data *drv; |
| 6804 | dl_list_for_each(drv, &global->interfaces, |
| 6805 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6806 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6807 | return 1; |
| 6808 | } |
| 6809 | return 0; |
| 6810 | } |
| 6811 | |
| 6812 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6813 | 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] | 6814 | { |
| 6815 | unsigned int idx; |
| 6816 | |
| 6817 | if (!drv->global) |
| 6818 | return -1; |
| 6819 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6820 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6821 | for (idx = 0; idx < 64; idx++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6822 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6823 | new_addr[0] ^= idx << 2; |
| 6824 | if (!nl80211_addr_in_use(drv->global, new_addr)) |
| 6825 | break; |
| 6826 | } |
| 6827 | if (idx == 64) |
| 6828 | return -1; |
| 6829 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6830 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6831 | MACSTR, MAC2STR(new_addr)); |
| 6832 | |
| 6833 | return 0; |
| 6834 | } |
| 6835 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6836 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6837 | struct wdev_info { |
| 6838 | u64 wdev_id; |
| 6839 | int wdev_id_set; |
| 6840 | u8 macaddr[ETH_ALEN]; |
| 6841 | }; |
| 6842 | |
| 6843 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) |
| 6844 | { |
| 6845 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6846 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6847 | struct wdev_info *wi = arg; |
| 6848 | |
| 6849 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6850 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6851 | if (tb[NL80211_ATTR_WDEV]) { |
| 6852 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 6853 | wi->wdev_id_set = 1; |
| 6854 | } |
| 6855 | |
| 6856 | if (tb[NL80211_ATTR_MAC]) |
| 6857 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 6858 | ETH_ALEN); |
| 6859 | |
| 6860 | return NL_SKIP; |
| 6861 | } |
| 6862 | |
| 6863 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6864 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
| 6865 | const char *ifname, const u8 *addr, |
| 6866 | void *bss_ctx, void **drv_priv, |
| 6867 | char *force_ifname, u8 *if_addr, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6868 | const char *bridge, int use_existing, |
| 6869 | int setup_ap) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6870 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6871 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6872 | struct i802_bss *bss = priv; |
| 6873 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6874 | int ifidx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6875 | int added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6876 | |
| 6877 | if (addr) |
| 6878 | os_memcpy(if_addr, addr, ETH_ALEN); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6879 | nlmode = wpa_driver_nl80211_if_type(type); |
| 6880 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 6881 | struct wdev_info p2pdev_info; |
| 6882 | |
| 6883 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); |
| 6884 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
| 6885 | 0, nl80211_wdev_handler, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6886 | &p2pdev_info, use_existing); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6887 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
| 6888 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
| 6889 | ifname); |
| 6890 | return -1; |
| 6891 | } |
| 6892 | |
| 6893 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; |
| 6894 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; |
| 6895 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) |
| 6896 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); |
| 6897 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", |
| 6898 | ifname, |
| 6899 | (long long unsigned int) p2pdev_info.wdev_id); |
| 6900 | } else { |
| 6901 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6902 | 0, NULL, NULL, use_existing); |
| 6903 | if (use_existing && ifidx == -ENFILE) { |
| 6904 | added = 0; |
| 6905 | ifidx = if_nametoindex(ifname); |
| 6906 | } else if (ifidx < 0) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6907 | return -1; |
| 6908 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6909 | } |
| 6910 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6911 | if (!addr) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6912 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6913 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
| 6914 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6915 | ifname, if_addr) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6916 | if (added) |
| 6917 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6918 | return -1; |
| 6919 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6920 | } |
| 6921 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6922 | if (!addr && |
| 6923 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6924 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
| 6925 | type == WPA_IF_STATION)) { |
| 6926 | /* Enforce unique address */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6927 | u8 new_addr[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6928 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6929 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6930 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6931 | if (added) |
| 6932 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6933 | return -1; |
| 6934 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6935 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6936 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6937 | "for interface %s type %d", ifname, type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6938 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6939 | if (added) |
| 6940 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6941 | return -1; |
| 6942 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6943 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6944 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6945 | if (added) |
| 6946 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6947 | return -1; |
| 6948 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6949 | } |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6950 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6951 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6952 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6953 | if (type == WPA_IF_AP_BSS && setup_ap) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6954 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
| 6955 | if (new_bss == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6956 | if (added) |
| 6957 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6958 | return -1; |
| 6959 | } |
| 6960 | |
| 6961 | if (bridge && |
| 6962 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { |
| 6963 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " |
| 6964 | "interface %s to a bridge %s", |
| 6965 | ifname, bridge); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6966 | if (added) |
| 6967 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6968 | os_free(new_bss); |
| 6969 | return -1; |
| 6970 | } |
| 6971 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6972 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
| 6973 | { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6974 | if (added) |
| 6975 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6976 | os_free(new_bss); |
| 6977 | return -1; |
| 6978 | } |
| 6979 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6980 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6981 | new_bss->ifindex = ifidx; |
| 6982 | new_bss->drv = drv; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6983 | new_bss->next = drv->first_bss->next; |
| 6984 | new_bss->freq = drv->first_bss->freq; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6985 | new_bss->ctx = bss_ctx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6986 | new_bss->added_if = added; |
| 6987 | drv->first_bss->next = new_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6988 | if (drv_priv) |
| 6989 | *drv_priv = new_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6990 | nl80211_init_bss(new_bss); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6991 | |
| 6992 | /* Subscribe management frames for this WPA_IF_AP_BSS */ |
| 6993 | if (nl80211_setup_ap(new_bss)) |
| 6994 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6995 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6996 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6997 | if (drv->global) |
| 6998 | drv->global->if_add_ifindex = ifidx; |
| 6999 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7000 | /* |
| 7001 | * Some virtual interfaces need to process EAPOL packets and events on |
| 7002 | * the parent interface. This is used mainly with hostapd. |
| 7003 | */ |
| 7004 | if (ifidx > 0 && |
| 7005 | (drv->hostapd || |
| 7006 | nlmode == NL80211_IFTYPE_AP_VLAN || |
| 7007 | nlmode == NL80211_IFTYPE_WDS || |
| 7008 | nlmode == NL80211_IFTYPE_MONITOR)) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7009 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7010 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7011 | return 0; |
| 7012 | } |
| 7013 | |
| 7014 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7015 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7016 | enum wpa_driver_if_type type, |
| 7017 | const char *ifname) |
| 7018 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7019 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7020 | int ifindex = if_nametoindex(ifname); |
| 7021 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7022 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
| 7023 | __func__, type, ifname, ifindex, bss->added_if); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 7024 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7025 | nl80211_remove_iface(drv, ifindex); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 7026 | else if (ifindex > 0 && !bss->added_if) { |
| 7027 | struct wpa_driver_nl80211_data *drv2; |
| 7028 | dl_list_for_each(drv2, &drv->global->interfaces, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7029 | struct wpa_driver_nl80211_data, list) { |
| 7030 | del_ifidx(drv2, ifindex, IFIDX_ANY); |
| 7031 | del_ifidx(drv2, IFIDX_ANY, ifindex); |
| 7032 | } |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 7033 | } |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7034 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7035 | if (type != WPA_IF_AP_BSS) |
| 7036 | return 0; |
| 7037 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7038 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7039 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 7040 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7041 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 7042 | "interface %s from bridge %s: %s", |
| 7043 | bss->ifname, bss->brname, strerror(errno)); |
| 7044 | } |
| 7045 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7046 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7047 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 7048 | "bridge %s: %s", |
| 7049 | bss->brname, strerror(errno)); |
| 7050 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7051 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7052 | if (bss != drv->first_bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7053 | struct i802_bss *tbss; |
| 7054 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7055 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
| 7056 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7057 | if (tbss->next == bss) { |
| 7058 | tbss->next = bss->next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7059 | /* Unsubscribe management frames */ |
| 7060 | nl80211_teardown_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7061 | nl80211_destroy_bss(bss); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7062 | if (!bss->added_if) |
| 7063 | i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7064 | os_free(bss); |
| 7065 | bss = NULL; |
| 7066 | break; |
| 7067 | } |
| 7068 | } |
| 7069 | if (bss) |
| 7070 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " |
| 7071 | "BSS %p in the list", __func__, bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7072 | } else { |
| 7073 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
| 7074 | nl80211_teardown_ap(bss); |
| 7075 | if (!bss->added_if && !drv->first_bss->next) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 7076 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7077 | nl80211_destroy_bss(bss); |
| 7078 | if (!bss->added_if) |
| 7079 | i802_set_iface_flags(bss, 0); |
| 7080 | if (drv->first_bss->next) { |
| 7081 | drv->first_bss = drv->first_bss->next; |
| 7082 | drv->ctx = drv->first_bss->ctx; |
| 7083 | os_free(bss); |
| 7084 | } else { |
| 7085 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); |
| 7086 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7087 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7088 | |
| 7089 | return 0; |
| 7090 | } |
| 7091 | |
| 7092 | |
| 7093 | static int cookie_handler(struct nl_msg *msg, void *arg) |
| 7094 | { |
| 7095 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7096 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7097 | u64 *cookie = arg; |
| 7098 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7099 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7100 | if (tb[NL80211_ATTR_COOKIE]) |
| 7101 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 7102 | return NL_SKIP; |
| 7103 | } |
| 7104 | |
| 7105 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7106 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7107 | unsigned int freq, unsigned int wait, |
| 7108 | const u8 *buf, size_t buf_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7109 | u64 *cookie_out, int no_cck, int no_ack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7110 | int offchanok, const u16 *csa_offs, |
| 7111 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7112 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7113 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7114 | struct nl_msg *msg; |
| 7115 | u64 cookie; |
| 7116 | int ret = -1; |
| 7117 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7118 | 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] | 7119 | "no_ack=%d offchanok=%d", |
| 7120 | freq, wait, no_cck, no_ack, offchanok); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7121 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7122 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7123 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
| 7124 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 7125 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || |
| 7126 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 7127 | drv->test_use_roc_tx) && |
| 7128 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || |
| 7129 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || |
| 7130 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7131 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
| 7132 | csa_offs_len * sizeof(u16), csa_offs)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7133 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
| 7134 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7135 | |
| 7136 | cookie = 0; |
| 7137 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 7138 | msg = NULL; |
| 7139 | if (ret) { |
| 7140 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 7141 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
| 7142 | freq, wait); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7143 | } else { |
| 7144 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " |
| 7145 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
| 7146 | (long long unsigned int) cookie); |
| 7147 | |
| 7148 | if (cookie_out) |
| 7149 | *cookie_out = no_ack ? (u64) -1 : cookie; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7150 | |
| 7151 | if (drv->num_send_action_cookies == MAX_SEND_ACTION_COOKIES) { |
| 7152 | wpa_printf(MSG_DEBUG, |
| 7153 | "nl80211: Drop oldest pending send action cookie 0x%llx", |
| 7154 | (long long unsigned int) |
| 7155 | drv->send_action_cookies[0]); |
| 7156 | os_memmove(&drv->send_action_cookies[0], |
| 7157 | &drv->send_action_cookies[1], |
| 7158 | (MAX_SEND_ACTION_COOKIES - 1) * |
| 7159 | sizeof(u64)); |
| 7160 | drv->num_send_action_cookies--; |
| 7161 | } |
| 7162 | drv->send_action_cookies[drv->num_send_action_cookies] = cookie; |
| 7163 | drv->num_send_action_cookies++; |
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 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7166 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7167 | nlmsg_free(msg); |
| 7168 | return ret; |
| 7169 | } |
| 7170 | |
| 7171 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7172 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
| 7173 | unsigned int freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7174 | unsigned int wait_time, |
| 7175 | const u8 *dst, const u8 *src, |
| 7176 | const u8 *bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7177 | const u8 *data, size_t data_len, |
| 7178 | int no_cck) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7179 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7180 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7181 | int ret = -1; |
| 7182 | u8 *buf; |
| 7183 | struct ieee80211_hdr *hdr; |
| 7184 | |
| 7185 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7186 | "freq=%u MHz wait=%d ms no_cck=%d)", |
| 7187 | drv->ifindex, freq, wait_time, no_cck); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7188 | |
| 7189 | buf = os_zalloc(24 + data_len); |
| 7190 | if (buf == NULL) |
| 7191 | return ret; |
| 7192 | os_memcpy(buf + 24, data, data_len); |
| 7193 | hdr = (struct ieee80211_hdr *) buf; |
| 7194 | hdr->frame_control = |
| 7195 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); |
| 7196 | os_memcpy(hdr->addr1, dst, ETH_ALEN); |
| 7197 | os_memcpy(hdr->addr2, src, ETH_ALEN); |
| 7198 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); |
| 7199 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 7200 | if (os_memcmp(bss->addr, src, ETH_ALEN) != 0) { |
| 7201 | wpa_printf(MSG_DEBUG, "nl80211: Use random TA " MACSTR, |
| 7202 | MAC2STR(src)); |
| 7203 | os_memcpy(bss->rand_addr, src, ETH_ALEN); |
| 7204 | } else { |
| 7205 | os_memset(bss->rand_addr, 0, ETH_ALEN); |
| 7206 | } |
| 7207 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7208 | if (is_ap_interface(drv->nlmode) && |
| 7209 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 7210 | (int) freq == bss->freq || drv->device_ap_sme || |
| 7211 | !drv->use_monitor)) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7212 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
| 7213 | 0, freq, no_cck, 1, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7214 | wait_time, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7215 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7216 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7217 | 24 + data_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7218 | &drv->send_action_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7219 | no_cck, 0, 1, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7220 | |
| 7221 | os_free(buf); |
| 7222 | return ret; |
| 7223 | } |
| 7224 | |
| 7225 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7226 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7227 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7228 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7229 | struct nl_msg *msg; |
| 7230 | int ret; |
| 7231 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 7232 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7233 | (long long unsigned int) cookie); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7234 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7235 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7236 | nlmsg_free(msg); |
| 7237 | return; |
| 7238 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7239 | |
| 7240 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7241 | if (ret) |
| 7242 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " |
| 7243 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7244 | } |
| 7245 | |
| 7246 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7247 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
| 7248 | { |
| 7249 | struct i802_bss *bss = priv; |
| 7250 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7251 | unsigned int i; |
| 7252 | u64 cookie; |
| 7253 | |
| 7254 | /* Cancel the last pending TX cookie */ |
| 7255 | nl80211_frame_wait_cancel(bss, drv->send_action_cookie); |
| 7256 | |
| 7257 | /* |
| 7258 | * Cancel the other pending TX cookies, if any. This is needed since |
| 7259 | * the driver may keep a list of all pending offchannel TX operations |
| 7260 | * and free up the radio only once they have expired or cancelled. |
| 7261 | */ |
| 7262 | for (i = drv->num_send_action_cookies; i > 0; i--) { |
| 7263 | cookie = drv->send_action_cookies[i - 1]; |
| 7264 | if (cookie != drv->send_action_cookie) |
| 7265 | nl80211_frame_wait_cancel(bss, cookie); |
| 7266 | } |
| 7267 | drv->num_send_action_cookies = 0; |
| 7268 | } |
| 7269 | |
| 7270 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7271 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
| 7272 | unsigned int duration) |
| 7273 | { |
| 7274 | struct i802_bss *bss = priv; |
| 7275 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7276 | struct nl_msg *msg; |
| 7277 | int ret; |
| 7278 | u64 cookie; |
| 7279 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7280 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
| 7281 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 7282 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { |
| 7283 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7284 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7285 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7286 | |
| 7287 | cookie = 0; |
| 7288 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 7289 | if (ret == 0) { |
| 7290 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " |
| 7291 | "0x%llx for freq=%u MHz duration=%u", |
| 7292 | (long long unsigned int) cookie, freq, duration); |
| 7293 | drv->remain_on_chan_cookie = cookie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7294 | drv->pending_remain_on_chan = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7295 | return 0; |
| 7296 | } |
| 7297 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " |
| 7298 | "(freq=%d duration=%u): %d (%s)", |
| 7299 | freq, duration, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7300 | return -1; |
| 7301 | } |
| 7302 | |
| 7303 | |
| 7304 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) |
| 7305 | { |
| 7306 | struct i802_bss *bss = priv; |
| 7307 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7308 | struct nl_msg *msg; |
| 7309 | int ret; |
| 7310 | |
| 7311 | if (!drv->pending_remain_on_chan) { |
| 7312 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " |
| 7313 | "to cancel"); |
| 7314 | return -1; |
| 7315 | } |
| 7316 | |
| 7317 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " |
| 7318 | "0x%llx", |
| 7319 | (long long unsigned int) drv->remain_on_chan_cookie); |
| 7320 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7321 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
| 7322 | if (!msg || |
| 7323 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
| 7324 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7325 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7326 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7327 | |
| 7328 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7329 | if (ret == 0) |
| 7330 | return 0; |
| 7331 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " |
| 7332 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7333 | return -1; |
| 7334 | } |
| 7335 | |
| 7336 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7337 | 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] | 7338 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7339 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 7340 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7341 | if (!report) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7342 | if (bss->nl_preq && drv->device_ap_sme && |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 7343 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
| 7344 | !bss->static_ap) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7345 | /* |
| 7346 | * Do not disable Probe Request reporting that was |
| 7347 | * enabled in nl80211_setup_ap(). |
| 7348 | */ |
| 7349 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " |
| 7350 | "Probe Request reporting nl_preq=%p while " |
| 7351 | "in AP mode", bss->nl_preq); |
| 7352 | } else if (bss->nl_preq) { |
| 7353 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
| 7354 | "reporting nl_preq=%p", bss->nl_preq); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7355 | nl80211_destroy_eloop_handle(&bss->nl_preq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7356 | } |
| 7357 | return 0; |
| 7358 | } |
| 7359 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7360 | if (bss->nl_preq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7361 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7362 | "already on! nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7363 | return 0; |
| 7364 | } |
| 7365 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7366 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
| 7367 | if (bss->nl_preq == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7368 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7369 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
| 7370 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7371 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7372 | if (nl80211_register_frame(bss, bss->nl_preq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7373 | (WLAN_FC_TYPE_MGMT << 2) | |
| 7374 | (WLAN_FC_STYPE_PROBE_REQ << 4), |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7375 | NULL, 0) < 0) |
| 7376 | goto out_err; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 7377 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7378 | nl80211_register_eloop_read(&bss->nl_preq, |
| 7379 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7380 | bss->nl_cb, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7381 | |
| 7382 | return 0; |
| 7383 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7384 | out_err: |
| 7385 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7386 | return -1; |
| 7387 | } |
| 7388 | |
| 7389 | |
| 7390 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 7391 | int ifindex, int disabled) |
| 7392 | { |
| 7393 | struct nl_msg *msg; |
| 7394 | struct nlattr *bands, *band; |
| 7395 | int ret; |
| 7396 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7397 | wpa_printf(MSG_DEBUG, |
| 7398 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", |
| 7399 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : |
| 7400 | "no NL80211_TXRATE_LEGACY constraint"); |
| 7401 | |
| 7402 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
| 7403 | NL80211_CMD_SET_TX_BITRATE_MASK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7404 | if (!msg) |
| 7405 | return -1; |
| 7406 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7407 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 7408 | if (!bands) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7409 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7410 | |
| 7411 | /* |
| 7412 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything |
| 7413 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS |
| 7414 | * rates. All 5 GHz rates are left enabled. |
| 7415 | */ |
| 7416 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7417 | if (!band || |
| 7418 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, |
| 7419 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) |
| 7420 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7421 | nla_nest_end(msg, band); |
| 7422 | |
| 7423 | nla_nest_end(msg, bands); |
| 7424 | |
| 7425 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7426 | if (ret) { |
| 7427 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " |
| 7428 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7429 | } else |
| 7430 | drv->disabled_11b_rates = disabled; |
| 7431 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7432 | return ret; |
| 7433 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7434 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7435 | nlmsg_free(msg); |
| 7436 | return -1; |
| 7437 | } |
| 7438 | |
| 7439 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7440 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
| 7441 | { |
| 7442 | struct i802_bss *bss = priv; |
| 7443 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7444 | if (!is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7445 | return -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 7446 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7447 | bss->beacon_set = 0; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7448 | |
| 7449 | /* |
| 7450 | * If the P2P GO interface was dynamically added, then it is |
| 7451 | * possible that the interface change to station is not possible. |
| 7452 | */ |
| 7453 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) |
| 7454 | return 0; |
| 7455 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7456 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7457 | } |
| 7458 | |
| 7459 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7460 | static int wpa_driver_nl80211_stop_ap(void *priv) |
| 7461 | { |
| 7462 | struct i802_bss *bss = priv; |
| 7463 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7464 | if (!is_ap_interface(drv->nlmode)) |
| 7465 | return -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 7466 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7467 | bss->beacon_set = 0; |
| 7468 | return 0; |
| 7469 | } |
| 7470 | |
| 7471 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7472 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
| 7473 | { |
| 7474 | struct i802_bss *bss = priv; |
| 7475 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7476 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) |
| 7477 | return -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7478 | |
| 7479 | /* |
| 7480 | * If the P2P Client interface was dynamically added, then it is |
| 7481 | * possible that the interface change to station is not possible. |
| 7482 | */ |
| 7483 | if (bss->if_dynamic) |
| 7484 | return 0; |
| 7485 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7486 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
| 7487 | } |
| 7488 | |
| 7489 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7490 | static void wpa_driver_nl80211_resume(void *priv) |
| 7491 | { |
| 7492 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7493 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7494 | |
| 7495 | if (i802_set_iface_flags(bss, 1)) |
| 7496 | 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] | 7497 | |
| 7498 | if (is_p2p_net_interface(nlmode)) |
| 7499 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7500 | } |
| 7501 | |
| 7502 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7503 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
| 7504 | { |
| 7505 | struct i802_bss *bss = priv; |
| 7506 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7507 | struct nl_msg *msg; |
| 7508 | struct nlattr *cqm; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7509 | |
| 7510 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " |
| 7511 | "hysteresis=%d", threshold, hysteresis); |
| 7512 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7513 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
| 7514 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
| 7515 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || |
| 7516 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { |
| 7517 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7518 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7519 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7520 | nla_nest_end(msg, cqm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7521 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7522 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7523 | } |
| 7524 | |
| 7525 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7526 | static int get_channel_width(struct nl_msg *msg, void *arg) |
| 7527 | { |
| 7528 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7529 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7530 | struct wpa_signal_info *sig_change = arg; |
| 7531 | |
| 7532 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7533 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7534 | |
| 7535 | sig_change->center_frq1 = -1; |
| 7536 | sig_change->center_frq2 = -1; |
| 7537 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 7538 | |
| 7539 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 7540 | sig_change->chanwidth = convert2width( |
| 7541 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 7542 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 7543 | sig_change->center_frq1 = |
| 7544 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 7545 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 7546 | sig_change->center_frq2 = |
| 7547 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 7548 | } |
| 7549 | |
| 7550 | return NL_SKIP; |
| 7551 | } |
| 7552 | |
| 7553 | |
| 7554 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, |
| 7555 | struct wpa_signal_info *sig) |
| 7556 | { |
| 7557 | struct nl_msg *msg; |
| 7558 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7559 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7560 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7561 | } |
| 7562 | |
| 7563 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7564 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
| 7565 | { |
| 7566 | struct i802_bss *bss = priv; |
| 7567 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7568 | int res; |
| 7569 | |
| 7570 | os_memset(si, 0, sizeof(*si)); |
| 7571 | res = nl80211_get_link_signal(drv, si); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7572 | if (res) { |
| 7573 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && |
| 7574 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
| 7575 | return res; |
| 7576 | si->current_signal = 0; |
| 7577 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7578 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7579 | res = nl80211_get_channel_width(drv, si); |
| 7580 | if (res != 0) |
| 7581 | return res; |
| 7582 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7583 | return nl80211_get_link_noise(drv, si); |
| 7584 | } |
| 7585 | |
| 7586 | |
| 7587 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
| 7588 | int encrypt) |
| 7589 | { |
| 7590 | struct i802_bss *bss = priv; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7591 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7592 | 0, 0, 0, 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7593 | } |
| 7594 | |
| 7595 | |
| 7596 | static int nl80211_set_param(void *priv, const char *param) |
| 7597 | { |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 7598 | struct i802_bss *bss = priv; |
| 7599 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7600 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7601 | if (param == NULL) |
| 7602 | return 0; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7603 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7604 | |
| 7605 | #ifdef CONFIG_P2P |
| 7606 | if (os_strstr(param, "use_p2p_group_interface=1")) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7607 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 7608 | "interface"); |
| 7609 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 7610 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 7611 | } |
| 7612 | #endif /* CONFIG_P2P */ |
| 7613 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 7614 | if (os_strstr(param, "use_monitor=1")) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7615 | drv->use_monitor = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7616 | |
| 7617 | if (os_strstr(param, "force_connect_cmd=1")) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7618 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7619 | drv->force_connect_cmd = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7620 | } |
| 7621 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 7622 | if (os_strstr(param, "force_bss_selection=1")) |
| 7623 | drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
| 7624 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 7625 | if (os_strstr(param, "no_offchannel_tx=1")) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 7626 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 7627 | drv->test_use_roc_tx = 1; |
| 7628 | } |
| 7629 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7630 | return 0; |
| 7631 | } |
| 7632 | |
| 7633 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7634 | static void * nl80211_global_init(void *ctx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7635 | { |
| 7636 | struct nl80211_global *global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7637 | struct netlink_config *cfg; |
| 7638 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7639 | global = os_zalloc(sizeof(*global)); |
| 7640 | if (global == NULL) |
| 7641 | return NULL; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7642 | global->ctx = ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7643 | global->ioctl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7644 | dl_list_init(&global->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7645 | global->if_add_ifindex = -1; |
| 7646 | |
| 7647 | cfg = os_zalloc(sizeof(*cfg)); |
| 7648 | if (cfg == NULL) |
| 7649 | goto err; |
| 7650 | |
| 7651 | cfg->ctx = global; |
| 7652 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; |
| 7653 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; |
| 7654 | global->netlink = netlink_init(cfg); |
| 7655 | if (global->netlink == NULL) { |
| 7656 | os_free(cfg); |
| 7657 | goto err; |
| 7658 | } |
| 7659 | |
| 7660 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
| 7661 | goto err; |
| 7662 | |
| 7663 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 7664 | if (global->ioctl_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7665 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
| 7666 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7667 | goto err; |
| 7668 | } |
| 7669 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7670 | return global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7671 | |
| 7672 | err: |
| 7673 | nl80211_global_deinit(global); |
| 7674 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7675 | } |
| 7676 | |
| 7677 | |
| 7678 | static void nl80211_global_deinit(void *priv) |
| 7679 | { |
| 7680 | struct nl80211_global *global = priv; |
| 7681 | if (global == NULL) |
| 7682 | return; |
| 7683 | if (!dl_list_empty(&global->interfaces)) { |
| 7684 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " |
| 7685 | "nl80211_global_deinit", |
| 7686 | dl_list_len(&global->interfaces)); |
| 7687 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7688 | |
| 7689 | if (global->netlink) |
| 7690 | netlink_deinit(global->netlink); |
| 7691 | |
| 7692 | nl_destroy_handles(&global->nl); |
| 7693 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7694 | if (global->nl_event) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7695 | nl80211_destroy_eloop_handle(&global->nl_event, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7696 | |
| 7697 | nl_cb_put(global->nl_cb); |
| 7698 | |
| 7699 | if (global->ioctl_sock >= 0) |
| 7700 | close(global->ioctl_sock); |
| 7701 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7702 | os_free(global); |
| 7703 | } |
| 7704 | |
| 7705 | |
| 7706 | static const char * nl80211_get_radio_name(void *priv) |
| 7707 | { |
| 7708 | struct i802_bss *bss = priv; |
| 7709 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7710 | return drv->phyname; |
| 7711 | } |
| 7712 | |
| 7713 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7714 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, |
| 7715 | struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7716 | { |
| 7717 | struct nl_msg *msg; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7718 | const size_t PMK_MAX_LEN = 48; /* current cfg80211 limit */ |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7719 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7720 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7721 | (params->pmkid && |
| 7722 | nla_put(msg, NL80211_ATTR_PMKID, 16, params->pmkid)) || |
| 7723 | (params->bssid && |
| 7724 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) || |
| 7725 | (params->ssid_len && |
| 7726 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || |
| 7727 | (params->fils_cache_id && |
| 7728 | nla_put(msg, NL80211_ATTR_FILS_CACHE_ID, 2, |
| 7729 | params->fils_cache_id)) || |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7730 | (params->pmk_len && params->pmk_len <= PMK_MAX_LEN && |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7731 | nla_put(msg, NL80211_ATTR_PMK, params->pmk_len, params->pmk))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7732 | nlmsg_free(msg); |
| 7733 | return -ENOBUFS; |
| 7734 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7735 | |
| 7736 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7737 | } |
| 7738 | |
| 7739 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7740 | static int nl80211_add_pmkid(void *priv, struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7741 | { |
| 7742 | struct i802_bss *bss = priv; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7743 | int ret; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7744 | |
| 7745 | if (params->bssid) |
| 7746 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, |
| 7747 | MAC2STR(params->bssid)); |
| 7748 | else if (params->fils_cache_id && params->ssid_len) { |
| 7749 | wpa_printf(MSG_DEBUG, |
| 7750 | "nl80211: Add PMKSA for cache id %02x%02x SSID %s", |
| 7751 | params->fils_cache_id[0], params->fils_cache_id[1], |
| 7752 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
| 7753 | } |
| 7754 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7755 | ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params); |
| 7756 | if (ret < 0) { |
| 7757 | wpa_printf(MSG_DEBUG, |
| 7758 | "nl80211: NL80211_CMD_SET_PMKSA failed: %d (%s)", |
| 7759 | ret, strerror(-ret)); |
| 7760 | } |
| 7761 | |
| 7762 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7763 | } |
| 7764 | |
| 7765 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7766 | static int nl80211_remove_pmkid(void *priv, struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7767 | { |
| 7768 | struct i802_bss *bss = priv; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7769 | int ret; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7770 | |
| 7771 | if (params->bssid) |
| 7772 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, |
| 7773 | MAC2STR(params->bssid)); |
| 7774 | else if (params->fils_cache_id && params->ssid_len) { |
| 7775 | wpa_printf(MSG_DEBUG, |
| 7776 | "nl80211: Delete PMKSA for cache id %02x%02x SSID %s", |
| 7777 | params->fils_cache_id[0], params->fils_cache_id[1], |
| 7778 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
| 7779 | } |
| 7780 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7781 | ret = nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, params); |
| 7782 | if (ret < 0) { |
| 7783 | wpa_printf(MSG_DEBUG, |
| 7784 | "nl80211: NL80211_CMD_DEL_PMKSA failed: %d (%s)", |
| 7785 | ret, strerror(-ret)); |
| 7786 | } |
| 7787 | |
| 7788 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7789 | } |
| 7790 | |
| 7791 | |
| 7792 | static int nl80211_flush_pmkid(void *priv) |
| 7793 | { |
| 7794 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7795 | struct nl_msg *msg; |
| 7796 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7797 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7798 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_FLUSH_PMKSA); |
| 7799 | if (!msg) |
| 7800 | return -ENOBUFS; |
| 7801 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7802 | } |
| 7803 | |
| 7804 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7805 | static void clean_survey_results(struct survey_results *survey_results) |
| 7806 | { |
| 7807 | struct freq_survey *survey, *tmp; |
| 7808 | |
| 7809 | if (dl_list_empty(&survey_results->survey_list)) |
| 7810 | return; |
| 7811 | |
| 7812 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 7813 | struct freq_survey, list) { |
| 7814 | dl_list_del(&survey->list); |
| 7815 | os_free(survey); |
| 7816 | } |
| 7817 | } |
| 7818 | |
| 7819 | |
| 7820 | static void add_survey(struct nlattr **sinfo, u32 ifidx, |
| 7821 | struct dl_list *survey_list) |
| 7822 | { |
| 7823 | struct freq_survey *survey; |
| 7824 | |
| 7825 | survey = os_zalloc(sizeof(struct freq_survey)); |
| 7826 | if (!survey) |
| 7827 | return; |
| 7828 | |
| 7829 | survey->ifidx = ifidx; |
| 7830 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 7831 | survey->filled = 0; |
| 7832 | |
| 7833 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { |
| 7834 | survey->nf = (int8_t) |
| 7835 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 7836 | survey->filled |= SURVEY_HAS_NF; |
| 7837 | } |
| 7838 | |
| 7839 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { |
| 7840 | survey->channel_time = |
| 7841 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); |
| 7842 | survey->filled |= SURVEY_HAS_CHAN_TIME; |
| 7843 | } |
| 7844 | |
| 7845 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { |
| 7846 | survey->channel_time_busy = |
| 7847 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); |
| 7848 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; |
| 7849 | } |
| 7850 | |
| 7851 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { |
| 7852 | survey->channel_time_rx = |
| 7853 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); |
| 7854 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; |
| 7855 | } |
| 7856 | |
| 7857 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { |
| 7858 | survey->channel_time_tx = |
| 7859 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); |
| 7860 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; |
| 7861 | } |
| 7862 | |
| 7863 | 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)", |
| 7864 | survey->freq, |
| 7865 | survey->nf, |
| 7866 | (unsigned long int) survey->channel_time, |
| 7867 | (unsigned long int) survey->channel_time_busy, |
| 7868 | (unsigned long int) survey->channel_time_tx, |
| 7869 | (unsigned long int) survey->channel_time_rx, |
| 7870 | survey->filled); |
| 7871 | |
| 7872 | dl_list_add_tail(survey_list, &survey->list); |
| 7873 | } |
| 7874 | |
| 7875 | |
| 7876 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, |
| 7877 | unsigned int freq_filter) |
| 7878 | { |
| 7879 | if (!freq_filter) |
| 7880 | return 1; |
| 7881 | |
| 7882 | return freq_filter == surveyed_freq; |
| 7883 | } |
| 7884 | |
| 7885 | |
| 7886 | static int survey_handler(struct nl_msg *msg, void *arg) |
| 7887 | { |
| 7888 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7889 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7890 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 7891 | struct survey_results *survey_results; |
| 7892 | u32 surveyed_freq = 0; |
| 7893 | u32 ifidx; |
| 7894 | |
| 7895 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 7896 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 7897 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 7898 | }; |
| 7899 | |
| 7900 | survey_results = (struct survey_results *) arg; |
| 7901 | |
| 7902 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7903 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7904 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 7905 | if (!tb[NL80211_ATTR_IFINDEX]) |
| 7906 | return NL_SKIP; |
| 7907 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7908 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 7909 | |
| 7910 | if (!tb[NL80211_ATTR_SURVEY_INFO]) |
| 7911 | return NL_SKIP; |
| 7912 | |
| 7913 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 7914 | tb[NL80211_ATTR_SURVEY_INFO], |
| 7915 | survey_policy)) |
| 7916 | return NL_SKIP; |
| 7917 | |
| 7918 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { |
| 7919 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); |
| 7920 | return NL_SKIP; |
| 7921 | } |
| 7922 | |
| 7923 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 7924 | |
| 7925 | if (!check_survey_ok(sinfo, surveyed_freq, |
| 7926 | survey_results->freq_filter)) |
| 7927 | return NL_SKIP; |
| 7928 | |
| 7929 | if (survey_results->freq_filter && |
| 7930 | survey_results->freq_filter != surveyed_freq) { |
| 7931 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", |
| 7932 | surveyed_freq); |
| 7933 | return NL_SKIP; |
| 7934 | } |
| 7935 | |
| 7936 | add_survey(sinfo, ifidx, &survey_results->survey_list); |
| 7937 | |
| 7938 | return NL_SKIP; |
| 7939 | } |
| 7940 | |
| 7941 | |
| 7942 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) |
| 7943 | { |
| 7944 | struct i802_bss *bss = priv; |
| 7945 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7946 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7947 | int err; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7948 | union wpa_event_data data; |
| 7949 | struct survey_results *survey_results; |
| 7950 | |
| 7951 | os_memset(&data, 0, sizeof(data)); |
| 7952 | survey_results = &data.survey_results; |
| 7953 | |
| 7954 | dl_list_init(&survey_results->survey_list); |
| 7955 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7956 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7957 | if (!msg) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7958 | return -ENOBUFS; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7959 | |
| 7960 | if (freq) |
| 7961 | data.survey_results.freq_filter = freq; |
| 7962 | |
| 7963 | do { |
| 7964 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); |
| 7965 | err = send_and_recv_msgs(drv, msg, survey_handler, |
| 7966 | survey_results); |
| 7967 | } while (err > 0); |
| 7968 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7969 | if (err) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7970 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7971 | else |
| 7972 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7973 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7974 | clean_survey_results(survey_results); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7975 | return err; |
| 7976 | } |
| 7977 | |
| 7978 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 7979 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
| 7980 | const u8 *kck, size_t kck_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7981 | const u8 *replay_ctr) |
| 7982 | { |
| 7983 | struct i802_bss *bss = priv; |
| 7984 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7985 | struct nlattr *replay_nested; |
| 7986 | struct nl_msg *msg; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 7987 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7988 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 7989 | if (!drv->set_rekey_offload) |
| 7990 | return; |
| 7991 | |
| 7992 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7993 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
| 7994 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 7995 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7996 | (kck_len && nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7997 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
| 7998 | replay_ctr)) { |
| 7999 | nl80211_nlmsg_clear(msg); |
| 8000 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8001 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8002 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8003 | |
| 8004 | nla_nest_end(msg, replay_nested); |
| 8005 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8006 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 8007 | if (ret == -EOPNOTSUPP) { |
| 8008 | wpa_printf(MSG_DEBUG, |
| 8009 | "nl80211: Driver does not support rekey offload"); |
| 8010 | drv->set_rekey_offload = 0; |
| 8011 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8012 | } |
| 8013 | |
| 8014 | |
| 8015 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
| 8016 | const u8 *addr, int qos) |
| 8017 | { |
| 8018 | /* send data frame to poll STA and check whether |
| 8019 | * this frame is ACKed */ |
| 8020 | struct { |
| 8021 | struct ieee80211_hdr hdr; |
| 8022 | u16 qos_ctl; |
| 8023 | } STRUCT_PACKED nulldata; |
| 8024 | size_t size; |
| 8025 | |
| 8026 | /* Send data frame to poll STA and check whether this frame is ACKed */ |
| 8027 | |
| 8028 | os_memset(&nulldata, 0, sizeof(nulldata)); |
| 8029 | |
| 8030 | if (qos) { |
| 8031 | nulldata.hdr.frame_control = |
| 8032 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 8033 | WLAN_FC_STYPE_QOS_NULL); |
| 8034 | size = sizeof(nulldata); |
| 8035 | } else { |
| 8036 | nulldata.hdr.frame_control = |
| 8037 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 8038 | WLAN_FC_STYPE_NULLFUNC); |
| 8039 | size = sizeof(struct ieee80211_hdr); |
| 8040 | } |
| 8041 | |
| 8042 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 8043 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 8044 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 8045 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 8046 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8047 | 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] | 8048 | 0, 0, NULL, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8049 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
| 8050 | "send poll frame"); |
| 8051 | } |
| 8052 | |
| 8053 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
| 8054 | int qos) |
| 8055 | { |
| 8056 | struct i802_bss *bss = priv; |
| 8057 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8058 | struct nl_msg *msg; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8059 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8060 | |
| 8061 | if (!drv->poll_command_supported) { |
| 8062 | nl80211_send_null_frame(bss, own_addr, addr, qos); |
| 8063 | return; |
| 8064 | } |
| 8065 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8066 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
| 8067 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 8068 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8069 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8070 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8071 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8072 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8073 | if (ret < 0) { |
| 8074 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " |
| 8075 | MACSTR " failed: ret=%d (%s)", |
| 8076 | MAC2STR(addr), ret, strerror(-ret)); |
| 8077 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8078 | } |
| 8079 | |
| 8080 | |
| 8081 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
| 8082 | { |
| 8083 | struct nl_msg *msg; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8084 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8085 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8086 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
| 8087 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
| 8088 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { |
| 8089 | nlmsg_free(msg); |
| 8090 | return -ENOBUFS; |
| 8091 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8092 | |
| 8093 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 8094 | if (ret < 0) { |
| 8095 | wpa_printf(MSG_DEBUG, |
| 8096 | "nl80211: Setting PS state %s failed: %d (%s)", |
| 8097 | enabled ? "enabled" : "disabled", |
| 8098 | ret, strerror(-ret)); |
| 8099 | } |
| 8100 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8101 | } |
| 8102 | |
| 8103 | |
| 8104 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, |
| 8105 | int ctwindow) |
| 8106 | { |
| 8107 | struct i802_bss *bss = priv; |
| 8108 | |
| 8109 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " |
| 8110 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); |
| 8111 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8112 | if (opp_ps != -1 || ctwindow != -1) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8113 | #ifdef ANDROID_P2P |
| 8114 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8115 | #else /* ANDROID_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8116 | return -1; /* Not yet supported */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8117 | #endif /* ANDROID_P2P */ |
| 8118 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8119 | |
| 8120 | if (legacy_ps == -1) |
| 8121 | return 0; |
| 8122 | if (legacy_ps != 0 && legacy_ps != 1) |
| 8123 | return -1; /* Not yet supported */ |
| 8124 | |
| 8125 | return nl80211_set_power_save(bss, legacy_ps); |
| 8126 | } |
| 8127 | |
| 8128 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8129 | static int nl80211_start_radar_detection(void *priv, |
| 8130 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8131 | { |
| 8132 | struct i802_bss *bss = priv; |
| 8133 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8134 | struct nl_msg *msg; |
| 8135 | int ret; |
| 8136 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8137 | 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)", |
| 8138 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 8139 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 8140 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8141 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
| 8142 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " |
| 8143 | "detection"); |
| 8144 | return -1; |
| 8145 | } |
| 8146 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8147 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
| 8148 | nl80211_put_freq_params(msg, freq) < 0) { |
| 8149 | nlmsg_free(msg); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8150 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8151 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8152 | |
| 8153 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8154 | if (ret == 0) |
| 8155 | return 0; |
| 8156 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " |
| 8157 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8158 | return -1; |
| 8159 | } |
| 8160 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8161 | #ifdef CONFIG_TDLS |
| 8162 | |
| 8163 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, |
| 8164 | u8 dialog_token, u16 status_code, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 8165 | u32 peer_capab, int initiator, const u8 *buf, |
| 8166 | size_t len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8167 | { |
| 8168 | struct i802_bss *bss = priv; |
| 8169 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8170 | struct nl_msg *msg; |
| 8171 | |
| 8172 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 8173 | return -EOPNOTSUPP; |
| 8174 | |
| 8175 | if (!dst) |
| 8176 | return -EINVAL; |
| 8177 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8178 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
| 8179 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 8180 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || |
| 8181 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || |
| 8182 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) |
| 8183 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8184 | if (peer_capab) { |
| 8185 | /* |
| 8186 | * The internal enum tdls_peer_capability definition is |
| 8187 | * currently identical with the nl80211 enum |
| 8188 | * nl80211_tdls_peer_capability, so no conversion is needed |
| 8189 | * here. |
| 8190 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8191 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
| 8192 | peer_capab)) |
| 8193 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8194 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8195 | if ((initiator && |
| 8196 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || |
| 8197 | nla_put(msg, NL80211_ATTR_IE, len, buf)) |
| 8198 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8199 | |
| 8200 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8201 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8202 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8203 | nlmsg_free(msg); |
| 8204 | return -ENOBUFS; |
| 8205 | } |
| 8206 | |
| 8207 | |
| 8208 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) |
| 8209 | { |
| 8210 | struct i802_bss *bss = priv; |
| 8211 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8212 | struct nl_msg *msg; |
| 8213 | enum nl80211_tdls_operation nl80211_oper; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8214 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8215 | |
| 8216 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 8217 | return -EOPNOTSUPP; |
| 8218 | |
| 8219 | switch (oper) { |
| 8220 | case TDLS_DISCOVERY_REQ: |
| 8221 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; |
| 8222 | break; |
| 8223 | case TDLS_SETUP: |
| 8224 | nl80211_oper = NL80211_TDLS_SETUP; |
| 8225 | break; |
| 8226 | case TDLS_TEARDOWN: |
| 8227 | nl80211_oper = NL80211_TDLS_TEARDOWN; |
| 8228 | break; |
| 8229 | case TDLS_ENABLE_LINK: |
| 8230 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; |
| 8231 | break; |
| 8232 | case TDLS_DISABLE_LINK: |
| 8233 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; |
| 8234 | break; |
| 8235 | case TDLS_ENABLE: |
| 8236 | return 0; |
| 8237 | case TDLS_DISABLE: |
| 8238 | return 0; |
| 8239 | default: |
| 8240 | return -EINVAL; |
| 8241 | } |
| 8242 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8243 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
| 8244 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
| 8245 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
| 8246 | nlmsg_free(msg); |
| 8247 | return -ENOBUFS; |
| 8248 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8249 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8250 | res = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8251 | wpa_printf(MSG_DEBUG, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR |
| 8252 | " --> res=%d (%s)", nl80211_oper, MAC2STR(peer), res, |
| 8253 | strerror(-res)); |
| 8254 | return res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8255 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8256 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8257 | |
| 8258 | static int |
| 8259 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, |
| 8260 | const struct hostapd_freq_params *params) |
| 8261 | { |
| 8262 | struct i802_bss *bss = priv; |
| 8263 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8264 | struct nl_msg *msg; |
| 8265 | int ret = -ENOBUFS; |
| 8266 | |
| 8267 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 8268 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 8269 | return -EOPNOTSUPP; |
| 8270 | |
| 8271 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR |
| 8272 | " oper_class=%u freq=%u", |
| 8273 | MAC2STR(addr), oper_class, params->freq); |
| 8274 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); |
| 8275 | if (!msg || |
| 8276 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 8277 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || |
| 8278 | (ret = nl80211_put_freq_params(msg, params))) { |
| 8279 | nlmsg_free(msg); |
| 8280 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); |
| 8281 | return ret; |
| 8282 | } |
| 8283 | |
| 8284 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8285 | } |
| 8286 | |
| 8287 | |
| 8288 | static int |
| 8289 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) |
| 8290 | { |
| 8291 | struct i802_bss *bss = priv; |
| 8292 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8293 | struct nl_msg *msg; |
| 8294 | |
| 8295 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 8296 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 8297 | return -EOPNOTSUPP; |
| 8298 | |
| 8299 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, |
| 8300 | MAC2STR(addr)); |
| 8301 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); |
| 8302 | if (!msg || |
| 8303 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 8304 | nlmsg_free(msg); |
| 8305 | wpa_printf(MSG_DEBUG, |
| 8306 | "nl80211: Could not build TDLS cancel chan switch"); |
| 8307 | return -ENOBUFS; |
| 8308 | } |
| 8309 | |
| 8310 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8311 | } |
| 8312 | |
| 8313 | #endif /* CONFIG TDLS */ |
| 8314 | |
| 8315 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8316 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
| 8317 | enum wpa_alg alg, const u8 *addr, |
| 8318 | int key_idx, int set_tx, |
| 8319 | const u8 *seq, size_t seq_len, |
| 8320 | const u8 *key, size_t key_len) |
| 8321 | { |
| 8322 | struct i802_bss *bss = priv; |
| 8323 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, |
| 8324 | set_tx, seq, seq_len, key, key_len); |
| 8325 | } |
| 8326 | |
| 8327 | |
| 8328 | static int driver_nl80211_scan2(void *priv, |
| 8329 | struct wpa_driver_scan_params *params) |
| 8330 | { |
| 8331 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8332 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 8333 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8334 | |
| 8335 | /* |
| 8336 | * Do a vendor specific scan if possible. If only_new_results is |
| 8337 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush |
| 8338 | * cannot be achieved through a vendor scan. The below condition may |
| 8339 | * need to be modified if new scan flags are added in the future whose |
| 8340 | * functionality can only be achieved through a normal scan. |
| 8341 | */ |
| 8342 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) |
| 8343 | return wpa_driver_nl80211_vendor_scan(bss, params); |
| 8344 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8345 | return wpa_driver_nl80211_scan(bss, params); |
| 8346 | } |
| 8347 | |
| 8348 | |
| 8349 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
| 8350 | int reason_code) |
| 8351 | { |
| 8352 | struct i802_bss *bss = priv; |
| 8353 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); |
| 8354 | } |
| 8355 | |
| 8356 | |
| 8357 | static int driver_nl80211_authenticate(void *priv, |
| 8358 | struct wpa_driver_auth_params *params) |
| 8359 | { |
| 8360 | struct i802_bss *bss = priv; |
| 8361 | return wpa_driver_nl80211_authenticate(bss, params); |
| 8362 | } |
| 8363 | |
| 8364 | |
| 8365 | static void driver_nl80211_deinit(void *priv) |
| 8366 | { |
| 8367 | struct i802_bss *bss = priv; |
| 8368 | wpa_driver_nl80211_deinit(bss); |
| 8369 | } |
| 8370 | |
| 8371 | |
| 8372 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, |
| 8373 | const char *ifname) |
| 8374 | { |
| 8375 | struct i802_bss *bss = priv; |
| 8376 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 8377 | } |
| 8378 | |
| 8379 | |
| 8380 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8381 | size_t data_len, int noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8382 | unsigned int freq, |
| 8383 | const u16 *csa_offs, size_t csa_offs_len) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8384 | { |
| 8385 | struct i802_bss *bss = priv; |
| 8386 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8387 | freq, 0, 0, 0, csa_offs, |
| 8388 | csa_offs_len); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8389 | } |
| 8390 | |
| 8391 | |
| 8392 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) |
| 8393 | { |
| 8394 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8395 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8396 | } |
| 8397 | |
| 8398 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8399 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
| 8400 | const char *ifname, int vlan_id) |
| 8401 | { |
| 8402 | struct i802_bss *bss = priv; |
| 8403 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); |
| 8404 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8405 | |
| 8406 | |
| 8407 | static int driver_nl80211_read_sta_data(void *priv, |
| 8408 | struct hostap_sta_driver_data *data, |
| 8409 | const u8 *addr) |
| 8410 | { |
| 8411 | struct i802_bss *bss = priv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 8412 | |
| 8413 | os_memset(data, 0, sizeof(*data)); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8414 | return i802_read_sta_data(bss, data, addr); |
| 8415 | } |
| 8416 | |
| 8417 | |
| 8418 | static int driver_nl80211_send_action(void *priv, unsigned int freq, |
| 8419 | unsigned int wait_time, |
| 8420 | const u8 *dst, const u8 *src, |
| 8421 | const u8 *bssid, |
| 8422 | const u8 *data, size_t data_len, |
| 8423 | int no_cck) |
| 8424 | { |
| 8425 | struct i802_bss *bss = priv; |
| 8426 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, |
| 8427 | bssid, data, data_len, no_cck); |
| 8428 | } |
| 8429 | |
| 8430 | |
| 8431 | static int driver_nl80211_probe_req_report(void *priv, int report) |
| 8432 | { |
| 8433 | struct i802_bss *bss = priv; |
| 8434 | return wpa_driver_nl80211_probe_req_report(bss, report); |
| 8435 | } |
| 8436 | |
| 8437 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8438 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
| 8439 | const u8 *ies, size_t ies_len) |
| 8440 | { |
| 8441 | int ret; |
| 8442 | struct nl_msg *msg; |
| 8443 | struct i802_bss *bss = priv; |
| 8444 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8445 | u16 mdid = WPA_GET_LE16(md); |
| 8446 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8447 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8448 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
| 8449 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
| 8450 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { |
| 8451 | nlmsg_free(msg); |
| 8452 | return -ENOBUFS; |
| 8453 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8454 | |
| 8455 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8456 | if (ret) { |
| 8457 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " |
| 8458 | "err=%d (%s)", ret, strerror(-ret)); |
| 8459 | } |
| 8460 | |
| 8461 | return ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8462 | } |
| 8463 | |
| 8464 | |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 8465 | static const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8466 | { |
| 8467 | struct i802_bss *bss = priv; |
| 8468 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8469 | |
| 8470 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 8471 | return NULL; |
| 8472 | |
| 8473 | return bss->addr; |
| 8474 | } |
| 8475 | |
| 8476 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8477 | static const char * scan_state_str(enum scan_states scan_state) |
| 8478 | { |
| 8479 | switch (scan_state) { |
| 8480 | case NO_SCAN: |
| 8481 | return "NO_SCAN"; |
| 8482 | case SCAN_REQUESTED: |
| 8483 | return "SCAN_REQUESTED"; |
| 8484 | case SCAN_STARTED: |
| 8485 | return "SCAN_STARTED"; |
| 8486 | case SCAN_COMPLETED: |
| 8487 | return "SCAN_COMPLETED"; |
| 8488 | case SCAN_ABORTED: |
| 8489 | return "SCAN_ABORTED"; |
| 8490 | case SCHED_SCAN_STARTED: |
| 8491 | return "SCHED_SCAN_STARTED"; |
| 8492 | case SCHED_SCAN_STOPPED: |
| 8493 | return "SCHED_SCAN_STOPPED"; |
| 8494 | case SCHED_SCAN_RESULTS: |
| 8495 | return "SCHED_SCAN_RESULTS"; |
| 8496 | } |
| 8497 | |
| 8498 | return "??"; |
| 8499 | } |
| 8500 | |
| 8501 | |
| 8502 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) |
| 8503 | { |
| 8504 | struct i802_bss *bss = priv; |
| 8505 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8506 | int res; |
| 8507 | char *pos, *end; |
| 8508 | |
| 8509 | pos = buf; |
| 8510 | end = buf + buflen; |
| 8511 | |
| 8512 | res = os_snprintf(pos, end - pos, |
| 8513 | "ifindex=%d\n" |
| 8514 | "ifname=%s\n" |
| 8515 | "brname=%s\n" |
| 8516 | "addr=" MACSTR "\n" |
| 8517 | "freq=%d\n" |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 8518 | "%s%s%s%s%s%s", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8519 | bss->ifindex, |
| 8520 | bss->ifname, |
| 8521 | bss->brname, |
| 8522 | MAC2STR(bss->addr), |
| 8523 | bss->freq, |
| 8524 | bss->beacon_set ? "beacon_set=1\n" : "", |
| 8525 | bss->added_if_into_bridge ? |
| 8526 | "added_if_into_bridge=1\n" : "", |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 8527 | bss->already_in_bridge ? "already_in_bridge=1\n" : "", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8528 | bss->added_bridge ? "added_bridge=1\n" : "", |
| 8529 | bss->in_deinit ? "in_deinit=1\n" : "", |
| 8530 | bss->if_dynamic ? "if_dynamic=1\n" : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8531 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8532 | return pos - buf; |
| 8533 | pos += res; |
| 8534 | |
| 8535 | if (bss->wdev_id_set) { |
| 8536 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", |
| 8537 | (unsigned long long) bss->wdev_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8538 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8539 | return pos - buf; |
| 8540 | pos += res; |
| 8541 | } |
| 8542 | |
| 8543 | res = os_snprintf(pos, end - pos, |
| 8544 | "phyname=%s\n" |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8545 | "perm_addr=" MACSTR "\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8546 | "drv_ifindex=%d\n" |
| 8547 | "operstate=%d\n" |
| 8548 | "scan_state=%s\n" |
| 8549 | "auth_bssid=" MACSTR "\n" |
| 8550 | "auth_attempt_bssid=" MACSTR "\n" |
| 8551 | "bssid=" MACSTR "\n" |
| 8552 | "prev_bssid=" MACSTR "\n" |
| 8553 | "associated=%d\n" |
| 8554 | "assoc_freq=%u\n" |
| 8555 | "monitor_sock=%d\n" |
| 8556 | "monitor_ifidx=%d\n" |
| 8557 | "monitor_refcount=%d\n" |
| 8558 | "last_mgmt_freq=%u\n" |
| 8559 | "eapol_tx_sock=%d\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8560 | "%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] | 8561 | drv->phyname, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8562 | MAC2STR(drv->perm_addr), |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8563 | drv->ifindex, |
| 8564 | drv->operstate, |
| 8565 | scan_state_str(drv->scan_state), |
| 8566 | MAC2STR(drv->auth_bssid), |
| 8567 | MAC2STR(drv->auth_attempt_bssid), |
| 8568 | MAC2STR(drv->bssid), |
| 8569 | MAC2STR(drv->prev_bssid), |
| 8570 | drv->associated, |
| 8571 | drv->assoc_freq, |
| 8572 | drv->monitor_sock, |
| 8573 | drv->monitor_ifidx, |
| 8574 | drv->monitor_refcount, |
| 8575 | drv->last_mgmt_freq, |
| 8576 | drv->eapol_tx_sock, |
| 8577 | drv->ignore_if_down_event ? |
| 8578 | "ignore_if_down_event=1\n" : "", |
| 8579 | drv->scan_complete_events ? |
| 8580 | "scan_complete_events=1\n" : "", |
| 8581 | drv->disabled_11b_rates ? |
| 8582 | "disabled_11b_rates=1\n" : "", |
| 8583 | drv->pending_remain_on_chan ? |
| 8584 | "pending_remain_on_chan=1\n" : "", |
| 8585 | drv->in_interface_list ? "in_interface_list=1\n" : "", |
| 8586 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", |
| 8587 | drv->poll_command_supported ? |
| 8588 | "poll_command_supported=1\n" : "", |
| 8589 | drv->data_tx_status ? "data_tx_status=1\n" : "", |
| 8590 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", |
| 8591 | drv->retry_auth ? "retry_auth=1\n" : "", |
| 8592 | drv->use_monitor ? "use_monitor=1\n" : "", |
| 8593 | drv->ignore_next_local_disconnect ? |
| 8594 | "ignore_next_local_disconnect=1\n" : "", |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 8595 | drv->ignore_next_local_deauth ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8596 | "ignore_next_local_deauth=1\n" : ""); |
| 8597 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8598 | return pos - buf; |
| 8599 | pos += res; |
| 8600 | |
| 8601 | if (drv->has_capability) { |
| 8602 | res = os_snprintf(pos, end - pos, |
| 8603 | "capa.key_mgmt=0x%x\n" |
| 8604 | "capa.enc=0x%x\n" |
| 8605 | "capa.auth=0x%x\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8606 | "capa.flags=0x%llx\n" |
| 8607 | "capa.rrm_flags=0x%x\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8608 | "capa.max_scan_ssids=%d\n" |
| 8609 | "capa.max_sched_scan_ssids=%d\n" |
| 8610 | "capa.sched_scan_supported=%d\n" |
| 8611 | "capa.max_match_sets=%d\n" |
| 8612 | "capa.max_remain_on_chan=%u\n" |
| 8613 | "capa.max_stations=%u\n" |
| 8614 | "capa.probe_resp_offloads=0x%x\n" |
| 8615 | "capa.max_acl_mac_addrs=%u\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8616 | "capa.num_multichan_concurrent=%u\n" |
| 8617 | "capa.mac_addr_rand_sched_scan_supported=%d\n" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8618 | "capa.mac_addr_rand_scan_supported=%d\n" |
| 8619 | "capa.conc_capab=%u\n" |
| 8620 | "capa.max_conc_chan_2_4=%u\n" |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8621 | "capa.max_conc_chan_5_0=%u\n" |
| 8622 | "capa.max_sched_scan_plans=%u\n" |
| 8623 | "capa.max_sched_scan_plan_interval=%u\n" |
| 8624 | "capa.max_sched_scan_plan_iterations=%u\n", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8625 | drv->capa.key_mgmt, |
| 8626 | drv->capa.enc, |
| 8627 | drv->capa.auth, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8628 | (unsigned long long) drv->capa.flags, |
| 8629 | drv->capa.rrm_flags, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8630 | drv->capa.max_scan_ssids, |
| 8631 | drv->capa.max_sched_scan_ssids, |
| 8632 | drv->capa.sched_scan_supported, |
| 8633 | drv->capa.max_match_sets, |
| 8634 | drv->capa.max_remain_on_chan, |
| 8635 | drv->capa.max_stations, |
| 8636 | drv->capa.probe_resp_offloads, |
| 8637 | drv->capa.max_acl_mac_addrs, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8638 | drv->capa.num_multichan_concurrent, |
| 8639 | drv->capa.mac_addr_rand_sched_scan_supported, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8640 | drv->capa.mac_addr_rand_scan_supported, |
| 8641 | drv->capa.conc_capab, |
| 8642 | drv->capa.max_conc_chan_2_4, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8643 | drv->capa.max_conc_chan_5_0, |
| 8644 | drv->capa.max_sched_scan_plans, |
| 8645 | drv->capa.max_sched_scan_plan_interval, |
| 8646 | drv->capa.max_sched_scan_plan_iterations); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8647 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8648 | return pos - buf; |
| 8649 | pos += res; |
| 8650 | } |
| 8651 | |
| 8652 | return pos - buf; |
| 8653 | } |
| 8654 | |
| 8655 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8656 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
| 8657 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8658 | if ((settings->head && |
| 8659 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, |
| 8660 | settings->head_len, settings->head)) || |
| 8661 | (settings->tail && |
| 8662 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, |
| 8663 | settings->tail_len, settings->tail)) || |
| 8664 | (settings->beacon_ies && |
| 8665 | nla_put(msg, NL80211_ATTR_IE, |
| 8666 | settings->beacon_ies_len, settings->beacon_ies)) || |
| 8667 | (settings->proberesp_ies && |
| 8668 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 8669 | settings->proberesp_ies_len, settings->proberesp_ies)) || |
| 8670 | (settings->assocresp_ies && |
| 8671 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 8672 | settings->assocresp_ies_len, settings->assocresp_ies)) || |
| 8673 | (settings->probe_resp && |
| 8674 | nla_put(msg, NL80211_ATTR_PROBE_RESP, |
| 8675 | settings->probe_resp_len, settings->probe_resp))) |
| 8676 | return -ENOBUFS; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8677 | |
| 8678 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8679 | } |
| 8680 | |
| 8681 | |
| 8682 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) |
| 8683 | { |
| 8684 | struct nl_msg *msg; |
| 8685 | struct i802_bss *bss = priv; |
| 8686 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8687 | struct nlattr *beacon_csa; |
| 8688 | int ret = -ENOBUFS; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8689 | int csa_off_len = 0; |
| 8690 | int i; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8691 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 8692 | 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] | 8693 | settings->cs_count, settings->block_tx, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 8694 | settings->freq_params.freq, settings->freq_params.bandwidth, |
| 8695 | settings->freq_params.center_freq1, |
| 8696 | settings->freq_params.center_freq2); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8697 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8698 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8699 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
| 8700 | return -EOPNOTSUPP; |
| 8701 | } |
| 8702 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8703 | if (drv->nlmode != NL80211_IFTYPE_AP && |
| 8704 | drv->nlmode != NL80211_IFTYPE_P2P_GO && |
| 8705 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8706 | return -EOPNOTSUPP; |
| 8707 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8708 | /* |
| 8709 | * Remove empty counters, assuming Probe Response and Beacon frame |
| 8710 | * counters match. This implementation assumes that there are only two |
| 8711 | * counters. |
| 8712 | */ |
| 8713 | if (settings->counter_offset_beacon[0] && |
| 8714 | !settings->counter_offset_beacon[1]) { |
| 8715 | csa_off_len = 1; |
| 8716 | } else if (settings->counter_offset_beacon[1] && |
| 8717 | !settings->counter_offset_beacon[0]) { |
| 8718 | csa_off_len = 1; |
| 8719 | settings->counter_offset_beacon[0] = |
| 8720 | settings->counter_offset_beacon[1]; |
| 8721 | settings->counter_offset_presp[0] = |
| 8722 | settings->counter_offset_presp[1]; |
| 8723 | } else if (settings->counter_offset_beacon[1] && |
| 8724 | settings->counter_offset_beacon[0]) { |
| 8725 | csa_off_len = 2; |
| 8726 | } else { |
| 8727 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); |
| 8728 | return -EINVAL; |
| 8729 | } |
| 8730 | |
| 8731 | /* Check CSA counters validity */ |
| 8732 | if (drv->capa.max_csa_counters && |
| 8733 | csa_off_len > drv->capa.max_csa_counters) { |
| 8734 | wpa_printf(MSG_ERROR, |
| 8735 | "nl80211: Too many CSA counters provided"); |
| 8736 | return -EINVAL; |
| 8737 | } |
| 8738 | |
| 8739 | if (!settings->beacon_csa.tail) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8740 | return -EINVAL; |
| 8741 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8742 | for (i = 0; i < csa_off_len; i++) { |
| 8743 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; |
| 8744 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; |
| 8745 | |
| 8746 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || |
| 8747 | (settings->beacon_csa.tail[csa_c_off_bcn] != |
| 8748 | settings->cs_count)) |
| 8749 | return -EINVAL; |
| 8750 | |
| 8751 | if (settings->beacon_csa.probe_resp && |
| 8752 | ((settings->beacon_csa.probe_resp_len <= |
| 8753 | csa_c_off_presp) || |
| 8754 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != |
| 8755 | settings->cs_count))) |
| 8756 | return -EINVAL; |
| 8757 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8758 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8759 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
| 8760 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
| 8761 | settings->cs_count) || |
| 8762 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || |
| 8763 | (settings->block_tx && |
| 8764 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8765 | goto error; |
| 8766 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8767 | /* beacon_after params */ |
| 8768 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 8769 | if (ret) |
| 8770 | goto error; |
| 8771 | |
| 8772 | /* beacon_csa params */ |
| 8773 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); |
| 8774 | if (!beacon_csa) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8775 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8776 | |
| 8777 | ret = set_beacon_data(msg, &settings->beacon_csa); |
| 8778 | if (ret) |
| 8779 | goto error; |
| 8780 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8781 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
| 8782 | csa_off_len * sizeof(u16), |
| 8783 | settings->counter_offset_beacon) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8784 | (settings->beacon_csa.probe_resp && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8785 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
| 8786 | csa_off_len * sizeof(u16), |
| 8787 | settings->counter_offset_presp))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8788 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8789 | |
| 8790 | nla_nest_end(msg, beacon_csa); |
| 8791 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8792 | if (ret) { |
| 8793 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", |
| 8794 | ret, strerror(-ret)); |
| 8795 | } |
| 8796 | return ret; |
| 8797 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8798 | fail: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8799 | ret = -ENOBUFS; |
| 8800 | error: |
| 8801 | nlmsg_free(msg); |
| 8802 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); |
| 8803 | return ret; |
| 8804 | } |
| 8805 | |
| 8806 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8807 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
| 8808 | u8 user_priority, u16 admitted_time) |
| 8809 | { |
| 8810 | struct i802_bss *bss = priv; |
| 8811 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8812 | struct nl_msg *msg; |
| 8813 | int ret; |
| 8814 | |
| 8815 | wpa_printf(MSG_DEBUG, |
| 8816 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", |
| 8817 | tsid, admitted_time, user_priority); |
| 8818 | |
| 8819 | if (!is_sta_interface(drv->nlmode)) |
| 8820 | return -ENOTSUP; |
| 8821 | |
| 8822 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
| 8823 | if (!msg || |
| 8824 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 8825 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 8826 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || |
| 8827 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { |
| 8828 | nlmsg_free(msg); |
| 8829 | return -ENOBUFS; |
| 8830 | } |
| 8831 | |
| 8832 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8833 | if (ret) |
| 8834 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", |
| 8835 | ret, strerror(-ret)); |
| 8836 | return ret; |
| 8837 | } |
| 8838 | |
| 8839 | |
| 8840 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) |
| 8841 | { |
| 8842 | struct i802_bss *bss = priv; |
| 8843 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8844 | struct nl_msg *msg; |
| 8845 | int ret; |
| 8846 | |
| 8847 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); |
| 8848 | |
| 8849 | if (!is_sta_interface(drv->nlmode)) |
| 8850 | return -ENOTSUP; |
| 8851 | |
| 8852 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
| 8853 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 8854 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 8855 | nlmsg_free(msg); |
| 8856 | return -ENOBUFS; |
| 8857 | } |
| 8858 | |
| 8859 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8860 | if (ret) |
| 8861 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", |
| 8862 | ret, strerror(-ret)); |
| 8863 | return ret; |
| 8864 | } |
| 8865 | |
| 8866 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8867 | #ifdef CONFIG_TESTING_OPTIONS |
| 8868 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) |
| 8869 | { |
| 8870 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8871 | struct wpabuf *buf = arg; |
| 8872 | |
| 8873 | if (!buf) |
| 8874 | return NL_SKIP; |
| 8875 | |
| 8876 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { |
| 8877 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); |
| 8878 | return NL_SKIP; |
| 8879 | } |
| 8880 | |
| 8881 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), |
| 8882 | genlmsg_attrlen(gnlh, 0)); |
| 8883 | |
| 8884 | return NL_SKIP; |
| 8885 | } |
| 8886 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 8887 | |
| 8888 | |
| 8889 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
| 8890 | { |
| 8891 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8892 | struct nlattr *nl_vendor_reply, *nl; |
| 8893 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8894 | struct wpabuf *buf = arg; |
| 8895 | int rem; |
| 8896 | |
| 8897 | if (!buf) |
| 8898 | return NL_SKIP; |
| 8899 | |
| 8900 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8901 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8902 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; |
| 8903 | |
| 8904 | if (!nl_vendor_reply) |
| 8905 | return NL_SKIP; |
| 8906 | |
| 8907 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { |
| 8908 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); |
| 8909 | return NL_SKIP; |
| 8910 | } |
| 8911 | |
| 8912 | nla_for_each_nested(nl, nl_vendor_reply, rem) { |
| 8913 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); |
| 8914 | } |
| 8915 | |
| 8916 | return NL_SKIP; |
| 8917 | } |
| 8918 | |
| 8919 | |
| 8920 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, |
| 8921 | unsigned int subcmd, const u8 *data, |
| 8922 | size_t data_len, struct wpabuf *buf) |
| 8923 | { |
| 8924 | struct i802_bss *bss = priv; |
| 8925 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8926 | struct nl_msg *msg; |
| 8927 | int ret; |
| 8928 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8929 | #ifdef CONFIG_TESTING_OPTIONS |
| 8930 | if (vendor_id == 0xffffffff) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8931 | msg = nlmsg_alloc(); |
| 8932 | if (!msg) |
| 8933 | return -ENOMEM; |
| 8934 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8935 | nl80211_cmd(drv, msg, 0, subcmd); |
| 8936 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < |
| 8937 | 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8938 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8939 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
| 8940 | if (ret) |
| 8941 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", |
| 8942 | ret); |
| 8943 | return ret; |
| 8944 | } |
| 8945 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 8946 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8947 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 8948 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
| 8949 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || |
| 8950 | (data && |
| 8951 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) |
| 8952 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8953 | |
| 8954 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); |
| 8955 | if (ret) |
| 8956 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", |
| 8957 | ret); |
| 8958 | return ret; |
| 8959 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8960 | fail: |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8961 | nlmsg_free(msg); |
| 8962 | return -ENOBUFS; |
| 8963 | } |
| 8964 | |
| 8965 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8966 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
| 8967 | u8 qos_map_set_len) |
| 8968 | { |
| 8969 | struct i802_bss *bss = priv; |
| 8970 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8971 | struct nl_msg *msg; |
| 8972 | int ret; |
| 8973 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8974 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
| 8975 | qos_map_set, qos_map_set_len); |
| 8976 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8977 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
| 8978 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
| 8979 | nlmsg_free(msg); |
| 8980 | return -ENOBUFS; |
| 8981 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8982 | |
| 8983 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8984 | if (ret) |
| 8985 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); |
| 8986 | |
| 8987 | return ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8988 | } |
| 8989 | |
| 8990 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8991 | static int nl80211_set_wowlan(void *priv, |
| 8992 | const struct wowlan_triggers *triggers) |
| 8993 | { |
| 8994 | struct i802_bss *bss = priv; |
| 8995 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8996 | struct nl_msg *msg; |
| 8997 | struct nlattr *wowlan_triggers; |
| 8998 | int ret; |
| 8999 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9000 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
| 9001 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 9002 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9003 | !(wowlan_triggers = nla_nest_start(msg, |
| 9004 | NL80211_ATTR_WOWLAN_TRIGGERS)) || |
| 9005 | (triggers->any && |
| 9006 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 9007 | (triggers->disconnect && |
| 9008 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 9009 | (triggers->magic_pkt && |
| 9010 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 9011 | (triggers->gtk_rekey_failure && |
| 9012 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 9013 | (triggers->eap_identity_req && |
| 9014 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 9015 | (triggers->four_way_handshake && |
| 9016 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 9017 | (triggers->rfkill_release && |
| 9018 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { |
| 9019 | nlmsg_free(msg); |
| 9020 | return -ENOBUFS; |
| 9021 | } |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9022 | |
| 9023 | nla_nest_end(msg, wowlan_triggers); |
| 9024 | |
| 9025 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9026 | if (ret) |
| 9027 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); |
| 9028 | |
| 9029 | return ret; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9030 | } |
| 9031 | |
| 9032 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9033 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9034 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
| 9035 | { |
| 9036 | struct i802_bss *bss = priv; |
| 9037 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9038 | struct nl_msg *msg; |
| 9039 | struct nlattr *params; |
| 9040 | |
| 9041 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); |
| 9042 | |
| 9043 | if (!drv->roaming_vendor_cmd_avail) { |
| 9044 | wpa_printf(MSG_DEBUG, |
| 9045 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); |
| 9046 | return -1; |
| 9047 | } |
| 9048 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9049 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9050 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9051 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9052 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || |
| 9053 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9054 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, |
| 9055 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : |
| 9056 | QCA_ROAMING_NOT_ALLOWED) || |
| 9057 | (bssid && |
| 9058 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { |
| 9059 | nlmsg_free(msg); |
| 9060 | return -1; |
| 9061 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9062 | nla_nest_end(msg, params); |
| 9063 | |
| 9064 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9065 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9066 | |
| 9067 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9068 | static int nl80211_disable_fils(void *priv, int disable) |
| 9069 | { |
| 9070 | struct i802_bss *bss = priv; |
| 9071 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9072 | struct nl_msg *msg; |
| 9073 | struct nlattr *params; |
| 9074 | |
| 9075 | wpa_printf(MSG_DEBUG, "nl80211: Disable FILS=%d", disable); |
| 9076 | |
| 9077 | if (!drv->set_wifi_conf_vendor_cmd_avail) |
| 9078 | return -1; |
| 9079 | |
| 9080 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9081 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9082 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9083 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) || |
| 9084 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9085 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS, |
| 9086 | disable)) { |
| 9087 | nlmsg_free(msg); |
| 9088 | return -1; |
| 9089 | } |
| 9090 | nla_nest_end(msg, params); |
| 9091 | |
| 9092 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9093 | } |
| 9094 | |
| 9095 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9096 | /* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */ |
| 9097 | #define WPA_SUPPLICANT_CLIENT_ID 1 |
| 9098 | |
| 9099 | static int nl80211_set_bssid_blacklist(void *priv, unsigned int num_bssid, |
| 9100 | const u8 *bssid) |
| 9101 | { |
| 9102 | struct i802_bss *bss = priv; |
| 9103 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9104 | struct nl_msg *msg; |
| 9105 | struct nlattr *params, *nlbssids, *attr; |
| 9106 | unsigned int i; |
| 9107 | |
| 9108 | wpa_printf(MSG_DEBUG, "nl80211: Set blacklist BSSID (num=%u)", |
| 9109 | num_bssid); |
| 9110 | |
| 9111 | if (!drv->roam_vendor_cmd_avail) |
| 9112 | return -1; |
| 9113 | |
| 9114 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9115 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9116 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9117 | QCA_NL80211_VENDOR_SUBCMD_ROAM) || |
| 9118 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9119 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD, |
| 9120 | QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_SET_BLACKLIST_BSSID) || |
| 9121 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID, |
| 9122 | WPA_SUPPLICANT_CLIENT_ID) || |
| 9123 | nla_put_u32(msg, |
| 9124 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID, |
| 9125 | num_bssid)) |
| 9126 | goto fail; |
| 9127 | |
| 9128 | nlbssids = nla_nest_start( |
| 9129 | msg, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS); |
| 9130 | if (!nlbssids) |
| 9131 | goto fail; |
| 9132 | |
| 9133 | for (i = 0; i < num_bssid; i++) { |
| 9134 | attr = nla_nest_start(msg, i); |
| 9135 | if (!attr) |
| 9136 | goto fail; |
| 9137 | if (nla_put(msg, |
| 9138 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID, |
| 9139 | ETH_ALEN, &bssid[i * ETH_ALEN])) |
| 9140 | goto fail; |
| 9141 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%u]: " MACSTR, i, |
| 9142 | MAC2STR(&bssid[i * ETH_ALEN])); |
| 9143 | nla_nest_end(msg, attr); |
| 9144 | } |
| 9145 | nla_nest_end(msg, nlbssids); |
| 9146 | nla_nest_end(msg, params); |
| 9147 | |
| 9148 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9149 | |
| 9150 | fail: |
| 9151 | nlmsg_free(msg); |
| 9152 | return -1; |
| 9153 | } |
| 9154 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9155 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9156 | |
| 9157 | |
| 9158 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
| 9159 | { |
| 9160 | struct i802_bss *bss = priv; |
| 9161 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9162 | int new_addr = addr != NULL; |
| 9163 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9164 | if (TEST_FAIL()) |
| 9165 | return -1; |
| 9166 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9167 | if (!addr) |
| 9168 | addr = drv->perm_addr; |
| 9169 | |
| 9170 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) |
| 9171 | return -1; |
| 9172 | |
| 9173 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) |
| 9174 | { |
| 9175 | wpa_printf(MSG_DEBUG, |
| 9176 | "nl80211: failed to set_mac_addr for %s to " MACSTR, |
| 9177 | bss->ifname, MAC2STR(addr)); |
| 9178 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 9179 | 1) < 0) { |
| 9180 | wpa_printf(MSG_DEBUG, |
| 9181 | "nl80211: Could not restore interface UP after failed set_mac_addr"); |
| 9182 | } |
| 9183 | return -1; |
| 9184 | } |
| 9185 | |
| 9186 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, |
| 9187 | bss->ifname, MAC2STR(addr)); |
| 9188 | drv->addr_changed = new_addr; |
| 9189 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 9190 | |
| 9191 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) |
| 9192 | { |
| 9193 | wpa_printf(MSG_DEBUG, |
| 9194 | "nl80211: Could not restore interface UP after set_mac_addr"); |
| 9195 | } |
| 9196 | |
| 9197 | return 0; |
| 9198 | } |
| 9199 | |
| 9200 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9201 | #ifdef CONFIG_MESH |
| 9202 | |
| 9203 | static int wpa_driver_nl80211_init_mesh(void *priv) |
| 9204 | { |
| 9205 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { |
| 9206 | wpa_printf(MSG_INFO, |
| 9207 | "nl80211: Failed to set interface into mesh mode"); |
| 9208 | return -1; |
| 9209 | } |
| 9210 | return 0; |
| 9211 | } |
| 9212 | |
| 9213 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9214 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
| 9215 | size_t mesh_id_len) |
| 9216 | { |
| 9217 | if (mesh_id) { |
| 9218 | wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)", |
| 9219 | mesh_id, mesh_id_len); |
| 9220 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); |
| 9221 | } |
| 9222 | |
| 9223 | return 0; |
| 9224 | } |
| 9225 | |
| 9226 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9227 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
| 9228 | struct wpa_driver_mesh_bss_params *params) |
| 9229 | { |
| 9230 | struct nlattr *container; |
| 9231 | |
| 9232 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
| 9233 | if (!container) |
| 9234 | return -1; |
| 9235 | |
| 9236 | if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9237 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 9238 | params->auto_plinks)) || |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9239 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) && |
| 9240 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9241 | params->max_peer_links)) || |
| 9242 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD) && |
| 9243 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 9244 | params->rssi_threshold))) |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9245 | return -1; |
| 9246 | |
| 9247 | /* |
| 9248 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because |
| 9249 | * the timer could disconnect stations even in that case. |
| 9250 | */ |
| 9251 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) && |
| 9252 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 9253 | params->peer_link_timeout)) { |
| 9254 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); |
| 9255 | return -1; |
| 9256 | } |
| 9257 | |
| 9258 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) && |
| 9259 | nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) { |
| 9260 | wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE"); |
| 9261 | return -1; |
| 9262 | } |
| 9263 | |
| 9264 | nla_nest_end(msg, container); |
| 9265 | |
| 9266 | return 0; |
| 9267 | } |
| 9268 | |
| 9269 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9270 | static int nl80211_join_mesh(struct i802_bss *bss, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9271 | struct wpa_driver_mesh_join_params *params) |
| 9272 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9273 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9274 | struct nl_msg *msg; |
| 9275 | struct nlattr *container; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 9276 | int ret = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9277 | |
| 9278 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
| 9279 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9280 | if (!msg || |
| 9281 | nl80211_put_freq_params(msg, ¶ms->freq) || |
| 9282 | nl80211_put_basic_rates(msg, params->basic_rates) || |
| 9283 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 9284 | nl80211_put_beacon_int(msg, params->beacon_int) || |
| 9285 | nl80211_put_dtim_period(msg, params->dtim_period)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9286 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9287 | |
| 9288 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
| 9289 | |
| 9290 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); |
| 9291 | if (!container) |
| 9292 | goto fail; |
| 9293 | |
| 9294 | if (params->ies) { |
| 9295 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); |
| 9296 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
| 9297 | params->ies)) |
| 9298 | goto fail; |
| 9299 | } |
| 9300 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ |
| 9301 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { |
| 9302 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
| 9303 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) |
| 9304 | goto fail; |
| 9305 | } |
| 9306 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
| 9307 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) |
| 9308 | goto fail; |
| 9309 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && |
| 9310 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) |
| 9311 | goto fail; |
| 9312 | nla_nest_end(msg, container); |
| 9313 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9314 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS; |
| 9315 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT; |
| 9316 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS; |
| 9317 | if (nl80211_put_mesh_config(msg, ¶ms->conf) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9318 | goto fail; |
| 9319 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9320 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9321 | msg = NULL; |
| 9322 | if (ret) { |
| 9323 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", |
| 9324 | ret, strerror(-ret)); |
| 9325 | goto fail; |
| 9326 | } |
| 9327 | ret = 0; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 9328 | drv->assoc_freq = bss->freq = params->freq.freq; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9329 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
| 9330 | |
| 9331 | fail: |
| 9332 | nlmsg_free(msg); |
| 9333 | return ret; |
| 9334 | } |
| 9335 | |
| 9336 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9337 | static int |
| 9338 | wpa_driver_nl80211_join_mesh(void *priv, |
| 9339 | struct wpa_driver_mesh_join_params *params) |
| 9340 | { |
| 9341 | struct i802_bss *bss = priv; |
| 9342 | int ret, timeout; |
| 9343 | |
| 9344 | timeout = params->conf.peer_link_timeout; |
| 9345 | |
| 9346 | /* Disable kernel inactivity timer */ |
| 9347 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) |
| 9348 | params->conf.peer_link_timeout = 0; |
| 9349 | |
| 9350 | ret = nl80211_join_mesh(bss, params); |
| 9351 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { |
| 9352 | wpa_printf(MSG_DEBUG, |
| 9353 | "nl80211: Mesh join retry for peer_link_timeout"); |
| 9354 | /* |
| 9355 | * Old kernel does not support setting |
| 9356 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds |
| 9357 | * into future from peer_link_timeout. |
| 9358 | */ |
| 9359 | params->conf.peer_link_timeout = timeout + 60; |
| 9360 | ret = nl80211_join_mesh(priv, params); |
| 9361 | } |
| 9362 | |
| 9363 | params->conf.peer_link_timeout = timeout; |
| 9364 | return ret; |
| 9365 | } |
| 9366 | |
| 9367 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9368 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
| 9369 | { |
| 9370 | struct i802_bss *bss = priv; |
| 9371 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9372 | struct nl_msg *msg; |
| 9373 | int ret; |
| 9374 | |
| 9375 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); |
| 9376 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
| 9377 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9378 | if (ret) { |
| 9379 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", |
| 9380 | ret, strerror(-ret)); |
| 9381 | } else { |
| 9382 | wpa_printf(MSG_DEBUG, |
| 9383 | "nl80211: mesh leave request send successfully"); |
| 9384 | } |
| 9385 | |
| 9386 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
| 9387 | NL80211_IFTYPE_STATION)) { |
| 9388 | wpa_printf(MSG_INFO, |
| 9389 | "nl80211: Failed to set interface into station mode"); |
| 9390 | } |
| 9391 | return ret; |
| 9392 | } |
| 9393 | |
| 9394 | #endif /* CONFIG_MESH */ |
| 9395 | |
| 9396 | |
| 9397 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
| 9398 | const u8 *ipaddr, int prefixlen, |
| 9399 | const u8 *addr) |
| 9400 | { |
| 9401 | #ifdef CONFIG_LIBNL3_ROUTE |
| 9402 | struct i802_bss *bss = priv; |
| 9403 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9404 | struct rtnl_neigh *rn; |
| 9405 | struct nl_addr *nl_ipaddr = NULL; |
| 9406 | struct nl_addr *nl_lladdr = NULL; |
| 9407 | int family, addrsize; |
| 9408 | int res; |
| 9409 | |
| 9410 | if (!ipaddr || prefixlen == 0 || !addr) |
| 9411 | return -EINVAL; |
| 9412 | |
| 9413 | if (bss->br_ifindex == 0) { |
| 9414 | wpa_printf(MSG_DEBUG, |
| 9415 | "nl80211: bridge must be set before adding an ip neigh to it"); |
| 9416 | return -1; |
| 9417 | } |
| 9418 | |
| 9419 | if (!drv->rtnl_sk) { |
| 9420 | wpa_printf(MSG_DEBUG, |
| 9421 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 9422 | return -1; |
| 9423 | } |
| 9424 | |
| 9425 | if (version == 4) { |
| 9426 | family = AF_INET; |
| 9427 | addrsize = 4; |
| 9428 | } else if (version == 6) { |
| 9429 | family = AF_INET6; |
| 9430 | addrsize = 16; |
| 9431 | } else { |
| 9432 | return -EINVAL; |
| 9433 | } |
| 9434 | |
| 9435 | rn = rtnl_neigh_alloc(); |
| 9436 | if (rn == NULL) |
| 9437 | return -ENOMEM; |
| 9438 | |
| 9439 | /* set the destination ip address for neigh */ |
| 9440 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 9441 | if (nl_ipaddr == NULL) { |
| 9442 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 9443 | res = -ENOMEM; |
| 9444 | goto errout; |
| 9445 | } |
| 9446 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); |
| 9447 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 9448 | if (res) { |
| 9449 | wpa_printf(MSG_DEBUG, |
| 9450 | "nl80211: neigh set destination addr failed"); |
| 9451 | goto errout; |
| 9452 | } |
| 9453 | |
| 9454 | /* set the corresponding lladdr for neigh */ |
| 9455 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); |
| 9456 | if (nl_lladdr == NULL) { |
| 9457 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); |
| 9458 | res = -ENOMEM; |
| 9459 | goto errout; |
| 9460 | } |
| 9461 | rtnl_neigh_set_lladdr(rn, nl_lladdr); |
| 9462 | |
| 9463 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 9464 | rtnl_neigh_set_state(rn, NUD_PERMANENT); |
| 9465 | |
| 9466 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); |
| 9467 | if (res) { |
| 9468 | wpa_printf(MSG_DEBUG, |
| 9469 | "nl80211: Adding bridge ip neigh failed: %s", |
| 9470 | strerror(errno)); |
| 9471 | } |
| 9472 | errout: |
| 9473 | if (nl_lladdr) |
| 9474 | nl_addr_put(nl_lladdr); |
| 9475 | if (nl_ipaddr) |
| 9476 | nl_addr_put(nl_ipaddr); |
| 9477 | if (rn) |
| 9478 | rtnl_neigh_put(rn); |
| 9479 | return res; |
| 9480 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 9481 | return -1; |
| 9482 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 9483 | } |
| 9484 | |
| 9485 | |
| 9486 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
| 9487 | const u8 *ipaddr) |
| 9488 | { |
| 9489 | #ifdef CONFIG_LIBNL3_ROUTE |
| 9490 | struct i802_bss *bss = priv; |
| 9491 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9492 | struct rtnl_neigh *rn; |
| 9493 | struct nl_addr *nl_ipaddr; |
| 9494 | int family, addrsize; |
| 9495 | int res; |
| 9496 | |
| 9497 | if (!ipaddr) |
| 9498 | return -EINVAL; |
| 9499 | |
| 9500 | if (version == 4) { |
| 9501 | family = AF_INET; |
| 9502 | addrsize = 4; |
| 9503 | } else if (version == 6) { |
| 9504 | family = AF_INET6; |
| 9505 | addrsize = 16; |
| 9506 | } else { |
| 9507 | return -EINVAL; |
| 9508 | } |
| 9509 | |
| 9510 | if (bss->br_ifindex == 0) { |
| 9511 | wpa_printf(MSG_DEBUG, |
| 9512 | "nl80211: bridge must be set to delete an ip neigh"); |
| 9513 | return -1; |
| 9514 | } |
| 9515 | |
| 9516 | if (!drv->rtnl_sk) { |
| 9517 | wpa_printf(MSG_DEBUG, |
| 9518 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 9519 | return -1; |
| 9520 | } |
| 9521 | |
| 9522 | rn = rtnl_neigh_alloc(); |
| 9523 | if (rn == NULL) |
| 9524 | return -ENOMEM; |
| 9525 | |
| 9526 | /* set the destination ip address for neigh */ |
| 9527 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 9528 | if (nl_ipaddr == NULL) { |
| 9529 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 9530 | res = -ENOMEM; |
| 9531 | goto errout; |
| 9532 | } |
| 9533 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 9534 | if (res) { |
| 9535 | wpa_printf(MSG_DEBUG, |
| 9536 | "nl80211: neigh set destination addr failed"); |
| 9537 | goto errout; |
| 9538 | } |
| 9539 | |
| 9540 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 9541 | |
| 9542 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 9543 | if (res) { |
| 9544 | wpa_printf(MSG_DEBUG, |
| 9545 | "nl80211: Deleting bridge ip neigh failed: %s", |
| 9546 | strerror(errno)); |
| 9547 | } |
| 9548 | errout: |
| 9549 | if (nl_ipaddr) |
| 9550 | nl_addr_put(nl_ipaddr); |
| 9551 | if (rn) |
| 9552 | rtnl_neigh_put(rn); |
| 9553 | return res; |
| 9554 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 9555 | return -1; |
| 9556 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 9557 | } |
| 9558 | |
| 9559 | |
| 9560 | static int linux_write_system_file(const char *path, unsigned int val) |
| 9561 | { |
| 9562 | char buf[50]; |
| 9563 | int fd, len; |
| 9564 | |
| 9565 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); |
| 9566 | if (os_snprintf_error(sizeof(buf), len)) |
| 9567 | return -1; |
| 9568 | |
| 9569 | fd = open(path, O_WRONLY); |
| 9570 | if (fd < 0) |
| 9571 | return -1; |
| 9572 | |
| 9573 | if (write(fd, buf, len) < 0) { |
| 9574 | wpa_printf(MSG_DEBUG, |
| 9575 | "nl80211: Failed to write Linux system file: %s with the value of %d", |
| 9576 | path, val); |
| 9577 | close(fd); |
| 9578 | return -1; |
| 9579 | } |
| 9580 | close(fd); |
| 9581 | |
| 9582 | return 0; |
| 9583 | } |
| 9584 | |
| 9585 | |
| 9586 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) |
| 9587 | { |
| 9588 | switch (attr) { |
| 9589 | case DRV_BR_PORT_ATTR_PROXYARP: |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 9590 | return "proxyarp_wifi"; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9591 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
| 9592 | return "hairpin_mode"; |
| 9593 | } |
| 9594 | |
| 9595 | return NULL; |
| 9596 | } |
| 9597 | |
| 9598 | |
| 9599 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, |
| 9600 | unsigned int val) |
| 9601 | { |
| 9602 | struct i802_bss *bss = priv; |
| 9603 | char path[128]; |
| 9604 | const char *attr_txt; |
| 9605 | |
| 9606 | attr_txt = drv_br_port_attr_str(attr); |
| 9607 | if (attr_txt == NULL) |
| 9608 | return -EINVAL; |
| 9609 | |
| 9610 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", |
| 9611 | bss->ifname, attr_txt); |
| 9612 | |
| 9613 | if (linux_write_system_file(path, val)) |
| 9614 | return -1; |
| 9615 | |
| 9616 | return 0; |
| 9617 | } |
| 9618 | |
| 9619 | |
| 9620 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
| 9621 | { |
| 9622 | switch (param) { |
| 9623 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 9624 | return "arp_accept"; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 9625 | default: |
| 9626 | return NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9627 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9628 | } |
| 9629 | |
| 9630 | |
| 9631 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, |
| 9632 | unsigned int val) |
| 9633 | { |
| 9634 | struct i802_bss *bss = priv; |
| 9635 | char path[128]; |
| 9636 | const char *param_txt; |
| 9637 | int ip_version = 4; |
| 9638 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 9639 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
| 9640 | os_snprintf(path, sizeof(path), |
| 9641 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", |
| 9642 | bss->brname); |
| 9643 | goto set_val; |
| 9644 | } |
| 9645 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9646 | param_txt = drv_br_net_param_str(param); |
| 9647 | if (param_txt == NULL) |
| 9648 | return -EINVAL; |
| 9649 | |
| 9650 | switch (param) { |
| 9651 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 9652 | ip_version = 4; |
| 9653 | break; |
| 9654 | default: |
| 9655 | return -EINVAL; |
| 9656 | } |
| 9657 | |
| 9658 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", |
| 9659 | ip_version, bss->brname, param_txt); |
| 9660 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 9661 | set_val: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9662 | if (linux_write_system_file(path, val)) |
| 9663 | return -1; |
| 9664 | |
| 9665 | return 0; |
| 9666 | } |
| 9667 | |
| 9668 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9669 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 9670 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9671 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
| 9672 | { |
| 9673 | switch (hw_mode) { |
| 9674 | case HOSTAPD_MODE_IEEE80211B: |
| 9675 | return QCA_ACS_MODE_IEEE80211B; |
| 9676 | case HOSTAPD_MODE_IEEE80211G: |
| 9677 | return QCA_ACS_MODE_IEEE80211G; |
| 9678 | case HOSTAPD_MODE_IEEE80211A: |
| 9679 | return QCA_ACS_MODE_IEEE80211A; |
| 9680 | case HOSTAPD_MODE_IEEE80211AD: |
| 9681 | return QCA_ACS_MODE_IEEE80211AD; |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 9682 | case HOSTAPD_MODE_IEEE80211ANY: |
| 9683 | return QCA_ACS_MODE_IEEE80211ANY; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9684 | default: |
| 9685 | return -1; |
| 9686 | } |
| 9687 | } |
| 9688 | |
| 9689 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9690 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
| 9691 | { |
| 9692 | int i, len, ret; |
| 9693 | u32 *freqs; |
| 9694 | |
| 9695 | if (!freq_list) |
| 9696 | return 0; |
| 9697 | len = int_array_len(freq_list); |
| 9698 | freqs = os_malloc(sizeof(u32) * len); |
| 9699 | if (!freqs) |
| 9700 | return -1; |
| 9701 | for (i = 0; i < len; i++) |
| 9702 | freqs[i] = freq_list[i]; |
| 9703 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, |
| 9704 | sizeof(u32) * len, freqs); |
| 9705 | os_free(freqs); |
| 9706 | return ret; |
| 9707 | } |
| 9708 | |
| 9709 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9710 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
| 9711 | { |
| 9712 | struct i802_bss *bss = priv; |
| 9713 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9714 | struct nl_msg *msg; |
| 9715 | struct nlattr *data; |
| 9716 | int ret; |
| 9717 | int mode; |
| 9718 | |
| 9719 | mode = hw_mode_to_qca_acs(params->hw_mode); |
| 9720 | if (mode < 0) |
| 9721 | return -1; |
| 9722 | |
| 9723 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9724 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9725 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9726 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || |
| 9727 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9728 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || |
| 9729 | (params->ht_enabled && |
| 9730 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || |
| 9731 | (params->ht40_enabled && |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 9732 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
| 9733 | (params->vht_enabled && |
| 9734 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || |
| 9735 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, |
| 9736 | params->ch_width) || |
| 9737 | (params->ch_list_len && |
| 9738 | 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] | 9739 | params->ch_list)) || |
| 9740 | add_acs_freq_list(msg, params->freq_list)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9741 | nlmsg_free(msg); |
| 9742 | return -ENOBUFS; |
| 9743 | } |
| 9744 | nla_nest_end(msg, data); |
| 9745 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 9746 | wpa_printf(MSG_DEBUG, |
| 9747 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u", |
| 9748 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
| 9749 | params->vht_enabled, params->ch_width, params->ch_list_len); |
| 9750 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9751 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9752 | if (ret) { |
| 9753 | wpa_printf(MSG_DEBUG, |
| 9754 | "nl80211: Failed to invoke driver ACS function: %s", |
| 9755 | strerror(errno)); |
| 9756 | } |
| 9757 | return ret; |
| 9758 | } |
| 9759 | |
| 9760 | |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 9761 | static int nl80211_set_band(void *priv, enum set_band band) |
| 9762 | { |
| 9763 | struct i802_bss *bss = priv; |
| 9764 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9765 | struct nl_msg *msg; |
| 9766 | struct nlattr *data; |
| 9767 | int ret; |
| 9768 | enum qca_set_band qca_band; |
| 9769 | |
| 9770 | if (!drv->setband_vendor_cmd_avail) |
| 9771 | return -1; |
| 9772 | |
| 9773 | switch (band) { |
| 9774 | case WPA_SETBAND_AUTO: |
| 9775 | qca_band = QCA_SETBAND_AUTO; |
| 9776 | break; |
| 9777 | case WPA_SETBAND_5G: |
| 9778 | qca_band = QCA_SETBAND_5G; |
| 9779 | break; |
| 9780 | case WPA_SETBAND_2G: |
| 9781 | qca_band = QCA_SETBAND_2G; |
| 9782 | break; |
| 9783 | default: |
| 9784 | return -1; |
| 9785 | } |
| 9786 | |
| 9787 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9788 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9789 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9790 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || |
| 9791 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9792 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) { |
| 9793 | nlmsg_free(msg); |
| 9794 | return -ENOBUFS; |
| 9795 | } |
| 9796 | nla_nest_end(msg, data); |
| 9797 | |
| 9798 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9799 | if (ret) { |
| 9800 | wpa_printf(MSG_DEBUG, |
| 9801 | "nl80211: Driver setband function failed: %s", |
| 9802 | strerror(errno)); |
| 9803 | } |
| 9804 | return ret; |
| 9805 | } |
| 9806 | |
| 9807 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9808 | struct nl80211_pcl { |
| 9809 | unsigned int num; |
| 9810 | unsigned int *freq_list; |
| 9811 | }; |
| 9812 | |
| 9813 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) |
| 9814 | { |
| 9815 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9816 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9817 | struct nl80211_pcl *param = arg; |
| 9818 | struct nlattr *nl_vend, *attr; |
| 9819 | enum qca_iface_type iface_type; |
| 9820 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 9821 | unsigned int num, max_num; |
| 9822 | u32 *freqs; |
| 9823 | |
| 9824 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9825 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9826 | |
| 9827 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; |
| 9828 | if (!nl_vend) |
| 9829 | return NL_SKIP; |
| 9830 | |
| 9831 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 9832 | nla_data(nl_vend), nla_len(nl_vend), NULL); |
| 9833 | |
| 9834 | attr = tb_vendor[ |
| 9835 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; |
| 9836 | if (!attr) { |
| 9837 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); |
| 9838 | param->num = 0; |
| 9839 | return NL_SKIP; |
| 9840 | } |
| 9841 | |
| 9842 | iface_type = (enum qca_iface_type) nla_get_u32(attr); |
| 9843 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", |
| 9844 | iface_type); |
| 9845 | |
| 9846 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; |
| 9847 | if (!attr) { |
| 9848 | wpa_printf(MSG_ERROR, |
| 9849 | "nl80211: preferred_freq_list couldn't be found"); |
| 9850 | param->num = 0; |
| 9851 | return NL_SKIP; |
| 9852 | } |
| 9853 | |
| 9854 | /* |
| 9855 | * param->num has the maximum number of entries for which there |
| 9856 | * is room in the freq_list provided by the caller. |
| 9857 | */ |
| 9858 | freqs = nla_data(attr); |
| 9859 | max_num = nla_len(attr) / sizeof(u32); |
| 9860 | if (max_num > param->num) |
| 9861 | max_num = param->num; |
| 9862 | for (num = 0; num < max_num; num++) |
| 9863 | param->freq_list[num] = freqs[num]; |
| 9864 | param->num = num; |
| 9865 | |
| 9866 | return NL_SKIP; |
| 9867 | } |
| 9868 | |
| 9869 | |
| 9870 | static int nl80211_get_pref_freq_list(void *priv, |
| 9871 | enum wpa_driver_if_type if_type, |
| 9872 | unsigned int *num, |
| 9873 | unsigned int *freq_list) |
| 9874 | { |
| 9875 | struct i802_bss *bss = priv; |
| 9876 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9877 | struct nl_msg *msg; |
| 9878 | int ret; |
| 9879 | unsigned int i; |
| 9880 | struct nlattr *params; |
| 9881 | struct nl80211_pcl param; |
| 9882 | enum qca_iface_type iface_type; |
| 9883 | |
| 9884 | if (!drv->get_pref_freq_list) |
| 9885 | return -1; |
| 9886 | |
| 9887 | switch (if_type) { |
| 9888 | case WPA_IF_STATION: |
| 9889 | iface_type = QCA_IFACE_TYPE_STA; |
| 9890 | break; |
| 9891 | case WPA_IF_AP_BSS: |
| 9892 | iface_type = QCA_IFACE_TYPE_AP; |
| 9893 | break; |
| 9894 | case WPA_IF_P2P_GO: |
| 9895 | iface_type = QCA_IFACE_TYPE_P2P_GO; |
| 9896 | break; |
| 9897 | case WPA_IF_P2P_CLIENT: |
| 9898 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; |
| 9899 | break; |
| 9900 | case WPA_IF_IBSS: |
| 9901 | iface_type = QCA_IFACE_TYPE_IBSS; |
| 9902 | break; |
| 9903 | case WPA_IF_TDLS: |
| 9904 | iface_type = QCA_IFACE_TYPE_TDLS; |
| 9905 | break; |
| 9906 | default: |
| 9907 | return -1; |
| 9908 | } |
| 9909 | |
| 9910 | param.num = *num; |
| 9911 | param.freq_list = freq_list; |
| 9912 | |
| 9913 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9914 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || |
| 9915 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9916 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9917 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || |
| 9918 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9919 | nla_put_u32(msg, |
| 9920 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, |
| 9921 | iface_type)) { |
| 9922 | wpa_printf(MSG_ERROR, |
| 9923 | "%s: err in adding vendor_cmd and vendor_data", |
| 9924 | __func__); |
| 9925 | nlmsg_free(msg); |
| 9926 | return -1; |
| 9927 | } |
| 9928 | nla_nest_end(msg, params); |
| 9929 | |
| 9930 | os_memset(freq_list, 0, *num * sizeof(freq_list[0])); |
| 9931 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m); |
| 9932 | if (ret) { |
| 9933 | wpa_printf(MSG_ERROR, |
| 9934 | "%s: err in send_and_recv_msgs", __func__); |
| 9935 | return ret; |
| 9936 | } |
| 9937 | |
| 9938 | *num = param.num; |
| 9939 | |
| 9940 | for (i = 0; i < *num; i++) { |
| 9941 | wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d", |
| 9942 | i, freq_list[i]); |
| 9943 | } |
| 9944 | |
| 9945 | return 0; |
| 9946 | } |
| 9947 | |
| 9948 | |
| 9949 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
| 9950 | { |
| 9951 | struct i802_bss *bss = priv; |
| 9952 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9953 | struct nl_msg *msg; |
| 9954 | int ret; |
| 9955 | struct nlattr *params; |
| 9956 | |
| 9957 | if (!drv->set_prob_oper_freq) |
| 9958 | return -1; |
| 9959 | |
| 9960 | wpa_printf(MSG_DEBUG, |
| 9961 | "nl80211: Set P2P probable operating freq %u for ifindex %d", |
| 9962 | freq, bss->ifindex); |
| 9963 | |
| 9964 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9965 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9966 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9967 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || |
| 9968 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9969 | nla_put_u32(msg, |
| 9970 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, |
| 9971 | QCA_IFACE_TYPE_P2P_CLIENT) || |
| 9972 | nla_put_u32(msg, |
| 9973 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, |
| 9974 | freq)) { |
| 9975 | wpa_printf(MSG_ERROR, |
| 9976 | "%s: err in adding vendor_cmd and vendor_data", |
| 9977 | __func__); |
| 9978 | nlmsg_free(msg); |
| 9979 | return -1; |
| 9980 | } |
| 9981 | nla_nest_end(msg, params); |
| 9982 | |
| 9983 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9984 | msg = NULL; |
| 9985 | if (ret) { |
| 9986 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", |
| 9987 | __func__); |
| 9988 | return ret; |
| 9989 | } |
| 9990 | nlmsg_free(msg); |
| 9991 | return 0; |
| 9992 | } |
| 9993 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 9994 | |
| 9995 | static int nl80211_p2p_lo_start(void *priv, unsigned int freq, |
| 9996 | unsigned int period, unsigned int interval, |
| 9997 | unsigned int count, const u8 *device_types, |
| 9998 | size_t dev_types_len, |
| 9999 | const u8 *ies, size_t ies_len) |
| 10000 | { |
| 10001 | struct i802_bss *bss = priv; |
| 10002 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10003 | struct nl_msg *msg; |
| 10004 | struct nlattr *container; |
| 10005 | int ret; |
| 10006 | |
| 10007 | wpa_printf(MSG_DEBUG, |
| 10008 | "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u", |
| 10009 | freq, period, interval, count); |
| 10010 | |
| 10011 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 10012 | return -1; |
| 10013 | |
| 10014 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10015 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10016 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10017 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START)) |
| 10018 | goto fail; |
| 10019 | |
| 10020 | container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 10021 | if (!container) |
| 10022 | goto fail; |
| 10023 | |
| 10024 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL, |
| 10025 | freq) || |
| 10026 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD, |
| 10027 | period) || |
| 10028 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL, |
| 10029 | interval) || |
| 10030 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT, |
| 10031 | count) || |
| 10032 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES, |
| 10033 | dev_types_len, device_types) || |
| 10034 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE, |
| 10035 | ies_len, ies)) |
| 10036 | goto fail; |
| 10037 | |
| 10038 | nla_nest_end(msg, container); |
| 10039 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10040 | msg = NULL; |
| 10041 | if (ret) { |
| 10042 | wpa_printf(MSG_DEBUG, |
| 10043 | "nl80211: Failed to send P2P Listen offload vendor command"); |
| 10044 | goto fail; |
| 10045 | } |
| 10046 | |
| 10047 | return 0; |
| 10048 | |
| 10049 | fail: |
| 10050 | nlmsg_free(msg); |
| 10051 | return -1; |
| 10052 | } |
| 10053 | |
| 10054 | |
| 10055 | static int nl80211_p2p_lo_stop(void *priv) |
| 10056 | { |
| 10057 | struct i802_bss *bss = priv; |
| 10058 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10059 | struct nl_msg *msg; |
| 10060 | |
| 10061 | wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload"); |
| 10062 | |
| 10063 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 10064 | return -1; |
| 10065 | |
| 10066 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10067 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10068 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10069 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) { |
| 10070 | nlmsg_free(msg); |
| 10071 | return -1; |
| 10072 | } |
| 10073 | |
| 10074 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10075 | } |
| 10076 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 10077 | |
| 10078 | static int nl80211_set_tdls_mode(void *priv, int tdls_external_control) |
| 10079 | { |
| 10080 | struct i802_bss *bss = priv; |
| 10081 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10082 | struct nl_msg *msg; |
| 10083 | struct nlattr *params; |
| 10084 | int ret; |
| 10085 | u32 tdls_mode; |
| 10086 | |
| 10087 | wpa_printf(MSG_DEBUG, |
| 10088 | "nl80211: Set TDKS mode: tdls_external_control=%d", |
| 10089 | tdls_external_control); |
| 10090 | |
| 10091 | if (tdls_external_control == 1) |
| 10092 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT | |
| 10093 | QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL; |
| 10094 | else |
| 10095 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT; |
| 10096 | |
| 10097 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10098 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10099 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10100 | QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS)) |
| 10101 | goto fail; |
| 10102 | |
| 10103 | params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 10104 | if (!params) |
| 10105 | goto fail; |
| 10106 | |
| 10107 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE, |
| 10108 | tdls_mode)) |
| 10109 | goto fail; |
| 10110 | |
| 10111 | nla_nest_end(msg, params); |
| 10112 | |
| 10113 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10114 | msg = NULL; |
| 10115 | if (ret) { |
| 10116 | wpa_printf(MSG_ERROR, |
| 10117 | "nl80211: Set TDLS mode failed: ret=%d (%s)", |
| 10118 | ret, strerror(-ret)); |
| 10119 | goto fail; |
| 10120 | } |
| 10121 | return 0; |
| 10122 | fail: |
| 10123 | nlmsg_free(msg); |
| 10124 | return -1; |
| 10125 | } |
| 10126 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10127 | |
| 10128 | #ifdef CONFIG_MBO |
| 10129 | |
| 10130 | static enum mbo_transition_reject_reason |
| 10131 | nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status) |
| 10132 | { |
| 10133 | switch (status) { |
| 10134 | case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED: |
| 10135 | return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS; |
| 10136 | case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED: |
| 10137 | return MBO_TRANSITION_REJECT_REASON_DELAY; |
| 10138 | case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY: |
| 10139 | return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY; |
| 10140 | case QCA_STATUS_REJECT_LOW_RSSI: |
| 10141 | return MBO_TRANSITION_REJECT_REASON_RSSI; |
| 10142 | case QCA_STATUS_REJECT_HIGH_INTERFERENCE: |
| 10143 | return MBO_TRANSITION_REJECT_REASON_INTERFERENCE; |
| 10144 | case QCA_STATUS_REJECT_UNKNOWN: |
| 10145 | default: |
| 10146 | return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED; |
| 10147 | } |
| 10148 | } |
| 10149 | |
| 10150 | |
| 10151 | static void nl80211_parse_btm_candidate_info(struct candidate_list *candidate, |
| 10152 | struct nlattr *tb[], int num) |
| 10153 | { |
| 10154 | enum qca_wlan_btm_candidate_status status; |
| 10155 | char buf[50]; |
| 10156 | |
| 10157 | os_memcpy(candidate->bssid, |
| 10158 | nla_data(tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID]), |
| 10159 | ETH_ALEN); |
| 10160 | |
| 10161 | status = nla_get_u32( |
| 10162 | tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]); |
| 10163 | candidate->is_accept = status == QCA_STATUS_ACCEPT; |
| 10164 | candidate->reject_reason = nl80211_mbo_reject_reason_mapping(status); |
| 10165 | |
| 10166 | if (candidate->is_accept) |
| 10167 | os_snprintf(buf, sizeof(buf), "Accepted"); |
| 10168 | else |
| 10169 | os_snprintf(buf, sizeof(buf), |
| 10170 | "Rejected, Reject_reason: %d", |
| 10171 | candidate->reject_reason); |
| 10172 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR " %s", |
| 10173 | num, MAC2STR(candidate->bssid), buf); |
| 10174 | } |
| 10175 | |
| 10176 | |
| 10177 | static int |
| 10178 | nl80211_get_bss_transition_status_handler(struct nl_msg *msg, void *arg) |
| 10179 | { |
| 10180 | struct wpa_bss_candidate_info *info = arg; |
| 10181 | struct candidate_list *candidate = info->candidates; |
| 10182 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 10183 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 10184 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1]; |
| 10185 | static struct nla_policy policy[ |
| 10186 | QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1] = { |
| 10187 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] = { |
| 10188 | .minlen = ETH_ALEN |
| 10189 | }, |
| 10190 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS] = { |
| 10191 | .type = NLA_U32, |
| 10192 | }, |
| 10193 | }; |
| 10194 | struct nlattr *attr; |
| 10195 | int rem; |
| 10196 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 10197 | u8 num; |
| 10198 | |
| 10199 | num = info->num; /* number of candidates sent to driver */ |
| 10200 | info->num = 0; |
| 10201 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 10202 | genlmsg_attrlen(gnlh, 0), NULL); |
| 10203 | |
| 10204 | if (!tb_msg[NL80211_ATTR_VENDOR_DATA] || |
| 10205 | nla_parse_nested(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 10206 | tb_msg[NL80211_ATTR_VENDOR_DATA], NULL) || |
| 10207 | !tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO]) |
| 10208 | return NL_SKIP; |
| 10209 | |
| 10210 | wpa_printf(MSG_DEBUG, |
| 10211 | "nl80211: WNM Candidate list received from driver"); |
| 10212 | nla_for_each_nested(attr, |
| 10213 | tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO], |
| 10214 | rem) { |
| 10215 | if (info->num >= num || |
| 10216 | nla_parse_nested( |
| 10217 | tb, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX, |
| 10218 | attr, policy) || |
| 10219 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] || |
| 10220 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]) |
| 10221 | break; |
| 10222 | |
| 10223 | nl80211_parse_btm_candidate_info(candidate, tb, info->num); |
| 10224 | |
| 10225 | candidate++; |
| 10226 | info->num++; |
| 10227 | } |
| 10228 | |
| 10229 | return NL_SKIP; |
| 10230 | } |
| 10231 | |
| 10232 | |
| 10233 | static struct wpa_bss_candidate_info * |
| 10234 | nl80211_get_bss_transition_status(void *priv, struct wpa_bss_trans_info *params) |
| 10235 | { |
| 10236 | struct i802_bss *bss = priv; |
| 10237 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10238 | struct nl_msg *msg; |
| 10239 | struct nlattr *attr, *attr1, *attr2; |
| 10240 | struct wpa_bss_candidate_info *info; |
| 10241 | u8 i; |
| 10242 | int ret; |
| 10243 | u8 *pos; |
| 10244 | |
| 10245 | if (!drv->fetch_bss_trans_status) |
| 10246 | return NULL; |
| 10247 | |
| 10248 | info = os_zalloc(sizeof(*info)); |
| 10249 | if (!info) |
| 10250 | return NULL; |
| 10251 | /* Allocate memory for number of candidates sent to driver */ |
| 10252 | info->candidates = os_calloc(params->n_candidates, |
| 10253 | sizeof(*info->candidates)); |
| 10254 | if (!info->candidates) { |
| 10255 | os_free(info); |
| 10256 | return NULL; |
| 10257 | } |
| 10258 | |
| 10259 | /* Copy the number of candidates being sent to driver. This is used in |
| 10260 | * nl80211_get_bss_transition_status_handler() to limit the number of |
| 10261 | * candidates that can be populated in info->candidates and will be |
| 10262 | * later overwritten with the actual number of candidates received from |
| 10263 | * the driver. |
| 10264 | */ |
| 10265 | info->num = params->n_candidates; |
| 10266 | |
| 10267 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10268 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10269 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10270 | QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS)) |
| 10271 | goto fail; |
| 10272 | |
| 10273 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 10274 | if (!attr) |
| 10275 | goto fail; |
| 10276 | |
| 10277 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON, |
| 10278 | params->mbo_transition_reason)) |
| 10279 | goto fail; |
| 10280 | |
| 10281 | attr1 = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO); |
| 10282 | if (!attr1) |
| 10283 | goto fail; |
| 10284 | |
| 10285 | wpa_printf(MSG_DEBUG, |
| 10286 | "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d", |
| 10287 | params->mbo_transition_reason, params->n_candidates); |
| 10288 | pos = params->bssid; |
| 10289 | for (i = 0; i < params->n_candidates; i++) { |
| 10290 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR, i, |
| 10291 | MAC2STR(pos)); |
| 10292 | attr2 = nla_nest_start(msg, i); |
| 10293 | if (!attr2 || |
| 10294 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID, |
| 10295 | ETH_ALEN, pos)) |
| 10296 | goto fail; |
| 10297 | pos += ETH_ALEN; |
| 10298 | nla_nest_end(msg, attr2); |
| 10299 | } |
| 10300 | |
| 10301 | nla_nest_end(msg, attr1); |
| 10302 | nla_nest_end(msg, attr); |
| 10303 | |
| 10304 | ret = send_and_recv_msgs(drv, msg, |
| 10305 | nl80211_get_bss_transition_status_handler, |
| 10306 | info); |
| 10307 | msg = NULL; |
| 10308 | if (ret) { |
| 10309 | wpa_printf(MSG_ERROR, |
| 10310 | "nl80211: WNM Get BSS transition status failed: ret=%d (%s)", |
| 10311 | ret, strerror(-ret)); |
| 10312 | goto fail; |
| 10313 | } |
| 10314 | return info; |
| 10315 | |
| 10316 | fail: |
| 10317 | nlmsg_free(msg); |
| 10318 | os_free(info->candidates); |
| 10319 | os_free(info); |
| 10320 | return NULL; |
| 10321 | } |
| 10322 | |
| 10323 | |
| 10324 | /** |
| 10325 | * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow |
| 10326 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() |
| 10327 | * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore |
| 10328 | * Returns: 0 on success, -1 on failure |
| 10329 | */ |
| 10330 | static int nl80211_ignore_assoc_disallow(void *priv, int ignore_disallow) |
| 10331 | { |
| 10332 | struct i802_bss *bss = priv; |
| 10333 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10334 | struct nl_msg *msg; |
| 10335 | struct nlattr *attr; |
| 10336 | int ret = -1; |
| 10337 | |
| 10338 | if (!drv->set_wifi_conf_vendor_cmd_avail) |
| 10339 | return -1; |
| 10340 | |
| 10341 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10342 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10343 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10344 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) |
| 10345 | goto fail; |
| 10346 | |
| 10347 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 10348 | if (!attr) |
| 10349 | goto fail; |
| 10350 | |
| 10351 | wpa_printf(MSG_DEBUG, "nl80211: Set ignore_assoc_disallow %d", |
| 10352 | ignore_disallow); |
| 10353 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED, |
| 10354 | ignore_disallow)) |
| 10355 | goto fail; |
| 10356 | |
| 10357 | nla_nest_end(msg, attr); |
| 10358 | |
| 10359 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10360 | msg = NULL; |
| 10361 | if (ret) { |
| 10362 | wpa_printf(MSG_ERROR, |
| 10363 | "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)", |
| 10364 | ret, strerror(-ret)); |
| 10365 | goto fail; |
| 10366 | } |
| 10367 | |
| 10368 | fail: |
| 10369 | nlmsg_free(msg); |
| 10370 | return ret; |
| 10371 | } |
| 10372 | |
| 10373 | #endif /* CONFIG_MBO */ |
| 10374 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10375 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 10376 | |
| 10377 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10378 | static int nl80211_write_to_file(const char *name, unsigned int val) |
| 10379 | { |
| 10380 | int fd, len; |
| 10381 | char tmp[128]; |
| 10382 | |
| 10383 | fd = open(name, O_RDWR); |
| 10384 | if (fd < 0) { |
| 10385 | wpa_printf(MSG_ERROR, "nl80211: Failed to open %s: %s", |
| 10386 | name, strerror(errno)); |
| 10387 | return fd; |
| 10388 | } |
| 10389 | |
| 10390 | len = os_snprintf(tmp, sizeof(tmp), "%u\n", val); |
| 10391 | len = write(fd, tmp, len); |
| 10392 | if (len < 0) |
| 10393 | wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s", |
| 10394 | name, strerror(errno)); |
| 10395 | close(fd); |
| 10396 | |
| 10397 | return 0; |
| 10398 | } |
| 10399 | |
| 10400 | |
| 10401 | static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags) |
| 10402 | { |
| 10403 | struct i802_bss *bss = priv; |
| 10404 | char path[128]; |
| 10405 | int ret; |
| 10406 | |
| 10407 | wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x", |
| 10408 | filter_flags); |
| 10409 | |
| 10410 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 10411 | ret = os_snprintf(path, sizeof(path), |
| 10412 | "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast", |
| 10413 | bss->ifname); |
| 10414 | if (os_snprintf_error(sizeof(path), ret)) |
| 10415 | return -1; |
| 10416 | |
| 10417 | ret = nl80211_write_to_file(path, |
| 10418 | !!(filter_flags & |
| 10419 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 10420 | if (ret) { |
| 10421 | wpa_printf(MSG_ERROR, |
| 10422 | "nl80211: Failed to set IPv4 unicast in multicast filter"); |
| 10423 | return ret; |
| 10424 | } |
| 10425 | |
| 10426 | os_snprintf(path, sizeof(path), |
| 10427 | "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast", |
| 10428 | bss->ifname); |
| 10429 | ret = nl80211_write_to_file(path, |
| 10430 | !!(filter_flags & |
| 10431 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 10432 | |
| 10433 | if (ret) { |
| 10434 | wpa_printf(MSG_ERROR, |
| 10435 | "nl80211: Failed to set IPv6 unicast in multicast filter"); |
| 10436 | return ret; |
| 10437 | } |
| 10438 | |
| 10439 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 10440 | os_snprintf(path, sizeof(path), |
| 10441 | "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp", |
| 10442 | bss->ifname); |
| 10443 | ret = nl80211_write_to_file(path, |
| 10444 | !!(filter_flags & |
| 10445 | WPA_DATA_FRAME_FILTER_FLAG_ARP)); |
| 10446 | if (ret) { |
| 10447 | wpa_printf(MSG_ERROR, |
| 10448 | "nl80211: Failed set gratuitous ARP filter"); |
| 10449 | return ret; |
| 10450 | } |
| 10451 | |
| 10452 | /* Configure filtering of IPv6 NA frames */ |
| 10453 | os_snprintf(path, sizeof(path), |
| 10454 | "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na", |
| 10455 | bss->ifname); |
| 10456 | ret = nl80211_write_to_file(path, |
| 10457 | !!(filter_flags & |
| 10458 | WPA_DATA_FRAME_FILTER_FLAG_NA)); |
| 10459 | if (ret) { |
| 10460 | wpa_printf(MSG_ERROR, |
| 10461 | "nl80211: Failed to set unsolicited NA filter"); |
| 10462 | return ret; |
| 10463 | } |
| 10464 | |
| 10465 | return 0; |
| 10466 | } |
| 10467 | |
| 10468 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 10469 | static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type, |
| 10470 | const u8 **ext_capa, const u8 **ext_capa_mask, |
| 10471 | unsigned int *ext_capa_len) |
| 10472 | { |
| 10473 | struct i802_bss *bss = priv; |
| 10474 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10475 | enum nl80211_iftype nlmode; |
| 10476 | unsigned int i; |
| 10477 | |
| 10478 | if (!ext_capa || !ext_capa_mask || !ext_capa_len) |
| 10479 | return -1; |
| 10480 | |
| 10481 | nlmode = wpa_driver_nl80211_if_type(type); |
| 10482 | |
| 10483 | /* By default, use the per-radio values */ |
| 10484 | *ext_capa = drv->extended_capa; |
| 10485 | *ext_capa_mask = drv->extended_capa_mask; |
| 10486 | *ext_capa_len = drv->extended_capa_len; |
| 10487 | |
| 10488 | /* Replace the default value if a per-interface type value exists */ |
| 10489 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 10490 | if (nlmode == drv->iface_ext_capa[i].iftype) { |
| 10491 | *ext_capa = drv->iface_ext_capa[i].ext_capa; |
| 10492 | *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask; |
| 10493 | *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len; |
| 10494 | break; |
| 10495 | } |
| 10496 | } |
| 10497 | |
| 10498 | return 0; |
| 10499 | } |
| 10500 | |
| 10501 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10502 | static int nl80211_update_connection_params( |
| 10503 | void *priv, struct wpa_driver_associate_params *params, |
| 10504 | enum wpa_drv_update_connect_params_mask mask) |
| 10505 | { |
| 10506 | struct i802_bss *bss = priv; |
| 10507 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10508 | struct nl_msg *msg; |
| 10509 | int ret = -1; |
| 10510 | enum nl80211_auth_type type; |
| 10511 | |
| 10512 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS); |
| 10513 | if (!msg) |
| 10514 | goto fail; |
| 10515 | |
| 10516 | wpa_printf(MSG_DEBUG, "nl80211: Update connection params (ifindex=%d)", |
| 10517 | drv->ifindex); |
| 10518 | |
| 10519 | if ((mask & WPA_DRV_UPDATE_ASSOC_IES) && params->wpa_ie) { |
| 10520 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 10521 | params->wpa_ie)) |
| 10522 | goto fail; |
| 10523 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, |
| 10524 | params->wpa_ie_len); |
| 10525 | } |
| 10526 | |
| 10527 | if (mask & WPA_DRV_UPDATE_AUTH_TYPE) { |
| 10528 | type = get_nl_auth_type(params->auth_alg); |
| 10529 | if (type == NL80211_AUTHTYPE_MAX || |
| 10530 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 10531 | goto fail; |
| 10532 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
| 10533 | } |
| 10534 | |
| 10535 | if ((mask & WPA_DRV_UPDATE_FILS_ERP_INFO) && |
| 10536 | nl80211_put_fils_connect_params(drv, params, msg)) |
| 10537 | goto fail; |
| 10538 | |
| 10539 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10540 | msg = NULL; |
| 10541 | if (ret) |
| 10542 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 10543 | "nl80211: Update connect params command failed: ret=%d (%s)", |
| 10544 | ret, strerror(-ret)); |
| 10545 | |
| 10546 | fail: |
| 10547 | nlmsg_free(msg); |
| 10548 | return ret; |
| 10549 | } |
| 10550 | |
| 10551 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10552 | static int nl80211_send_external_auth_status(void *priv, |
| 10553 | struct external_auth *params) |
| 10554 | { |
| 10555 | struct i802_bss *bss = priv; |
| 10556 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10557 | struct nl_msg *msg = NULL; |
| 10558 | int ret = -1; |
| 10559 | |
| 10560 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 10561 | "nl80211: External auth status: %u", params->status); |
| 10562 | |
| 10563 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_EXTERNAL_AUTH); |
| 10564 | if (!msg || |
| 10565 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, params->status) || |
| 10566 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 10567 | params->ssid) || |
| 10568 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid)) |
| 10569 | goto fail; |
| 10570 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10571 | msg = NULL; |
| 10572 | if (ret) { |
| 10573 | wpa_printf(MSG_DEBUG, |
| 10574 | "nl80211: External Auth status update failed: ret=%d (%s)", |
| 10575 | ret, strerror(-ret)); |
| 10576 | goto fail; |
| 10577 | } |
| 10578 | fail: |
| 10579 | nlmsg_free(msg); |
| 10580 | return ret; |
| 10581 | } |
| 10582 | |
| 10583 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10584 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 10585 | .name = "nl80211", |
| 10586 | .desc = "Linux nl80211/cfg80211", |
| 10587 | .get_bssid = wpa_driver_nl80211_get_bssid, |
| 10588 | .get_ssid = wpa_driver_nl80211_get_ssid, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10589 | .set_key = driver_nl80211_set_key, |
| 10590 | .scan2 = driver_nl80211_scan2, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10591 | .sched_scan = wpa_driver_nl80211_sched_scan, |
| 10592 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10593 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 10594 | .abort_scan = wpa_driver_nl80211_abort_scan, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10595 | .deauthenticate = driver_nl80211_deauthenticate, |
| 10596 | .authenticate = driver_nl80211_authenticate, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10597 | .associate = wpa_driver_nl80211_associate, |
| 10598 | .global_init = nl80211_global_init, |
| 10599 | .global_deinit = nl80211_global_deinit, |
| 10600 | .init2 = wpa_driver_nl80211_init, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10601 | .deinit = driver_nl80211_deinit, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10602 | .get_capa = wpa_driver_nl80211_get_capa, |
| 10603 | .set_operstate = wpa_driver_nl80211_set_operstate, |
| 10604 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
| 10605 | .set_country = wpa_driver_nl80211_set_country, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 10606 | .get_country = wpa_driver_nl80211_get_country, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10607 | .set_ap = wpa_driver_nl80211_set_ap, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 10608 | .set_acl = wpa_driver_nl80211_set_acl, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10609 | .if_add = wpa_driver_nl80211_if_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10610 | .if_remove = driver_nl80211_if_remove, |
| 10611 | .send_mlme = driver_nl80211_send_mlme, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10612 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10613 | .sta_add = wpa_driver_nl80211_sta_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10614 | .sta_remove = driver_nl80211_sta_remove, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10615 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
| 10616 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10617 | .hapd_init = i802_init, |
| 10618 | .hapd_deinit = i802_deinit, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10619 | .set_wds_sta = i802_set_wds_sta, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10620 | .get_seqnum = i802_get_seqnum, |
| 10621 | .flush = i802_flush, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10622 | .get_inact_sec = i802_get_inact_sec, |
| 10623 | .sta_clear_stats = i802_sta_clear_stats, |
| 10624 | .set_rts = i802_set_rts, |
| 10625 | .set_frag = i802_set_frag, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10626 | .set_tx_queue_params = i802_set_tx_queue_params, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10627 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10628 | .sta_deauth = i802_sta_deauth, |
| 10629 | .sta_disassoc = i802_sta_disassoc, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10630 | .read_sta_data = driver_nl80211_read_sta_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10631 | .set_freq = i802_set_freq, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10632 | .send_action = driver_nl80211_send_action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10633 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
| 10634 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
| 10635 | .cancel_remain_on_channel = |
| 10636 | wpa_driver_nl80211_cancel_remain_on_channel, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10637 | .probe_req_report = driver_nl80211_probe_req_report, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10638 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 10639 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10640 | .resume = wpa_driver_nl80211_resume, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10641 | .signal_monitor = nl80211_signal_monitor, |
| 10642 | .signal_poll = nl80211_signal_poll, |
| 10643 | .send_frame = nl80211_send_frame, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10644 | .set_param = nl80211_set_param, |
| 10645 | .get_radio_name = nl80211_get_radio_name, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10646 | .add_pmkid = nl80211_add_pmkid, |
| 10647 | .remove_pmkid = nl80211_remove_pmkid, |
| 10648 | .flush_pmkid = nl80211_flush_pmkid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10649 | .set_rekey_info = nl80211_set_rekey_info, |
| 10650 | .poll_client = nl80211_poll_client, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10651 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 10652 | .start_dfs_cac = nl80211_start_radar_detection, |
| 10653 | .stop_ap = wpa_driver_nl80211_stop_ap, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10654 | #ifdef CONFIG_TDLS |
| 10655 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, |
| 10656 | .tdls_oper = nl80211_tdls_oper, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10657 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
| 10658 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10659 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 10660 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 10661 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10662 | .get_survey = wpa_driver_nl80211_get_survey, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10663 | .status = wpa_driver_nl80211_status, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10664 | .switch_channel = nl80211_switch_channel, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10665 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 10666 | .set_noa = wpa_driver_set_p2p_noa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10667 | .get_noa = wpa_driver_get_p2p_noa, |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 10668 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 10669 | #endif /* ANDROID_P2P */ |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 10670 | #ifdef ANDROID |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 10671 | #ifndef ANDROID_LIB_STUB |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 10672 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 10673 | #endif /* !ANDROID_LIB_STUB */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 10674 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10675 | .vendor_cmd = nl80211_vendor_cmd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10676 | .set_qos_map = nl80211_set_qos_map, |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 10677 | .set_wowlan = nl80211_set_wowlan, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10678 | .set_mac_addr = nl80211_set_mac_addr, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10679 | #ifdef CONFIG_MESH |
| 10680 | .init_mesh = wpa_driver_nl80211_init_mesh, |
| 10681 | .join_mesh = wpa_driver_nl80211_join_mesh, |
| 10682 | .leave_mesh = wpa_driver_nl80211_leave_mesh, |
| 10683 | #endif /* CONFIG_MESH */ |
| 10684 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
| 10685 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, |
| 10686 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
| 10687 | .br_set_net_param = wpa_driver_br_set_net_param, |
| 10688 | .add_tx_ts = nl80211_add_ts, |
| 10689 | .del_tx_ts = nl80211_del_ts, |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 10690 | .get_ifindex = nl80211_get_ifindex, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10691 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 10692 | .roaming = nl80211_roaming, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10693 | .disable_fils = nl80211_disable_fils, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10694 | .do_acs = wpa_driver_do_acs, |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 10695 | .set_band = nl80211_set_band, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10696 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
| 10697 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 10698 | .p2p_lo_start = nl80211_p2p_lo_start, |
| 10699 | .p2p_lo_stop = nl80211_p2p_lo_stop, |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 10700 | .set_default_scan_ies = nl80211_set_default_scan_ies, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 10701 | .set_tdls_mode = nl80211_set_tdls_mode, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10702 | #ifdef CONFIG_MBO |
| 10703 | .get_bss_transition_status = nl80211_get_bss_transition_status, |
| 10704 | .ignore_assoc_disallow = nl80211_ignore_assoc_disallow, |
| 10705 | #endif /* CONFIG_MBO */ |
| 10706 | .set_bssid_blacklist = nl80211_set_bssid_blacklist, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10707 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10708 | .configure_data_frame_filters = nl80211_configure_data_frame_filters, |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 10709 | .get_ext_capab = nl80211_get_ext_capab, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10710 | .update_connect_params = nl80211_update_connection_params, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10711 | .send_external_auth_status = nl80211_send_external_auth_status, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10712 | }; |