Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Driver interaction with Linux nl80211/cfg80211 |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 3 | * Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4 | * Copyright (c) 2003-2004, Instant802 Networks, Inc. |
| 5 | * Copyright (c) 2005-2006, Devicescape Software, Inc. |
| 6 | * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net> |
| 7 | * Copyright (c) 2009-2010, Atheros Communications |
| 8 | * |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 9 | * This software may be distributed under the terms of the BSD license. |
| 10 | * See README for more details. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include "includes.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 14 | #include <sys/types.h> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 15 | #include <fcntl.h> |
| 16 | #include <net/if.h> |
| 17 | #include <netlink/genl/genl.h> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 18 | #include <netlink/genl/ctrl.h> |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 19 | #ifdef CONFIG_LIBNL3_ROUTE |
| 20 | #include <netlink/route/neighbour.h> |
| 21 | #endif /* CONFIG_LIBNL3_ROUTE */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 22 | #include <linux/rtnetlink.h> |
| 23 | #include <netpacket/packet.h> |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 24 | #include <linux/errqueue.h> |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 25 | |
| 26 | #include "common.h" |
| 27 | #include "eloop.h" |
Dmitry Shmidt | cf32e60 | 2014-01-28 10:57:39 -0800 | [diff] [blame] | 28 | #include "common/qca-vendor.h" |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 29 | #include "common/qca-vendor-attr.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 30 | #include "common/ieee802_11_defs.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 31 | #include "common/ieee802_11_common.h" |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 32 | #include "common/wpa_common.h" |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 33 | #include "l2_packet/l2_packet.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 34 | #include "netlink.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 35 | #include "linux_defines.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 36 | #include "linux_ioctl.h" |
| 37 | #include "radiotap.h" |
| 38 | #include "radiotap_iter.h" |
| 39 | #include "rfkill.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 40 | #include "driver_nl80211.h" |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 41 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 42 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame^] | 43 | /* support for extack if compilation headers are too old */ |
| 44 | #ifndef NETLINK_EXT_ACK |
| 45 | #define NETLINK_EXT_ACK 11 |
| 46 | enum nlmsgerr_attrs { |
| 47 | NLMSGERR_ATTR_UNUSED, |
| 48 | NLMSGERR_ATTR_MSG, |
| 49 | NLMSGERR_ATTR_OFFS, |
| 50 | NLMSGERR_ATTR_COOKIE, |
| 51 | |
| 52 | __NLMSGERR_ATTR_MAX, |
| 53 | NLMSGERR_ATTR_MAX = __NLMSGERR_ATTR_MAX - 1 |
| 54 | }; |
| 55 | #endif |
| 56 | #ifndef NLM_F_CAPPED |
| 57 | #define NLM_F_CAPPED 0x100 |
| 58 | #endif |
| 59 | #ifndef NLM_F_ACK_TLVS |
| 60 | #define NLM_F_ACK_TLVS 0x200 |
| 61 | #endif |
| 62 | #ifndef SOL_NETLINK |
| 63 | #define SOL_NETLINK 270 |
| 64 | #endif |
| 65 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 66 | #ifndef CONFIG_LIBNL20 |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 67 | /* |
| 68 | * libnl 1.1 has a bug, it tries to allocate socket numbers densely |
| 69 | * but when you free a socket again it will mess up its bitmap and |
| 70 | * and use the wrong number the next time it needs a socket ID. |
| 71 | * Therefore, we wrap the handle alloc/destroy and add our own pid |
| 72 | * accounting. |
| 73 | */ |
| 74 | static uint32_t port_bitmap[32] = { 0 }; |
| 75 | |
| 76 | static struct nl_handle *nl80211_handle_alloc(void *cb) |
| 77 | { |
| 78 | struct nl_handle *handle; |
| 79 | uint32_t pid = getpid() & 0x3FFFFF; |
| 80 | int i; |
| 81 | |
| 82 | handle = nl_handle_alloc_cb(cb); |
| 83 | |
| 84 | for (i = 0; i < 1024; i++) { |
| 85 | if (port_bitmap[i / 32] & (1 << (i % 32))) |
| 86 | continue; |
| 87 | port_bitmap[i / 32] |= 1 << (i % 32); |
| 88 | pid += i << 22; |
| 89 | break; |
| 90 | } |
| 91 | |
| 92 | nl_socket_set_local_port(handle, pid); |
| 93 | |
| 94 | return handle; |
| 95 | } |
| 96 | |
| 97 | static void nl80211_handle_destroy(struct nl_handle *handle) |
| 98 | { |
| 99 | uint32_t port = nl_socket_get_local_port(handle); |
| 100 | |
| 101 | port >>= 22; |
| 102 | port_bitmap[port / 32] &= ~(1 << (port % 32)); |
| 103 | |
| 104 | nl_handle_destroy(handle); |
| 105 | } |
| 106 | #endif /* CONFIG_LIBNL20 */ |
| 107 | |
| 108 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 109 | #ifdef ANDROID |
| 110 | /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */ |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 111 | #undef nl_socket_set_nonblocking |
| 112 | #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 113 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 114 | #endif /* ANDROID */ |
| 115 | |
| 116 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 117 | static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg) |
| 118 | { |
| 119 | struct nl_handle *handle; |
| 120 | |
| 121 | handle = nl80211_handle_alloc(cb); |
| 122 | if (handle == NULL) { |
| 123 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 124 | "callbacks (%s)", dbg); |
| 125 | return NULL; |
| 126 | } |
| 127 | |
| 128 | if (genl_connect(handle)) { |
| 129 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " |
| 130 | "netlink (%s)", dbg); |
| 131 | nl80211_handle_destroy(handle); |
| 132 | return NULL; |
| 133 | } |
| 134 | |
| 135 | return handle; |
| 136 | } |
| 137 | |
| 138 | |
| 139 | static void nl_destroy_handles(struct nl_handle **handle) |
| 140 | { |
| 141 | if (*handle == NULL) |
| 142 | return; |
| 143 | nl80211_handle_destroy(*handle); |
| 144 | *handle = NULL; |
| 145 | } |
| 146 | |
| 147 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 148 | #if __WORDSIZE == 64 |
| 149 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL |
| 150 | #else |
| 151 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL |
| 152 | #endif |
| 153 | |
| 154 | static void nl80211_register_eloop_read(struct nl_handle **handle, |
| 155 | eloop_sock_handler handler, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 156 | void *eloop_data, int persist) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 157 | { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 158 | #ifdef CONFIG_LIBNL20 |
| 159 | /* |
| 160 | * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB) |
| 161 | * by default. It is possible to hit that limit in some cases where |
| 162 | * operations are blocked, e.g., with a burst of Deauthentication frames |
| 163 | * to hostapd and STA entry deletion. Try to increase the buffer to make |
| 164 | * this less likely to occur. |
| 165 | */ |
| 166 | if (nl_socket_set_buffer_size(*handle, 262144, 0) < 0) { |
| 167 | wpa_printf(MSG_DEBUG, |
| 168 | "nl80211: Could not set nl_socket RX buffer size: %s", |
| 169 | strerror(errno)); |
| 170 | /* continue anyway with the default (smaller) buffer */ |
| 171 | } |
| 172 | #endif /* CONFIG_LIBNL20 */ |
| 173 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 174 | nl_socket_set_nonblocking(*handle); |
| 175 | eloop_register_read_sock(nl_socket_get_fd(*handle), handler, |
| 176 | eloop_data, *handle); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 177 | if (!persist) |
| 178 | *handle = (void *) (((intptr_t) *handle) ^ |
| 179 | ELOOP_SOCKET_INVALID); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 183 | static void nl80211_destroy_eloop_handle(struct nl_handle **handle, int persist) |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 184 | { |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 185 | if (!persist) |
| 186 | *handle = (void *) (((intptr_t) *handle) ^ |
| 187 | ELOOP_SOCKET_INVALID); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 188 | eloop_unregister_read_sock(nl_socket_get_fd(*handle)); |
| 189 | nl_destroy_handles(handle); |
| 190 | } |
| 191 | |
| 192 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 193 | static void nl80211_global_deinit(void *priv); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 194 | static void nl80211_check_global(struct nl80211_global *global); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 195 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 196 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 197 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 198 | struct hostapd_freq_params *freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 199 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 200 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 201 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 202 | const u8 *set_addr, int first, |
| 203 | const char *driver_params); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 204 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 205 | unsigned int freq, unsigned int wait, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 206 | const u8 *buf, size_t buf_len, u64 *cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 207 | int no_cck, int no_ack, int offchanok, |
| 208 | const u16 *csa_offs, size_t csa_offs_len); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 209 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, |
| 210 | int report); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 211 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 212 | #define IFIDX_ANY -1 |
| 213 | |
| 214 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 215 | int ifidx_reason); |
| 216 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 217 | int ifidx_reason); |
| 218 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 219 | int ifidx_reason); |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 220 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 221 | static int nl80211_set_channel(struct i802_bss *bss, |
| 222 | struct hostapd_freq_params *freq, int set_chan); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 223 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 224 | int ifindex, int disabled); |
| 225 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 226 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 227 | int reset_mode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 228 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 229 | static int i802_set_iface_flags(struct i802_bss *bss, int up); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 230 | static int nl80211_set_param(void *priv, const char *param); |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 231 | #ifdef CONFIG_MESH |
| 232 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
| 233 | struct wpa_driver_mesh_bss_params *params); |
| 234 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 235 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
| 236 | int reason); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 237 | |
| 238 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 239 | /* Converts nl80211_chan_width to a common format */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 240 | enum chan_width convert2width(int width) |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 241 | { |
| 242 | switch (width) { |
| 243 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 244 | return CHAN_WIDTH_20_NOHT; |
| 245 | case NL80211_CHAN_WIDTH_20: |
| 246 | return CHAN_WIDTH_20; |
| 247 | case NL80211_CHAN_WIDTH_40: |
| 248 | return CHAN_WIDTH_40; |
| 249 | case NL80211_CHAN_WIDTH_80: |
| 250 | return CHAN_WIDTH_80; |
| 251 | case NL80211_CHAN_WIDTH_80P80: |
| 252 | return CHAN_WIDTH_80P80; |
| 253 | case NL80211_CHAN_WIDTH_160: |
| 254 | return CHAN_WIDTH_160; |
| 255 | } |
| 256 | return CHAN_WIDTH_UNKNOWN; |
| 257 | } |
| 258 | |
| 259 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 260 | int is_ap_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 261 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 262 | return nlmode == NL80211_IFTYPE_AP || |
| 263 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 267 | int is_sta_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 268 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 269 | return nlmode == NL80211_IFTYPE_STATION || |
| 270 | nlmode == NL80211_IFTYPE_P2P_CLIENT; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 274 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 275 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 276 | return nlmode == NL80211_IFTYPE_P2P_CLIENT || |
| 277 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 278 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 279 | |
| 280 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 281 | struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, |
| 282 | int ifindex) |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 283 | { |
| 284 | struct i802_bss *bss; |
| 285 | |
| 286 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 287 | if (bss->ifindex == ifindex) |
| 288 | return bss; |
| 289 | } |
| 290 | |
| 291 | return NULL; |
| 292 | } |
| 293 | |
| 294 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 295 | static int is_mesh_interface(enum nl80211_iftype nlmode) |
| 296 | { |
| 297 | return nlmode == NL80211_IFTYPE_MESH_POINT; |
| 298 | } |
| 299 | |
| 300 | |
| 301 | void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 302 | { |
| 303 | if (drv->associated) |
| 304 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); |
| 305 | drv->associated = 0; |
| 306 | os_memset(drv->bssid, 0, ETH_ALEN); |
| 307 | } |
| 308 | |
| 309 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 310 | /* nl80211 code */ |
| 311 | static int ack_handler(struct nl_msg *msg, void *arg) |
| 312 | { |
| 313 | int *err = arg; |
| 314 | *err = 0; |
| 315 | return NL_STOP; |
| 316 | } |
| 317 | |
| 318 | static int finish_handler(struct nl_msg *msg, void *arg) |
| 319 | { |
| 320 | int *ret = arg; |
| 321 | *ret = 0; |
| 322 | return NL_SKIP; |
| 323 | } |
| 324 | |
| 325 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, |
| 326 | void *arg) |
| 327 | { |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame^] | 328 | struct nlmsghdr *nlh = (struct nlmsghdr *) err - 1; |
| 329 | int len = nlh->nlmsg_len; |
| 330 | struct nlattr *attrs; |
| 331 | struct nlattr *tb[NLMSGERR_ATTR_MAX + 1]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 332 | int *ret = arg; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame^] | 333 | int ack_len = sizeof(*nlh) + sizeof(int) + sizeof(*nlh); |
| 334 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 335 | *ret = err->error; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame^] | 336 | |
| 337 | if (!(nlh->nlmsg_flags & NLM_F_ACK_TLVS)) |
| 338 | return NL_SKIP; |
| 339 | |
| 340 | if (!(nlh->nlmsg_flags & NLM_F_CAPPED)) |
| 341 | ack_len += err->msg.nlmsg_len - sizeof(*nlh); |
| 342 | |
| 343 | if (len <= ack_len) |
| 344 | return NL_STOP; |
| 345 | |
| 346 | attrs = (void *) ((unsigned char *) nlh + ack_len); |
| 347 | len -= ack_len; |
| 348 | |
| 349 | nla_parse(tb, NLMSGERR_ATTR_MAX, attrs, len, NULL); |
| 350 | if (tb[NLMSGERR_ATTR_MSG]) { |
| 351 | len = strnlen((char *) nla_data(tb[NLMSGERR_ATTR_MSG]), |
| 352 | nla_len(tb[NLMSGERR_ATTR_MSG])); |
| 353 | wpa_printf(MSG_ERROR, "nl80211: kernel reports: %*s", |
| 354 | len, (char *) nla_data(tb[NLMSGERR_ATTR_MSG])); |
| 355 | } |
| 356 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 357 | return NL_SKIP; |
| 358 | } |
| 359 | |
| 360 | |
| 361 | static int no_seq_check(struct nl_msg *msg, void *arg) |
| 362 | { |
| 363 | return NL_OK; |
| 364 | } |
| 365 | |
| 366 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 367 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
| 368 | { |
| 369 | /* |
| 370 | * Clear nlmsg data, e.g., to make sure key material is not left in |
| 371 | * heap memory for unnecessarily long time. |
| 372 | */ |
| 373 | if (msg) { |
| 374 | struct nlmsghdr *hdr = nlmsg_hdr(msg); |
| 375 | void *data = nlmsg_data(hdr); |
| 376 | /* |
| 377 | * This would use nlmsg_datalen() or the older nlmsg_len() if |
| 378 | * only libnl were to maintain a stable API.. Neither will work |
| 379 | * with all released versions, so just calculate the length |
| 380 | * here. |
| 381 | */ |
| 382 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; |
| 383 | |
| 384 | os_memset(data, 0, len); |
| 385 | } |
| 386 | } |
| 387 | |
| 388 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 389 | static int send_and_recv(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 390 | struct nl_handle *nl_handle, struct nl_msg *msg, |
| 391 | int (*valid_handler)(struct nl_msg *, void *), |
| 392 | void *valid_data) |
| 393 | { |
| 394 | struct nl_cb *cb; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame^] | 395 | int err = -ENOMEM, opt; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 396 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 397 | if (!msg) |
| 398 | return -ENOMEM; |
| 399 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 400 | cb = nl_cb_clone(global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 401 | if (!cb) |
| 402 | goto out; |
| 403 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame^] | 404 | /* try to set NETLINK_EXT_ACK to 1, ignoring errors */ |
| 405 | opt = 1; |
| 406 | setsockopt(nl_socket_get_fd(nl_handle), SOL_NETLINK, |
| 407 | NETLINK_EXT_ACK, &opt, sizeof(opt)); |
| 408 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 409 | err = nl_send_auto_complete(nl_handle, msg); |
| 410 | if (err < 0) |
| 411 | goto out; |
| 412 | |
| 413 | err = 1; |
| 414 | |
| 415 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); |
| 416 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
| 417 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
| 418 | |
| 419 | if (valid_handler) |
| 420 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 421 | valid_handler, valid_data); |
| 422 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 423 | while (err > 0) { |
| 424 | int res = nl_recvmsgs(nl_handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 425 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 426 | wpa_printf(MSG_INFO, |
| 427 | "nl80211: %s->nl_recvmsgs failed: %d", |
| 428 | __func__, res); |
| 429 | } |
| 430 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 431 | out: |
| 432 | nl_cb_put(cb); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 433 | if (!valid_handler && valid_data == (void *) -1) |
| 434 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 435 | nlmsg_free(msg); |
| 436 | return err; |
| 437 | } |
| 438 | |
| 439 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 440 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
| 441 | struct nl_msg *msg, |
| 442 | int (*valid_handler)(struct nl_msg *, void *), |
| 443 | void *valid_data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 444 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 445 | return send_and_recv(drv->global, drv->global->nl, msg, |
| 446 | valid_handler, valid_data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | |
| 450 | struct family_data { |
| 451 | const char *group; |
| 452 | int id; |
| 453 | }; |
| 454 | |
| 455 | |
| 456 | static int family_handler(struct nl_msg *msg, void *arg) |
| 457 | { |
| 458 | struct family_data *res = arg; |
| 459 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; |
| 460 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 461 | struct nlattr *mcgrp; |
| 462 | int i; |
| 463 | |
| 464 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 465 | genlmsg_attrlen(gnlh, 0), NULL); |
| 466 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) |
| 467 | return NL_SKIP; |
| 468 | |
| 469 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { |
| 470 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; |
| 471 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), |
| 472 | nla_len(mcgrp), NULL); |
| 473 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || |
| 474 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || |
| 475 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), |
| 476 | res->group, |
| 477 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) |
| 478 | continue; |
| 479 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); |
| 480 | break; |
| 481 | }; |
| 482 | |
| 483 | return NL_SKIP; |
| 484 | } |
| 485 | |
| 486 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 487 | static int nl_get_multicast_id(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 488 | const char *family, const char *group) |
| 489 | { |
| 490 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 491 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 492 | struct family_data res = { group, -ENOENT }; |
| 493 | |
| 494 | msg = nlmsg_alloc(); |
| 495 | if (!msg) |
| 496 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 497 | if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
| 498 | 0, 0, CTRL_CMD_GETFAMILY, 0) || |
| 499 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { |
| 500 | nlmsg_free(msg); |
| 501 | return -1; |
| 502 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 503 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 504 | ret = send_and_recv(global, global->nl, msg, family_handler, &res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 505 | if (ret == 0) |
| 506 | ret = res.id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 507 | return ret; |
| 508 | } |
| 509 | |
| 510 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 511 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
| 512 | struct nl_msg *msg, int flags, uint8_t cmd) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 513 | { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 514 | if (TEST_FAIL()) |
| 515 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 516 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
| 517 | 0, flags, cmd, 0); |
| 518 | } |
| 519 | |
| 520 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 521 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
| 522 | { |
| 523 | if (bss->wdev_id_set) |
| 524 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); |
| 525 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 526 | } |
| 527 | |
| 528 | |
| 529 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 530 | { |
| 531 | struct nl_msg *msg; |
| 532 | |
| 533 | msg = nlmsg_alloc(); |
| 534 | if (!msg) |
| 535 | return NULL; |
| 536 | |
| 537 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || |
| 538 | nl80211_set_iface_id(msg, bss) < 0) { |
| 539 | nlmsg_free(msg); |
| 540 | return NULL; |
| 541 | } |
| 542 | |
| 543 | return msg; |
| 544 | } |
| 545 | |
| 546 | |
| 547 | static struct nl_msg * |
| 548 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, |
| 549 | int flags, uint8_t cmd) |
| 550 | { |
| 551 | struct nl_msg *msg; |
| 552 | |
| 553 | msg = nlmsg_alloc(); |
| 554 | if (!msg) |
| 555 | return NULL; |
| 556 | |
| 557 | if (!nl80211_cmd(drv, msg, flags, cmd) || |
| 558 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { |
| 559 | nlmsg_free(msg); |
| 560 | return NULL; |
| 561 | } |
| 562 | |
| 563 | return msg; |
| 564 | } |
| 565 | |
| 566 | |
| 567 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, |
| 568 | uint8_t cmd) |
| 569 | { |
| 570 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); |
| 571 | } |
| 572 | |
| 573 | |
| 574 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 575 | { |
| 576 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); |
| 577 | } |
| 578 | |
| 579 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 580 | struct wiphy_idx_data { |
| 581 | int wiphy_idx; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 582 | enum nl80211_iftype nlmode; |
| 583 | u8 *macaddr; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 584 | }; |
| 585 | |
| 586 | |
| 587 | static int netdev_info_handler(struct nl_msg *msg, void *arg) |
| 588 | { |
| 589 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 590 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 591 | struct wiphy_idx_data *info = arg; |
| 592 | |
| 593 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 594 | genlmsg_attrlen(gnlh, 0), NULL); |
| 595 | |
| 596 | if (tb[NL80211_ATTR_WIPHY]) |
| 597 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 598 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 599 | if (tb[NL80211_ATTR_IFTYPE]) |
| 600 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); |
| 601 | |
| 602 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
| 603 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 604 | ETH_ALEN); |
| 605 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 606 | return NL_SKIP; |
| 607 | } |
| 608 | |
| 609 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 610 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 611 | { |
| 612 | struct nl_msg *msg; |
| 613 | struct wiphy_idx_data data = { |
| 614 | .wiphy_idx = -1, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 615 | .macaddr = NULL, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 616 | }; |
| 617 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 618 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 619 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 620 | |
| 621 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) |
| 622 | return data.wiphy_idx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 623 | return -1; |
| 624 | } |
| 625 | |
| 626 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 627 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
| 628 | { |
| 629 | struct nl_msg *msg; |
| 630 | struct wiphy_idx_data data = { |
| 631 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
| 632 | .macaddr = NULL, |
| 633 | }; |
| 634 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 635 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 636 | return NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 637 | |
| 638 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) |
| 639 | return data.nlmode; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 640 | return NL80211_IFTYPE_UNSPECIFIED; |
| 641 | } |
| 642 | |
| 643 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 644 | static int nl80211_get_macaddr(struct i802_bss *bss) |
| 645 | { |
| 646 | struct nl_msg *msg; |
| 647 | struct wiphy_idx_data data = { |
| 648 | .macaddr = bss->addr, |
| 649 | }; |
| 650 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 651 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 652 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 653 | |
| 654 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 655 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 656 | |
| 657 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 658 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
| 659 | struct nl80211_wiphy_data *w) |
| 660 | { |
| 661 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 662 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 663 | |
| 664 | msg = nlmsg_alloc(); |
| 665 | if (!msg) |
| 666 | return -1; |
| 667 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 668 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
| 669 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { |
| 670 | nlmsg_free(msg); |
| 671 | return -1; |
| 672 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 673 | |
| 674 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 675 | if (ret) { |
| 676 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " |
| 677 | "failed: ret=%d (%s)", |
| 678 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 679 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 680 | return ret; |
| 681 | } |
| 682 | |
| 683 | |
| 684 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) |
| 685 | { |
| 686 | struct nl80211_wiphy_data *w = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 687 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 688 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 689 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 690 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 691 | res = nl_recvmsgs(handle, w->nl_cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 692 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 693 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 694 | __func__, res); |
| 695 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | |
| 699 | static int process_beacon_event(struct nl_msg *msg, void *arg) |
| 700 | { |
| 701 | struct nl80211_wiphy_data *w = arg; |
| 702 | struct wpa_driver_nl80211_data *drv; |
| 703 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 704 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 705 | union wpa_event_data event; |
| 706 | |
| 707 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 708 | genlmsg_attrlen(gnlh, 0), NULL); |
| 709 | |
| 710 | if (gnlh->cmd != NL80211_CMD_FRAME) { |
| 711 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", |
| 712 | gnlh->cmd); |
| 713 | return NL_SKIP; |
| 714 | } |
| 715 | |
| 716 | if (!tb[NL80211_ATTR_FRAME]) |
| 717 | return NL_SKIP; |
| 718 | |
| 719 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, |
| 720 | wiphy_list) { |
| 721 | os_memset(&event, 0, sizeof(event)); |
| 722 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); |
| 723 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); |
| 724 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
| 725 | } |
| 726 | |
| 727 | return NL_SKIP; |
| 728 | } |
| 729 | |
| 730 | |
| 731 | static struct nl80211_wiphy_data * |
| 732 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) |
| 733 | { |
| 734 | static DEFINE_DL_LIST(nl80211_wiphys); |
| 735 | struct nl80211_wiphy_data *w; |
| 736 | int wiphy_idx, found = 0; |
| 737 | struct i802_bss *tmp_bss; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 738 | u8 channel; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 739 | |
| 740 | if (bss->wiphy_data != NULL) |
| 741 | return bss->wiphy_data; |
| 742 | |
| 743 | wiphy_idx = nl80211_get_wiphy_index(bss); |
| 744 | |
| 745 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { |
| 746 | if (w->wiphy_idx == wiphy_idx) |
| 747 | goto add; |
| 748 | } |
| 749 | |
| 750 | /* alloc new one */ |
| 751 | w = os_zalloc(sizeof(*w)); |
| 752 | if (w == NULL) |
| 753 | return NULL; |
| 754 | w->wiphy_idx = wiphy_idx; |
| 755 | dl_list_init(&w->bsss); |
| 756 | dl_list_init(&w->drvs); |
| 757 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 758 | /* Beacon frames not supported in IEEE 802.11ad */ |
| 759 | if (ieee80211_freq_to_chan(bss->freq, &channel) != |
| 760 | HOSTAPD_MODE_IEEE80211AD) { |
| 761 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 762 | if (!w->nl_cb) { |
| 763 | os_free(w); |
| 764 | return NULL; |
| 765 | } |
| 766 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 767 | no_seq_check, NULL); |
| 768 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 769 | process_beacon_event, w); |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 770 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 771 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, |
| 772 | "wiphy beacons"); |
| 773 | if (w->nl_beacons == NULL) { |
| 774 | os_free(w); |
| 775 | return NULL; |
| 776 | } |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 777 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 778 | if (nl80211_register_beacons(bss->drv, w)) { |
| 779 | nl_destroy_handles(&w->nl_beacons); |
| 780 | os_free(w); |
| 781 | return NULL; |
| 782 | } |
Rebecca Silberstein | 055a67c | 2017-02-01 23:05:56 +0000 | [diff] [blame] | 783 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 784 | nl80211_register_eloop_read(&w->nl_beacons, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 785 | nl80211_recv_beacons, w, 0); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 786 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 787 | |
| 788 | dl_list_add(&nl80211_wiphys, &w->list); |
| 789 | |
| 790 | add: |
| 791 | /* drv entry for this bss already there? */ |
| 792 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 793 | if (tmp_bss->drv == bss->drv) { |
| 794 | found = 1; |
| 795 | break; |
| 796 | } |
| 797 | } |
| 798 | /* if not add it */ |
| 799 | if (!found) |
| 800 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); |
| 801 | |
| 802 | dl_list_add(&w->bsss, &bss->wiphy_list); |
| 803 | bss->wiphy_data = w; |
| 804 | return w; |
| 805 | } |
| 806 | |
| 807 | |
| 808 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) |
| 809 | { |
| 810 | struct nl80211_wiphy_data *w = bss->wiphy_data; |
| 811 | struct i802_bss *tmp_bss; |
| 812 | int found = 0; |
| 813 | |
| 814 | if (w == NULL) |
| 815 | return; |
| 816 | bss->wiphy_data = NULL; |
| 817 | dl_list_del(&bss->wiphy_list); |
| 818 | |
| 819 | /* still any for this drv present? */ |
| 820 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 821 | if (tmp_bss->drv == bss->drv) { |
| 822 | found = 1; |
| 823 | break; |
| 824 | } |
| 825 | } |
| 826 | /* if not remove it */ |
| 827 | if (!found) |
| 828 | dl_list_del(&bss->drv->wiphy_list); |
| 829 | |
| 830 | if (!dl_list_empty(&w->bsss)) |
| 831 | return; |
| 832 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 833 | if (w->nl_beacons) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 834 | nl80211_destroy_eloop_handle(&w->nl_beacons, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 835 | |
| 836 | nl_cb_put(w->nl_cb); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 837 | dl_list_del(&w->list); |
| 838 | os_free(w); |
| 839 | } |
| 840 | |
| 841 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 842 | static unsigned int nl80211_get_ifindex(void *priv) |
| 843 | { |
| 844 | struct i802_bss *bss = priv; |
| 845 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 846 | |
| 847 | return drv->ifindex; |
| 848 | } |
| 849 | |
| 850 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 851 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
| 852 | { |
| 853 | struct i802_bss *bss = priv; |
| 854 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 855 | if (!drv->associated) |
| 856 | return -1; |
| 857 | os_memcpy(bssid, drv->bssid, ETH_ALEN); |
| 858 | return 0; |
| 859 | } |
| 860 | |
| 861 | |
| 862 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
| 863 | { |
| 864 | struct i802_bss *bss = priv; |
| 865 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 866 | if (!drv->associated) |
| 867 | return -1; |
| 868 | os_memcpy(ssid, drv->ssid, drv->ssid_len); |
| 869 | return drv->ssid_len; |
| 870 | } |
| 871 | |
| 872 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 873 | static void wpa_driver_nl80211_event_newlink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 874 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 875 | int ifindex, const char *ifname) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 876 | { |
| 877 | union wpa_event_data event; |
| 878 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 879 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 880 | if (if_nametoindex(drv->first_bss->ifname) == 0) { |
| 881 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", |
| 882 | drv->first_bss->ifname); |
| 883 | return; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 884 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 885 | if (!drv->if_removed) |
| 886 | return; |
| 887 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", |
| 888 | drv->first_bss->ifname); |
| 889 | drv->if_removed = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 890 | } |
| 891 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 892 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 893 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 894 | os_strlcpy(event.interface_status.ifname, ifname, |
| 895 | sizeof(event.interface_status.ifname)); |
| 896 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 897 | if (drv) |
| 898 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 899 | else |
| 900 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 901 | &event); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 902 | } |
| 903 | |
| 904 | |
| 905 | static void wpa_driver_nl80211_event_dellink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 906 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 907 | int ifindex, const char *ifname) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 908 | { |
| 909 | union wpa_event_data event; |
| 910 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 911 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 912 | if (drv->if_removed) { |
| 913 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", |
| 914 | ifname); |
| 915 | return; |
| 916 | } |
| 917 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
| 918 | ifname); |
| 919 | drv->if_removed = 1; |
| 920 | } else { |
| 921 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", |
| 922 | ifname); |
| 923 | } |
| 924 | |
| 925 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 926 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 927 | os_strlcpy(event.interface_status.ifname, ifname, |
| 928 | sizeof(event.interface_status.ifname)); |
| 929 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 930 | if (drv) |
| 931 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 932 | else |
| 933 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 934 | &event); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | |
| 938 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
| 939 | u8 *buf, size_t len) |
| 940 | { |
| 941 | int attrlen, rta_len; |
| 942 | struct rtattr *attr; |
| 943 | |
| 944 | attrlen = len; |
| 945 | attr = (struct rtattr *) buf; |
| 946 | |
| 947 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
| 948 | while (RTA_OK(attr, attrlen)) { |
| 949 | if (attr->rta_type == IFLA_IFNAME) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 950 | if (os_strcmp(((char *) attr) + rta_len, |
| 951 | drv->first_bss->ifname) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 952 | return 1; |
| 953 | else |
| 954 | break; |
| 955 | } |
| 956 | attr = RTA_NEXT(attr, attrlen); |
| 957 | } |
| 958 | |
| 959 | return 0; |
| 960 | } |
| 961 | |
| 962 | |
| 963 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, |
| 964 | int ifindex, u8 *buf, size_t len) |
| 965 | { |
| 966 | if (drv->ifindex == ifindex) |
| 967 | return 1; |
| 968 | |
| 969 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 970 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 971 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
| 972 | "interface"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 973 | if (wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL) < 0) |
| 974 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 975 | return 1; |
| 976 | } |
| 977 | |
| 978 | return 0; |
| 979 | } |
| 980 | |
| 981 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 982 | static struct wpa_driver_nl80211_data * |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 983 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len, |
| 984 | int *init_failed) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 985 | { |
| 986 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 987 | int res; |
| 988 | |
| 989 | if (init_failed) |
| 990 | *init_failed = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 991 | dl_list_for_each(drv, &global->interfaces, |
| 992 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 993 | res = wpa_driver_nl80211_own_ifindex(drv, idx, buf, len); |
| 994 | if (res < 0) { |
| 995 | wpa_printf(MSG_DEBUG, |
| 996 | "nl80211: Found matching own interface, but failed to complete reinitialization"); |
| 997 | if (init_failed) |
| 998 | *init_failed = 1; |
| 999 | return drv; |
| 1000 | } |
| 1001 | if (res > 0 || have_ifidx(drv, idx, IFIDX_ANY)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1002 | return drv; |
| 1003 | } |
| 1004 | return NULL; |
| 1005 | } |
| 1006 | |
| 1007 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1008 | static void nl80211_refresh_mac(struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1009 | int ifindex, int notify) |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1010 | { |
| 1011 | struct i802_bss *bss; |
| 1012 | u8 addr[ETH_ALEN]; |
| 1013 | |
| 1014 | bss = get_bss_ifindex(drv, ifindex); |
| 1015 | if (bss && |
| 1016 | linux_get_ifhwaddr(drv->global->ioctl_sock, |
| 1017 | bss->ifname, addr) < 0) { |
| 1018 | wpa_printf(MSG_DEBUG, |
| 1019 | "nl80211: %s: failed to re-read MAC address", |
| 1020 | bss->ifname); |
| 1021 | } else if (bss && os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { |
| 1022 | wpa_printf(MSG_DEBUG, |
| 1023 | "nl80211: Own MAC address on ifindex %d (%s) changed from " |
| 1024 | MACSTR " to " MACSTR, |
| 1025 | ifindex, bss->ifname, |
| 1026 | MAC2STR(bss->addr), MAC2STR(addr)); |
| 1027 | os_memcpy(bss->addr, addr, ETH_ALEN); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1028 | if (notify) |
| 1029 | wpa_supplicant_event(drv->ctx, |
| 1030 | EVENT_INTERFACE_MAC_CHANGED, NULL); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1035 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
| 1036 | struct ifinfomsg *ifi, |
| 1037 | u8 *buf, size_t len) |
| 1038 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1039 | struct nl80211_global *global = ctx; |
| 1040 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1041 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1042 | struct rtattr *attr; |
| 1043 | u32 brid = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1044 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1045 | char ifname[IFNAMSIZ + 1]; |
| 1046 | char extra[100], *pos, *end; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1047 | int init_failed; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1048 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1049 | extra[0] = '\0'; |
| 1050 | pos = extra; |
| 1051 | end = pos + sizeof(extra); |
| 1052 | ifname[0] = '\0'; |
| 1053 | |
| 1054 | attrlen = len; |
| 1055 | attr = (struct rtattr *) buf; |
| 1056 | while (RTA_OK(attr, attrlen)) { |
| 1057 | switch (attr->rta_type) { |
| 1058 | case IFLA_IFNAME: |
| 1059 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) |
| 1060 | break; |
| 1061 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1062 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1063 | break; |
| 1064 | case IFLA_MASTER: |
| 1065 | brid = nla_get_u32((struct nlattr *) attr); |
| 1066 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1067 | break; |
| 1068 | case IFLA_WIRELESS: |
| 1069 | pos += os_snprintf(pos, end - pos, " wext"); |
| 1070 | break; |
| 1071 | case IFLA_OPERSTATE: |
| 1072 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1073 | nla_get_u32((struct nlattr *) attr)); |
| 1074 | break; |
| 1075 | case IFLA_LINKMODE: |
| 1076 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1077 | nla_get_u32((struct nlattr *) attr)); |
| 1078 | break; |
| 1079 | } |
| 1080 | attr = RTA_NEXT(attr, attrlen); |
| 1081 | } |
| 1082 | extra[sizeof(extra) - 1] = '\0'; |
| 1083 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1084 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1085 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1086 | ifi->ifi_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1087 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1088 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1089 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1090 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1091 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1092 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, &init_failed); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1093 | if (!drv) |
| 1094 | goto event_newlink; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1095 | if (init_failed) |
| 1096 | return; /* do not update interface state */ |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1097 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1098 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1099 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1100 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1101 | linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1102 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1103 | "event since interface %s is up", namebuf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1104 | drv->ignore_if_down_event = 0; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1105 | /* Re-read MAC address as it may have changed */ |
| 1106 | nl80211_refresh_mac(drv, ifi->ifi_index, 1); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1107 | return; |
| 1108 | } |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1109 | wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", |
| 1110 | namebuf, ifname); |
| 1111 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 1112 | wpa_printf(MSG_DEBUG, |
| 1113 | "nl80211: Not the main interface (%s) - do not indicate interface down", |
| 1114 | drv->first_bss->ifname); |
| 1115 | } else if (drv->ignore_if_down_event) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1116 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1117 | "event generated by mode change"); |
| 1118 | drv->ignore_if_down_event = 0; |
| 1119 | } else { |
| 1120 | drv->if_disabled = 1; |
| 1121 | wpa_supplicant_event(drv->ctx, |
| 1122 | EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1123 | |
| 1124 | /* |
| 1125 | * Try to get drv again, since it may be removed as |
| 1126 | * part of the EVENT_INTERFACE_DISABLED handling for |
| 1127 | * dynamic interfaces |
| 1128 | */ |
| 1129 | drv = nl80211_find_drv(global, ifi->ifi_index, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1130 | buf, len, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1131 | if (!drv) |
| 1132 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1133 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
| 1136 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 1137 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1138 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1139 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1140 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1141 | "event since interface %s is down", |
| 1142 | namebuf); |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 1143 | return; |
| 1144 | } |
| 1145 | wpa_printf(MSG_DEBUG, "nl80211: Interface up (%s/%s)", |
| 1146 | namebuf, ifname); |
| 1147 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 1148 | wpa_printf(MSG_DEBUG, |
| 1149 | "nl80211: Not the main interface (%s) - do not indicate interface up", |
| 1150 | drv->first_bss->ifname); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1151 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1152 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1153 | "event since interface %s does not exist", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1154 | drv->first_bss->ifname); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1155 | } else if (drv->if_removed) { |
| 1156 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1157 | "event since interface %s is marked " |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1158 | "removed", drv->first_bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1159 | } else { |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1160 | /* Re-read MAC address as it may have changed */ |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1161 | nl80211_refresh_mac(drv, ifi->ifi_index, 0); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1162 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1163 | drv->if_disabled = 0; |
| 1164 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, |
| 1165 | NULL); |
| 1166 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | /* |
| 1170 | * Some drivers send the association event before the operup event--in |
| 1171 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() |
| 1172 | * fails. This will hit us when wpa_supplicant does not need to do |
| 1173 | * IEEE 802.1X authentication |
| 1174 | */ |
| 1175 | if (drv->operstate == 1 && |
| 1176 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1177 | !(ifi->ifi_flags & IFF_RUNNING)) { |
| 1178 | 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] | 1179 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1180 | -1, IF_OPER_UP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1181 | } |
| 1182 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1183 | event_newlink: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1184 | if (ifname[0]) |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1185 | wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index, |
| 1186 | ifname); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1187 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1188 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1189 | struct i802_bss *bss; |
| 1190 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1191 | /* device has been added to bridge */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1192 | if (!if_indextoname(brid, namebuf)) { |
| 1193 | wpa_printf(MSG_DEBUG, |
| 1194 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1195 | brid); |
| 1196 | return; |
| 1197 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1198 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
| 1199 | brid, namebuf); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1200 | add_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1201 | |
| 1202 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 1203 | if (os_strcmp(ifname, bss->ifname) == 0) { |
| 1204 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); |
| 1205 | break; |
| 1206 | } |
| 1207 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1208 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | |
| 1212 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
| 1213 | struct ifinfomsg *ifi, |
| 1214 | u8 *buf, size_t len) |
| 1215 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1216 | struct nl80211_global *global = ctx; |
| 1217 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1218 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1219 | struct rtattr *attr; |
| 1220 | u32 brid = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1221 | char ifname[IFNAMSIZ + 1]; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1222 | char extra[100], *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1223 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1224 | extra[0] = '\0'; |
| 1225 | pos = extra; |
| 1226 | end = pos + sizeof(extra); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1227 | ifname[0] = '\0'; |
| 1228 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1229 | attrlen = len; |
| 1230 | attr = (struct rtattr *) buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1231 | while (RTA_OK(attr, attrlen)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1232 | switch (attr->rta_type) { |
| 1233 | case IFLA_IFNAME: |
| 1234 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) |
| 1235 | break; |
| 1236 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1237 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1238 | break; |
| 1239 | case IFLA_MASTER: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1240 | brid = nla_get_u32((struct nlattr *) attr); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1241 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1242 | break; |
| 1243 | case IFLA_OPERSTATE: |
| 1244 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1245 | nla_get_u32((struct nlattr *) attr)); |
| 1246 | break; |
| 1247 | case IFLA_LINKMODE: |
| 1248 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1249 | nla_get_u32((struct nlattr *) attr)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1250 | break; |
| 1251 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1252 | attr = RTA_NEXT(attr, attrlen); |
| 1253 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1254 | extra[sizeof(extra) - 1] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1255 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1256 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1257 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1258 | ifi->ifi_flags, |
| 1259 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1260 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1261 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1262 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1263 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 1264 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1265 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1266 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1267 | /* device has been removed from bridge */ |
| 1268 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1269 | |
| 1270 | if (!if_indextoname(brid, namebuf)) { |
| 1271 | wpa_printf(MSG_DEBUG, |
| 1272 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1273 | brid); |
| 1274 | } else { |
| 1275 | wpa_printf(MSG_DEBUG, |
| 1276 | "nl80211: Remove ifindex %u for bridge %s", |
| 1277 | brid, namebuf); |
| 1278 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1279 | del_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1280 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1281 | |
| 1282 | if (ifi->ifi_family != AF_BRIDGE || !brid) |
| 1283 | wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index, |
| 1284 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1285 | } |
| 1286 | |
| 1287 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1288 | struct nl80211_get_assoc_freq_arg { |
| 1289 | struct wpa_driver_nl80211_data *drv; |
| 1290 | unsigned int assoc_freq; |
| 1291 | unsigned int ibss_freq; |
| 1292 | u8 assoc_bssid[ETH_ALEN]; |
| 1293 | u8 assoc_ssid[SSID_MAX_LEN]; |
| 1294 | u8 assoc_ssid_len; |
| 1295 | }; |
| 1296 | |
| 1297 | static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg) |
| 1298 | { |
| 1299 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1300 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1301 | struct nlattr *bss[NL80211_BSS_MAX + 1]; |
| 1302 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { |
| 1303 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, |
| 1304 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, |
| 1305 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, |
| 1306 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
| 1307 | }; |
| 1308 | struct nl80211_get_assoc_freq_arg *ctx = arg; |
| 1309 | enum nl80211_bss_status status; |
| 1310 | |
| 1311 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1312 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1313 | if (!tb[NL80211_ATTR_BSS] || |
| 1314 | nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], |
| 1315 | bss_policy) || |
| 1316 | !bss[NL80211_BSS_STATUS]) |
| 1317 | return NL_SKIP; |
| 1318 | |
| 1319 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); |
| 1320 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1321 | bss[NL80211_BSS_FREQUENCY]) { |
| 1322 | ctx->assoc_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1323 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", |
| 1324 | ctx->assoc_freq); |
| 1325 | } |
| 1326 | if (status == NL80211_BSS_STATUS_IBSS_JOINED && |
| 1327 | bss[NL80211_BSS_FREQUENCY]) { |
| 1328 | ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1329 | wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz", |
| 1330 | ctx->ibss_freq); |
| 1331 | } |
| 1332 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1333 | bss[NL80211_BSS_BSSID]) { |
| 1334 | os_memcpy(ctx->assoc_bssid, |
| 1335 | nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN); |
| 1336 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " |
| 1337 | MACSTR, MAC2STR(ctx->assoc_bssid)); |
| 1338 | } |
| 1339 | |
| 1340 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1341 | bss[NL80211_BSS_INFORMATION_ELEMENTS]) { |
| 1342 | const u8 *ie, *ssid; |
| 1343 | size_t ie_len; |
| 1344 | |
| 1345 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1346 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1347 | ssid = get_ie(ie, ie_len, WLAN_EID_SSID); |
| 1348 | if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) { |
| 1349 | ctx->assoc_ssid_len = ssid[1]; |
| 1350 | os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]); |
| 1351 | } |
| 1352 | } |
| 1353 | |
| 1354 | return NL_SKIP; |
| 1355 | } |
| 1356 | |
| 1357 | |
| 1358 | 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] | 1359 | { |
| 1360 | struct nl_msg *msg; |
| 1361 | int ret; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1362 | struct nl80211_get_assoc_freq_arg arg; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1363 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1364 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1365 | os_memset(&arg, 0, sizeof(arg)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1366 | arg.drv = drv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1367 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
| 1368 | &arg); |
| 1369 | if (ret == 0) { |
| 1370 | os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len); |
| 1371 | return arg.assoc_ssid_len; |
| 1372 | } |
| 1373 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)", |
| 1374 | ret, strerror(-ret)); |
| 1375 | return ret; |
| 1376 | } |
| 1377 | |
| 1378 | |
| 1379 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
| 1380 | { |
| 1381 | struct nl_msg *msg; |
| 1382 | int ret; |
| 1383 | struct nl80211_get_assoc_freq_arg arg; |
| 1384 | |
| 1385 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
| 1386 | os_memset(&arg, 0, sizeof(arg)); |
| 1387 | arg.drv = drv; |
| 1388 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
| 1389 | &arg); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1390 | if (ret == 0) { |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1391 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
| 1392 | arg.ibss_freq : arg.assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1393 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1394 | "associated BSS from scan results: %u MHz", freq); |
| 1395 | if (freq) |
| 1396 | drv->assoc_freq = freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1397 | return drv->assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1398 | } |
| 1399 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
| 1400 | "(%s)", ret, strerror(-ret)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1401 | return drv->assoc_freq; |
| 1402 | } |
| 1403 | |
| 1404 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1405 | static int get_link_signal(struct nl_msg *msg, void *arg) |
| 1406 | { |
| 1407 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1408 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1409 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; |
| 1410 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { |
| 1411 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1412 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1413 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1414 | }; |
| 1415 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
| 1416 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 1417 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 1418 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 1419 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, |
| 1420 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 1421 | }; |
| 1422 | struct wpa_signal_info *sig_change = arg; |
| 1423 | |
| 1424 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1425 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1426 | if (!tb[NL80211_ATTR_STA_INFO] || |
| 1427 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, |
| 1428 | tb[NL80211_ATTR_STA_INFO], policy)) |
| 1429 | return NL_SKIP; |
| 1430 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) |
| 1431 | return NL_SKIP; |
| 1432 | |
| 1433 | sig_change->current_signal = |
| 1434 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); |
| 1435 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1436 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
| 1437 | sig_change->avg_signal = |
| 1438 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); |
| 1439 | else |
| 1440 | sig_change->avg_signal = 0; |
| 1441 | |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1442 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
| 1443 | sig_change->avg_beacon_signal = |
| 1444 | (s8) |
| 1445 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); |
| 1446 | else |
| 1447 | sig_change->avg_beacon_signal = 0; |
| 1448 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1449 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
| 1450 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, |
| 1451 | sinfo[NL80211_STA_INFO_TX_BITRATE], |
| 1452 | rate_policy)) { |
| 1453 | sig_change->current_txrate = 0; |
| 1454 | } else { |
| 1455 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { |
| 1456 | sig_change->current_txrate = |
| 1457 | nla_get_u16(rinfo[ |
| 1458 | NL80211_RATE_INFO_BITRATE]) * 100; |
| 1459 | } |
| 1460 | } |
| 1461 | } |
| 1462 | |
| 1463 | return NL_SKIP; |
| 1464 | } |
| 1465 | |
| 1466 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1467 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
| 1468 | struct wpa_signal_info *sig) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1469 | { |
| 1470 | struct nl_msg *msg; |
| 1471 | |
| 1472 | sig->current_signal = -9999; |
| 1473 | sig->current_txrate = 0; |
| 1474 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1475 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
| 1476 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) { |
| 1477 | nlmsg_free(msg); |
| 1478 | return -ENOBUFS; |
| 1479 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1480 | |
| 1481 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | |
| 1485 | static int get_link_noise(struct nl_msg *msg, void *arg) |
| 1486 | { |
| 1487 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1488 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1489 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 1490 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 1491 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 1492 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 1493 | }; |
| 1494 | struct wpa_signal_info *sig_change = arg; |
| 1495 | |
| 1496 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1497 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1498 | |
| 1499 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 1500 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); |
| 1501 | return NL_SKIP; |
| 1502 | } |
| 1503 | |
| 1504 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 1505 | tb[NL80211_ATTR_SURVEY_INFO], |
| 1506 | survey_policy)) { |
| 1507 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " |
| 1508 | "attributes!"); |
| 1509 | return NL_SKIP; |
| 1510 | } |
| 1511 | |
| 1512 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 1513 | return NL_SKIP; |
| 1514 | |
| 1515 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 1516 | sig_change->frequency) |
| 1517 | return NL_SKIP; |
| 1518 | |
| 1519 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 1520 | return NL_SKIP; |
| 1521 | |
| 1522 | sig_change->current_noise = |
| 1523 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 1524 | |
| 1525 | return NL_SKIP; |
| 1526 | } |
| 1527 | |
| 1528 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1529 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
| 1530 | struct wpa_signal_info *sig_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1531 | { |
| 1532 | struct nl_msg *msg; |
| 1533 | |
| 1534 | sig_change->current_noise = 9999; |
| 1535 | sig_change->frequency = drv->assoc_freq; |
| 1536 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1537 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1538 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1539 | } |
| 1540 | |
| 1541 | |
| 1542 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
| 1543 | void *handle) |
| 1544 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1545 | struct nl_cb *cb = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1546 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1547 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1548 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1549 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1550 | res = nl_recvmsgs(handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 1551 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1552 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 1553 | __func__, res); |
| 1554 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1555 | } |
| 1556 | |
| 1557 | |
| 1558 | /** |
| 1559 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain |
| 1560 | * @priv: driver_nl80211 private data |
| 1561 | * @alpha2_arg: country to which to switch to |
| 1562 | * Returns: 0 on success, -1 on failure |
| 1563 | * |
| 1564 | * This asks nl80211 to set the regulatory domain for given |
| 1565 | * country ISO / IEC alpha2. |
| 1566 | */ |
| 1567 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) |
| 1568 | { |
| 1569 | struct i802_bss *bss = priv; |
| 1570 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1571 | char alpha2[3]; |
| 1572 | struct nl_msg *msg; |
| 1573 | |
| 1574 | msg = nlmsg_alloc(); |
| 1575 | if (!msg) |
| 1576 | return -ENOMEM; |
| 1577 | |
| 1578 | alpha2[0] = alpha2_arg[0]; |
| 1579 | alpha2[1] = alpha2_arg[1]; |
| 1580 | alpha2[2] = '\0'; |
| 1581 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1582 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
| 1583 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { |
| 1584 | nlmsg_free(msg); |
| 1585 | return -EINVAL; |
| 1586 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1587 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) |
| 1588 | return -EINVAL; |
| 1589 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1593 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
| 1594 | { |
| 1595 | char *alpha2 = arg; |
| 1596 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 1597 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1598 | |
| 1599 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1600 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1601 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { |
| 1602 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); |
| 1603 | return NL_SKIP; |
| 1604 | } |
| 1605 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); |
| 1606 | return NL_SKIP; |
| 1607 | } |
| 1608 | |
| 1609 | |
| 1610 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) |
| 1611 | { |
| 1612 | struct i802_bss *bss = priv; |
| 1613 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1614 | struct nl_msg *msg; |
| 1615 | int ret; |
| 1616 | |
| 1617 | msg = nlmsg_alloc(); |
| 1618 | if (!msg) |
| 1619 | return -ENOMEM; |
| 1620 | |
| 1621 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
| 1622 | alpha2[0] = '\0'; |
| 1623 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2); |
| 1624 | if (!alpha2[0]) |
| 1625 | ret = -1; |
| 1626 | |
| 1627 | return ret; |
| 1628 | } |
| 1629 | |
| 1630 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1631 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1632 | { |
| 1633 | int ret; |
| 1634 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1635 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1636 | if (global->nl_cb == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1637 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 1638 | "callbacks"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1639 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1640 | } |
| 1641 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1642 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
| 1643 | if (global->nl == NULL) |
| 1644 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1645 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1646 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
| 1647 | if (global->nl80211_id < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1648 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
| 1649 | "found"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1650 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1651 | } |
| 1652 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1653 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
| 1654 | if (global->nl_event == NULL) |
| 1655 | goto err; |
| 1656 | |
| 1657 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1658 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1659 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1660 | if (ret < 0) { |
| 1661 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1662 | "membership for scan events: %d (%s)", |
| 1663 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1664 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1665 | } |
| 1666 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1667 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1668 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1669 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1670 | if (ret < 0) { |
| 1671 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1672 | "membership for mlme events: %d (%s)", |
| 1673 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1674 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1675 | } |
| 1676 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1677 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1678 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1679 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1680 | if (ret < 0) { |
| 1681 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1682 | "membership for regulatory events: %d (%s)", |
| 1683 | ret, strerror(-ret)); |
| 1684 | /* Continue without regulatory events */ |
| 1685 | } |
| 1686 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1687 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
| 1688 | if (ret >= 0) |
| 1689 | ret = nl_socket_add_membership(global->nl_event, ret); |
| 1690 | if (ret < 0) { |
| 1691 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1692 | "membership for vendor events: %d (%s)", |
| 1693 | ret, strerror(-ret)); |
| 1694 | /* Continue without vendor events */ |
| 1695 | } |
| 1696 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1697 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1698 | no_seq_check, NULL); |
| 1699 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1700 | process_global_event, global); |
| 1701 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1702 | nl80211_register_eloop_read(&global->nl_event, |
| 1703 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 1704 | global->nl_cb, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1705 | |
| 1706 | return 0; |
| 1707 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1708 | err: |
| 1709 | nl_destroy_handles(&global->nl_event); |
| 1710 | nl_destroy_handles(&global->nl); |
| 1711 | nl_cb_put(global->nl_cb); |
| 1712 | global->nl_cb = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1713 | return -1; |
| 1714 | } |
| 1715 | |
| 1716 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1717 | static void nl80211_check_global(struct nl80211_global *global) |
| 1718 | { |
| 1719 | struct nl_handle *handle; |
| 1720 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; |
| 1721 | int ret; |
| 1722 | unsigned int i; |
| 1723 | |
| 1724 | /* |
| 1725 | * Try to re-add memberships to handle case of cfg80211 getting reloaded |
| 1726 | * and all registration having been cleared. |
| 1727 | */ |
| 1728 | handle = (void *) (((intptr_t) global->nl_event) ^ |
| 1729 | ELOOP_SOCKET_INVALID); |
| 1730 | |
| 1731 | for (i = 0; groups[i]; i++) { |
| 1732 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); |
| 1733 | if (ret >= 0) |
| 1734 | ret = nl_socket_add_membership(handle, ret); |
| 1735 | if (ret < 0) { |
| 1736 | wpa_printf(MSG_INFO, |
| 1737 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", |
| 1738 | groups[i], ret, strerror(-ret)); |
| 1739 | } |
| 1740 | } |
| 1741 | } |
| 1742 | |
| 1743 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1744 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
| 1745 | { |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1746 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1747 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1748 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1749 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1750 | /* |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1751 | * rtnetlink ifdown handler will report interfaces other than the P2P |
| 1752 | * Device interface as disabled. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1753 | */ |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1754 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 1755 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1756 | } |
| 1757 | |
| 1758 | |
| 1759 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) |
| 1760 | { |
| 1761 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1762 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1763 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1764 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
| 1765 | "after rfkill unblock"); |
| 1766 | return; |
| 1767 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1768 | |
| 1769 | if (is_p2p_net_interface(drv->nlmode)) |
| 1770 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
| 1771 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1772 | /* |
| 1773 | * rtnetlink ifup handler will report interfaces other than the P2P |
| 1774 | * Device interface as enabled. |
| 1775 | */ |
| 1776 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 1777 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1778 | } |
| 1779 | |
| 1780 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1781 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
| 1782 | void *eloop_ctx, |
| 1783 | void *handle) |
| 1784 | { |
| 1785 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 1786 | u8 data[2048]; |
| 1787 | struct msghdr msg; |
| 1788 | struct iovec entry; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1789 | u8 control[512]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1790 | struct cmsghdr *cmsg; |
| 1791 | int res, found_ee = 0, found_wifi = 0, acked = 0; |
| 1792 | union wpa_event_data event; |
| 1793 | |
| 1794 | memset(&msg, 0, sizeof(msg)); |
| 1795 | msg.msg_iov = &entry; |
| 1796 | msg.msg_iovlen = 1; |
| 1797 | entry.iov_base = data; |
| 1798 | entry.iov_len = sizeof(data); |
| 1799 | msg.msg_control = &control; |
| 1800 | msg.msg_controllen = sizeof(control); |
| 1801 | |
| 1802 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); |
| 1803 | /* if error or not fitting 802.3 header, return */ |
| 1804 | if (res < 14) |
| 1805 | return; |
| 1806 | |
| 1807 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
| 1808 | { |
| 1809 | if (cmsg->cmsg_level == SOL_SOCKET && |
| 1810 | cmsg->cmsg_type == SCM_WIFI_STATUS) { |
| 1811 | int *ack; |
| 1812 | |
| 1813 | found_wifi = 1; |
| 1814 | ack = (void *)CMSG_DATA(cmsg); |
| 1815 | acked = *ack; |
| 1816 | } |
| 1817 | |
| 1818 | if (cmsg->cmsg_level == SOL_PACKET && |
| 1819 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { |
| 1820 | struct sock_extended_err *err = |
| 1821 | (struct sock_extended_err *)CMSG_DATA(cmsg); |
| 1822 | |
| 1823 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) |
| 1824 | found_ee = 1; |
| 1825 | } |
| 1826 | } |
| 1827 | |
| 1828 | if (!found_ee || !found_wifi) |
| 1829 | return; |
| 1830 | |
| 1831 | memset(&event, 0, sizeof(event)); |
| 1832 | event.eapol_tx_status.dst = data; |
| 1833 | event.eapol_tx_status.data = data + 14; |
| 1834 | event.eapol_tx_status.data_len = res - 14; |
| 1835 | event.eapol_tx_status.ack = acked; |
| 1836 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); |
| 1837 | } |
| 1838 | |
| 1839 | |
| 1840 | static int nl80211_init_bss(struct i802_bss *bss) |
| 1841 | { |
| 1842 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1843 | if (!bss->nl_cb) |
| 1844 | return -1; |
| 1845 | |
| 1846 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1847 | no_seq_check, NULL); |
| 1848 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1849 | process_bss_event, bss); |
| 1850 | |
| 1851 | return 0; |
| 1852 | } |
| 1853 | |
| 1854 | |
| 1855 | static void nl80211_destroy_bss(struct i802_bss *bss) |
| 1856 | { |
| 1857 | nl_cb_put(bss->nl_cb); |
| 1858 | bss->nl_cb = NULL; |
| 1859 | } |
| 1860 | |
| 1861 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1862 | static void |
| 1863 | wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv) |
| 1864 | { |
| 1865 | struct rfkill_config *rcfg; |
| 1866 | |
| 1867 | if (drv->rfkill) |
| 1868 | return; |
| 1869 | |
| 1870 | rcfg = os_zalloc(sizeof(*rcfg)); |
| 1871 | if (!rcfg) |
| 1872 | return; |
| 1873 | |
| 1874 | rcfg->ctx = drv; |
| 1875 | |
| 1876 | /* rfkill uses netdev sysfs for initialization. However, P2P Device is |
| 1877 | * not associated with a netdev, so use the name of some other interface |
| 1878 | * sharing the same wiphy as the P2P Device interface. |
| 1879 | * |
| 1880 | * Note: This is valid, as a P2P Device interface is always dynamically |
| 1881 | * created and is created only once another wpa_s interface was added. |
| 1882 | */ |
| 1883 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 1884 | struct nl80211_global *global = drv->global; |
| 1885 | struct wpa_driver_nl80211_data *tmp1; |
| 1886 | |
| 1887 | dl_list_for_each(tmp1, &global->interfaces, |
| 1888 | struct wpa_driver_nl80211_data, list) { |
| 1889 | if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx || |
| 1890 | !tmp1->rfkill) |
| 1891 | continue; |
| 1892 | |
| 1893 | wpa_printf(MSG_DEBUG, |
| 1894 | "nl80211: Use (%s) to initialize P2P Device rfkill", |
| 1895 | tmp1->first_bss->ifname); |
| 1896 | os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname, |
| 1897 | sizeof(rcfg->ifname)); |
| 1898 | break; |
| 1899 | } |
| 1900 | } else { |
| 1901 | os_strlcpy(rcfg->ifname, drv->first_bss->ifname, |
| 1902 | sizeof(rcfg->ifname)); |
| 1903 | } |
| 1904 | |
| 1905 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; |
| 1906 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; |
| 1907 | drv->rfkill = rfkill_init(rcfg); |
| 1908 | if (!drv->rfkill) { |
| 1909 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
| 1910 | os_free(rcfg); |
| 1911 | } |
| 1912 | } |
| 1913 | |
| 1914 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1915 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
| 1916 | void *global_priv, int hostapd, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1917 | const u8 *set_addr, |
| 1918 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1919 | { |
| 1920 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1921 | struct i802_bss *bss; |
| 1922 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1923 | if (global_priv == NULL) |
| 1924 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1925 | drv = os_zalloc(sizeof(*drv)); |
| 1926 | if (drv == NULL) |
| 1927 | return NULL; |
| 1928 | drv->global = global_priv; |
| 1929 | drv->ctx = ctx; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1930 | drv->hostapd = !!hostapd; |
| 1931 | drv->eapol_sock = -1; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1932 | |
| 1933 | /* |
| 1934 | * There is no driver capability flag for this, so assume it is |
| 1935 | * supported and disable this on first attempt to use if the driver |
| 1936 | * rejects the command due to missing support. |
| 1937 | */ |
| 1938 | drv->set_rekey_offload = 1; |
| 1939 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1940 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
| 1941 | drv->if_indices = drv->default_if_indices; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1942 | drv->if_indices_reason = drv->default_if_indices_reason; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1943 | |
| 1944 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); |
| 1945 | if (!drv->first_bss) { |
| 1946 | os_free(drv); |
| 1947 | return NULL; |
| 1948 | } |
| 1949 | bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1950 | bss->drv = drv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1951 | bss->ctx = ctx; |
| 1952 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1953 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
| 1954 | drv->monitor_ifidx = -1; |
| 1955 | drv->monitor_sock = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1956 | drv->eapol_tx_sock = -1; |
| 1957 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1958 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1959 | if (nl80211_init_bss(bss)) |
| 1960 | goto failed; |
| 1961 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1962 | 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] | 1963 | goto failed; |
| 1964 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1965 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
| 1966 | if (drv->eapol_tx_sock < 0) |
| 1967 | goto failed; |
| 1968 | |
| 1969 | if (drv->data_tx_status) { |
| 1970 | int enabled = 1; |
| 1971 | |
| 1972 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, |
| 1973 | &enabled, sizeof(enabled)) < 0) { |
| 1974 | wpa_printf(MSG_DEBUG, |
| 1975 | "nl80211: wifi status sockopt failed\n"); |
| 1976 | drv->data_tx_status = 0; |
| 1977 | if (!drv->use_monitor) |
| 1978 | drv->capa.flags &= |
| 1979 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
| 1980 | } else { |
| 1981 | eloop_register_read_sock(drv->eapol_tx_sock, |
| 1982 | wpa_driver_nl80211_handle_eapol_tx_status, |
| 1983 | drv, NULL); |
| 1984 | } |
| 1985 | } |
| 1986 | |
| 1987 | if (drv->global) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1988 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1989 | dl_list_add(&drv->global->interfaces, &drv->list); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1990 | drv->in_interface_list = 1; |
| 1991 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1992 | |
| 1993 | return bss; |
| 1994 | |
| 1995 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1996 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1997 | return NULL; |
| 1998 | } |
| 1999 | |
| 2000 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2001 | /** |
| 2002 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface |
| 2003 | * @ctx: context to be used when calling wpa_supplicant functions, |
| 2004 | * e.g., wpa_supplicant_event() |
| 2005 | * @ifname: interface name, e.g., wlan0 |
| 2006 | * @global_priv: private driver global data from global_init() |
| 2007 | * Returns: Pointer to private data, %NULL on failure |
| 2008 | */ |
| 2009 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
| 2010 | void *global_priv) |
| 2011 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2012 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
| 2013 | NULL); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2014 | } |
| 2015 | |
| 2016 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2017 | static int nl80211_register_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2018 | struct nl_handle *nl_handle, |
| 2019 | u16 type, const u8 *match, size_t match_len) |
| 2020 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2021 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2022 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2023 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2024 | char buf[30]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2025 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2026 | buf[0] = '\0'; |
| 2027 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 2028 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s", |
| 2029 | type, fc2str(type), nl_handle, buf); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2030 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2031 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) || |
| 2032 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
| 2033 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { |
| 2034 | nlmsg_free(msg); |
| 2035 | return -1; |
| 2036 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2037 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2038 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2039 | if (ret) { |
| 2040 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
| 2041 | "failed (type=%u): ret=%d (%s)", |
| 2042 | type, ret, strerror(-ret)); |
| 2043 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", |
| 2044 | match, match_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2045 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2046 | return ret; |
| 2047 | } |
| 2048 | |
| 2049 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2050 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
| 2051 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2052 | if (bss->nl_mgmt) { |
| 2053 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
| 2054 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
| 2055 | return -1; |
| 2056 | } |
| 2057 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2058 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2059 | if (bss->nl_mgmt == NULL) |
| 2060 | return -1; |
| 2061 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2062 | return 0; |
| 2063 | } |
| 2064 | |
| 2065 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2066 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
| 2067 | { |
| 2068 | nl80211_register_eloop_read(&bss->nl_mgmt, |
| 2069 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2070 | bss->nl_cb, 0); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2074 | static int nl80211_register_action_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2075 | const u8 *match, size_t match_len) |
| 2076 | { |
| 2077 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2078 | return nl80211_register_frame(bss, bss->nl_mgmt, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2079 | type, match, match_len); |
| 2080 | } |
| 2081 | |
| 2082 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2083 | static int nl80211_init_connect_handle(struct i802_bss *bss) |
| 2084 | { |
| 2085 | if (bss->nl_connect) { |
| 2086 | wpa_printf(MSG_DEBUG, |
| 2087 | "nl80211: Connect handle already created (nl_connect=%p)", |
| 2088 | bss->nl_connect); |
| 2089 | return -1; |
| 2090 | } |
| 2091 | |
| 2092 | bss->nl_connect = nl_create_handle(bss->nl_cb, "connect"); |
| 2093 | if (!bss->nl_connect) |
| 2094 | return -1; |
| 2095 | nl80211_register_eloop_read(&bss->nl_connect, |
| 2096 | wpa_driver_nl80211_event_receive, |
| 2097 | bss->nl_cb, 1); |
| 2098 | return 0; |
| 2099 | } |
| 2100 | |
| 2101 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2102 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2103 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2104 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2105 | int ret = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2106 | |
| 2107 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2108 | return -1; |
| 2109 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
| 2110 | "handle %p", bss->nl_mgmt); |
| 2111 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2112 | if (drv->nlmode == NL80211_IFTYPE_ADHOC || |
| 2113 | ((drv->capa.flags & WPA_DRIVER_FLAGS_SAE) && |
| 2114 | !(drv->capa.flags & WPA_DRIVER_FLAGS_SME))) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2115 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
| 2116 | |
| 2117 | /* register for any AUTH message */ |
| 2118 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); |
| 2119 | } |
| 2120 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2121 | #ifdef CONFIG_INTERWORKING |
| 2122 | /* QoS Map Configure */ |
| 2123 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2124 | ret = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2125 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2126 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) || defined(CONFIG_DPP) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2127 | /* GAS Initial Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2128 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2129 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2130 | /* GAS Initial Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2131 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2132 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2133 | /* GAS Comeback Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2134 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2135 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2136 | /* GAS Comeback Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2137 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2138 | ret = -1; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2139 | /* Protected GAS Initial Request */ |
| 2140 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) |
| 2141 | ret = -1; |
| 2142 | /* Protected GAS Initial Response */ |
| 2143 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) |
| 2144 | ret = -1; |
| 2145 | /* Protected GAS Comeback Request */ |
| 2146 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) |
| 2147 | ret = -1; |
| 2148 | /* Protected GAS Comeback Response */ |
| 2149 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) |
| 2150 | ret = -1; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2151 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING || CONFIG_DPP */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2152 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2153 | /* P2P Public Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2154 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2155 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
| 2156 | 6) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2157 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2158 | /* P2P Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2159 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2160 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
| 2161 | 5) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2162 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2163 | #endif /* CONFIG_P2P */ |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 2164 | #ifdef CONFIG_DPP |
| 2165 | /* DPP Public Action */ |
| 2166 | if (nl80211_register_action_frame(bss, |
| 2167 | (u8 *) "\x04\x09\x50\x6f\x9a\x1a", |
| 2168 | 6) < 0) |
| 2169 | ret = -1; |
| 2170 | #endif /* CONFIG_DPP */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2171 | #ifdef CONFIG_IEEE80211W |
| 2172 | /* SA Query Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2173 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2174 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2175 | #endif /* CONFIG_IEEE80211W */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2176 | #ifdef CONFIG_TDLS |
| 2177 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { |
| 2178 | /* TDLS Discovery Response */ |
| 2179 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
| 2180 | 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2181 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2182 | } |
| 2183 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2184 | #ifdef CONFIG_FST |
| 2185 | /* FST Action frames */ |
| 2186 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2187 | ret = -1; |
| 2188 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2189 | |
| 2190 | /* FT Action frames */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2191 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2192 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2193 | else |
| 2194 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | |
| 2195 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; |
| 2196 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2197 | /* WNM - BSS Transition Management Request */ |
| 2198 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2199 | ret = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2200 | /* WNM-Sleep Mode Response */ |
| 2201 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2202 | ret = -1; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame^] | 2203 | #ifdef CONFIG_WNM |
| 2204 | /* WNM - Collocated Interference Request */ |
| 2205 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x0b", 2) < 0) |
| 2206 | ret = -1; |
| 2207 | #endif /* CONFIG_WNM */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2208 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2209 | #ifdef CONFIG_HS20 |
| 2210 | /* WNM-Notification */ |
| 2211 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2212 | ret = -1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2213 | #endif /* CONFIG_HS20 */ |
| 2214 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2215 | /* WMM-AC ADDTS Response */ |
| 2216 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) |
| 2217 | ret = -1; |
| 2218 | |
| 2219 | /* WMM-AC DELTS */ |
| 2220 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) |
| 2221 | ret = -1; |
| 2222 | |
| 2223 | /* Radio Measurement - Neighbor Report Response */ |
| 2224 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) |
| 2225 | ret = -1; |
| 2226 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2227 | /* Radio Measurement - Radio Measurement Request */ |
| 2228 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0) |
| 2229 | ret = -1; |
| 2230 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2231 | /* Radio Measurement - Link Measurement Request */ |
| 2232 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && |
| 2233 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) |
| 2234 | ret = -1; |
| 2235 | |
| 2236 | nl80211_mgmt_handle_register_eloop(bss); |
| 2237 | |
| 2238 | return ret; |
| 2239 | } |
| 2240 | |
| 2241 | |
| 2242 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
| 2243 | { |
| 2244 | int ret = 0; |
| 2245 | |
| 2246 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2247 | return -1; |
| 2248 | |
| 2249 | wpa_printf(MSG_DEBUG, |
| 2250 | "nl80211: Subscribe to mgmt frames with mesh handle %p", |
| 2251 | bss->nl_mgmt); |
| 2252 | |
| 2253 | /* Auth frames for mesh SAE */ |
| 2254 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2255 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2256 | (WLAN_FC_STYPE_AUTH << 4), |
| 2257 | NULL, 0) < 0) |
| 2258 | ret = -1; |
| 2259 | |
| 2260 | /* Mesh peering open */ |
| 2261 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) |
| 2262 | ret = -1; |
| 2263 | /* Mesh peering confirm */ |
| 2264 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) |
| 2265 | ret = -1; |
| 2266 | /* Mesh peering close */ |
| 2267 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) |
| 2268 | ret = -1; |
| 2269 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2270 | nl80211_mgmt_handle_register_eloop(bss); |
| 2271 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2272 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2273 | } |
| 2274 | |
| 2275 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2276 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
| 2277 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2278 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2279 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2280 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2281 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
| 2282 | 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] | 2283 | if (ret) { |
| 2284 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " |
| 2285 | "failed: ret=%d (%s)", |
| 2286 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2287 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2288 | return ret; |
| 2289 | } |
| 2290 | |
| 2291 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2292 | static int nl80211_action_subscribe_ap(struct i802_bss *bss) |
| 2293 | { |
| 2294 | int ret = 0; |
| 2295 | |
| 2296 | /* Public Action frames */ |
| 2297 | if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0) |
| 2298 | ret = -1; |
| 2299 | /* RRM Measurement Report */ |
| 2300 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0) |
| 2301 | ret = -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2302 | /* RRM Link Measurement Report */ |
| 2303 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x03", 2) < 0) |
| 2304 | ret = -1; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2305 | /* RRM Neighbor Report Request */ |
| 2306 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0) |
| 2307 | ret = -1; |
| 2308 | /* FT Action frames */ |
| 2309 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
| 2310 | ret = -1; |
| 2311 | #ifdef CONFIG_IEEE80211W |
| 2312 | /* SA Query */ |
| 2313 | if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0) |
| 2314 | ret = -1; |
| 2315 | #endif /* CONFIG_IEEE80211W */ |
| 2316 | /* Protected Dual of Public Action */ |
| 2317 | if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0) |
| 2318 | ret = -1; |
| 2319 | /* WNM */ |
| 2320 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0) |
| 2321 | ret = -1; |
| 2322 | /* WMM */ |
| 2323 | if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0) |
| 2324 | ret = -1; |
| 2325 | #ifdef CONFIG_FST |
| 2326 | /* FST Action frames */ |
| 2327 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2328 | ret = -1; |
| 2329 | #endif /* CONFIG_FST */ |
| 2330 | /* Vendor-specific */ |
| 2331 | if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0) |
| 2332 | ret = -1; |
| 2333 | |
| 2334 | return ret; |
| 2335 | } |
| 2336 | |
| 2337 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2338 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
| 2339 | { |
| 2340 | static const int stypes[] = { |
| 2341 | WLAN_FC_STYPE_AUTH, |
| 2342 | WLAN_FC_STYPE_ASSOC_REQ, |
| 2343 | WLAN_FC_STYPE_REASSOC_REQ, |
| 2344 | WLAN_FC_STYPE_DISASSOC, |
| 2345 | WLAN_FC_STYPE_DEAUTH, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2346 | WLAN_FC_STYPE_PROBE_REQ, |
| 2347 | /* Beacon doesn't work as mac80211 doesn't currently allow |
| 2348 | * it, but it wouldn't really be the right thing anyway as |
| 2349 | * it isn't per interface ... maybe just dump the scan |
| 2350 | * results periodically for OLBC? |
| 2351 | */ |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2352 | /* WLAN_FC_STYPE_BEACON, */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2353 | }; |
| 2354 | unsigned int i; |
| 2355 | |
| 2356 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2357 | return -1; |
| 2358 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2359 | "handle %p", bss->nl_mgmt); |
| 2360 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2361 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2362 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2363 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2364 | (stypes[i] << 4), |
| 2365 | NULL, 0) < 0) { |
| 2366 | goto out_err; |
| 2367 | } |
| 2368 | } |
| 2369 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2370 | if (nl80211_action_subscribe_ap(bss)) |
| 2371 | goto out_err; |
| 2372 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2373 | if (nl80211_register_spurious_class3(bss)) |
| 2374 | goto out_err; |
| 2375 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2376 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2377 | return 0; |
| 2378 | |
| 2379 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2380 | nl_destroy_handles(&bss->nl_mgmt); |
| 2381 | return -1; |
| 2382 | } |
| 2383 | |
| 2384 | |
| 2385 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
| 2386 | { |
| 2387 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2388 | return -1; |
| 2389 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2390 | "handle %p (device SME)", bss->nl_mgmt); |
| 2391 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2392 | if (nl80211_action_subscribe_ap(bss)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2393 | goto out_err; |
| 2394 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2395 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2396 | return 0; |
| 2397 | |
| 2398 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2399 | nl_destroy_handles(&bss->nl_mgmt); |
| 2400 | return -1; |
| 2401 | } |
| 2402 | |
| 2403 | |
| 2404 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
| 2405 | { |
| 2406 | if (bss->nl_mgmt == NULL) |
| 2407 | return; |
| 2408 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
| 2409 | "(%s)", bss->nl_mgmt, reason); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2410 | nl80211_destroy_eloop_handle(&bss->nl_mgmt, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2411 | |
| 2412 | nl80211_put_wiphy_data_ap(bss); |
| 2413 | } |
| 2414 | |
| 2415 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2416 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
| 2417 | { |
| 2418 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); |
| 2419 | } |
| 2420 | |
| 2421 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2422 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
| 2423 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2424 | struct nl_msg *msg; |
| 2425 | int ret; |
| 2426 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2427 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
| 2428 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2429 | |
| 2430 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", |
| 2431 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2432 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2433 | } |
| 2434 | |
| 2435 | |
| 2436 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
| 2437 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2438 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2439 | int ret; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2440 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2441 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
| 2442 | NL80211_CMD_STOP_P2P_DEVICE); |
| 2443 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2444 | |
| 2445 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
| 2446 | start ? "Start" : "Stop", |
| 2447 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2448 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2449 | return ret; |
| 2450 | } |
| 2451 | |
| 2452 | |
| 2453 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
| 2454 | { |
| 2455 | enum nl80211_iftype nlmode; |
| 2456 | |
| 2457 | nlmode = nl80211_get_ifmode(bss); |
| 2458 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2459 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, |
| 2460 | bss->ifname, up); |
| 2461 | } |
| 2462 | |
| 2463 | /* P2P Device has start/stop which is equivalent */ |
| 2464 | return nl80211_set_p2pdev(bss, up); |
| 2465 | } |
| 2466 | |
| 2467 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2468 | #ifdef CONFIG_TESTING_OPTIONS |
| 2469 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) |
| 2470 | { |
| 2471 | /* struct wpa_driver_nl80211_data *drv = arg; */ |
| 2472 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 2473 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2474 | |
| 2475 | |
| 2476 | wpa_printf(MSG_DEBUG, |
| 2477 | "nl80211: QCA vendor test command response received"); |
| 2478 | |
| 2479 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2480 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2481 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { |
| 2482 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); |
| 2483 | return NL_SKIP; |
| 2484 | } |
| 2485 | |
| 2486 | wpa_hexdump(MSG_DEBUG, |
| 2487 | "nl80211: Received QCA vendor test command response", |
| 2488 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), |
| 2489 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); |
| 2490 | |
| 2491 | return NL_SKIP; |
| 2492 | } |
| 2493 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2494 | |
| 2495 | |
| 2496 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) |
| 2497 | { |
| 2498 | #ifdef CONFIG_TESTING_OPTIONS |
| 2499 | struct nl_msg *msg; |
| 2500 | struct nlattr *params; |
| 2501 | int ret; |
| 2502 | |
| 2503 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2504 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2505 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2506 | QCA_NL80211_VENDOR_SUBCMD_TEST) || |
| 2507 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 2508 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { |
| 2509 | nlmsg_free(msg); |
| 2510 | return; |
| 2511 | } |
| 2512 | nla_nest_end(msg, params); |
| 2513 | |
| 2514 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv); |
| 2515 | wpa_printf(MSG_DEBUG, |
| 2516 | "nl80211: QCA vendor test command returned %d (%s)", |
| 2517 | ret, strerror(-ret)); |
| 2518 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2519 | } |
| 2520 | |
| 2521 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2522 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2523 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2524 | const u8 *set_addr, int first, |
| 2525 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2526 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2527 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2528 | int send_rfkill_event = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2529 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2530 | |
| 2531 | drv->ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2532 | bss->ifindex = drv->ifindex; |
| 2533 | bss->wdev_id = drv->global->if_add_wdevid; |
| 2534 | bss->wdev_id_set = drv->global->if_add_wdevid_set; |
| 2535 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2536 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
| 2537 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2538 | drv->global->if_add_wdevid_set = 0; |
| 2539 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2540 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2541 | bss->static_ap = 1; |
| 2542 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 2543 | if (first && |
| 2544 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && |
| 2545 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) |
| 2546 | drv->start_iface_up = 1; |
| 2547 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2548 | if (wpa_driver_nl80211_capa(drv)) |
| 2549 | return -1; |
| 2550 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2551 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
| 2552 | return -1; |
| 2553 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2554 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
| 2555 | bss->ifname, drv->phyname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2556 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2557 | if (set_addr && |
| 2558 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || |
| 2559 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2560 | set_addr))) |
| 2561 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2562 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2563 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2564 | drv->start_mode_ap = 1; |
| 2565 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2566 | if (drv->hostapd || bss->static_ap) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2567 | nlmode = NL80211_IFTYPE_AP; |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 2568 | else if (bss->if_dynamic || |
| 2569 | nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2570 | nlmode = nl80211_get_ifmode(bss); |
| 2571 | else |
| 2572 | nlmode = NL80211_IFTYPE_STATION; |
| 2573 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2574 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2575 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2576 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2577 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2578 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2579 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2580 | nl80211_get_macaddr(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2581 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2582 | wpa_driver_nl80211_drv_init_rfkill(drv); |
| 2583 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2584 | if (!rfkill_is_blocked(drv->rfkill)) { |
| 2585 | int ret = i802_set_iface_flags(bss, 1); |
| 2586 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2587 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
| 2588 | "interface '%s' UP", bss->ifname); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2589 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2590 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2591 | |
| 2592 | if (is_p2p_net_interface(nlmode)) |
| 2593 | nl80211_disable_11b_rates(bss->drv, |
| 2594 | bss->drv->ifindex, 1); |
| 2595 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2596 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2597 | return ret; |
| 2598 | } else { |
| 2599 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " |
| 2600 | "interface '%s' due to rfkill", bss->ifname); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2601 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 2602 | drv->if_disabled = 1; |
| 2603 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2604 | send_rfkill_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2605 | } |
| 2606 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2607 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2608 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
| 2609 | 1, IF_OPER_DORMANT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2610 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2611 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2612 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2613 | bss->addr)) |
| 2614 | return -1; |
| 2615 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); |
| 2616 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2617 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2618 | if (send_rfkill_event) { |
| 2619 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, |
| 2620 | drv, drv->ctx); |
| 2621 | } |
| 2622 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2623 | if (drv->vendor_cmd_test_avail) |
| 2624 | qca_vendor_test(drv); |
| 2625 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2626 | nl80211_init_connect_handle(bss); |
| 2627 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2628 | return 0; |
| 2629 | } |
| 2630 | |
| 2631 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2632 | static int wpa_driver_nl80211_del_beacon(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2633 | { |
| 2634 | struct nl_msg *msg; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2635 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2636 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2637 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
| 2638 | drv->ifindex); |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2639 | nl80211_put_wiphy_data_ap(bss); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2640 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2641 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2642 | } |
| 2643 | |
| 2644 | |
| 2645 | /** |
| 2646 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2647 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2648 | * |
| 2649 | * Shut down driver interface and processing of driver events. Free |
| 2650 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). |
| 2651 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2652 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2653 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2654 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2655 | unsigned int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2656 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2657 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
| 2658 | bss->ifname, drv->disabled_11b_rates); |
| 2659 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2660 | bss->in_deinit = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2661 | if (drv->data_tx_status) |
| 2662 | eloop_unregister_read_sock(drv->eapol_tx_sock); |
| 2663 | if (drv->eapol_tx_sock >= 0) |
| 2664 | close(drv->eapol_tx_sock); |
| 2665 | |
| 2666 | if (bss->nl_preq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2667 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 2668 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2669 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 2670 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2671 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2672 | "interface %s from bridge %s: %s", |
| 2673 | bss->ifname, bss->brname, strerror(errno)); |
| 2674 | } |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 2675 | |
| 2676 | if (drv->rtnl_sk) |
| 2677 | nl80211_handle_destroy(drv->rtnl_sk); |
| 2678 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2679 | if (bss->added_bridge) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2680 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
| 2681 | 0) < 0) |
| 2682 | wpa_printf(MSG_INFO, |
| 2683 | "nl80211: Could not set bridge %s down", |
| 2684 | bss->brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2685 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2686 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2687 | "bridge %s: %s", |
| 2688 | bss->brname, strerror(errno)); |
| 2689 | } |
| 2690 | |
| 2691 | nl80211_remove_monitor_interface(drv); |
| 2692 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2693 | if (is_ap_interface(drv->nlmode)) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2694 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2695 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2696 | if (drv->eapol_sock >= 0) { |
| 2697 | eloop_unregister_read_sock(drv->eapol_sock); |
| 2698 | close(drv->eapol_sock); |
| 2699 | } |
| 2700 | |
| 2701 | if (drv->if_indices != drv->default_if_indices) |
| 2702 | os_free(drv->if_indices); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2703 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2704 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
| 2705 | os_free(drv->if_indices_reason); |
| 2706 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2707 | if (drv->disabled_11b_rates) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2708 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 2709 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2710 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
| 2711 | IF_OPER_UP); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 2712 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2713 | rfkill_deinit(drv->rfkill); |
| 2714 | |
| 2715 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 2716 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2717 | if (!drv->start_iface_up) |
| 2718 | (void) i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2719 | |
| 2720 | if (drv->addr_changed) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2721 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 2722 | 0) < 0) { |
| 2723 | wpa_printf(MSG_DEBUG, |
| 2724 | "nl80211: Could not set interface down to restore permanent MAC address"); |
| 2725 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2726 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2727 | drv->perm_addr) < 0) { |
| 2728 | wpa_printf(MSG_DEBUG, |
| 2729 | "nl80211: Could not restore permanent MAC address"); |
| 2730 | } |
| 2731 | } |
| 2732 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2733 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2734 | if (!drv->hostapd || !drv->start_mode_ap) |
| 2735 | wpa_driver_nl80211_set_mode(bss, |
| 2736 | NL80211_IFTYPE_STATION); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2737 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2738 | } else { |
| 2739 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
| 2740 | nl80211_del_p2pdev(bss); |
| 2741 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2742 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2743 | if (bss->nl_connect) |
| 2744 | nl80211_destroy_eloop_handle(&bss->nl_connect, 1); |
| 2745 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2746 | nl80211_destroy_bss(drv->first_bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2747 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2748 | os_free(drv->filter_ssids); |
| 2749 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2750 | os_free(drv->auth_ie); |
| 2751 | |
| 2752 | if (drv->in_interface_list) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2753 | dl_list_del(&drv->list); |
| 2754 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2755 | os_free(drv->extended_capa); |
| 2756 | os_free(drv->extended_capa_mask); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2757 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 2758 | os_free(drv->iface_ext_capa[i].ext_capa); |
| 2759 | os_free(drv->iface_ext_capa[i].ext_capa_mask); |
| 2760 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2761 | os_free(drv->first_bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2762 | os_free(drv); |
| 2763 | } |
| 2764 | |
| 2765 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2766 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
| 2767 | { |
| 2768 | switch (alg) { |
| 2769 | case WPA_ALG_WEP: |
| 2770 | if (key_len == 5) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2771 | return RSN_CIPHER_SUITE_WEP40; |
| 2772 | return RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2773 | case WPA_ALG_TKIP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2774 | return RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2775 | case WPA_ALG_CCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2776 | return RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2777 | case WPA_ALG_GCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2778 | return RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2779 | case WPA_ALG_CCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2780 | return RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2781 | case WPA_ALG_GCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2782 | return RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2783 | case WPA_ALG_IGTK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2784 | return RSN_CIPHER_SUITE_AES_128_CMAC; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2785 | case WPA_ALG_BIP_GMAC_128: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2786 | return RSN_CIPHER_SUITE_BIP_GMAC_128; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2787 | case WPA_ALG_BIP_GMAC_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2788 | return RSN_CIPHER_SUITE_BIP_GMAC_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2789 | case WPA_ALG_BIP_CMAC_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2790 | return RSN_CIPHER_SUITE_BIP_CMAC_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2791 | case WPA_ALG_SMS4: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2792 | return RSN_CIPHER_SUITE_SMS4; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2793 | case WPA_ALG_KRK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2794 | return RSN_CIPHER_SUITE_KRK; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2795 | case WPA_ALG_NONE: |
| 2796 | case WPA_ALG_PMK: |
| 2797 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", |
| 2798 | alg); |
| 2799 | return 0; |
| 2800 | } |
| 2801 | |
| 2802 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", |
| 2803 | alg); |
| 2804 | return 0; |
| 2805 | } |
| 2806 | |
| 2807 | |
| 2808 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) |
| 2809 | { |
| 2810 | switch (cipher) { |
| 2811 | case WPA_CIPHER_CCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2812 | return RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2813 | case WPA_CIPHER_GCMP_256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2814 | return RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2815 | case WPA_CIPHER_CCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2816 | return RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2817 | case WPA_CIPHER_GCMP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2818 | return RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2819 | case WPA_CIPHER_TKIP: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2820 | return RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2821 | case WPA_CIPHER_WEP104: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2822 | return RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2823 | case WPA_CIPHER_WEP40: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2824 | return RSN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2825 | case WPA_CIPHER_GTK_NOT_USED: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2826 | return RSN_CIPHER_SUITE_NO_GROUP_ADDRESSED; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2827 | } |
| 2828 | |
| 2829 | return 0; |
| 2830 | } |
| 2831 | |
| 2832 | |
| 2833 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], |
| 2834 | int max_suites) |
| 2835 | { |
| 2836 | int num_suites = 0; |
| 2837 | |
| 2838 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2839 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2840 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2841 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP_256; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2842 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2843 | suites[num_suites++] = RSN_CIPHER_SUITE_CCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2844 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2845 | suites[num_suites++] = RSN_CIPHER_SUITE_GCMP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2846 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2847 | suites[num_suites++] = RSN_CIPHER_SUITE_TKIP; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2848 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2849 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP104; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2850 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 2851 | suites[num_suites++] = RSN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2852 | |
| 2853 | return num_suites; |
| 2854 | } |
| 2855 | |
| 2856 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2857 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2858 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 2859 | const u8 *key, size_t key_len) |
| 2860 | { |
| 2861 | struct nl_msg *msg; |
| 2862 | int ret; |
| 2863 | |
| 2864 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
| 2865 | return 0; |
| 2866 | |
| 2867 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2868 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2869 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2870 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || |
| 2871 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { |
| 2872 | nl80211_nlmsg_clear(msg); |
| 2873 | nlmsg_free(msg); |
| 2874 | return -1; |
| 2875 | } |
| 2876 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 2877 | if (ret) { |
| 2878 | wpa_printf(MSG_DEBUG, |
| 2879 | "nl80211: Key management set key failed: ret=%d (%s)", |
| 2880 | ret, strerror(-ret)); |
| 2881 | } |
| 2882 | |
| 2883 | return ret; |
| 2884 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2885 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2886 | |
| 2887 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2888 | static int nl80211_set_pmk(struct wpa_driver_nl80211_data *drv, |
| 2889 | const u8 *key, size_t key_len, |
| 2890 | const u8 *addr) |
| 2891 | { |
| 2892 | struct nl_msg *msg = NULL; |
| 2893 | int ret; |
| 2894 | |
| 2895 | /* |
| 2896 | * If the authenticator address is not set, assume it is |
| 2897 | * the current BSSID. |
| 2898 | */ |
| 2899 | if (!addr && drv->associated) |
| 2900 | addr = drv->bssid; |
| 2901 | else if (!addr) |
| 2902 | return -1; |
| 2903 | |
| 2904 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK to the driver for " MACSTR, |
| 2905 | MAC2STR(addr)); |
| 2906 | wpa_hexdump_key(MSG_DEBUG, "nl80211: PMK", key, key_len); |
| 2907 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_PMK); |
| 2908 | if (!msg || |
| 2909 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 2910 | nla_put(msg, NL80211_ATTR_PMK, key_len, key)) { |
| 2911 | nl80211_nlmsg_clear(msg); |
| 2912 | nlmsg_free(msg); |
| 2913 | return -ENOBUFS; |
| 2914 | } |
| 2915 | |
| 2916 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 2917 | if (ret) { |
| 2918 | wpa_printf(MSG_DEBUG, "nl80211: Set PMK failed: ret=%d (%s)", |
| 2919 | ret, strerror(-ret)); |
| 2920 | } |
| 2921 | |
| 2922 | return ret; |
| 2923 | } |
| 2924 | |
| 2925 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2926 | 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] | 2927 | enum wpa_alg alg, const u8 *addr, |
| 2928 | int key_idx, int set_tx, |
| 2929 | const u8 *seq, size_t seq_len, |
| 2930 | const u8 *key, size_t key_len) |
| 2931 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2932 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2933 | int ifindex; |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2934 | struct nl_msg *msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2935 | int ret; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2936 | int tdls = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2937 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2938 | /* Ignore for P2P Device */ |
| 2939 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2940 | return 0; |
| 2941 | |
| 2942 | ifindex = if_nametoindex(ifname); |
| 2943 | 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] | 2944 | "set_tx=%d seq_len=%lu key_len=%lu", |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2945 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2946 | (unsigned long) seq_len, (unsigned long) key_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2947 | #ifdef CONFIG_TDLS |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2948 | if (key_idx == -1) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2949 | key_idx = 0; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2950 | tdls = 1; |
| 2951 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2952 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2953 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2954 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2955 | if (alg == WPA_ALG_PMK && |
| 2956 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { |
| 2957 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
| 2958 | __func__); |
| 2959 | ret = issue_key_mgmt_set_key(drv, key, key_len); |
| 2960 | return ret; |
| 2961 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2962 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2963 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 2964 | if (alg == WPA_ALG_PMK && |
| 2965 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE)) |
| 2966 | return nl80211_set_pmk(drv, key, key_len, addr); |
| 2967 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2968 | if (alg == WPA_ALG_NONE) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2969 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
| 2970 | if (!msg) |
| 2971 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2972 | } else { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2973 | u32 suite; |
| 2974 | |
| 2975 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 2976 | if (!suite) |
| 2977 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2978 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
| 2979 | if (!msg || |
| 2980 | nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2981 | nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, suite)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2982 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2983 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2984 | } |
| 2985 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2986 | if (seq && seq_len) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2987 | if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq)) |
| 2988 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2989 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
| 2990 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2991 | |
| 2992 | if (addr && !is_broadcast_ether_addr(addr)) { |
| 2993 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2994 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 2995 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2996 | |
| 2997 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { |
| 2998 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2999 | if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, |
| 3000 | NL80211_KEYTYPE_GROUP)) |
| 3001 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3002 | } |
| 3003 | } else if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3004 | struct nlattr *types; |
| 3005 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3006 | wpa_printf(MSG_DEBUG, " broadcast key"); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3007 | |
| 3008 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3009 | if (!types || |
| 3010 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 3011 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3012 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3013 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3014 | if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 3015 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3016 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3017 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3018 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
| 3019 | ret = 0; |
| 3020 | if (ret) |
| 3021 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", |
| 3022 | ret, strerror(-ret)); |
| 3023 | |
| 3024 | /* |
| 3025 | * If we failed or don't need to set the default TX key (below), |
| 3026 | * we're done here. |
| 3027 | */ |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 3028 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3029 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3030 | if (is_ap_interface(drv->nlmode) && addr && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3031 | !is_broadcast_ether_addr(addr)) |
| 3032 | return ret; |
| 3033 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3034 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
| 3035 | if (!msg || |
| 3036 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 3037 | nla_put_flag(msg, (alg == WPA_ALG_IGTK || |
| 3038 | alg == WPA_ALG_BIP_GMAC_128 || |
| 3039 | alg == WPA_ALG_BIP_GMAC_256 || |
| 3040 | alg == WPA_ALG_BIP_CMAC_256) ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3041 | NL80211_ATTR_KEY_DEFAULT_MGMT : |
| 3042 | NL80211_ATTR_KEY_DEFAULT)) |
| 3043 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3044 | if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3045 | struct nlattr *types; |
| 3046 | |
| 3047 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3048 | if (!types || |
| 3049 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 3050 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3051 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3052 | } else if (addr) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3053 | struct nlattr *types; |
| 3054 | |
| 3055 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3056 | if (!types || |
| 3057 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) |
| 3058 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3059 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3060 | } |
| 3061 | |
| 3062 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3063 | if (ret == -ENOENT) |
| 3064 | ret = 0; |
| 3065 | if (ret) |
| 3066 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " |
| 3067 | "err=%d %s)", ret, strerror(-ret)); |
| 3068 | return ret; |
| 3069 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3070 | fail: |
| 3071 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3072 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3073 | return -ENOBUFS; |
| 3074 | } |
| 3075 | |
| 3076 | |
| 3077 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
| 3078 | int key_idx, int defkey, |
| 3079 | const u8 *seq, size_t seq_len, |
| 3080 | const u8 *key, size_t key_len) |
| 3081 | { |
| 3082 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3083 | u32 suite; |
| 3084 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3085 | if (!key_attr) |
| 3086 | return -1; |
| 3087 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3088 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 3089 | if (!suite) |
| 3090 | return -1; |
| 3091 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3092 | if (defkey && alg == WPA_ALG_IGTK) { |
| 3093 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) |
| 3094 | return -1; |
| 3095 | } else if (defkey) { |
| 3096 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) |
| 3097 | return -1; |
| 3098 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3099 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3100 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 3101 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3102 | (seq && seq_len && |
| 3103 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || |
| 3104 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) |
| 3105 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3106 | |
| 3107 | nla_nest_end(msg, key_attr); |
| 3108 | |
| 3109 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3110 | } |
| 3111 | |
| 3112 | |
| 3113 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
| 3114 | struct nl_msg *msg) |
| 3115 | { |
| 3116 | int i, privacy = 0; |
| 3117 | struct nlattr *nl_keys, *nl_key; |
| 3118 | |
| 3119 | for (i = 0; i < 4; i++) { |
| 3120 | if (!params->wep_key[i]) |
| 3121 | continue; |
| 3122 | privacy = 1; |
| 3123 | break; |
| 3124 | } |
| 3125 | if (params->wps == WPS_MODE_PRIVACY) |
| 3126 | privacy = 1; |
| 3127 | if (params->pairwise_suite && |
| 3128 | params->pairwise_suite != WPA_CIPHER_NONE) |
| 3129 | privacy = 1; |
| 3130 | |
| 3131 | if (!privacy) |
| 3132 | return 0; |
| 3133 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3134 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 3135 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3136 | |
| 3137 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); |
| 3138 | if (!nl_keys) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3139 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3140 | |
| 3141 | for (i = 0; i < 4; i++) { |
| 3142 | if (!params->wep_key[i]) |
| 3143 | continue; |
| 3144 | |
| 3145 | nl_key = nla_nest_start(msg, i); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3146 | if (!nl_key || |
| 3147 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], |
| 3148 | params->wep_key[i]) || |
| 3149 | nla_put_u32(msg, NL80211_KEY_CIPHER, |
| 3150 | params->wep_key_len[i] == 5 ? |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3151 | RSN_CIPHER_SUITE_WEP40 : |
| 3152 | RSN_CIPHER_SUITE_WEP104) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3153 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
| 3154 | (i == params->wep_tx_keyidx && |
| 3155 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) |
| 3156 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3157 | |
| 3158 | nla_nest_end(msg, nl_key); |
| 3159 | } |
| 3160 | nla_nest_end(msg, nl_keys); |
| 3161 | |
| 3162 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3163 | } |
| 3164 | |
| 3165 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3166 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 3167 | const u8 *addr, int cmd, u16 reason_code, |
| 3168 | int local_state_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3169 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3170 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3171 | struct nl_msg *msg; |
| 3172 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3173 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
| 3174 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
| 3175 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 3176 | (local_state_change && |
| 3177 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { |
| 3178 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3179 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3180 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3181 | |
| 3182 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3183 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3184 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 3185 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", |
| 3186 | reason_code, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3187 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3188 | return ret; |
| 3189 | } |
| 3190 | |
| 3191 | |
| 3192 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3193 | int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3194 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3195 | int ret; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3196 | int drv_associated = drv->associated; |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3197 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3198 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3199 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3200 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3201 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
| 3202 | reason_code, 0); |
| 3203 | /* |
| 3204 | * For locally generated disconnect, supplicant already generates a |
| 3205 | * DEAUTH event, so ignore the event from NL80211. |
| 3206 | */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3207 | drv->ignore_next_local_disconnect = drv_associated && (ret == 0); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3208 | |
| 3209 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3210 | } |
| 3211 | |
| 3212 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3213 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
| 3214 | const u8 *addr, int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3215 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3216 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3217 | int ret; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3218 | int drv_associated = drv->associated; |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3219 | |
| 3220 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3221 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3222 | return nl80211_leave_ibss(drv, 1); |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3223 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3224 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3225 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3226 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
| 3227 | __func__, MAC2STR(addr), reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3228 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3229 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
| 3230 | reason_code, 0); |
| 3231 | /* |
| 3232 | * For locally generated deauthenticate, supplicant already generates a |
| 3233 | * DEAUTH event, so ignore the event from NL80211. |
| 3234 | */ |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 3235 | drv->ignore_next_local_deauth = drv_associated && (ret == 0); |
| 3236 | |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3237 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3238 | } |
| 3239 | |
| 3240 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3241 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
| 3242 | struct wpa_driver_auth_params *params) |
| 3243 | { |
| 3244 | int i; |
| 3245 | |
| 3246 | drv->auth_freq = params->freq; |
| 3247 | drv->auth_alg = params->auth_alg; |
| 3248 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; |
| 3249 | drv->auth_local_state_change = params->local_state_change; |
| 3250 | drv->auth_p2p = params->p2p; |
| 3251 | |
| 3252 | if (params->bssid) |
| 3253 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); |
| 3254 | else |
| 3255 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); |
| 3256 | |
| 3257 | if (params->ssid) { |
| 3258 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); |
| 3259 | drv->auth_ssid_len = params->ssid_len; |
| 3260 | } else |
| 3261 | drv->auth_ssid_len = 0; |
| 3262 | |
| 3263 | |
| 3264 | os_free(drv->auth_ie); |
| 3265 | drv->auth_ie = NULL; |
| 3266 | drv->auth_ie_len = 0; |
| 3267 | if (params->ie) { |
| 3268 | drv->auth_ie = os_malloc(params->ie_len); |
| 3269 | if (drv->auth_ie) { |
| 3270 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); |
| 3271 | drv->auth_ie_len = params->ie_len; |
| 3272 | } |
| 3273 | } |
| 3274 | |
| 3275 | for (i = 0; i < 4; i++) { |
| 3276 | if (params->wep_key[i] && params->wep_key_len[i] && |
| 3277 | params->wep_key_len[i] <= 16) { |
| 3278 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], |
| 3279 | params->wep_key_len[i]); |
| 3280 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; |
| 3281 | } else |
| 3282 | drv->auth_wep_key_len[i] = 0; |
| 3283 | } |
| 3284 | } |
| 3285 | |
| 3286 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3287 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
| 3288 | { |
| 3289 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3290 | |
| 3291 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) |
| 3292 | return; |
| 3293 | |
| 3294 | /* |
| 3295 | * Looks like we failed to unmask 11b rates previously. This could |
| 3296 | * happen, e.g., if the interface was down at the point in time when a |
| 3297 | * P2P group was terminated. |
| 3298 | */ |
| 3299 | wpa_printf(MSG_DEBUG, |
| 3300 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", |
| 3301 | bss->ifname); |
| 3302 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 3303 | } |
| 3304 | |
| 3305 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3306 | static enum nl80211_auth_type get_nl_auth_type(int wpa_auth_alg) |
| 3307 | { |
| 3308 | if (wpa_auth_alg & WPA_AUTH_ALG_OPEN) |
| 3309 | return NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 3310 | if (wpa_auth_alg & WPA_AUTH_ALG_SHARED) |
| 3311 | return NL80211_AUTHTYPE_SHARED_KEY; |
| 3312 | if (wpa_auth_alg & WPA_AUTH_ALG_LEAP) |
| 3313 | return NL80211_AUTHTYPE_NETWORK_EAP; |
| 3314 | if (wpa_auth_alg & WPA_AUTH_ALG_FT) |
| 3315 | return NL80211_AUTHTYPE_FT; |
| 3316 | if (wpa_auth_alg & WPA_AUTH_ALG_SAE) |
| 3317 | return NL80211_AUTHTYPE_SAE; |
| 3318 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS) |
| 3319 | return NL80211_AUTHTYPE_FILS_SK; |
| 3320 | if (wpa_auth_alg & WPA_AUTH_ALG_FILS_SK_PFS) |
| 3321 | return NL80211_AUTHTYPE_FILS_SK_PFS; |
| 3322 | |
| 3323 | return NL80211_AUTHTYPE_MAX; |
| 3324 | } |
| 3325 | |
| 3326 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3327 | static int wpa_driver_nl80211_authenticate( |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3328 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3329 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3330 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3331 | int ret = -1, i; |
| 3332 | struct nl_msg *msg; |
| 3333 | enum nl80211_auth_type type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3334 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3335 | int count = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3336 | int is_retry; |
| 3337 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3338 | nl80211_unmask_11b_rates(bss); |
| 3339 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3340 | is_retry = drv->retry_auth; |
| 3341 | drv->retry_auth = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3342 | drv->ignore_deauth_event = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3343 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3344 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3345 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3346 | if (params->bssid) |
| 3347 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 3348 | else |
| 3349 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3350 | /* FIX: IBSS mode */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3351 | nlmode = params->p2p ? |
| 3352 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 3353 | if (drv->nlmode != nlmode && |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3354 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3355 | return -1; |
| 3356 | |
| 3357 | retry: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3358 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
| 3359 | drv->ifindex); |
| 3360 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3361 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
| 3362 | if (!msg) |
| 3363 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3364 | |
| 3365 | for (i = 0; i < 4; i++) { |
| 3366 | if (!params->wep_key[i]) |
| 3367 | continue; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3368 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3369 | NULL, i, |
| 3370 | i == params->wep_tx_keyidx, NULL, 0, |
| 3371 | params->wep_key[i], |
| 3372 | params->wep_key_len[i]); |
| 3373 | if (params->wep_tx_keyidx != i) |
| 3374 | continue; |
| 3375 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3376 | params->wep_key[i], params->wep_key_len[i])) |
| 3377 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3378 | } |
| 3379 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3380 | if (params->bssid) { |
| 3381 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 3382 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3383 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 3384 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3385 | } |
| 3386 | if (params->freq) { |
| 3387 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3388 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
| 3389 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3390 | } |
| 3391 | if (params->ssid) { |
| 3392 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 3393 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3394 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 3395 | params->ssid)) |
| 3396 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3397 | } |
| 3398 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3399 | if (params->ie && |
| 3400 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) |
| 3401 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3402 | if (params->auth_data) { |
| 3403 | wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data, |
| 3404 | params->auth_data_len); |
| 3405 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len, |
| 3406 | params->auth_data)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3407 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3408 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3409 | type = get_nl_auth_type(params->auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3410 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 3411 | if (type == NL80211_AUTHTYPE_MAX || |
| 3412 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3413 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3414 | if (params->local_state_change) { |
| 3415 | wpa_printf(MSG_DEBUG, " * Local state change only"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3416 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
| 3417 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3418 | } |
| 3419 | |
| 3420 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3421 | msg = NULL; |
| 3422 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3423 | wpa_dbg(drv->ctx, MSG_DEBUG, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3424 | "nl80211: MLME command failed (auth): count=%d ret=%d (%s)", |
| 3425 | count, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3426 | count++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 3427 | if ((ret == -EALREADY || ret == -EEXIST) && count == 1 && |
| 3428 | params->bssid && !params->local_state_change) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3429 | /* |
| 3430 | * mac80211 does not currently accept new |
| 3431 | * authentication if we are already authenticated. As a |
| 3432 | * workaround, force deauthentication and try again. |
| 3433 | */ |
| 3434 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " |
| 3435 | "after forced deauthentication"); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3436 | drv->ignore_deauth_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3437 | wpa_driver_nl80211_deauthenticate( |
| 3438 | bss, params->bssid, |
| 3439 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 3440 | nlmsg_free(msg); |
| 3441 | goto retry; |
| 3442 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3443 | |
| 3444 | if (ret == -ENOENT && params->freq && !is_retry) { |
| 3445 | /* |
| 3446 | * cfg80211 has likely expired the BSS entry even |
| 3447 | * though it was previously available in our internal |
| 3448 | * BSS table. To recover quickly, start a single |
| 3449 | * channel scan on the specified channel. |
| 3450 | */ |
| 3451 | struct wpa_driver_scan_params scan; |
| 3452 | int freqs[2]; |
| 3453 | |
| 3454 | os_memset(&scan, 0, sizeof(scan)); |
| 3455 | scan.num_ssids = 1; |
| 3456 | if (params->ssid) { |
| 3457 | scan.ssids[0].ssid = params->ssid; |
| 3458 | scan.ssids[0].ssid_len = params->ssid_len; |
| 3459 | } |
| 3460 | freqs[0] = params->freq; |
| 3461 | freqs[1] = 0; |
| 3462 | scan.freqs = freqs; |
| 3463 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " |
| 3464 | "channel scan to refresh cfg80211 BSS " |
| 3465 | "entry"); |
| 3466 | ret = wpa_driver_nl80211_scan(bss, &scan); |
| 3467 | if (ret == 0) { |
| 3468 | nl80211_copy_auth_params(drv, params); |
| 3469 | drv->scan_for_auth = 1; |
| 3470 | } |
| 3471 | } else if (is_retry) { |
| 3472 | /* |
| 3473 | * Need to indicate this with an event since the return |
| 3474 | * value from the retry is not delivered to core code. |
| 3475 | */ |
| 3476 | union wpa_event_data event; |
| 3477 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " |
| 3478 | "failed"); |
| 3479 | os_memset(&event, 0, sizeof(event)); |
| 3480 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, |
| 3481 | ETH_ALEN); |
| 3482 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, |
| 3483 | &event); |
| 3484 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3485 | } else { |
| 3486 | wpa_printf(MSG_DEBUG, |
| 3487 | "nl80211: Authentication request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3488 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3489 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3490 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3491 | nlmsg_free(msg); |
| 3492 | return ret; |
| 3493 | } |
| 3494 | |
| 3495 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3496 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3497 | { |
| 3498 | struct wpa_driver_auth_params params; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3499 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3500 | int i; |
| 3501 | |
| 3502 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); |
| 3503 | |
| 3504 | os_memset(¶ms, 0, sizeof(params)); |
| 3505 | params.freq = drv->auth_freq; |
| 3506 | params.auth_alg = drv->auth_alg; |
| 3507 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; |
| 3508 | params.local_state_change = drv->auth_local_state_change; |
| 3509 | params.p2p = drv->auth_p2p; |
| 3510 | |
| 3511 | if (!is_zero_ether_addr(drv->auth_bssid_)) |
| 3512 | params.bssid = drv->auth_bssid_; |
| 3513 | |
| 3514 | if (drv->auth_ssid_len) { |
| 3515 | params.ssid = drv->auth_ssid; |
| 3516 | params.ssid_len = drv->auth_ssid_len; |
| 3517 | } |
| 3518 | |
| 3519 | params.ie = drv->auth_ie; |
| 3520 | params.ie_len = drv->auth_ie_len; |
| 3521 | |
| 3522 | for (i = 0; i < 4; i++) { |
| 3523 | if (drv->auth_wep_key_len[i]) { |
| 3524 | params.wep_key[i] = drv->auth_wep_key[i]; |
| 3525 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; |
| 3526 | } |
| 3527 | } |
| 3528 | |
| 3529 | drv->retry_auth = 1; |
| 3530 | return wpa_driver_nl80211_authenticate(bss, ¶ms); |
| 3531 | } |
| 3532 | |
| 3533 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3534 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
| 3535 | const void *data, size_t len, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3536 | int encrypt, int noack, |
| 3537 | unsigned int freq, int no_cck, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3538 | int offchanok, unsigned int wait_time, |
| 3539 | const u16 *csa_offs, |
| 3540 | size_t csa_offs_len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3541 | { |
| 3542 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3543 | u64 cookie; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3544 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3545 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 3546 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3547 | freq = nl80211_get_assoc_freq(drv); |
| 3548 | wpa_printf(MSG_DEBUG, |
| 3549 | "nl80211: send_frame - Use assoc_freq=%u for IBSS", |
| 3550 | freq); |
| 3551 | } |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3552 | if (freq == 0) { |
| 3553 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", |
| 3554 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3555 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3556 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3557 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3558 | if (drv->use_monitor) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3559 | 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] | 3560 | freq, bss->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3561 | return nl80211_send_monitor(drv, data, len, encrypt, noack); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3562 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3563 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3564 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3565 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3566 | &cookie, no_cck, noack, offchanok, |
| 3567 | csa_offs, csa_offs_len); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3568 | if (res == 0 && !noack) { |
| 3569 | const struct ieee80211_mgmt *mgmt; |
| 3570 | u16 fc; |
| 3571 | |
| 3572 | mgmt = (const struct ieee80211_mgmt *) data; |
| 3573 | fc = le_to_host16(mgmt->frame_control); |
| 3574 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3575 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { |
| 3576 | wpa_printf(MSG_MSGDUMP, |
| 3577 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", |
| 3578 | (long long unsigned int) |
| 3579 | drv->send_action_cookie, |
| 3580 | (long long unsigned int) cookie); |
| 3581 | drv->send_action_cookie = cookie; |
| 3582 | } |
| 3583 | } |
| 3584 | |
| 3585 | return res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3586 | } |
| 3587 | |
| 3588 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3589 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
| 3590 | size_t data_len, int noack, |
| 3591 | unsigned int freq, int no_cck, |
| 3592 | int offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3593 | unsigned int wait_time, |
| 3594 | const u16 *csa_offs, |
| 3595 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3596 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3597 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3598 | struct ieee80211_mgmt *mgmt; |
| 3599 | int encrypt = 1; |
| 3600 | u16 fc; |
| 3601 | |
| 3602 | mgmt = (struct ieee80211_mgmt *) data; |
| 3603 | fc = le_to_host16(mgmt->frame_control); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 3604 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR |
| 3605 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d", |
| 3606 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, |
| 3607 | fc, fc2str(fc), drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3608 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3609 | if ((is_sta_interface(drv->nlmode) || |
| 3610 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3611 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3612 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { |
| 3613 | /* |
| 3614 | * The use of last_mgmt_freq is a bit of a hack, |
| 3615 | * but it works due to the single-threaded nature |
| 3616 | * of wpa_supplicant. |
| 3617 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3618 | if (freq == 0) { |
| 3619 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", |
| 3620 | drv->last_mgmt_freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3621 | freq = drv->last_mgmt_freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3622 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3623 | return nl80211_send_frame_cmd(bss, freq, 0, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3624 | data, data_len, NULL, 1, noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3625 | 1, csa_offs, csa_offs_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3626 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3627 | |
| 3628 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3629 | if (freq == 0) { |
| 3630 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", |
| 3631 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3632 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3633 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3634 | return nl80211_send_frame_cmd(bss, freq, |
| 3635 | (int) freq == bss->freq ? 0 : |
| 3636 | wait_time, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3637 | data, data_len, |
| 3638 | &drv->send_action_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3639 | no_cck, noack, offchanok, |
| 3640 | csa_offs, csa_offs_len); |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 3641 | } |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 3642 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3643 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3644 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 3645 | /* |
| 3646 | * Only one of the authentication frame types is encrypted. |
| 3647 | * In order for static WEP encryption to work properly (i.e., |
| 3648 | * to not encrypt the frame), we need to tell mac80211 about |
| 3649 | * the frames that must not be encrypted. |
| 3650 | */ |
| 3651 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 3652 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); |
| 3653 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
| 3654 | encrypt = 0; |
| 3655 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3656 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3657 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3658 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3659 | noack, freq, no_cck, offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3660 | wait_time, csa_offs, |
| 3661 | csa_offs_len); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3662 | } |
| 3663 | |
| 3664 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3665 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
| 3666 | { |
| 3667 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 3668 | u8 rates_len = 0; |
| 3669 | int i; |
| 3670 | |
| 3671 | if (!basic_rates) |
| 3672 | return 0; |
| 3673 | |
| 3674 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) |
| 3675 | rates[rates_len++] = basic_rates[i] / 5; |
| 3676 | |
| 3677 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); |
| 3678 | } |
| 3679 | |
| 3680 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3681 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
| 3682 | int slot, int ht_opmode, int ap_isolate, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3683 | const int *basic_rates) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3684 | { |
| 3685 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3686 | struct nl_msg *msg; |
| 3687 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3688 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
| 3689 | (cts >= 0 && |
| 3690 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || |
| 3691 | (preamble >= 0 && |
| 3692 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || |
| 3693 | (slot >= 0 && |
| 3694 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || |
| 3695 | (ht_opmode >= 0 && |
| 3696 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || |
| 3697 | (ap_isolate >= 0 && |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3698 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
| 3699 | nl80211_put_basic_rates(msg, basic_rates)) { |
| 3700 | nlmsg_free(msg); |
| 3701 | return -ENOBUFS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3702 | } |
| 3703 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3704 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3705 | } |
| 3706 | |
| 3707 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3708 | static int wpa_driver_nl80211_set_acl(void *priv, |
| 3709 | struct hostapd_acl_params *params) |
| 3710 | { |
| 3711 | struct i802_bss *bss = priv; |
| 3712 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3713 | struct nl_msg *msg; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3714 | struct nl_msg *acl; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3715 | unsigned int i; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3716 | int ret; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3717 | |
| 3718 | if (!(drv->capa.max_acl_mac_addrs)) |
| 3719 | return -ENOTSUP; |
| 3720 | |
| 3721 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) |
| 3722 | return -ENOTSUP; |
| 3723 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3724 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
| 3725 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); |
| 3726 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3727 | acl = nlmsg_alloc(); |
| 3728 | if (!acl) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3729 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3730 | for (i = 0; i < params->num_mac_acl; i++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3731 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { |
| 3732 | nlmsg_free(acl); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3733 | return -ENOMEM; |
| 3734 | } |
| 3735 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3736 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3737 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
| 3738 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
| 3739 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : |
| 3740 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || |
| 3741 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
| 3742 | nlmsg_free(msg); |
| 3743 | nlmsg_free(acl); |
| 3744 | return -ENOMEM; |
| 3745 | } |
| 3746 | nlmsg_free(acl); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3747 | |
| 3748 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3749 | if (ret) { |
| 3750 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", |
| 3751 | ret, strerror(-ret)); |
| 3752 | } |
| 3753 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3754 | return ret; |
| 3755 | } |
| 3756 | |
| 3757 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3758 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
| 3759 | { |
| 3760 | if (beacon_int > 0) { |
| 3761 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); |
| 3762 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 3763 | beacon_int); |
| 3764 | } |
| 3765 | |
| 3766 | return 0; |
| 3767 | } |
| 3768 | |
| 3769 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3770 | static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period) |
| 3771 | { |
| 3772 | if (dtim_period > 0) { |
| 3773 | wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period); |
| 3774 | return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); |
| 3775 | } |
| 3776 | |
| 3777 | return 0; |
| 3778 | } |
| 3779 | |
| 3780 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3781 | #ifdef CONFIG_MESH |
| 3782 | static int nl80211_set_mesh_config(void *priv, |
| 3783 | struct wpa_driver_mesh_bss_params *params) |
| 3784 | { |
| 3785 | struct i802_bss *bss = priv; |
| 3786 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3787 | struct nl_msg *msg; |
| 3788 | int ret; |
| 3789 | |
| 3790 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG); |
| 3791 | if (!msg) |
| 3792 | return -1; |
| 3793 | |
| 3794 | ret = nl80211_put_mesh_config(msg, params); |
| 3795 | if (ret < 0) { |
| 3796 | nlmsg_free(msg); |
| 3797 | return ret; |
| 3798 | } |
| 3799 | |
| 3800 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3801 | if (ret) { |
| 3802 | wpa_printf(MSG_ERROR, |
| 3803 | "nl80211: Mesh config set failed: %d (%s)", |
| 3804 | ret, strerror(-ret)); |
| 3805 | return ret; |
| 3806 | } |
| 3807 | return 0; |
| 3808 | } |
| 3809 | #endif /* CONFIG_MESH */ |
| 3810 | |
| 3811 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3812 | static int nl80211_put_beacon_rate(struct nl_msg *msg, const u64 flags, |
| 3813 | struct wpa_driver_ap_params *params) |
| 3814 | { |
| 3815 | struct nlattr *bands, *band; |
| 3816 | struct nl80211_txrate_vht vht_rate; |
| 3817 | |
| 3818 | if (!params->freq || |
| 3819 | (params->beacon_rate == 0 && |
| 3820 | params->rate_type == BEACON_RATE_LEGACY)) |
| 3821 | return 0; |
| 3822 | |
| 3823 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 3824 | if (!bands) |
| 3825 | return -1; |
| 3826 | |
| 3827 | switch (params->freq->mode) { |
| 3828 | case HOSTAPD_MODE_IEEE80211B: |
| 3829 | case HOSTAPD_MODE_IEEE80211G: |
| 3830 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
| 3831 | break; |
| 3832 | case HOSTAPD_MODE_IEEE80211A: |
| 3833 | band = nla_nest_start(msg, NL80211_BAND_5GHZ); |
| 3834 | break; |
| 3835 | case HOSTAPD_MODE_IEEE80211AD: |
| 3836 | band = nla_nest_start(msg, NL80211_BAND_60GHZ); |
| 3837 | break; |
| 3838 | default: |
| 3839 | return 0; |
| 3840 | } |
| 3841 | |
| 3842 | if (!band) |
| 3843 | return -1; |
| 3844 | |
| 3845 | os_memset(&vht_rate, 0, sizeof(vht_rate)); |
| 3846 | |
| 3847 | switch (params->rate_type) { |
| 3848 | case BEACON_RATE_LEGACY: |
| 3849 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) { |
| 3850 | wpa_printf(MSG_INFO, |
| 3851 | "nl80211: Driver does not support setting Beacon frame rate (legacy)"); |
| 3852 | return -1; |
| 3853 | } |
| 3854 | |
| 3855 | if (nla_put_u8(msg, NL80211_TXRATE_LEGACY, |
| 3856 | (u8) params->beacon_rate / 5) || |
| 3857 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || |
| 3858 | (params->freq->vht_enabled && |
| 3859 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 3860 | &vht_rate))) |
| 3861 | return -1; |
| 3862 | |
| 3863 | wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)", |
| 3864 | params->beacon_rate); |
| 3865 | break; |
| 3866 | case BEACON_RATE_HT: |
| 3867 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) { |
| 3868 | wpa_printf(MSG_INFO, |
| 3869 | "nl80211: Driver does not support setting Beacon frame rate (HT)"); |
| 3870 | return -1; |
| 3871 | } |
| 3872 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || |
| 3873 | nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) || |
| 3874 | (params->freq->vht_enabled && |
| 3875 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 3876 | &vht_rate))) |
| 3877 | return -1; |
| 3878 | wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u", |
| 3879 | params->beacon_rate); |
| 3880 | break; |
| 3881 | case BEACON_RATE_VHT: |
| 3882 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) { |
| 3883 | wpa_printf(MSG_INFO, |
| 3884 | "nl80211: Driver does not support setting Beacon frame rate (VHT)"); |
| 3885 | return -1; |
| 3886 | } |
| 3887 | vht_rate.mcs[0] = BIT(params->beacon_rate); |
| 3888 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL)) |
| 3889 | return -1; |
| 3890 | if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL)) |
| 3891 | return -1; |
| 3892 | if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 3893 | &vht_rate)) |
| 3894 | return -1; |
| 3895 | wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u", |
| 3896 | params->beacon_rate); |
| 3897 | break; |
| 3898 | } |
| 3899 | |
| 3900 | nla_nest_end(msg, band); |
| 3901 | nla_nest_end(msg, bands); |
| 3902 | |
| 3903 | return 0; |
| 3904 | } |
| 3905 | |
| 3906 | |
| 3907 | static int nl80211_set_multicast_to_unicast(struct i802_bss *bss, |
| 3908 | int multicast_to_unicast) |
| 3909 | { |
| 3910 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3911 | struct nl_msg *msg; |
| 3912 | int ret; |
| 3913 | |
| 3914 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST); |
| 3915 | if (!msg || |
| 3916 | (multicast_to_unicast && |
| 3917 | nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) { |
| 3918 | wpa_printf(MSG_ERROR, |
| 3919 | "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s", |
| 3920 | bss->ifname); |
| 3921 | nlmsg_free(msg); |
| 3922 | return -ENOBUFS; |
| 3923 | } |
| 3924 | |
| 3925 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3926 | |
| 3927 | switch (ret) { |
| 3928 | case 0: |
| 3929 | wpa_printf(MSG_DEBUG, |
| 3930 | "nl80211: multicast to unicast %s on interface %s", |
| 3931 | multicast_to_unicast ? "enabled" : "disabled", |
| 3932 | bss->ifname); |
| 3933 | break; |
| 3934 | case -EOPNOTSUPP: |
| 3935 | if (!multicast_to_unicast) |
| 3936 | break; |
| 3937 | wpa_printf(MSG_INFO, |
| 3938 | "nl80211: multicast to unicast not supported on interface %s", |
| 3939 | bss->ifname); |
| 3940 | break; |
| 3941 | default: |
| 3942 | wpa_printf(MSG_ERROR, |
| 3943 | "nl80211: %s multicast to unicast failed with %d (%s) on interface %s", |
| 3944 | multicast_to_unicast ? "enabling" : "disabling", |
| 3945 | ret, strerror(-ret), bss->ifname); |
| 3946 | break; |
| 3947 | } |
| 3948 | |
| 3949 | return ret; |
| 3950 | } |
| 3951 | |
| 3952 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3953 | static int wpa_driver_nl80211_set_ap(void *priv, |
| 3954 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3955 | { |
| 3956 | struct i802_bss *bss = priv; |
| 3957 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3958 | struct nl_msg *msg; |
| 3959 | u8 cmd = NL80211_CMD_NEW_BEACON; |
| 3960 | int ret; |
| 3961 | int beacon_set; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3962 | int num_suites; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3963 | int smps_mode; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3964 | u32 suites[10], suite; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3965 | u32 ver; |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3966 | #ifdef CONFIG_MESH |
| 3967 | struct wpa_driver_mesh_bss_params mesh_params; |
| 3968 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3969 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3970 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3971 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3972 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
| 3973 | beacon_set); |
| 3974 | if (beacon_set) |
| 3975 | cmd = NL80211_CMD_SET_BEACON; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 3976 | else if (!drv->device_ap_sme && !drv->use_monitor && |
| 3977 | !nl80211_get_wiphy_data_ap(bss)) |
| 3978 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3979 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3980 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
| 3981 | params->head, params->head_len); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3982 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
| 3983 | params->tail, params->tail_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3984 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3985 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3986 | wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate); |
| 3987 | wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3988 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3989 | wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid", |
| 3990 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3991 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 3992 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
| 3993 | params->head) || |
| 3994 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, |
| 3995 | params->tail) || |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3996 | nl80211_put_beacon_int(msg, params->beacon_int) || |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3997 | nl80211_put_beacon_rate(msg, drv->capa.flags, params) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3998 | nl80211_put_dtim_period(msg, params->dtim_period) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3999 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 4000 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4001 | if (params->proberesp && params->proberesp_len) { |
| 4002 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", |
| 4003 | params->proberesp, params->proberesp_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4004 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
| 4005 | params->proberesp)) |
| 4006 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4007 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4008 | switch (params->hide_ssid) { |
| 4009 | case NO_SSID_HIDING: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4010 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4011 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 4012 | NL80211_HIDDEN_SSID_NOT_IN_USE)) |
| 4013 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4014 | break; |
| 4015 | case HIDDEN_SSID_ZERO_LEN: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4016 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4017 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 4018 | NL80211_HIDDEN_SSID_ZERO_LEN)) |
| 4019 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4020 | break; |
| 4021 | case HIDDEN_SSID_ZERO_CONTENTS: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4022 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4023 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 4024 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) |
| 4025 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4026 | break; |
| 4027 | } |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4028 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4029 | if (params->privacy && |
| 4030 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 4031 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4032 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4033 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
| 4034 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { |
| 4035 | /* Leave out the attribute */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4036 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
| 4037 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 4038 | NL80211_AUTHTYPE_SHARED_KEY)) |
| 4039 | goto fail; |
| 4040 | } else { |
| 4041 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 4042 | NL80211_AUTHTYPE_OPEN_SYSTEM)) |
| 4043 | goto fail; |
| 4044 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4045 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4046 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4047 | ver = 0; |
| 4048 | if (params->wpa_version & WPA_PROTO_WPA) |
| 4049 | ver |= NL80211_WPA_VERSION_1; |
| 4050 | if (params->wpa_version & WPA_PROTO_RSN) |
| 4051 | ver |= NL80211_WPA_VERSION_2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4052 | if (ver && |
| 4053 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 4054 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4055 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4056 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
| 4057 | params->key_mgmt_suites); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4058 | num_suites = 0; |
| 4059 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4060 | suites[num_suites++] = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4061 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4062 | suites[num_suites++] = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4063 | if (num_suites && |
| 4064 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), |
| 4065 | suites)) |
| 4066 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4067 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4068 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4069 | (!params->pairwise_ciphers || |
| 4070 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) && |
| 4071 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 4072 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4073 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4074 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4075 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
| 4076 | params->pairwise_ciphers); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4077 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
| 4078 | suites, ARRAY_SIZE(suites)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4079 | if (num_suites && |
| 4080 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 4081 | num_suites * sizeof(u32), suites)) |
| 4082 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4083 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4084 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
| 4085 | params->group_cipher); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4086 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4087 | if (suite && |
| 4088 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) |
| 4089 | goto fail; |
| 4090 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 4091 | if (params->ht_opmode != -1) { |
| 4092 | switch (params->smps_mode) { |
| 4093 | case HT_CAP_INFO_SMPS_DYNAMIC: |
| 4094 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic"); |
| 4095 | smps_mode = NL80211_SMPS_DYNAMIC; |
| 4096 | break; |
| 4097 | case HT_CAP_INFO_SMPS_STATIC: |
| 4098 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static"); |
| 4099 | smps_mode = NL80211_SMPS_STATIC; |
| 4100 | break; |
| 4101 | default: |
| 4102 | /* invalid - fallback to smps off */ |
| 4103 | case HT_CAP_INFO_SMPS_DISABLED: |
| 4104 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off"); |
| 4105 | smps_mode = NL80211_SMPS_OFF; |
| 4106 | break; |
| 4107 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 4108 | if (nla_put_u8(msg, NL80211_ATTR_SMPS_MODE, smps_mode)) |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 4109 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4110 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4111 | |
| 4112 | if (params->beacon_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4113 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
| 4114 | params->beacon_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4115 | if (nla_put(msg, NL80211_ATTR_IE, |
| 4116 | wpabuf_len(params->beacon_ies), |
| 4117 | wpabuf_head(params->beacon_ies))) |
| 4118 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4119 | } |
| 4120 | if (params->proberesp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4121 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
| 4122 | params->proberesp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4123 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 4124 | wpabuf_len(params->proberesp_ies), |
| 4125 | wpabuf_head(params->proberesp_ies))) |
| 4126 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4127 | } |
| 4128 | if (params->assocresp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4129 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
| 4130 | params->assocresp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4131 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 4132 | wpabuf_len(params->assocresp_ies), |
| 4133 | wpabuf_head(params->assocresp_ies))) |
| 4134 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4135 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4136 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4137 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 4138 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
| 4139 | params->ap_max_inactivity); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4140 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
| 4141 | params->ap_max_inactivity)) |
| 4142 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4143 | } |
| 4144 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4145 | #ifdef CONFIG_P2P |
| 4146 | if (params->p2p_go_ctwindow > 0) { |
| 4147 | if (drv->p2p_go_ctwindow_supported) { |
| 4148 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", |
| 4149 | params->p2p_go_ctwindow); |
| 4150 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, |
| 4151 | params->p2p_go_ctwindow)) |
| 4152 | goto fail; |
| 4153 | } else { |
| 4154 | wpa_printf(MSG_INFO, |
| 4155 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); |
| 4156 | } |
| 4157 | } |
| 4158 | #endif /* CONFIG_P2P */ |
| 4159 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4160 | if (params->pbss) { |
| 4161 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); |
| 4162 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 4163 | goto fail; |
| 4164 | } |
| 4165 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4166 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4167 | if (ret) { |
| 4168 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", |
| 4169 | ret, strerror(-ret)); |
| 4170 | } else { |
| 4171 | bss->beacon_set = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4172 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
| 4173 | params->short_slot_time, params->ht_opmode, |
| 4174 | params->isolate, params->basic_rates); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 4175 | nl80211_set_multicast_to_unicast(bss, |
| 4176 | params->multicast_to_unicast); |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4177 | if (beacon_set && params->freq && |
| 4178 | params->freq->bandwidth != bss->bandwidth) { |
| 4179 | wpa_printf(MSG_DEBUG, |
| 4180 | "nl80211: Update BSS %s bandwidth: %d -> %d", |
| 4181 | bss->ifname, bss->bandwidth, |
| 4182 | params->freq->bandwidth); |
| 4183 | ret = nl80211_set_channel(bss, params->freq, 1); |
| 4184 | if (ret) { |
| 4185 | wpa_printf(MSG_DEBUG, |
| 4186 | "nl80211: Frequency set failed: %d (%s)", |
| 4187 | ret, strerror(-ret)); |
| 4188 | } else { |
| 4189 | wpa_printf(MSG_DEBUG, |
| 4190 | "nl80211: Frequency set succeeded for ht2040 coex"); |
| 4191 | bss->bandwidth = params->freq->bandwidth; |
| 4192 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4193 | } else if (!beacon_set && params->freq) { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4194 | /* |
| 4195 | * cfg80211 updates the driver on frequence change in AP |
| 4196 | * mode only at the point when beaconing is started, so |
| 4197 | * set the initial value here. |
| 4198 | */ |
| 4199 | bss->bandwidth = params->freq->bandwidth; |
| 4200 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4201 | } |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4202 | |
| 4203 | #ifdef CONFIG_MESH |
| 4204 | if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) { |
| 4205 | os_memset(&mesh_params, 0, sizeof(mesh_params)); |
| 4206 | mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE; |
| 4207 | mesh_params.ht_opmode = params->ht_opmode; |
| 4208 | ret = nl80211_set_mesh_config(priv, &mesh_params); |
| 4209 | if (ret < 0) |
| 4210 | return ret; |
| 4211 | } |
| 4212 | #endif /* CONFIG_MESH */ |
| 4213 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4214 | return ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4215 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4216 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4217 | return -ENOBUFS; |
| 4218 | } |
| 4219 | |
| 4220 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4221 | static int nl80211_put_freq_params(struct nl_msg *msg, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4222 | const struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4223 | { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4224 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4225 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
| 4226 | return -ENOBUFS; |
| 4227 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4228 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
| 4229 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); |
| 4230 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4231 | if (freq->vht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4232 | enum nl80211_chan_width cw; |
| 4233 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4234 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4235 | switch (freq->bandwidth) { |
| 4236 | case 20: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4237 | cw = NL80211_CHAN_WIDTH_20; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4238 | break; |
| 4239 | case 40: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4240 | cw = NL80211_CHAN_WIDTH_40; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4241 | break; |
| 4242 | case 80: |
| 4243 | if (freq->center_freq2) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4244 | cw = NL80211_CHAN_WIDTH_80P80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4245 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4246 | cw = NL80211_CHAN_WIDTH_80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4247 | break; |
| 4248 | case 160: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4249 | cw = NL80211_CHAN_WIDTH_160; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4250 | break; |
| 4251 | default: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4252 | return -EINVAL; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4253 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4254 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4255 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
| 4256 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", |
| 4257 | freq->center_freq1); |
| 4258 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", |
| 4259 | freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4260 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
| 4261 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, |
| 4262 | freq->center_freq1) || |
| 4263 | (freq->center_freq2 && |
| 4264 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 4265 | freq->center_freq2))) |
| 4266 | return -ENOBUFS; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4267 | } else if (freq->ht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4268 | enum nl80211_channel_type ct; |
| 4269 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4270 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
| 4271 | freq->sec_channel_offset); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4272 | switch (freq->sec_channel_offset) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4273 | case -1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4274 | ct = NL80211_CHAN_HT40MINUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4275 | break; |
| 4276 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4277 | ct = NL80211_CHAN_HT40PLUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4278 | break; |
| 4279 | default: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4280 | ct = NL80211_CHAN_HT20; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4281 | break; |
| 4282 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4283 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4284 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4285 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
| 4286 | return -ENOBUFS; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4287 | } else { |
| 4288 | wpa_printf(MSG_DEBUG, " * channel_type=%d", |
| 4289 | NL80211_CHAN_NO_HT); |
| 4290 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 4291 | NL80211_CHAN_NO_HT)) |
| 4292 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4293 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4294 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4295 | } |
| 4296 | |
| 4297 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4298 | static int nl80211_set_channel(struct i802_bss *bss, |
| 4299 | struct hostapd_freq_params *freq, int set_chan) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4300 | { |
| 4301 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4302 | struct nl_msg *msg; |
| 4303 | int ret; |
| 4304 | |
| 4305 | wpa_printf(MSG_DEBUG, |
| 4306 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
| 4307 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 4308 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4309 | |
| 4310 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
| 4311 | NL80211_CMD_SET_WIPHY); |
| 4312 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { |
| 4313 | nlmsg_free(msg); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4314 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4315 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4316 | |
| 4317 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4318 | if (ret == 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4319 | bss->freq = freq->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4320 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4321 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4322 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4323 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4324 | return -1; |
| 4325 | } |
| 4326 | |
| 4327 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4328 | static u32 sta_flags_nl80211(int flags) |
| 4329 | { |
| 4330 | u32 f = 0; |
| 4331 | |
| 4332 | if (flags & WPA_STA_AUTHORIZED) |
| 4333 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 4334 | if (flags & WPA_STA_WMM) |
| 4335 | f |= BIT(NL80211_STA_FLAG_WME); |
| 4336 | if (flags & WPA_STA_SHORT_PREAMBLE) |
| 4337 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
| 4338 | if (flags & WPA_STA_MFP) |
| 4339 | f |= BIT(NL80211_STA_FLAG_MFP); |
| 4340 | if (flags & WPA_STA_TDLS_PEER) |
| 4341 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4342 | if (flags & WPA_STA_AUTHENTICATED) |
| 4343 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4344 | if (flags & WPA_STA_ASSOCIATED) |
| 4345 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4346 | |
| 4347 | return f; |
| 4348 | } |
| 4349 | |
| 4350 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4351 | #ifdef CONFIG_MESH |
| 4352 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) |
| 4353 | { |
| 4354 | switch (state) { |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4355 | case PLINK_IDLE: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4356 | return NL80211_PLINK_LISTEN; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4357 | case PLINK_OPN_SNT: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4358 | return NL80211_PLINK_OPN_SNT; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4359 | case PLINK_OPN_RCVD: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4360 | return NL80211_PLINK_OPN_RCVD; |
| 4361 | case PLINK_CNF_RCVD: |
| 4362 | return NL80211_PLINK_CNF_RCVD; |
| 4363 | case PLINK_ESTAB: |
| 4364 | return NL80211_PLINK_ESTAB; |
| 4365 | case PLINK_HOLDING: |
| 4366 | return NL80211_PLINK_HOLDING; |
| 4367 | case PLINK_BLOCKED: |
| 4368 | return NL80211_PLINK_BLOCKED; |
| 4369 | default: |
| 4370 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", |
| 4371 | state); |
| 4372 | } |
| 4373 | return -1; |
| 4374 | } |
| 4375 | #endif /* CONFIG_MESH */ |
| 4376 | |
| 4377 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4378 | static int wpa_driver_nl80211_sta_add(void *priv, |
| 4379 | struct hostapd_sta_add_params *params) |
| 4380 | { |
| 4381 | struct i802_bss *bss = priv; |
| 4382 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4383 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4384 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4385 | int ret = -ENOBUFS; |
| 4386 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4387 | if ((params->flags & WPA_STA_TDLS_PEER) && |
| 4388 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 4389 | return -EOPNOTSUPP; |
| 4390 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4391 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
| 4392 | params->set ? "Set" : "Add", MAC2STR(params->addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4393 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
| 4394 | NL80211_CMD_NEW_STATION); |
| 4395 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) |
| 4396 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4397 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4398 | /* |
| 4399 | * Set the below properties only in one of the following cases: |
| 4400 | * 1. New station is added, already associated. |
| 4401 | * 2. Set WPA_STA_TDLS_PEER station. |
| 4402 | * 3. Set an already added unassociated station, if driver supports |
| 4403 | * full AP client state. (Set these properties after station became |
| 4404 | * associated will be rejected by the driver). |
| 4405 | */ |
| 4406 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
| 4407 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 4408 | (params->flags & WPA_STA_ASSOCIATED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4409 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
| 4410 | params->supp_rates, params->supp_rates_len); |
| 4411 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
| 4412 | params->capability); |
| 4413 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, |
| 4414 | params->supp_rates_len, params->supp_rates) || |
| 4415 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, |
| 4416 | params->capability)) |
| 4417 | goto fail; |
| 4418 | |
| 4419 | if (params->ht_capabilities) { |
| 4420 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
| 4421 | (u8 *) params->ht_capabilities, |
| 4422 | sizeof(*params->ht_capabilities)); |
| 4423 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
| 4424 | sizeof(*params->ht_capabilities), |
| 4425 | params->ht_capabilities)) |
| 4426 | goto fail; |
| 4427 | } |
| 4428 | |
| 4429 | if (params->vht_capabilities) { |
| 4430 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
| 4431 | (u8 *) params->vht_capabilities, |
| 4432 | sizeof(*params->vht_capabilities)); |
| 4433 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
| 4434 | sizeof(*params->vht_capabilities), |
| 4435 | params->vht_capabilities)) |
| 4436 | goto fail; |
| 4437 | } |
| 4438 | |
| 4439 | if (params->ext_capab) { |
| 4440 | wpa_hexdump(MSG_DEBUG, " * ext_capab", |
| 4441 | params->ext_capab, params->ext_capab_len); |
| 4442 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
| 4443 | params->ext_capab_len, params->ext_capab)) |
| 4444 | goto fail; |
| 4445 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4446 | |
| 4447 | if (is_ap_interface(drv->nlmode) && |
| 4448 | nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS, |
| 4449 | params->support_p2p_ps ? |
| 4450 | NL80211_P2P_PS_SUPPORTED : |
| 4451 | NL80211_P2P_PS_UNSUPPORTED)) |
| 4452 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4453 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4454 | if (!params->set) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4455 | if (params->aid) { |
| 4456 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4457 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
| 4458 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4459 | } else { |
| 4460 | /* |
| 4461 | * cfg80211 validates that AID is non-zero, so we have |
| 4462 | * to make this a non-zero value for the TDLS case where |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4463 | * a dummy STA entry is used for now and for a station |
| 4464 | * that is still not associated. |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4465 | */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4466 | wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)", |
| 4467 | (params->flags & WPA_STA_TDLS_PEER) ? |
| 4468 | "TDLS" : "UNASSOC_STA"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4469 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
| 4470 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4471 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4472 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 4473 | params->listen_interval); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4474 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 4475 | params->listen_interval)) |
| 4476 | goto fail; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4477 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
| 4478 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4479 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
| 4480 | goto fail; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4481 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 4482 | (params->flags & WPA_STA_ASSOCIATED)) { |
| 4483 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
| 4484 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 4485 | params->listen_interval); |
| 4486 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || |
| 4487 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 4488 | params->listen_interval)) |
| 4489 | goto fail; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4490 | } |
| 4491 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 4492 | if (params->vht_opmode_enabled) { |
| 4493 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4494 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
| 4495 | params->vht_opmode)) |
| 4496 | goto fail; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4497 | } |
| 4498 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4499 | if (params->supp_channels) { |
| 4500 | wpa_hexdump(MSG_DEBUG, " * supported channels", |
| 4501 | params->supp_channels, params->supp_channels_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4502 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
| 4503 | params->supp_channels_len, params->supp_channels)) |
| 4504 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4505 | } |
| 4506 | |
| 4507 | if (params->supp_oper_classes) { |
| 4508 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", |
| 4509 | params->supp_oper_classes, |
| 4510 | params->supp_oper_classes_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4511 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
| 4512 | params->supp_oper_classes_len, |
| 4513 | params->supp_oper_classes)) |
| 4514 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4515 | } |
| 4516 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4517 | os_memset(&upd, 0, sizeof(upd)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4518 | upd.set = sta_flags_nl80211(params->flags); |
| 4519 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4520 | |
| 4521 | /* |
| 4522 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH |
| 4523 | * flags, as nl80211 driver moves a new station, by default, into |
| 4524 | * associated state. |
| 4525 | * |
| 4526 | * On the other hand, if the driver supports that feature and the |
| 4527 | * station is added in unauthenticated state, set the |
| 4528 | * authenticated/associated bits in the mask to prevent moving this |
| 4529 | * station to associated state before it is actually associated. |
| 4530 | * |
| 4531 | * This is irrelevant for mesh mode where the station is added to the |
| 4532 | * driver as authenticated already, and ASSOCIATED isn't part of the |
| 4533 | * nl80211 API. |
| 4534 | */ |
| 4535 | if (!is_mesh_interface(drv->nlmode)) { |
| 4536 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { |
| 4537 | wpa_printf(MSG_DEBUG, |
| 4538 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); |
| 4539 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4540 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); |
| 4541 | } else if (!params->set && |
| 4542 | !(params->flags & WPA_STA_TDLS_PEER)) { |
| 4543 | if (!(params->flags & WPA_STA_AUTHENTICATED)) |
| 4544 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
| 4545 | if (!(params->flags & WPA_STA_ASSOCIATED)) |
| 4546 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 4547 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4548 | #ifdef CONFIG_MESH |
| 4549 | } else { |
| 4550 | if (params->plink_state == PLINK_ESTAB && params->peer_aid) { |
| 4551 | ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID, |
| 4552 | params->peer_aid); |
| 4553 | if (ret) |
| 4554 | goto fail; |
| 4555 | } |
| 4556 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4557 | } |
| 4558 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4559 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
| 4560 | upd.set, upd.mask); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4561 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 4562 | goto fail; |
| 4563 | |
| 4564 | #ifdef CONFIG_MESH |
| 4565 | if (params->plink_state && |
| 4566 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, |
| 4567 | sta_plink_state_nl80211(params->plink_state))) |
| 4568 | goto fail; |
| 4569 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4570 | |
| 4571 | if (params->flags & WPA_STA_WMM) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4572 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 4573 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4574 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4575 | if (!wme || |
| 4576 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 4577 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || |
| 4578 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, |
| 4579 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
| 4580 | WMM_QOSINFO_STA_SP_MASK)) |
| 4581 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4582 | nla_nest_end(msg, wme); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4583 | } |
| 4584 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4585 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4586 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4587 | if (ret) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4588 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
| 4589 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, |
| 4590 | strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4591 | if (ret == -EEXIST) |
| 4592 | ret = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4593 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4594 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4595 | return ret; |
| 4596 | } |
| 4597 | |
| 4598 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4599 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
| 4600 | { |
| 4601 | #ifdef CONFIG_LIBNL3_ROUTE |
| 4602 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4603 | struct rtnl_neigh *rn; |
| 4604 | struct nl_addr *nl_addr; |
| 4605 | int err; |
| 4606 | |
| 4607 | rn = rtnl_neigh_alloc(); |
| 4608 | if (!rn) |
| 4609 | return; |
| 4610 | |
| 4611 | rtnl_neigh_set_family(rn, AF_BRIDGE); |
| 4612 | rtnl_neigh_set_ifindex(rn, bss->ifindex); |
| 4613 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); |
| 4614 | if (!nl_addr) { |
| 4615 | rtnl_neigh_put(rn); |
| 4616 | return; |
| 4617 | } |
| 4618 | rtnl_neigh_set_lladdr(rn, nl_addr); |
| 4619 | |
| 4620 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 4621 | if (err < 0) { |
| 4622 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " |
| 4623 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), |
| 4624 | bss->ifindex, nl_geterror(err)); |
| 4625 | } else { |
| 4626 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " |
| 4627 | MACSTR, MAC2STR(addr)); |
| 4628 | } |
| 4629 | |
| 4630 | nl_addr_put(nl_addr); |
| 4631 | rtnl_neigh_put(rn); |
| 4632 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 4633 | } |
| 4634 | |
| 4635 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4636 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
| 4637 | int deauth, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4638 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4639 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4640 | struct nl_msg *msg; |
| 4641 | int ret; |
| 4642 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4643 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
| 4644 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 4645 | (deauth == 0 && |
| 4646 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 4647 | WLAN_FC_STYPE_DISASSOC)) || |
| 4648 | (deauth == 1 && |
| 4649 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 4650 | WLAN_FC_STYPE_DEAUTH)) || |
| 4651 | (reason_code && |
| 4652 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { |
| 4653 | nlmsg_free(msg); |
| 4654 | return -ENOBUFS; |
| 4655 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4656 | |
| 4657 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 4658 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
| 4659 | " --> %d (%s)", |
| 4660 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4661 | |
| 4662 | if (drv->rtnl_sk) |
| 4663 | rtnl_neigh_delete_fdb_entry(bss, addr); |
| 4664 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4665 | if (ret == -ENOENT) |
| 4666 | return 0; |
| 4667 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4668 | } |
| 4669 | |
| 4670 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4671 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4672 | { |
| 4673 | struct nl_msg *msg; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4674 | struct wpa_driver_nl80211_data *drv2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4675 | |
| 4676 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
| 4677 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4678 | /* stop listening for EAPOL on this interface */ |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4679 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 4680 | struct wpa_driver_nl80211_data, list) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4681 | { |
| 4682 | del_ifidx(drv2, ifidx, IFIDX_ANY); |
| 4683 | /* Remove all bridges learned for this iface */ |
| 4684 | del_ifidx(drv2, IFIDX_ANY, ifidx); |
| 4685 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4686 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4687 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4688 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 4689 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4690 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
| 4691 | } |
| 4692 | |
| 4693 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 4694 | const char * nl80211_iftype_str(enum nl80211_iftype mode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4695 | { |
| 4696 | switch (mode) { |
| 4697 | case NL80211_IFTYPE_ADHOC: |
| 4698 | return "ADHOC"; |
| 4699 | case NL80211_IFTYPE_STATION: |
| 4700 | return "STATION"; |
| 4701 | case NL80211_IFTYPE_AP: |
| 4702 | return "AP"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 4703 | case NL80211_IFTYPE_AP_VLAN: |
| 4704 | return "AP_VLAN"; |
| 4705 | case NL80211_IFTYPE_WDS: |
| 4706 | return "WDS"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4707 | case NL80211_IFTYPE_MONITOR: |
| 4708 | return "MONITOR"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 4709 | case NL80211_IFTYPE_MESH_POINT: |
| 4710 | return "MESH_POINT"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4711 | case NL80211_IFTYPE_P2P_CLIENT: |
| 4712 | return "P2P_CLIENT"; |
| 4713 | case NL80211_IFTYPE_P2P_GO: |
| 4714 | return "P2P_GO"; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4715 | case NL80211_IFTYPE_P2P_DEVICE: |
| 4716 | return "P2P_DEVICE"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4717 | default: |
| 4718 | return "unknown"; |
| 4719 | } |
| 4720 | } |
| 4721 | |
| 4722 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4723 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
| 4724 | const char *ifname, |
| 4725 | enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4726 | const u8 *addr, int wds, |
| 4727 | int (*handler)(struct nl_msg *, void *), |
| 4728 | void *arg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4729 | { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4730 | struct nl_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4731 | int ifidx; |
| 4732 | int ret = -ENOBUFS; |
| 4733 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4734 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
| 4735 | iftype, nl80211_iftype_str(iftype)); |
| 4736 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4737 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
| 4738 | if (!msg || |
| 4739 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
| 4740 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) |
| 4741 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4742 | |
| 4743 | if (iftype == NL80211_IFTYPE_MONITOR) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4744 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4745 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4746 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4747 | if (!flags || |
| 4748 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) |
| 4749 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4750 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4751 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4752 | } else if (wds) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4753 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
| 4754 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4755 | } |
| 4756 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4757 | /* |
| 4758 | * Tell cfg80211 that the interface belongs to the socket that created |
| 4759 | * it, and the interface should be deleted when the socket is closed. |
| 4760 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4761 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 4762 | goto fail; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4763 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4764 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4765 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4766 | if (ret) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4767 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4768 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4769 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
| 4770 | ifname, ret, strerror(-ret)); |
| 4771 | return ret; |
| 4772 | } |
| 4773 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4774 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
| 4775 | return 0; |
| 4776 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4777 | ifidx = if_nametoindex(ifname); |
| 4778 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
| 4779 | ifname, ifidx); |
| 4780 | |
| 4781 | if (ifidx <= 0) |
| 4782 | return -1; |
| 4783 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4784 | /* |
| 4785 | * Some virtual interfaces need to process EAPOL packets and events on |
| 4786 | * the parent interface. This is used mainly with hostapd. |
| 4787 | */ |
| 4788 | if (drv->hostapd || |
| 4789 | iftype == NL80211_IFTYPE_AP_VLAN || |
| 4790 | iftype == NL80211_IFTYPE_WDS || |
| 4791 | iftype == NL80211_IFTYPE_MONITOR) { |
| 4792 | /* start listening for EAPOL on this interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4793 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4794 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4795 | |
| 4796 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4797 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4798 | nl80211_remove_iface(drv, ifidx); |
| 4799 | return -1; |
| 4800 | } |
| 4801 | |
| 4802 | return ifidx; |
| 4803 | } |
| 4804 | |
| 4805 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4806 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
| 4807 | const char *ifname, enum nl80211_iftype iftype, |
| 4808 | const u8 *addr, int wds, |
| 4809 | int (*handler)(struct nl_msg *, void *), |
| 4810 | void *arg, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4811 | { |
| 4812 | int ret; |
| 4813 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4814 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
| 4815 | arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4816 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4817 | /* if error occurred and interface exists already */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4818 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4819 | if (use_existing) { |
| 4820 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", |
| 4821 | ifname); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 4822 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
| 4823 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4824 | addr) < 0 && |
| 4825 | (linux_set_iface_flags(drv->global->ioctl_sock, |
| 4826 | ifname, 0) < 0 || |
| 4827 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4828 | addr) < 0 || |
| 4829 | linux_set_iface_flags(drv->global->ioctl_sock, |
| 4830 | ifname, 1) < 0)) |
| 4831 | return -1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4832 | return -ENFILE; |
| 4833 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4834 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
| 4835 | |
| 4836 | /* Try to remove the interface that was already there. */ |
| 4837 | nl80211_remove_iface(drv, if_nametoindex(ifname)); |
| 4838 | |
| 4839 | /* Try to create the interface again */ |
| 4840 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4841 | wds, handler, arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4842 | } |
| 4843 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4844 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
| 4845 | wpa_printf(MSG_DEBUG, |
| 4846 | "nl80211: Interface %s created for P2P - disable 11b rates", |
| 4847 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4848 | nl80211_disable_11b_rates(drv, ret, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4849 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4850 | |
| 4851 | return ret; |
| 4852 | } |
| 4853 | |
| 4854 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4855 | static int nl80211_setup_ap(struct i802_bss *bss) |
| 4856 | { |
| 4857 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4858 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4859 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 4860 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4861 | |
| 4862 | /* |
| 4863 | * Disable Probe Request reporting unless we need it in this way for |
| 4864 | * devices that include the AP SME, in the other case (unless using |
| 4865 | * monitor iface) we'll get it through the nl_mgmt socket instead. |
| 4866 | */ |
| 4867 | if (!drv->device_ap_sme) |
| 4868 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4869 | |
| 4870 | if (!drv->device_ap_sme && !drv->use_monitor) |
| 4871 | if (nl80211_mgmt_subscribe_ap(bss)) |
| 4872 | return -1; |
| 4873 | |
| 4874 | if (drv->device_ap_sme && !drv->use_monitor) |
| 4875 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4876 | wpa_printf(MSG_DEBUG, |
| 4877 | "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] | 4878 | |
| 4879 | if (!drv->device_ap_sme && drv->use_monitor && |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 4880 | nl80211_create_monitor_interface(drv) && |
| 4881 | !drv->device_ap_sme) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4882 | return -1; |
| 4883 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4884 | if (drv->device_ap_sme && |
| 4885 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { |
| 4886 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " |
| 4887 | "Probe Request frame reporting in AP mode"); |
| 4888 | /* Try to survive without this */ |
| 4889 | } |
| 4890 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4891 | return 0; |
| 4892 | } |
| 4893 | |
| 4894 | |
| 4895 | static void nl80211_teardown_ap(struct i802_bss *bss) |
| 4896 | { |
| 4897 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4898 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4899 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 4900 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4901 | if (drv->device_ap_sme) { |
| 4902 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4903 | if (!drv->use_monitor) |
| 4904 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); |
| 4905 | } else if (drv->use_monitor) |
| 4906 | nl80211_remove_monitor_interface(drv); |
| 4907 | else |
| 4908 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
| 4909 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 4910 | nl80211_put_wiphy_data_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4911 | bss->beacon_set = 0; |
| 4912 | } |
| 4913 | |
| 4914 | |
| 4915 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
| 4916 | const u8 *addr, const u8 *data, |
| 4917 | size_t data_len) |
| 4918 | { |
| 4919 | struct sockaddr_ll ll; |
| 4920 | int ret; |
| 4921 | |
| 4922 | if (bss->drv->eapol_tx_sock < 0) { |
| 4923 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); |
| 4924 | return -1; |
| 4925 | } |
| 4926 | |
| 4927 | os_memset(&ll, 0, sizeof(ll)); |
| 4928 | ll.sll_family = AF_PACKET; |
| 4929 | ll.sll_ifindex = bss->ifindex; |
| 4930 | ll.sll_protocol = htons(ETH_P_PAE); |
| 4931 | ll.sll_halen = ETH_ALEN; |
| 4932 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); |
| 4933 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, |
| 4934 | (struct sockaddr *) &ll, sizeof(ll)); |
| 4935 | if (ret < 0) |
| 4936 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", |
| 4937 | strerror(errno)); |
| 4938 | |
| 4939 | return ret; |
| 4940 | } |
| 4941 | |
| 4942 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4943 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 4944 | |
| 4945 | static int wpa_driver_nl80211_hapd_send_eapol( |
| 4946 | void *priv, const u8 *addr, const u8 *data, |
| 4947 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
| 4948 | { |
| 4949 | struct i802_bss *bss = priv; |
| 4950 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4951 | struct ieee80211_hdr *hdr; |
| 4952 | size_t len; |
| 4953 | u8 *pos; |
| 4954 | int res; |
| 4955 | int qos = flags & WPA_STA_WMM; |
Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 4956 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4957 | if (drv->device_ap_sme || !drv->use_monitor) |
| 4958 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
| 4959 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4960 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
| 4961 | data_len; |
| 4962 | hdr = os_zalloc(len); |
| 4963 | if (hdr == NULL) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4964 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
| 4965 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4966 | return -1; |
| 4967 | } |
| 4968 | |
| 4969 | hdr->frame_control = |
| 4970 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); |
| 4971 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 4972 | if (encrypt) |
| 4973 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); |
| 4974 | if (qos) { |
| 4975 | hdr->frame_control |= |
| 4976 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); |
| 4977 | } |
| 4978 | |
| 4979 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 4980 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 4981 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 4982 | pos = (u8 *) (hdr + 1); |
| 4983 | |
| 4984 | if (qos) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 4985 | /* Set highest priority in QoS header */ |
| 4986 | pos[0] = 7; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4987 | pos[1] = 0; |
| 4988 | pos += 2; |
| 4989 | } |
| 4990 | |
| 4991 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); |
| 4992 | pos += sizeof(rfc1042_header); |
| 4993 | WPA_PUT_BE16(pos, ETH_P_PAE); |
| 4994 | pos += 2; |
| 4995 | memcpy(pos, data, data_len); |
| 4996 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4997 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4998 | 0, 0, 0, 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4999 | if (res < 0) { |
| 5000 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " |
| 5001 | "failed: %d (%s)", |
| 5002 | (unsigned long) len, errno, strerror(errno)); |
| 5003 | } |
| 5004 | os_free(hdr); |
| 5005 | |
| 5006 | return res; |
| 5007 | } |
| 5008 | |
| 5009 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5010 | 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] | 5011 | unsigned int total_flags, |
| 5012 | unsigned int flags_or, |
| 5013 | unsigned int flags_and) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5014 | { |
| 5015 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5016 | struct nl_msg *msg; |
| 5017 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5018 | struct nl80211_sta_flag_update upd; |
| 5019 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 5020 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
| 5021 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", |
| 5022 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, |
| 5023 | !!(total_flags & WPA_STA_AUTHORIZED)); |
| 5024 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5025 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5026 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 5027 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5028 | |
| 5029 | /* |
| 5030 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This |
| 5031 | * can be removed eventually. |
| 5032 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5033 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5034 | if (!flags || |
| 5035 | ((total_flags & WPA_STA_AUTHORIZED) && |
| 5036 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || |
| 5037 | ((total_flags & WPA_STA_WMM) && |
| 5038 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || |
| 5039 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && |
| 5040 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || |
| 5041 | ((total_flags & WPA_STA_MFP) && |
| 5042 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || |
| 5043 | ((total_flags & WPA_STA_TDLS_PEER) && |
| 5044 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) |
| 5045 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5046 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 5047 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5048 | |
| 5049 | os_memset(&upd, 0, sizeof(upd)); |
| 5050 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); |
| 5051 | upd.set = sta_flags_nl80211(flags_or); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5052 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 5053 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5054 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5055 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 5056 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5057 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5058 | return -ENOBUFS; |
| 5059 | } |
| 5060 | |
| 5061 | |
| 5062 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
| 5063 | struct wpa_driver_associate_params *params) |
| 5064 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5065 | enum nl80211_iftype nlmode, old_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5066 | |
| 5067 | if (params->p2p) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5068 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
| 5069 | "group (GO)"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5070 | nlmode = NL80211_IFTYPE_P2P_GO; |
| 5071 | } else |
| 5072 | nlmode = NL80211_IFTYPE_AP; |
| 5073 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5074 | old_mode = drv->nlmode; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5075 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5076 | nl80211_remove_monitor_interface(drv); |
| 5077 | return -1; |
| 5078 | } |
| 5079 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 5080 | if (params->freq.freq && |
| 5081 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 5082 | if (old_mode != nlmode) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5083 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5084 | nl80211_remove_monitor_interface(drv); |
| 5085 | return -1; |
| 5086 | } |
| 5087 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5088 | return 0; |
| 5089 | } |
| 5090 | |
| 5091 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5092 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 5093 | int reset_mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5094 | { |
| 5095 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5096 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5097 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5098 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5099 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5100 | if (ret) { |
| 5101 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " |
| 5102 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5103 | } else { |
| 5104 | wpa_printf(MSG_DEBUG, |
| 5105 | "nl80211: Leave IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5106 | } |
| 5107 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5108 | if (reset_mode && |
| 5109 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 5110 | NL80211_IFTYPE_STATION)) { |
| 5111 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 5112 | "station mode"); |
| 5113 | } |
| 5114 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5115 | return ret; |
| 5116 | } |
| 5117 | |
| 5118 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5119 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
| 5120 | struct wpa_driver_associate_params *params) |
| 5121 | { |
| 5122 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) |
| 5123 | return -1; |
| 5124 | |
| 5125 | if (params->htcaps && params->htcaps_mask) { |
| 5126 | int sz = sizeof(struct ieee80211_ht_capabilities); |
| 5127 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); |
| 5128 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", |
| 5129 | params->htcaps_mask, sz); |
| 5130 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, |
| 5131 | params->htcaps) || |
| 5132 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 5133 | params->htcaps_mask)) |
| 5134 | return -1; |
| 5135 | } |
| 5136 | |
| 5137 | #ifdef CONFIG_VHT_OVERRIDES |
| 5138 | if (params->disable_vht) { |
| 5139 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
| 5140 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) |
| 5141 | return -1; |
| 5142 | } |
| 5143 | |
| 5144 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 5145 | int sz = sizeof(struct ieee80211_vht_capabilities); |
| 5146 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); |
| 5147 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", |
| 5148 | params->vhtcaps_mask, sz); |
| 5149 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, |
| 5150 | params->vhtcaps) || |
| 5151 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 5152 | params->vhtcaps_mask)) |
| 5153 | return -1; |
| 5154 | } |
| 5155 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 5156 | |
| 5157 | return 0; |
| 5158 | } |
| 5159 | |
| 5160 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5161 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
| 5162 | struct wpa_driver_associate_params *params) |
| 5163 | { |
| 5164 | struct nl_msg *msg; |
| 5165 | int ret = -1; |
| 5166 | int count = 0; |
| 5167 | |
| 5168 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); |
| 5169 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5170 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5171 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 5172 | "IBSS mode"); |
| 5173 | return -1; |
| 5174 | } |
| 5175 | |
| 5176 | retry: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5177 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
| 5178 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
| 5179 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5180 | |
| 5181 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 5182 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5183 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 5184 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5185 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 5186 | drv->ssid_len = params->ssid_len; |
| 5187 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 5188 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
| 5189 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5190 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5191 | |
| 5192 | ret = nl80211_set_conn_keys(params, msg); |
| 5193 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5194 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5195 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5196 | if (params->bssid && params->fixed_bssid) { |
| 5197 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, |
| 5198 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5199 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 5200 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5201 | } |
| 5202 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5203 | if (params->fixed_freq) { |
| 5204 | wpa_printf(MSG_DEBUG, " * fixed_freq"); |
| 5205 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) |
| 5206 | goto fail; |
| 5207 | } |
| 5208 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5209 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 5210 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 5211 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
| 5212 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5213 | wpa_printf(MSG_DEBUG, " * control port"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5214 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 5215 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5216 | } |
| 5217 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5218 | if (params->wpa_ie) { |
| 5219 | wpa_hexdump(MSG_DEBUG, |
| 5220 | " * Extra IEs for Beacon/Probe Response frames", |
| 5221 | params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5222 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 5223 | params->wpa_ie)) |
| 5224 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5225 | } |
| 5226 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 5227 | ret = nl80211_ht_vht_overrides(msg, params); |
| 5228 | if (ret < 0) |
| 5229 | goto fail; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5230 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5231 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5232 | msg = NULL; |
| 5233 | if (ret) { |
| 5234 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", |
| 5235 | ret, strerror(-ret)); |
| 5236 | count++; |
| 5237 | if (ret == -EALREADY && count == 1) { |
| 5238 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " |
| 5239 | "forced leave"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5240 | nl80211_leave_ibss(drv, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5241 | nlmsg_free(msg); |
| 5242 | goto retry; |
| 5243 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5244 | } else { |
| 5245 | wpa_printf(MSG_DEBUG, |
| 5246 | "nl80211: Join IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5247 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5248 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5249 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5250 | nlmsg_free(msg); |
| 5251 | return ret; |
| 5252 | } |
| 5253 | |
| 5254 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5255 | static int nl80211_put_fils_connect_params(struct wpa_driver_nl80211_data *drv, |
| 5256 | struct wpa_driver_associate_params *params, |
| 5257 | struct nl_msg *msg) |
| 5258 | { |
| 5259 | if (params->fils_erp_username_len) { |
| 5260 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP EMSKname/username", |
| 5261 | params->fils_erp_username, |
| 5262 | params->fils_erp_username_len); |
| 5263 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_USERNAME, |
| 5264 | params->fils_erp_username_len, |
| 5265 | params->fils_erp_username)) |
| 5266 | return -1; |
| 5267 | } |
| 5268 | |
| 5269 | if (params->fils_erp_realm_len) { |
| 5270 | wpa_hexdump_ascii(MSG_DEBUG, " * FILS ERP Realm", |
| 5271 | params->fils_erp_realm, |
| 5272 | params->fils_erp_realm_len); |
| 5273 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_REALM, |
| 5274 | params->fils_erp_realm_len, params->fils_erp_realm)) |
| 5275 | return -1; |
| 5276 | } |
| 5277 | |
| 5278 | wpa_printf(MSG_DEBUG, " * FILS ERP next seq %u", |
| 5279 | params->fils_erp_next_seq_num); |
| 5280 | if (nla_put_u16(msg, NL80211_ATTR_FILS_ERP_NEXT_SEQ_NUM, |
| 5281 | params->fils_erp_next_seq_num)) |
| 5282 | return -1; |
| 5283 | |
| 5284 | if (params->fils_erp_rrk_len) { |
| 5285 | wpa_printf(MSG_DEBUG, " * FILS ERP rRK (len=%lu)", |
| 5286 | (unsigned long) params->fils_erp_rrk_len); |
| 5287 | if (nla_put(msg, NL80211_ATTR_FILS_ERP_RRK, |
| 5288 | params->fils_erp_rrk_len, params->fils_erp_rrk)) |
| 5289 | return -1; |
| 5290 | } |
| 5291 | |
| 5292 | return 0; |
| 5293 | } |
| 5294 | |
| 5295 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5296 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
| 5297 | struct wpa_driver_associate_params *params, |
| 5298 | struct nl_msg *msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5299 | { |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5300 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 5301 | return -1; |
| 5302 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5303 | if (params->bssid) { |
| 5304 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 5305 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5306 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 5307 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5308 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5309 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5310 | if (params->bssid_hint) { |
| 5311 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, |
| 5312 | MAC2STR(params->bssid_hint)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5313 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
| 5314 | params->bssid_hint)) |
| 5315 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5316 | } |
| 5317 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5318 | if (params->freq.freq) { |
| 5319 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5320 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 5321 | params->freq.freq)) |
| 5322 | return -1; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5323 | drv->assoc_freq = params->freq.freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5324 | } else |
| 5325 | drv->assoc_freq = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5326 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5327 | if (params->freq_hint) { |
| 5328 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5329 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
| 5330 | params->freq_hint)) |
| 5331 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5332 | } |
| 5333 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5334 | if (params->bg_scan_period >= 0) { |
| 5335 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 5336 | params->bg_scan_period); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5337 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 5338 | params->bg_scan_period)) |
| 5339 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5340 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5341 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5342 | if (params->ssid) { |
| 5343 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 5344 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5345 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 5346 | params->ssid)) |
| 5347 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5348 | if (params->ssid_len > sizeof(drv->ssid)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5349 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5350 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 5351 | drv->ssid_len = params->ssid_len; |
| 5352 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5353 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5354 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5355 | if (params->wpa_ie && |
| 5356 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) |
| 5357 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5358 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5359 | if (params->wpa_proto) { |
| 5360 | enum nl80211_wpa_versions ver = 0; |
| 5361 | |
| 5362 | if (params->wpa_proto & WPA_PROTO_WPA) |
| 5363 | ver |= NL80211_WPA_VERSION_1; |
| 5364 | if (params->wpa_proto & WPA_PROTO_RSN) |
| 5365 | ver |= NL80211_WPA_VERSION_2; |
| 5366 | |
| 5367 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5368 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 5369 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5370 | } |
| 5371 | |
| 5372 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
| 5373 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
| 5374 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5375 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 5376 | cipher)) |
| 5377 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5378 | } |
| 5379 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 5380 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
| 5381 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { |
| 5382 | /* |
| 5383 | * This is likely to work even though many drivers do not |
| 5384 | * advertise support for operations without GTK. |
| 5385 | */ |
| 5386 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); |
| 5387 | } else if (params->group_suite != WPA_CIPHER_NONE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5388 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
| 5389 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5390 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
| 5391 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5392 | } |
| 5393 | |
| 5394 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 5395 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 5396 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || |
| 5397 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5398 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5399 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
| 5400 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5401 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5402 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5403 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192 || |
| 5404 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA256 || |
| 5405 | params->key_mgmt_suite == WPA_KEY_MGMT_FILS_SHA384 || |
| 5406 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA256 || |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5407 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_FILS_SHA384 || |
| 5408 | params->key_mgmt_suite == WPA_KEY_MGMT_OWE || |
| 5409 | params->key_mgmt_suite == WPA_KEY_MGMT_DPP) { |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5410 | int mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5411 | |
| 5412 | switch (params->key_mgmt_suite) { |
| 5413 | case WPA_KEY_MGMT_CCKM: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5414 | mgmt = RSN_AUTH_KEY_MGMT_CCKM; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5415 | break; |
| 5416 | case WPA_KEY_MGMT_IEEE8021X: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5417 | mgmt = RSN_AUTH_KEY_MGMT_UNSPEC_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5418 | break; |
| 5419 | case WPA_KEY_MGMT_FT_IEEE8021X: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5420 | mgmt = RSN_AUTH_KEY_MGMT_FT_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5421 | break; |
| 5422 | case WPA_KEY_MGMT_FT_PSK: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5423 | mgmt = RSN_AUTH_KEY_MGMT_FT_PSK; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5424 | break; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5425 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5426 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SHA256; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5427 | break; |
| 5428 | case WPA_KEY_MGMT_PSK_SHA256: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5429 | mgmt = RSN_AUTH_KEY_MGMT_PSK_SHA256; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5430 | break; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5431 | case WPA_KEY_MGMT_OSEN: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5432 | mgmt = RSN_AUTH_KEY_MGMT_OSEN; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5433 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5434 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5435 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5436 | break; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5437 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5438 | mgmt = RSN_AUTH_KEY_MGMT_802_1X_SUITE_B_192; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5439 | break; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5440 | case WPA_KEY_MGMT_FILS_SHA256: |
| 5441 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA256; |
| 5442 | break; |
| 5443 | case WPA_KEY_MGMT_FILS_SHA384: |
| 5444 | mgmt = RSN_AUTH_KEY_MGMT_FILS_SHA384; |
| 5445 | break; |
| 5446 | case WPA_KEY_MGMT_FT_FILS_SHA256: |
| 5447 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA256; |
| 5448 | break; |
| 5449 | case WPA_KEY_MGMT_FT_FILS_SHA384: |
| 5450 | mgmt = RSN_AUTH_KEY_MGMT_FT_FILS_SHA384; |
| 5451 | break; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5452 | case WPA_KEY_MGMT_OWE: |
| 5453 | mgmt = RSN_AUTH_KEY_MGMT_OWE; |
| 5454 | break; |
| 5455 | case WPA_KEY_MGMT_DPP: |
| 5456 | mgmt = RSN_AUTH_KEY_MGMT_DPP; |
| 5457 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5458 | case WPA_KEY_MGMT_PSK: |
| 5459 | default: |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 5460 | mgmt = RSN_AUTH_KEY_MGMT_PSK_OVER_802_1X; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5461 | break; |
| 5462 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5463 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5464 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
| 5465 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5466 | } |
| 5467 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5468 | /* Add PSK in case of 4-way handshake offload */ |
| 5469 | if (params->psk && |
| 5470 | (drv->capa.flags & WPA_DRIVER_FLAGS_4WAY_HANDSHAKE)) { |
| 5471 | wpa_hexdump_key(MSG_DEBUG, " * PSK", params->psk, 32); |
| 5472 | if (nla_put(msg, NL80211_ATTR_PMK, 32, params->psk)) |
| 5473 | return -1; |
| 5474 | } |
| 5475 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5476 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 5477 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5478 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 5479 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 5480 | (params->pairwise_suite == WPA_CIPHER_NONE || |
| 5481 | params->pairwise_suite == WPA_CIPHER_WEP104 || |
| 5482 | params->pairwise_suite == WPA_CIPHER_WEP40) && |
| 5483 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 5484 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
| 5485 | return -1; |
| 5486 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5487 | if (params->rrm_used) { |
| 5488 | u32 drv_rrm_flags = drv->capa.rrm_flags; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5489 | if ((!((drv_rrm_flags & |
| 5490 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && |
| 5491 | (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && |
| 5492 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5493 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
| 5494 | return -1; |
| 5495 | } |
| 5496 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5497 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5498 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5499 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5500 | if (params->p2p) |
| 5501 | wpa_printf(MSG_DEBUG, " * P2P group"); |
| 5502 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5503 | if (params->pbss) { |
| 5504 | wpa_printf(MSG_DEBUG, " * PBSS"); |
| 5505 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 5506 | return -1; |
| 5507 | } |
| 5508 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 5509 | drv->connect_reassoc = 0; |
| 5510 | if (params->prev_bssid) { |
| 5511 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, |
| 5512 | MAC2STR(params->prev_bssid)); |
| 5513 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
| 5514 | params->prev_bssid)) |
| 5515 | return -1; |
| 5516 | drv->connect_reassoc = 1; |
| 5517 | } |
| 5518 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5519 | if ((params->auth_alg & WPA_AUTH_ALG_FILS) && |
| 5520 | nl80211_put_fils_connect_params(drv, params, msg) != 0) |
| 5521 | return -1; |
| 5522 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5523 | if ((params->auth_alg & WPA_AUTH_ALG_SAE) && |
| 5524 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) && |
| 5525 | nla_put_flag(msg, NL80211_ATTR_EXTERNAL_AUTH_SUPPORT)) |
| 5526 | return -1; |
| 5527 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5528 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5529 | } |
| 5530 | |
| 5531 | |
| 5532 | static int wpa_driver_nl80211_try_connect( |
| 5533 | struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5534 | struct wpa_driver_associate_params *params, |
| 5535 | struct nl_handle *nl_connect) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5536 | { |
| 5537 | struct nl_msg *msg; |
| 5538 | enum nl80211_auth_type type; |
| 5539 | int ret; |
| 5540 | int algs; |
| 5541 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5542 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5543 | if (params->req_key_mgmt_offload && params->psk && |
| 5544 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 5545 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
| 5546 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { |
| 5547 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); |
| 5548 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); |
| 5549 | if (ret) |
| 5550 | return ret; |
| 5551 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5552 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5553 | |
| 5554 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
| 5555 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5556 | if (!msg) |
| 5557 | return -1; |
| 5558 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5559 | ret = nl80211_connect_common(drv, params, msg); |
| 5560 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5561 | goto fail; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5562 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5563 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 5564 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 5565 | goto fail; |
| 5566 | |
| 5567 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_OPTIONAL && |
| 5568 | (drv->capa.flags & WPA_DRIVER_FLAGS_MFP_OPTIONAL) && |
| 5569 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_OPTIONAL)) |
| 5570 | goto fail; |
| 5571 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5572 | algs = 0; |
| 5573 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 5574 | algs++; |
| 5575 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 5576 | algs++; |
| 5577 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 5578 | algs++; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5579 | if (params->auth_alg & WPA_AUTH_ALG_FILS) |
| 5580 | algs++; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5581 | if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 5582 | algs++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5583 | if (algs > 1) { |
| 5584 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " |
| 5585 | "selection"); |
| 5586 | goto skip_auth_type; |
| 5587 | } |
| 5588 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5589 | type = get_nl_auth_type(params->auth_alg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5590 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 5591 | if (type == NL80211_AUTHTYPE_MAX || |
| 5592 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5593 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5594 | |
| 5595 | skip_auth_type: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5596 | ret = nl80211_set_conn_keys(params, msg); |
| 5597 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5598 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5599 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5600 | if (nl_connect) |
| 5601 | ret = send_and_recv(drv->global, nl_connect, msg, NULL, NULL); |
| 5602 | else |
| 5603 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5604 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5605 | msg = NULL; |
| 5606 | if (ret) { |
| 5607 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " |
| 5608 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5609 | } else { |
| 5610 | wpa_printf(MSG_DEBUG, |
| 5611 | "nl80211: Connect request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5612 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5613 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5614 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5615 | nlmsg_free(msg); |
| 5616 | return ret; |
| 5617 | |
| 5618 | } |
| 5619 | |
| 5620 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5621 | static int wpa_driver_nl80211_connect( |
| 5622 | struct wpa_driver_nl80211_data *drv, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5623 | struct wpa_driver_associate_params *params, |
| 5624 | struct nl_handle *nl_connect) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5625 | { |
Jithu Jance | a7c60b4 | 2014-12-03 18:54:40 +0530 | [diff] [blame] | 5626 | int ret; |
| 5627 | |
| 5628 | /* Store the connection attempted bssid for future use */ |
| 5629 | if (params->bssid) |
| 5630 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 5631 | else |
| 5632 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
| 5633 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5634 | ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5635 | if (ret == -EALREADY) { |
| 5636 | /* |
| 5637 | * cfg80211 does not currently accept new connections if |
| 5638 | * we are already connected. As a workaround, force |
| 5639 | * disconnection and try again. |
| 5640 | */ |
| 5641 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " |
| 5642 | "disconnecting before reassociation " |
| 5643 | "attempt"); |
| 5644 | if (wpa_driver_nl80211_disconnect( |
| 5645 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) |
| 5646 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5647 | ret = wpa_driver_nl80211_try_connect(drv, params, nl_connect); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5648 | } |
| 5649 | return ret; |
| 5650 | } |
| 5651 | |
| 5652 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5653 | static int wpa_driver_nl80211_associate( |
| 5654 | void *priv, struct wpa_driver_associate_params *params) |
| 5655 | { |
| 5656 | struct i802_bss *bss = priv; |
| 5657 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5658 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5659 | struct nl_msg *msg; |
| 5660 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5661 | nl80211_unmask_11b_rates(bss); |
| 5662 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5663 | if (params->mode == IEEE80211_MODE_AP) |
| 5664 | return wpa_driver_nl80211_ap(drv, params); |
| 5665 | |
| 5666 | if (params->mode == IEEE80211_MODE_IBSS) |
| 5667 | return wpa_driver_nl80211_ibss(drv, params); |
| 5668 | |
| 5669 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5670 | enum nl80211_iftype nlmode = params->p2p ? |
| 5671 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5672 | struct nl_handle *nl_connect = NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5673 | |
| 5674 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5675 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5676 | if (params->auth_alg & WPA_AUTH_ALG_SAE) |
| 5677 | nl_connect = bss->nl_connect; |
| 5678 | return wpa_driver_nl80211_connect(drv, params, nl_connect); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5679 | } |
| 5680 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5681 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5682 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5683 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
| 5684 | drv->ifindex); |
| 5685 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5686 | if (!msg) |
| 5687 | return -1; |
| 5688 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5689 | ret = nl80211_connect_common(drv, params, msg); |
| 5690 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5691 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5692 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 5693 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 5694 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 5695 | goto fail; |
| 5696 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5697 | if (params->fils_kek) { |
| 5698 | wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)", |
| 5699 | (unsigned int) params->fils_kek_len); |
| 5700 | if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len, |
| 5701 | params->fils_kek)) |
| 5702 | goto fail; |
| 5703 | } |
| 5704 | if (params->fils_nonces) { |
| 5705 | wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)", |
| 5706 | params->fils_nonces, |
| 5707 | params->fils_nonces_len); |
| 5708 | if (nla_put(msg, NL80211_ATTR_FILS_NONCES, |
| 5709 | params->fils_nonces_len, params->fils_nonces)) |
| 5710 | goto fail; |
| 5711 | } |
| 5712 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5713 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5714 | msg = NULL; |
| 5715 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5716 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 5717 | "nl80211: MLME command failed (assoc): ret=%d (%s)", |
| 5718 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5719 | nl80211_dump_scan(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5720 | } else { |
| 5721 | wpa_printf(MSG_DEBUG, |
| 5722 | "nl80211: Association request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5723 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5724 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5725 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5726 | nlmsg_free(msg); |
| 5727 | return ret; |
| 5728 | } |
| 5729 | |
| 5730 | |
| 5731 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5732 | int ifindex, enum nl80211_iftype mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5733 | { |
| 5734 | struct nl_msg *msg; |
| 5735 | int ret = -ENOBUFS; |
| 5736 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5737 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
| 5738 | ifindex, mode, nl80211_iftype_str(mode)); |
| 5739 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5740 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 5741 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) |
| 5742 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5743 | |
| 5744 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5745 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5746 | if (!ret) |
| 5747 | return 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5748 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5749 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5750 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
| 5751 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); |
| 5752 | return ret; |
| 5753 | } |
| 5754 | |
| 5755 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5756 | static int wpa_driver_nl80211_set_mode_impl( |
| 5757 | struct i802_bss *bss, |
| 5758 | enum nl80211_iftype nlmode, |
| 5759 | struct hostapd_freq_params *desired_freq_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5760 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5761 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5762 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5763 | int i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5764 | int was_ap = is_ap_interface(drv->nlmode); |
| 5765 | int res; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5766 | int mode_switch_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5767 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5768 | if (TEST_FAIL()) |
| 5769 | return -1; |
| 5770 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5771 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 5772 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) |
| 5773 | mode_switch_res = 0; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5774 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5775 | if (mode_switch_res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5776 | drv->nlmode = nlmode; |
| 5777 | ret = 0; |
| 5778 | goto done; |
| 5779 | } |
| 5780 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5781 | if (mode_switch_res == -ENODEV) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5782 | return -1; |
| 5783 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5784 | if (nlmode == drv->nlmode) { |
| 5785 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
| 5786 | "requested mode - ignore error"); |
| 5787 | ret = 0; |
| 5788 | goto done; /* Already in the requested mode */ |
| 5789 | } |
| 5790 | |
| 5791 | /* mac80211 doesn't allow mode changes while the device is up, so |
| 5792 | * take the device down, try to set the mode again, and bring the |
| 5793 | * device back up. |
| 5794 | */ |
| 5795 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
| 5796 | "interface down"); |
| 5797 | for (i = 0; i < 10; i++) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5798 | res = i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5799 | if (res == -EACCES || res == -ENODEV) |
| 5800 | break; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5801 | if (res != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5802 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
| 5803 | "interface down"); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5804 | os_sleep(0, 100000); |
| 5805 | continue; |
| 5806 | } |
| 5807 | |
| 5808 | /* |
| 5809 | * Setting the mode will fail for some drivers if the phy is |
| 5810 | * on a frequency that the mode is disallowed in. |
| 5811 | */ |
| 5812 | if (desired_freq_params) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5813 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5814 | if (res) { |
| 5815 | wpa_printf(MSG_DEBUG, |
| 5816 | "nl80211: Failed to set frequency on interface"); |
| 5817 | } |
| 5818 | } |
| 5819 | |
| 5820 | /* Try to set the mode again while the interface is down */ |
| 5821 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 5822 | if (mode_switch_res == -EBUSY) { |
| 5823 | wpa_printf(MSG_DEBUG, |
| 5824 | "nl80211: Delaying mode set while interface going down"); |
| 5825 | os_sleep(0, 100000); |
| 5826 | continue; |
| 5827 | } |
| 5828 | ret = mode_switch_res; |
| 5829 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5830 | } |
| 5831 | |
| 5832 | if (!ret) { |
| 5833 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " |
| 5834 | "interface is down"); |
| 5835 | drv->nlmode = nlmode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5836 | drv->ignore_if_down_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5837 | } |
| 5838 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5839 | /* Bring the interface back up */ |
| 5840 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); |
| 5841 | if (res != 0) { |
| 5842 | wpa_printf(MSG_DEBUG, |
| 5843 | "nl80211: Failed to set interface up after switching mode"); |
| 5844 | ret = -1; |
| 5845 | } |
| 5846 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5847 | done: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5848 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5849 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " |
| 5850 | "from %d failed", nlmode, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5851 | return ret; |
| 5852 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5853 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5854 | if (is_p2p_net_interface(nlmode)) { |
| 5855 | wpa_printf(MSG_DEBUG, |
| 5856 | "nl80211: Interface %s mode change to P2P - disable 11b rates", |
| 5857 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5858 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5859 | } else if (drv->disabled_11b_rates) { |
| 5860 | wpa_printf(MSG_DEBUG, |
| 5861 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", |
| 5862 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5863 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5864 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5865 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5866 | if (is_ap_interface(nlmode)) { |
| 5867 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
| 5868 | /* Setup additional AP mode functionality if needed */ |
| 5869 | if (nl80211_setup_ap(bss)) |
| 5870 | return -1; |
| 5871 | } else if (was_ap) { |
| 5872 | /* Remove additional AP mode functionality */ |
| 5873 | nl80211_teardown_ap(bss); |
| 5874 | } else { |
| 5875 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
| 5876 | } |
| 5877 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5878 | if (is_mesh_interface(nlmode) && |
| 5879 | nl80211_mgmt_subscribe_mesh(bss)) |
| 5880 | return -1; |
| 5881 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5882 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5883 | !is_mesh_interface(nlmode) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5884 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 5885 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " |
| 5886 | "frame processing - ignore for now"); |
| 5887 | |
| 5888 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5889 | } |
| 5890 | |
| 5891 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5892 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 5893 | enum nl80211_iftype nlmode) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5894 | { |
| 5895 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); |
| 5896 | } |
| 5897 | |
| 5898 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5899 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 5900 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5901 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5902 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5903 | freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5904 | } |
| 5905 | |
| 5906 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5907 | static int wpa_driver_nl80211_get_capa(void *priv, |
| 5908 | struct wpa_driver_capa *capa) |
| 5909 | { |
| 5910 | struct i802_bss *bss = priv; |
| 5911 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 5912 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5913 | if (!drv->has_capability) |
| 5914 | return -1; |
| 5915 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5916 | if (drv->extended_capa && drv->extended_capa_mask) { |
| 5917 | capa->extended_capa = drv->extended_capa; |
| 5918 | capa->extended_capa_mask = drv->extended_capa_mask; |
| 5919 | capa->extended_capa_len = drv->extended_capa_len; |
| 5920 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5921 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5922 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5923 | } |
| 5924 | |
| 5925 | |
| 5926 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) |
| 5927 | { |
| 5928 | struct i802_bss *bss = priv; |
| 5929 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5930 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5931 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
| 5932 | bss->ifname, drv->operstate, state, |
| 5933 | state ? "UP" : "DORMANT"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5934 | drv->operstate = state; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5935 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5936 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
| 5937 | } |
| 5938 | |
| 5939 | |
| 5940 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) |
| 5941 | { |
| 5942 | struct i802_bss *bss = priv; |
| 5943 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5944 | struct nl_msg *msg; |
| 5945 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5946 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5947 | |
| 5948 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { |
| 5949 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); |
| 5950 | return 0; |
| 5951 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5952 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5953 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
| 5954 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); |
| 5955 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5956 | os_memset(&upd, 0, sizeof(upd)); |
| 5957 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 5958 | if (authorized) |
| 5959 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5960 | |
| 5961 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5962 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
| 5963 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { |
| 5964 | nlmsg_free(msg); |
| 5965 | return -ENOBUFS; |
| 5966 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5967 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5968 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5969 | if (!ret) |
| 5970 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5971 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
| 5972 | ret, strerror(-ret)); |
| 5973 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5974 | } |
| 5975 | |
| 5976 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5977 | /* Set kernel driver on given frequency (MHz) */ |
| 5978 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5979 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5980 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5981 | return nl80211_set_channel(bss, freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5982 | } |
| 5983 | |
| 5984 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5985 | static inline int min_int(int a, int b) |
| 5986 | { |
| 5987 | if (a < b) |
| 5988 | return a; |
| 5989 | return b; |
| 5990 | } |
| 5991 | |
| 5992 | |
| 5993 | static int get_key_handler(struct nl_msg *msg, void *arg) |
| 5994 | { |
| 5995 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5996 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5997 | |
| 5998 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5999 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6000 | |
| 6001 | /* |
| 6002 | * TODO: validate the key index and mac address! |
| 6003 | * Otherwise, there's a race condition as soon as |
| 6004 | * the kernel starts sending key notifications. |
| 6005 | */ |
| 6006 | |
| 6007 | if (tb[NL80211_ATTR_KEY_SEQ]) |
| 6008 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 6009 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); |
| 6010 | return NL_SKIP; |
| 6011 | } |
| 6012 | |
| 6013 | |
| 6014 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, |
| 6015 | int idx, u8 *seq) |
| 6016 | { |
| 6017 | struct i802_bss *bss = priv; |
| 6018 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6019 | struct nl_msg *msg; |
| 6020 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6021 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
| 6022 | NL80211_CMD_GET_KEY); |
| 6023 | if (!msg || |
| 6024 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 6025 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
| 6026 | nlmsg_free(msg); |
| 6027 | return -ENOBUFS; |
| 6028 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6029 | |
| 6030 | memset(seq, 0, 6); |
| 6031 | |
| 6032 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6033 | } |
| 6034 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6035 | |
| 6036 | static int i802_set_rts(void *priv, int rts) |
| 6037 | { |
| 6038 | struct i802_bss *bss = priv; |
| 6039 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6040 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6041 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6042 | u32 val; |
| 6043 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6044 | if (rts >= 2347) |
| 6045 | val = (u32) -1; |
| 6046 | else |
| 6047 | val = rts; |
| 6048 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6049 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 6050 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
| 6051 | nlmsg_free(msg); |
| 6052 | return -ENOBUFS; |
| 6053 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6054 | |
| 6055 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6056 | if (!ret) |
| 6057 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6058 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
| 6059 | "%d (%s)", rts, ret, strerror(-ret)); |
| 6060 | return ret; |
| 6061 | } |
| 6062 | |
| 6063 | |
| 6064 | static int i802_set_frag(void *priv, int frag) |
| 6065 | { |
| 6066 | struct i802_bss *bss = priv; |
| 6067 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6068 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6069 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6070 | u32 val; |
| 6071 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6072 | if (frag >= 2346) |
| 6073 | val = (u32) -1; |
| 6074 | else |
| 6075 | val = frag; |
| 6076 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6077 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 6078 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
| 6079 | nlmsg_free(msg); |
| 6080 | return -ENOBUFS; |
| 6081 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6082 | |
| 6083 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6084 | if (!ret) |
| 6085 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6086 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
| 6087 | "%d: %d (%s)", frag, ret, strerror(-ret)); |
| 6088 | return ret; |
| 6089 | } |
| 6090 | |
| 6091 | |
| 6092 | static int i802_flush(void *priv) |
| 6093 | { |
| 6094 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6095 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6096 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6097 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6098 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
| 6099 | bss->ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6100 | |
| 6101 | /* |
| 6102 | * XXX: FIX! this needs to flush all VLANs too |
| 6103 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6104 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
| 6105 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6106 | if (res) { |
| 6107 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " |
| 6108 | "(%s)", res, strerror(-res)); |
| 6109 | } |
| 6110 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6111 | } |
| 6112 | |
| 6113 | |
| 6114 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
| 6115 | { |
| 6116 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6117 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6118 | struct hostap_sta_driver_data *data = arg; |
| 6119 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; |
| 6120 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
| 6121 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, |
| 6122 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, |
| 6123 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, |
| 6124 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
| 6125 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 6126 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6127 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
| 6128 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6129 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6130 | [NL80211_STA_INFO_ACK_SIGNAL] = { .type = NLA_U8 }, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6131 | }; |
| 6132 | struct nlattr *rate[NL80211_RATE_INFO_MAX + 1]; |
| 6133 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 6134 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 6135 | [NL80211_RATE_INFO_BITRATE32] = { .type = NLA_U32 }, |
| 6136 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 6137 | [NL80211_RATE_INFO_VHT_MCS] = { .type = NLA_U8 }, |
| 6138 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 6139 | [NL80211_RATE_INFO_VHT_NSS] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6140 | }; |
| 6141 | |
| 6142 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6143 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6144 | |
| 6145 | /* |
| 6146 | * TODO: validate the interface and mac address! |
| 6147 | * Otherwise, there's a race condition as soon as |
| 6148 | * the kernel starts sending station notifications. |
| 6149 | */ |
| 6150 | |
| 6151 | if (!tb[NL80211_ATTR_STA_INFO]) { |
| 6152 | wpa_printf(MSG_DEBUG, "sta stats missing!"); |
| 6153 | return NL_SKIP; |
| 6154 | } |
| 6155 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, |
| 6156 | tb[NL80211_ATTR_STA_INFO], |
| 6157 | stats_policy)) { |
| 6158 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); |
| 6159 | return NL_SKIP; |
| 6160 | } |
| 6161 | |
| 6162 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) |
| 6163 | data->inactive_msec = |
| 6164 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6165 | /* For backwards compatibility, fetch the 32-bit counters first. */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6166 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
| 6167 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); |
| 6168 | if (stats[NL80211_STA_INFO_TX_BYTES]) |
| 6169 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 6170 | if (stats[NL80211_STA_INFO_RX_BYTES64] && |
| 6171 | stats[NL80211_STA_INFO_TX_BYTES64]) { |
| 6172 | /* |
| 6173 | * The driver supports 64-bit counters, so use them to override |
| 6174 | * the 32-bit values. |
| 6175 | */ |
| 6176 | data->rx_bytes = |
| 6177 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); |
| 6178 | data->tx_bytes = |
| 6179 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); |
| 6180 | data->bytes_64bit = 1; |
| 6181 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6182 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
| 6183 | data->rx_packets = |
| 6184 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); |
| 6185 | if (stats[NL80211_STA_INFO_TX_PACKETS]) |
| 6186 | data->tx_packets = |
| 6187 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 6188 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
| 6189 | data->tx_retry_failed = |
| 6190 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6191 | if (stats[NL80211_STA_INFO_SIGNAL]) |
| 6192 | data->signal = nla_get_u8(stats[NL80211_STA_INFO_SIGNAL]); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6193 | if (stats[NL80211_STA_INFO_ACK_SIGNAL]) { |
| 6194 | data->last_ack_rssi = |
| 6195 | nla_get_u8(stats[NL80211_STA_INFO_ACK_SIGNAL]); |
| 6196 | data->flags |= STA_DRV_DATA_LAST_ACK_RSSI; |
| 6197 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6198 | |
| 6199 | if (stats[NL80211_STA_INFO_TX_BITRATE] && |
| 6200 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, |
| 6201 | stats[NL80211_STA_INFO_TX_BITRATE], |
| 6202 | rate_policy) == 0) { |
| 6203 | if (rate[NL80211_RATE_INFO_BITRATE32]) |
| 6204 | data->current_tx_rate = |
| 6205 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); |
| 6206 | else if (rate[NL80211_RATE_INFO_BITRATE]) |
| 6207 | data->current_tx_rate = |
| 6208 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); |
| 6209 | |
| 6210 | if (rate[NL80211_RATE_INFO_MCS]) { |
| 6211 | data->tx_mcs = nla_get_u8(rate[NL80211_RATE_INFO_MCS]); |
| 6212 | data->flags |= STA_DRV_DATA_TX_MCS; |
| 6213 | } |
| 6214 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { |
| 6215 | data->tx_vhtmcs = |
| 6216 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); |
| 6217 | data->flags |= STA_DRV_DATA_TX_VHT_MCS; |
| 6218 | } |
| 6219 | if (rate[NL80211_RATE_INFO_SHORT_GI]) |
| 6220 | data->flags |= STA_DRV_DATA_TX_SHORT_GI; |
| 6221 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { |
| 6222 | data->tx_vht_nss = |
| 6223 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); |
| 6224 | data->flags |= STA_DRV_DATA_TX_VHT_NSS; |
| 6225 | } |
| 6226 | } |
| 6227 | |
| 6228 | if (stats[NL80211_STA_INFO_RX_BITRATE] && |
| 6229 | nla_parse_nested(rate, NL80211_RATE_INFO_MAX, |
| 6230 | stats[NL80211_STA_INFO_RX_BITRATE], |
| 6231 | rate_policy) == 0) { |
| 6232 | if (rate[NL80211_RATE_INFO_BITRATE32]) |
| 6233 | data->current_rx_rate = |
| 6234 | nla_get_u32(rate[NL80211_RATE_INFO_BITRATE32]); |
| 6235 | else if (rate[NL80211_RATE_INFO_BITRATE]) |
| 6236 | data->current_rx_rate = |
| 6237 | nla_get_u16(rate[NL80211_RATE_INFO_BITRATE]); |
| 6238 | |
| 6239 | if (rate[NL80211_RATE_INFO_MCS]) { |
| 6240 | data->rx_mcs = |
| 6241 | nla_get_u8(rate[NL80211_RATE_INFO_MCS]); |
| 6242 | data->flags |= STA_DRV_DATA_RX_MCS; |
| 6243 | } |
| 6244 | if (rate[NL80211_RATE_INFO_VHT_MCS]) { |
| 6245 | data->rx_vhtmcs = |
| 6246 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_MCS]); |
| 6247 | data->flags |= STA_DRV_DATA_RX_VHT_MCS; |
| 6248 | } |
| 6249 | if (rate[NL80211_RATE_INFO_SHORT_GI]) |
| 6250 | data->flags |= STA_DRV_DATA_RX_SHORT_GI; |
| 6251 | if (rate[NL80211_RATE_INFO_VHT_NSS]) { |
| 6252 | data->rx_vht_nss = |
| 6253 | nla_get_u8(rate[NL80211_RATE_INFO_VHT_NSS]); |
| 6254 | data->flags |= STA_DRV_DATA_RX_VHT_NSS; |
| 6255 | } |
| 6256 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6257 | |
| 6258 | return NL_SKIP; |
| 6259 | } |
| 6260 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6261 | static int i802_read_sta_data(struct i802_bss *bss, |
| 6262 | struct hostap_sta_driver_data *data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6263 | const u8 *addr) |
| 6264 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6265 | struct nl_msg *msg; |
| 6266 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6267 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
| 6268 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 6269 | nlmsg_free(msg); |
| 6270 | return -ENOBUFS; |
| 6271 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6272 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6273 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6274 | } |
| 6275 | |
| 6276 | |
| 6277 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
| 6278 | int cw_min, int cw_max, int burst_time) |
| 6279 | { |
| 6280 | struct i802_bss *bss = priv; |
| 6281 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6282 | struct nl_msg *msg; |
| 6283 | struct nlattr *txq, *params; |
| 6284 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6285 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6286 | if (!msg) |
| 6287 | return -1; |
| 6288 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6289 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
| 6290 | if (!txq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6291 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6292 | |
| 6293 | /* We are only sending parameters for a single TXQ at a time */ |
| 6294 | params = nla_nest_start(msg, 1); |
| 6295 | if (!params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6296 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6297 | |
| 6298 | switch (queue) { |
| 6299 | case 0: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6300 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
| 6301 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6302 | break; |
| 6303 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6304 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
| 6305 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6306 | break; |
| 6307 | case 2: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6308 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
| 6309 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6310 | break; |
| 6311 | case 3: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6312 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
| 6313 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6314 | break; |
| 6315 | } |
| 6316 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
| 6317 | * 32 usec, so need to convert the value here. */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6318 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
| 6319 | (burst_time * 100 + 16) / 32) || |
| 6320 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || |
| 6321 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || |
| 6322 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) |
| 6323 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6324 | |
| 6325 | nla_nest_end(msg, params); |
| 6326 | |
| 6327 | nla_nest_end(msg, txq); |
| 6328 | |
| 6329 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 6330 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6331 | msg = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6332 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6333 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6334 | return -1; |
| 6335 | } |
| 6336 | |
| 6337 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6338 | 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] | 6339 | const char *ifname, int vlan_id) |
| 6340 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6341 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6342 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6343 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6344 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6345 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
| 6346 | ", ifname=%s[%d], vlan_id=%d)", |
| 6347 | bss->ifname, if_nametoindex(bss->ifname), |
| 6348 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6349 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 6350 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 6351 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { |
| 6352 | nlmsg_free(msg); |
| 6353 | return -ENOBUFS; |
| 6354 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6355 | |
| 6356 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6357 | if (ret < 0) { |
| 6358 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" |
| 6359 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", |
| 6360 | MAC2STR(addr), ifname, vlan_id, ret, |
| 6361 | strerror(-ret)); |
| 6362 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6363 | return ret; |
| 6364 | } |
| 6365 | |
| 6366 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6367 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
| 6368 | { |
| 6369 | struct hostap_sta_driver_data data; |
| 6370 | int ret; |
| 6371 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 6372 | os_memset(&data, 0, sizeof(data)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6373 | data.inactive_msec = (unsigned long) -1; |
| 6374 | ret = i802_read_sta_data(priv, &data, addr); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 6375 | if (ret == -ENOENT) |
| 6376 | return -ENOENT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6377 | if (ret || data.inactive_msec == (unsigned long) -1) |
| 6378 | return -1; |
| 6379 | return data.inactive_msec / 1000; |
| 6380 | } |
| 6381 | |
| 6382 | |
| 6383 | static int i802_sta_clear_stats(void *priv, const u8 *addr) |
| 6384 | { |
| 6385 | #if 0 |
| 6386 | /* TODO */ |
| 6387 | #endif |
| 6388 | return 0; |
| 6389 | } |
| 6390 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6391 | |
| 6392 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
| 6393 | int reason) |
| 6394 | { |
| 6395 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6396 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6397 | struct ieee80211_mgmt mgmt; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame] | 6398 | u8 channel; |
| 6399 | |
| 6400 | if (ieee80211_freq_to_chan(bss->freq, &channel) == |
| 6401 | HOSTAPD_MODE_IEEE80211AD) { |
| 6402 | /* Deauthentication is not used in DMG/IEEE 802.11ad; |
| 6403 | * disassociate the STA instead. */ |
| 6404 | return i802_sta_disassoc(priv, own_addr, addr, reason); |
| 6405 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6406 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6407 | if (is_mesh_interface(drv->nlmode)) |
| 6408 | return -1; |
| 6409 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6410 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6411 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6412 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6413 | memset(&mgmt, 0, sizeof(mgmt)); |
| 6414 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 6415 | WLAN_FC_STYPE_DEAUTH); |
| 6416 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 6417 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 6418 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 6419 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
| 6420 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 6421 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6422 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6423 | 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6424 | } |
| 6425 | |
| 6426 | |
| 6427 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
| 6428 | int reason) |
| 6429 | { |
| 6430 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6431 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6432 | struct ieee80211_mgmt mgmt; |
| 6433 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6434 | if (is_mesh_interface(drv->nlmode)) |
| 6435 | return -1; |
| 6436 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6437 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6438 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6439 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6440 | memset(&mgmt, 0, sizeof(mgmt)); |
| 6441 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 6442 | WLAN_FC_STYPE_DISASSOC); |
| 6443 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 6444 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 6445 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 6446 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
| 6447 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 6448 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6449 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6450 | 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6451 | } |
| 6452 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6453 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6454 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
| 6455 | { |
| 6456 | char buf[200], *pos, *end; |
| 6457 | int i, res; |
| 6458 | |
| 6459 | pos = buf; |
| 6460 | end = pos + sizeof(buf); |
| 6461 | |
| 6462 | for (i = 0; i < drv->num_if_indices; i++) { |
| 6463 | if (!drv->if_indices[i]) |
| 6464 | continue; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6465 | res = os_snprintf(pos, end - pos, " %d(%d)", |
| 6466 | drv->if_indices[i], |
| 6467 | drv->if_indices_reason[i]); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6468 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6469 | break; |
| 6470 | pos += res; |
| 6471 | } |
| 6472 | *pos = '\0'; |
| 6473 | |
| 6474 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", |
| 6475 | drv->num_if_indices, buf); |
| 6476 | } |
| 6477 | |
| 6478 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6479 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 6480 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6481 | { |
| 6482 | int i; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6483 | int *old, *old_reason; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6484 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6485 | wpa_printf(MSG_DEBUG, |
| 6486 | "nl80211: Add own interface ifindex %d (ifidx_reason %d)", |
| 6487 | ifidx, ifidx_reason); |
| 6488 | if (have_ifidx(drv, ifidx, ifidx_reason)) { |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6489 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
| 6490 | ifidx); |
| 6491 | return; |
| 6492 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6493 | for (i = 0; i < drv->num_if_indices; i++) { |
| 6494 | if (drv->if_indices[i] == 0) { |
| 6495 | drv->if_indices[i] = ifidx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6496 | drv->if_indices_reason[i] = ifidx_reason; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6497 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6498 | return; |
| 6499 | } |
| 6500 | } |
| 6501 | |
| 6502 | if (drv->if_indices != drv->default_if_indices) |
| 6503 | old = drv->if_indices; |
| 6504 | else |
| 6505 | old = NULL; |
| 6506 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6507 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
| 6508 | old_reason = drv->if_indices_reason; |
| 6509 | else |
| 6510 | old_reason = NULL; |
| 6511 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6512 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
| 6513 | sizeof(int)); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6514 | drv->if_indices_reason = os_realloc_array(old_reason, |
| 6515 | drv->num_if_indices + 1, |
| 6516 | sizeof(int)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6517 | if (!drv->if_indices) { |
| 6518 | if (!old) |
| 6519 | drv->if_indices = drv->default_if_indices; |
| 6520 | else |
| 6521 | drv->if_indices = old; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6522 | } |
| 6523 | if (!drv->if_indices_reason) { |
| 6524 | if (!old_reason) |
| 6525 | drv->if_indices_reason = drv->default_if_indices_reason; |
| 6526 | else |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 6527 | drv->if_indices_reason = old_reason; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6528 | } |
| 6529 | if (!drv->if_indices || !drv->if_indices_reason) { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6530 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
| 6531 | "interfaces"); |
| 6532 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); |
| 6533 | return; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6534 | } |
| 6535 | if (!old) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6536 | os_memcpy(drv->if_indices, drv->default_if_indices, |
| 6537 | sizeof(drv->default_if_indices)); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6538 | if (!old_reason) |
| 6539 | os_memcpy(drv->if_indices_reason, |
| 6540 | drv->default_if_indices_reason, |
| 6541 | sizeof(drv->default_if_indices_reason)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6542 | drv->if_indices[drv->num_if_indices] = ifidx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6543 | drv->if_indices_reason[drv->num_if_indices] = ifidx_reason; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6544 | drv->num_if_indices++; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6545 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6546 | } |
| 6547 | |
| 6548 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6549 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 6550 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6551 | { |
| 6552 | int i; |
| 6553 | |
| 6554 | for (i = 0; i < drv->num_if_indices; i++) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6555 | if ((drv->if_indices[i] == ifidx || ifidx == IFIDX_ANY) && |
| 6556 | (drv->if_indices_reason[i] == ifidx_reason || |
| 6557 | ifidx_reason == IFIDX_ANY)) { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6558 | drv->if_indices[i] = 0; |
| 6559 | break; |
| 6560 | } |
| 6561 | } |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6562 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6563 | } |
| 6564 | |
| 6565 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6566 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 6567 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6568 | { |
| 6569 | int i; |
| 6570 | |
| 6571 | for (i = 0; i < drv->num_if_indices; i++) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6572 | if (drv->if_indices[i] == ifidx && |
| 6573 | (drv->if_indices_reason[i] == ifidx_reason || |
| 6574 | ifidx_reason == IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6575 | return 1; |
| 6576 | |
| 6577 | return 0; |
| 6578 | } |
| 6579 | |
| 6580 | |
| 6581 | 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] | 6582 | const char *bridge_ifname, char *ifname_wds) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6583 | { |
| 6584 | struct i802_bss *bss = priv; |
| 6585 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6586 | char name[IFNAMSIZ + 1]; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6587 | union wpa_event_data event; |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame^] | 6588 | int ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6589 | |
Hai Shalom | 39ba6fc | 2019-01-22 12:40:38 -0800 | [diff] [blame^] | 6590 | ret = os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
| 6591 | if (ret >= (int) sizeof(name)) |
| 6592 | wpa_printf(MSG_WARNING, |
| 6593 | "nl80211: WDS interface name was truncated"); |
| 6594 | else if (ret < 0) |
| 6595 | return ret; |
| 6596 | |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6597 | if (ifname_wds) |
| 6598 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); |
| 6599 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6600 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
| 6601 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); |
| 6602 | if (val) { |
| 6603 | if (!if_nametoindex(name)) { |
| 6604 | if (nl80211_create_iface(drv, name, |
| 6605 | NL80211_IFTYPE_AP_VLAN, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6606 | bss->addr, 1, NULL, NULL, 0) < |
| 6607 | 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6608 | return -1; |
| 6609 | if (bridge_ifname && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6610 | linux_br_add_if(drv->global->ioctl_sock, |
| 6611 | bridge_ifname, name) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6612 | return -1; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6613 | |
| 6614 | os_memset(&event, 0, sizeof(event)); |
| 6615 | event.wds_sta_interface.sta_addr = addr; |
| 6616 | event.wds_sta_interface.ifname = name; |
| 6617 | event.wds_sta_interface.istatus = INTERFACE_ADDED; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 6618 | wpa_supplicant_event(bss->ctx, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6619 | EVENT_WDS_STA_INTERFACE_STATUS, |
| 6620 | &event); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6621 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6622 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
| 6623 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " |
| 6624 | "interface %s up", name); |
| 6625 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6626 | return i802_set_sta_vlan(priv, addr, name, 0); |
| 6627 | } else { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6628 | if (bridge_ifname) |
| 6629 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, |
| 6630 | name); |
| 6631 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6632 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 6633 | nl80211_remove_iface(drv, if_nametoindex(name)); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6634 | os_memset(&event, 0, sizeof(event)); |
| 6635 | event.wds_sta_interface.sta_addr = addr; |
| 6636 | event.wds_sta_interface.ifname = name; |
| 6637 | event.wds_sta_interface.istatus = INTERFACE_REMOVED; |
Hai Shalom | ce48b4a | 2018-09-05 11:41:35 -0700 | [diff] [blame] | 6638 | wpa_supplicant_event(bss->ctx, EVENT_WDS_STA_INTERFACE_STATUS, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 6639 | &event); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 6640 | return 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6641 | } |
| 6642 | } |
| 6643 | |
| 6644 | |
| 6645 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
| 6646 | { |
| 6647 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 6648 | struct sockaddr_ll lladdr; |
| 6649 | unsigned char buf[3000]; |
| 6650 | int len; |
| 6651 | socklen_t fromlen = sizeof(lladdr); |
| 6652 | |
| 6653 | len = recvfrom(sock, buf, sizeof(buf), 0, |
| 6654 | (struct sockaddr *)&lladdr, &fromlen); |
| 6655 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6656 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
| 6657 | strerror(errno)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6658 | return; |
| 6659 | } |
| 6660 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6661 | if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6662 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
| 6663 | } |
| 6664 | |
| 6665 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6666 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
| 6667 | struct i802_bss *bss, |
| 6668 | const char *brname, const char *ifname) |
| 6669 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6670 | int br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6671 | char in_br[IFNAMSIZ]; |
| 6672 | |
| 6673 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6674 | br_ifindex = if_nametoindex(brname); |
| 6675 | if (br_ifindex == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6676 | /* |
| 6677 | * Bridge was configured, but the bridge device does |
| 6678 | * not exist. Try to add it now. |
| 6679 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6680 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6681 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
| 6682 | "bridge interface %s: %s", |
| 6683 | brname, strerror(errno)); |
| 6684 | return -1; |
| 6685 | } |
| 6686 | bss->added_bridge = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6687 | br_ifindex = if_nametoindex(brname); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6688 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6689 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6690 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6691 | |
| 6692 | if (linux_br_get(in_br, ifname) == 0) { |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 6693 | if (os_strcmp(in_br, brname) == 0) { |
| 6694 | bss->already_in_bridge = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6695 | return 0; /* already in the bridge */ |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 6696 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6697 | |
| 6698 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " |
| 6699 | "bridge %s", ifname, in_br); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6700 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
| 6701 | 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6702 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
| 6703 | "remove interface %s from bridge " |
| 6704 | "%s: %s", |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 6705 | ifname, in_br, strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6706 | return -1; |
| 6707 | } |
| 6708 | } |
| 6709 | |
| 6710 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", |
| 6711 | ifname, brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6712 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6713 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
| 6714 | "into bridge %s: %s", |
| 6715 | ifname, brname, strerror(errno)); |
| 6716 | return -1; |
| 6717 | } |
| 6718 | bss->added_if_into_bridge = 1; |
| 6719 | |
| 6720 | return 0; |
| 6721 | } |
| 6722 | |
| 6723 | |
| 6724 | static void *i802_init(struct hostapd_data *hapd, |
| 6725 | struct wpa_init_params *params) |
| 6726 | { |
| 6727 | struct wpa_driver_nl80211_data *drv; |
| 6728 | struct i802_bss *bss; |
| 6729 | size_t i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6730 | char master_ifname[IFNAMSIZ]; |
| 6731 | int ifindex, br_ifindex = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6732 | int br_added = 0; |
| 6733 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 6734 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
| 6735 | params->global_priv, 1, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6736 | params->bssid, params->driver_params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6737 | if (bss == NULL) |
| 6738 | return NULL; |
| 6739 | |
| 6740 | drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6741 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6742 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6743 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6744 | params->ifname, master_ifname); |
| 6745 | br_ifindex = if_nametoindex(master_ifname); |
| 6746 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 6747 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && |
| 6748 | linux_master_get(master_ifname, params->ifname) == 0) { |
| 6749 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", |
| 6750 | params->ifname, master_ifname); |
| 6751 | /* start listening for EAPOL on the master interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6752 | add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6753 | |
| 6754 | /* check if master itself is under bridge */ |
| 6755 | if (linux_br_get(master_ifname, master_ifname) == 0) { |
| 6756 | wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s", |
| 6757 | master_ifname); |
| 6758 | br_ifindex = if_nametoindex(master_ifname); |
| 6759 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 6760 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6761 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6762 | master_ifname[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6763 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6764 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6765 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6766 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6767 | for (i = 0; i < params->num_bridge; i++) { |
| 6768 | if (params->bridge[i]) { |
| 6769 | ifindex = if_nametoindex(params->bridge[i]); |
| 6770 | if (ifindex) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6771 | add_ifidx(drv, ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6772 | if (ifindex == br_ifindex) |
| 6773 | br_added = 1; |
| 6774 | } |
| 6775 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6776 | |
| 6777 | /* start listening for EAPOL on the default AP interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6778 | add_ifidx(drv, drv->ifindex, IFIDX_ANY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6779 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6780 | if (params->num_bridge && params->bridge[0]) { |
| 6781 | if (i802_check_bridge(drv, bss, params->bridge[0], |
| 6782 | params->ifname) < 0) |
| 6783 | goto failed; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6784 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6785 | br_added = 1; |
| 6786 | } |
| 6787 | |
| 6788 | if (!br_added && br_ifindex && |
| 6789 | (params->num_bridge == 0 || !params->bridge[0])) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6790 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6791 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6792 | #ifdef CONFIG_LIBNL3_ROUTE |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 6793 | if (bss->added_if_into_bridge || bss->already_in_bridge) { |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6794 | drv->rtnl_sk = nl_socket_alloc(); |
| 6795 | if (drv->rtnl_sk == NULL) { |
| 6796 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); |
| 6797 | goto failed; |
| 6798 | } |
| 6799 | |
| 6800 | if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) { |
| 6801 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", |
| 6802 | strerror(errno)); |
| 6803 | goto failed; |
| 6804 | } |
| 6805 | } |
| 6806 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 6807 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6808 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
| 6809 | if (drv->eapol_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6810 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
| 6811 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6812 | goto failed; |
| 6813 | } |
| 6814 | |
| 6815 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) |
| 6816 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6817 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6818 | goto failed; |
| 6819 | } |
| 6820 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6821 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 6822 | params->own_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6823 | goto failed; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6824 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6825 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6826 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
| 6827 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6828 | return bss; |
| 6829 | |
| 6830 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6831 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6832 | return NULL; |
| 6833 | } |
| 6834 | |
| 6835 | |
| 6836 | static void i802_deinit(void *priv) |
| 6837 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6838 | struct i802_bss *bss = priv; |
| 6839 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6840 | } |
| 6841 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6842 | |
| 6843 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
| 6844 | enum wpa_driver_if_type type) |
| 6845 | { |
| 6846 | switch (type) { |
| 6847 | case WPA_IF_STATION: |
| 6848 | return NL80211_IFTYPE_STATION; |
| 6849 | case WPA_IF_P2P_CLIENT: |
| 6850 | case WPA_IF_P2P_GROUP: |
| 6851 | return NL80211_IFTYPE_P2P_CLIENT; |
| 6852 | case WPA_IF_AP_VLAN: |
| 6853 | return NL80211_IFTYPE_AP_VLAN; |
| 6854 | case WPA_IF_AP_BSS: |
| 6855 | return NL80211_IFTYPE_AP; |
| 6856 | case WPA_IF_P2P_GO: |
| 6857 | return NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6858 | case WPA_IF_P2P_DEVICE: |
| 6859 | return NL80211_IFTYPE_P2P_DEVICE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6860 | case WPA_IF_MESH: |
| 6861 | return NL80211_IFTYPE_MESH_POINT; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6862 | default: |
| 6863 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6864 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6865 | } |
| 6866 | |
| 6867 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6868 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
| 6869 | { |
| 6870 | struct wpa_driver_nl80211_data *drv; |
| 6871 | dl_list_for_each(drv, &global->interfaces, |
| 6872 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6873 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6874 | return 1; |
| 6875 | } |
| 6876 | return 0; |
| 6877 | } |
| 6878 | |
| 6879 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6880 | 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] | 6881 | { |
| 6882 | unsigned int idx; |
| 6883 | |
| 6884 | if (!drv->global) |
| 6885 | return -1; |
| 6886 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6887 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6888 | for (idx = 0; idx < 64; idx++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6889 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6890 | new_addr[0] ^= idx << 2; |
| 6891 | if (!nl80211_addr_in_use(drv->global, new_addr)) |
| 6892 | break; |
| 6893 | } |
| 6894 | if (idx == 64) |
| 6895 | return -1; |
| 6896 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6897 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6898 | MACSTR, MAC2STR(new_addr)); |
| 6899 | |
| 6900 | return 0; |
| 6901 | } |
| 6902 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6903 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6904 | struct wdev_info { |
| 6905 | u64 wdev_id; |
| 6906 | int wdev_id_set; |
| 6907 | u8 macaddr[ETH_ALEN]; |
| 6908 | }; |
| 6909 | |
| 6910 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) |
| 6911 | { |
| 6912 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6913 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6914 | struct wdev_info *wi = arg; |
| 6915 | |
| 6916 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6917 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6918 | if (tb[NL80211_ATTR_WDEV]) { |
| 6919 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 6920 | wi->wdev_id_set = 1; |
| 6921 | } |
| 6922 | |
| 6923 | if (tb[NL80211_ATTR_MAC]) |
| 6924 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 6925 | ETH_ALEN); |
| 6926 | |
| 6927 | return NL_SKIP; |
| 6928 | } |
| 6929 | |
| 6930 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6931 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
| 6932 | const char *ifname, const u8 *addr, |
| 6933 | void *bss_ctx, void **drv_priv, |
| 6934 | char *force_ifname, u8 *if_addr, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6935 | const char *bridge, int use_existing, |
| 6936 | int setup_ap) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6937 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6938 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6939 | struct i802_bss *bss = priv; |
| 6940 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6941 | int ifidx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6942 | int added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6943 | |
| 6944 | if (addr) |
| 6945 | os_memcpy(if_addr, addr, ETH_ALEN); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6946 | nlmode = wpa_driver_nl80211_if_type(type); |
| 6947 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 6948 | struct wdev_info p2pdev_info; |
| 6949 | |
| 6950 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); |
| 6951 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
| 6952 | 0, nl80211_wdev_handler, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6953 | &p2pdev_info, use_existing); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6954 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
| 6955 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
| 6956 | ifname); |
| 6957 | return -1; |
| 6958 | } |
| 6959 | |
| 6960 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; |
| 6961 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; |
| 6962 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) |
| 6963 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); |
| 6964 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", |
| 6965 | ifname, |
| 6966 | (long long unsigned int) p2pdev_info.wdev_id); |
| 6967 | } else { |
| 6968 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6969 | 0, NULL, NULL, use_existing); |
| 6970 | if (use_existing && ifidx == -ENFILE) { |
| 6971 | added = 0; |
| 6972 | ifidx = if_nametoindex(ifname); |
| 6973 | } else if (ifidx < 0) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6974 | return -1; |
| 6975 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6976 | } |
| 6977 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6978 | if (!addr) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6979 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6980 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
| 6981 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6982 | ifname, if_addr) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6983 | if (added) |
| 6984 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6985 | return -1; |
| 6986 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6987 | } |
| 6988 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6989 | if (!addr && |
| 6990 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6991 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
| 6992 | type == WPA_IF_STATION)) { |
| 6993 | /* Enforce unique address */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6994 | u8 new_addr[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6995 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6996 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6997 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6998 | if (added) |
| 6999 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7000 | return -1; |
| 7001 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7002 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7003 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 7004 | "for interface %s type %d", ifname, type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7005 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 7006 | if (added) |
| 7007 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7008 | return -1; |
| 7009 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7010 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7011 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 7012 | if (added) |
| 7013 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7014 | return -1; |
| 7015 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7016 | } |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 7017 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7018 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7019 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7020 | if (type == WPA_IF_AP_BSS && setup_ap) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7021 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
| 7022 | if (new_bss == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7023 | if (added) |
| 7024 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7025 | return -1; |
| 7026 | } |
| 7027 | |
| 7028 | if (bridge && |
| 7029 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { |
| 7030 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " |
| 7031 | "interface %s to a bridge %s", |
| 7032 | ifname, bridge); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7033 | if (added) |
| 7034 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7035 | os_free(new_bss); |
| 7036 | return -1; |
| 7037 | } |
| 7038 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7039 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
| 7040 | { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 7041 | if (added) |
| 7042 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7043 | os_free(new_bss); |
| 7044 | return -1; |
| 7045 | } |
| 7046 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7047 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7048 | new_bss->ifindex = ifidx; |
| 7049 | new_bss->drv = drv; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7050 | new_bss->next = drv->first_bss->next; |
| 7051 | new_bss->freq = drv->first_bss->freq; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 7052 | new_bss->ctx = bss_ctx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7053 | new_bss->added_if = added; |
| 7054 | drv->first_bss->next = new_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7055 | if (drv_priv) |
| 7056 | *drv_priv = new_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7057 | nl80211_init_bss(new_bss); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7058 | |
| 7059 | /* Subscribe management frames for this WPA_IF_AP_BSS */ |
| 7060 | if (nl80211_setup_ap(new_bss)) |
| 7061 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7062 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7063 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7064 | if (drv->global) |
| 7065 | drv->global->if_add_ifindex = ifidx; |
| 7066 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 7067 | /* |
| 7068 | * Some virtual interfaces need to process EAPOL packets and events on |
| 7069 | * the parent interface. This is used mainly with hostapd. |
| 7070 | */ |
| 7071 | if (ifidx > 0 && |
| 7072 | (drv->hostapd || |
| 7073 | nlmode == NL80211_IFTYPE_AP_VLAN || |
| 7074 | nlmode == NL80211_IFTYPE_WDS || |
| 7075 | nlmode == NL80211_IFTYPE_MONITOR)) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7076 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7077 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7078 | return 0; |
| 7079 | } |
| 7080 | |
| 7081 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7082 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7083 | enum wpa_driver_if_type type, |
| 7084 | const char *ifname) |
| 7085 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7086 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7087 | int ifindex = if_nametoindex(ifname); |
| 7088 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7089 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
| 7090 | __func__, type, ifname, ifindex, bss->added_if); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 7091 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7092 | nl80211_remove_iface(drv, ifindex); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 7093 | else if (ifindex > 0 && !bss->added_if) { |
| 7094 | struct wpa_driver_nl80211_data *drv2; |
| 7095 | dl_list_for_each(drv2, &drv->global->interfaces, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 7096 | struct wpa_driver_nl80211_data, list) { |
| 7097 | del_ifidx(drv2, ifindex, IFIDX_ANY); |
| 7098 | del_ifidx(drv2, IFIDX_ANY, ifindex); |
| 7099 | } |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 7100 | } |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7101 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 7102 | if (type != WPA_IF_AP_BSS) |
| 7103 | return 0; |
| 7104 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7105 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7106 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 7107 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7108 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 7109 | "interface %s from bridge %s: %s", |
| 7110 | bss->ifname, bss->brname, strerror(errno)); |
| 7111 | } |
| 7112 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7113 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7114 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 7115 | "bridge %s: %s", |
| 7116 | bss->brname, strerror(errno)); |
| 7117 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7118 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7119 | if (bss != drv->first_bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7120 | struct i802_bss *tbss; |
| 7121 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7122 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
| 7123 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7124 | if (tbss->next == bss) { |
| 7125 | tbss->next = bss->next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7126 | /* Unsubscribe management frames */ |
| 7127 | nl80211_teardown_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7128 | nl80211_destroy_bss(bss); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7129 | if (!bss->added_if) |
| 7130 | i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7131 | os_free(bss); |
| 7132 | bss = NULL; |
| 7133 | break; |
| 7134 | } |
| 7135 | } |
| 7136 | if (bss) |
| 7137 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " |
| 7138 | "BSS %p in the list", __func__, bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7139 | } else { |
| 7140 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
| 7141 | nl80211_teardown_ap(bss); |
| 7142 | if (!bss->added_if && !drv->first_bss->next) |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 7143 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 7144 | nl80211_destroy_bss(bss); |
| 7145 | if (!bss->added_if) |
| 7146 | i802_set_iface_flags(bss, 0); |
| 7147 | if (drv->first_bss->next) { |
| 7148 | drv->first_bss = drv->first_bss->next; |
| 7149 | drv->ctx = drv->first_bss->ctx; |
| 7150 | os_free(bss); |
| 7151 | } else { |
| 7152 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); |
| 7153 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7154 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7155 | |
| 7156 | return 0; |
| 7157 | } |
| 7158 | |
| 7159 | |
| 7160 | static int cookie_handler(struct nl_msg *msg, void *arg) |
| 7161 | { |
| 7162 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7163 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7164 | u64 *cookie = arg; |
| 7165 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7166 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7167 | if (tb[NL80211_ATTR_COOKIE]) |
| 7168 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 7169 | return NL_SKIP; |
| 7170 | } |
| 7171 | |
| 7172 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7173 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7174 | unsigned int freq, unsigned int wait, |
| 7175 | const u8 *buf, size_t buf_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7176 | u64 *cookie_out, int no_cck, int no_ack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7177 | int offchanok, const u16 *csa_offs, |
| 7178 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7179 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7180 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7181 | struct nl_msg *msg; |
| 7182 | u64 cookie; |
| 7183 | int ret = -1; |
| 7184 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7185 | 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] | 7186 | "no_ack=%d offchanok=%d", |
| 7187 | freq, wait, no_cck, no_ack, offchanok); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 7188 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7189 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7190 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
| 7191 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 7192 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || |
| 7193 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 7194 | drv->test_use_roc_tx) && |
| 7195 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || |
| 7196 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || |
| 7197 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7198 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
| 7199 | csa_offs_len * sizeof(u16), csa_offs)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7200 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
| 7201 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7202 | |
| 7203 | cookie = 0; |
| 7204 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 7205 | msg = NULL; |
| 7206 | if (ret) { |
| 7207 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 7208 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
| 7209 | freq, wait); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7210 | } else { |
| 7211 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " |
| 7212 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
| 7213 | (long long unsigned int) cookie); |
| 7214 | |
| 7215 | if (cookie_out) |
| 7216 | *cookie_out = no_ack ? (u64) -1 : cookie; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7217 | |
| 7218 | if (drv->num_send_action_cookies == MAX_SEND_ACTION_COOKIES) { |
| 7219 | wpa_printf(MSG_DEBUG, |
| 7220 | "nl80211: Drop oldest pending send action cookie 0x%llx", |
| 7221 | (long long unsigned int) |
| 7222 | drv->send_action_cookies[0]); |
| 7223 | os_memmove(&drv->send_action_cookies[0], |
| 7224 | &drv->send_action_cookies[1], |
| 7225 | (MAX_SEND_ACTION_COOKIES - 1) * |
| 7226 | sizeof(u64)); |
| 7227 | drv->num_send_action_cookies--; |
| 7228 | } |
| 7229 | drv->send_action_cookies[drv->num_send_action_cookies] = cookie; |
| 7230 | drv->num_send_action_cookies++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7231 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7232 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7233 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7234 | nlmsg_free(msg); |
| 7235 | return ret; |
| 7236 | } |
| 7237 | |
| 7238 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7239 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
| 7240 | unsigned int freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7241 | unsigned int wait_time, |
| 7242 | const u8 *dst, const u8 *src, |
| 7243 | const u8 *bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7244 | const u8 *data, size_t data_len, |
| 7245 | int no_cck) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7246 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7247 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7248 | int ret = -1; |
| 7249 | u8 *buf; |
| 7250 | struct ieee80211_hdr *hdr; |
| 7251 | |
| 7252 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7253 | "freq=%u MHz wait=%d ms no_cck=%d)", |
| 7254 | drv->ifindex, freq, wait_time, no_cck); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7255 | |
| 7256 | buf = os_zalloc(24 + data_len); |
| 7257 | if (buf == NULL) |
| 7258 | return ret; |
| 7259 | os_memcpy(buf + 24, data, data_len); |
| 7260 | hdr = (struct ieee80211_hdr *) buf; |
| 7261 | hdr->frame_control = |
| 7262 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); |
| 7263 | os_memcpy(hdr->addr1, dst, ETH_ALEN); |
| 7264 | os_memcpy(hdr->addr2, src, ETH_ALEN); |
| 7265 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); |
| 7266 | |
Dmitry Shmidt | ebd93af | 2017-02-21 13:40:44 -0800 | [diff] [blame] | 7267 | if (os_memcmp(bss->addr, src, ETH_ALEN) != 0) { |
| 7268 | wpa_printf(MSG_DEBUG, "nl80211: Use random TA " MACSTR, |
| 7269 | MAC2STR(src)); |
| 7270 | os_memcpy(bss->rand_addr, src, ETH_ALEN); |
| 7271 | } else { |
| 7272 | os_memset(bss->rand_addr, 0, ETH_ALEN); |
| 7273 | } |
| 7274 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7275 | if (is_ap_interface(drv->nlmode) && |
| 7276 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 7277 | (int) freq == bss->freq || drv->device_ap_sme || |
| 7278 | !drv->use_monitor)) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7279 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
| 7280 | 0, freq, no_cck, 1, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7281 | wait_time, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7282 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7283 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7284 | 24 + data_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7285 | &drv->send_action_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7286 | no_cck, 0, 1, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7287 | |
| 7288 | os_free(buf); |
| 7289 | return ret; |
| 7290 | } |
| 7291 | |
| 7292 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7293 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7294 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7295 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7296 | struct nl_msg *msg; |
| 7297 | int ret; |
| 7298 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 7299 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7300 | (long long unsigned int) cookie); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7301 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7302 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7303 | nlmsg_free(msg); |
| 7304 | return; |
| 7305 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7306 | |
| 7307 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7308 | if (ret) |
| 7309 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " |
| 7310 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7311 | } |
| 7312 | |
| 7313 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7314 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
| 7315 | { |
| 7316 | struct i802_bss *bss = priv; |
| 7317 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7318 | unsigned int i; |
| 7319 | u64 cookie; |
| 7320 | |
| 7321 | /* Cancel the last pending TX cookie */ |
| 7322 | nl80211_frame_wait_cancel(bss, drv->send_action_cookie); |
| 7323 | |
| 7324 | /* |
| 7325 | * Cancel the other pending TX cookies, if any. This is needed since |
| 7326 | * the driver may keep a list of all pending offchannel TX operations |
| 7327 | * and free up the radio only once they have expired or cancelled. |
| 7328 | */ |
| 7329 | for (i = drv->num_send_action_cookies; i > 0; i--) { |
| 7330 | cookie = drv->send_action_cookies[i - 1]; |
| 7331 | if (cookie != drv->send_action_cookie) |
| 7332 | nl80211_frame_wait_cancel(bss, cookie); |
| 7333 | } |
| 7334 | drv->num_send_action_cookies = 0; |
| 7335 | } |
| 7336 | |
| 7337 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7338 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
| 7339 | unsigned int duration) |
| 7340 | { |
| 7341 | struct i802_bss *bss = priv; |
| 7342 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7343 | struct nl_msg *msg; |
| 7344 | int ret; |
| 7345 | u64 cookie; |
| 7346 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7347 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
| 7348 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 7349 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { |
| 7350 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7351 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7352 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7353 | |
| 7354 | cookie = 0; |
| 7355 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 7356 | if (ret == 0) { |
| 7357 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " |
| 7358 | "0x%llx for freq=%u MHz duration=%u", |
| 7359 | (long long unsigned int) cookie, freq, duration); |
| 7360 | drv->remain_on_chan_cookie = cookie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7361 | drv->pending_remain_on_chan = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7362 | return 0; |
| 7363 | } |
| 7364 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " |
| 7365 | "(freq=%d duration=%u): %d (%s)", |
| 7366 | freq, duration, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7367 | return -1; |
| 7368 | } |
| 7369 | |
| 7370 | |
| 7371 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) |
| 7372 | { |
| 7373 | struct i802_bss *bss = priv; |
| 7374 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7375 | struct nl_msg *msg; |
| 7376 | int ret; |
| 7377 | |
| 7378 | if (!drv->pending_remain_on_chan) { |
| 7379 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " |
| 7380 | "to cancel"); |
| 7381 | return -1; |
| 7382 | } |
| 7383 | |
| 7384 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " |
| 7385 | "0x%llx", |
| 7386 | (long long unsigned int) drv->remain_on_chan_cookie); |
| 7387 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7388 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
| 7389 | if (!msg || |
| 7390 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
| 7391 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7392 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7393 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7394 | |
| 7395 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7396 | if (ret == 0) |
| 7397 | return 0; |
| 7398 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " |
| 7399 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7400 | return -1; |
| 7401 | } |
| 7402 | |
| 7403 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7404 | 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] | 7405 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7406 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 7407 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7408 | if (!report) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7409 | if (bss->nl_preq && drv->device_ap_sme && |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 7410 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
| 7411 | !bss->static_ap) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7412 | /* |
| 7413 | * Do not disable Probe Request reporting that was |
| 7414 | * enabled in nl80211_setup_ap(). |
| 7415 | */ |
| 7416 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " |
| 7417 | "Probe Request reporting nl_preq=%p while " |
| 7418 | "in AP mode", bss->nl_preq); |
| 7419 | } else if (bss->nl_preq) { |
| 7420 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
| 7421 | "reporting nl_preq=%p", bss->nl_preq); |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7422 | nl80211_destroy_eloop_handle(&bss->nl_preq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7423 | } |
| 7424 | return 0; |
| 7425 | } |
| 7426 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7427 | if (bss->nl_preq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7428 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7429 | "already on! nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7430 | return 0; |
| 7431 | } |
| 7432 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7433 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
| 7434 | if (bss->nl_preq == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7435 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7436 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
| 7437 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7438 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7439 | if (nl80211_register_frame(bss, bss->nl_preq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7440 | (WLAN_FC_TYPE_MGMT << 2) | |
| 7441 | (WLAN_FC_STYPE_PROBE_REQ << 4), |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7442 | NULL, 0) < 0) |
| 7443 | goto out_err; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 7444 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7445 | nl80211_register_eloop_read(&bss->nl_preq, |
| 7446 | wpa_driver_nl80211_event_receive, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7447 | bss->nl_cb, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7448 | |
| 7449 | return 0; |
| 7450 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7451 | out_err: |
| 7452 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7453 | return -1; |
| 7454 | } |
| 7455 | |
| 7456 | |
| 7457 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 7458 | int ifindex, int disabled) |
| 7459 | { |
| 7460 | struct nl_msg *msg; |
| 7461 | struct nlattr *bands, *band; |
| 7462 | int ret; |
| 7463 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7464 | wpa_printf(MSG_DEBUG, |
| 7465 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", |
| 7466 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : |
| 7467 | "no NL80211_TXRATE_LEGACY constraint"); |
| 7468 | |
| 7469 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
| 7470 | NL80211_CMD_SET_TX_BITRATE_MASK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7471 | if (!msg) |
| 7472 | return -1; |
| 7473 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7474 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 7475 | if (!bands) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7476 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7477 | |
| 7478 | /* |
| 7479 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything |
| 7480 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS |
| 7481 | * rates. All 5 GHz rates are left enabled. |
| 7482 | */ |
| 7483 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7484 | if (!band || |
| 7485 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, |
| 7486 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) |
| 7487 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7488 | nla_nest_end(msg, band); |
| 7489 | |
| 7490 | nla_nest_end(msg, bands); |
| 7491 | |
| 7492 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7493 | if (ret) { |
| 7494 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " |
| 7495 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7496 | } else |
| 7497 | drv->disabled_11b_rates = disabled; |
| 7498 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7499 | return ret; |
| 7500 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7501 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7502 | nlmsg_free(msg); |
| 7503 | return -1; |
| 7504 | } |
| 7505 | |
| 7506 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7507 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
| 7508 | { |
| 7509 | struct i802_bss *bss = priv; |
| 7510 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7511 | if (!is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7512 | return -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 7513 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7514 | bss->beacon_set = 0; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7515 | |
| 7516 | /* |
| 7517 | * If the P2P GO interface was dynamically added, then it is |
| 7518 | * possible that the interface change to station is not possible. |
| 7519 | */ |
| 7520 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) |
| 7521 | return 0; |
| 7522 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7523 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7524 | } |
| 7525 | |
| 7526 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7527 | static int wpa_driver_nl80211_stop_ap(void *priv) |
| 7528 | { |
| 7529 | struct i802_bss *bss = priv; |
| 7530 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7531 | if (!is_ap_interface(drv->nlmode)) |
| 7532 | return -1; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 7533 | wpa_driver_nl80211_del_beacon(bss); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7534 | bss->beacon_set = 0; |
| 7535 | return 0; |
| 7536 | } |
| 7537 | |
| 7538 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7539 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
| 7540 | { |
| 7541 | struct i802_bss *bss = priv; |
| 7542 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7543 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) |
| 7544 | return -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7545 | |
| 7546 | /* |
| 7547 | * If the P2P Client interface was dynamically added, then it is |
| 7548 | * possible that the interface change to station is not possible. |
| 7549 | */ |
| 7550 | if (bss->if_dynamic) |
| 7551 | return 0; |
| 7552 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7553 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
| 7554 | } |
| 7555 | |
| 7556 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7557 | static void wpa_driver_nl80211_resume(void *priv) |
| 7558 | { |
| 7559 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7560 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7561 | |
| 7562 | if (i802_set_iface_flags(bss, 1)) |
| 7563 | 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] | 7564 | |
| 7565 | if (is_p2p_net_interface(nlmode)) |
| 7566 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7567 | } |
| 7568 | |
| 7569 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7570 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
| 7571 | { |
| 7572 | struct i802_bss *bss = priv; |
| 7573 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7574 | struct nl_msg *msg; |
| 7575 | struct nlattr *cqm; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7576 | |
| 7577 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " |
| 7578 | "hysteresis=%d", threshold, hysteresis); |
| 7579 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7580 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
| 7581 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
| 7582 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || |
| 7583 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { |
| 7584 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7585 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7586 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7587 | nla_nest_end(msg, cqm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7588 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7589 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7590 | } |
| 7591 | |
| 7592 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7593 | static int get_channel_width(struct nl_msg *msg, void *arg) |
| 7594 | { |
| 7595 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7596 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7597 | struct wpa_signal_info *sig_change = arg; |
| 7598 | |
| 7599 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7600 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7601 | |
| 7602 | sig_change->center_frq1 = -1; |
| 7603 | sig_change->center_frq2 = -1; |
| 7604 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 7605 | |
| 7606 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 7607 | sig_change->chanwidth = convert2width( |
| 7608 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 7609 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 7610 | sig_change->center_frq1 = |
| 7611 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 7612 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 7613 | sig_change->center_frq2 = |
| 7614 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 7615 | } |
| 7616 | |
| 7617 | return NL_SKIP; |
| 7618 | } |
| 7619 | |
| 7620 | |
| 7621 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, |
| 7622 | struct wpa_signal_info *sig) |
| 7623 | { |
| 7624 | struct nl_msg *msg; |
| 7625 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7626 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7627 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7628 | } |
| 7629 | |
| 7630 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7631 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
| 7632 | { |
| 7633 | struct i802_bss *bss = priv; |
| 7634 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7635 | int res; |
| 7636 | |
| 7637 | os_memset(si, 0, sizeof(*si)); |
| 7638 | res = nl80211_get_link_signal(drv, si); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7639 | if (res) { |
| 7640 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && |
| 7641 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
| 7642 | return res; |
| 7643 | si->current_signal = 0; |
| 7644 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7645 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7646 | res = nl80211_get_channel_width(drv, si); |
| 7647 | if (res != 0) |
| 7648 | return res; |
| 7649 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7650 | return nl80211_get_link_noise(drv, si); |
| 7651 | } |
| 7652 | |
| 7653 | |
| 7654 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
| 7655 | int encrypt) |
| 7656 | { |
| 7657 | struct i802_bss *bss = priv; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7658 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7659 | 0, 0, 0, 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7660 | } |
| 7661 | |
| 7662 | |
| 7663 | static int nl80211_set_param(void *priv, const char *param) |
| 7664 | { |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 7665 | struct i802_bss *bss = priv; |
| 7666 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7667 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7668 | if (param == NULL) |
| 7669 | return 0; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7670 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7671 | |
| 7672 | #ifdef CONFIG_P2P |
| 7673 | if (os_strstr(param, "use_p2p_group_interface=1")) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7674 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 7675 | "interface"); |
| 7676 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 7677 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 7678 | } |
| 7679 | #endif /* CONFIG_P2P */ |
| 7680 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 7681 | if (os_strstr(param, "use_monitor=1")) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7682 | drv->use_monitor = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7683 | |
| 7684 | if (os_strstr(param, "force_connect_cmd=1")) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7685 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7686 | drv->force_connect_cmd = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7687 | } |
| 7688 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 7689 | if (os_strstr(param, "force_bss_selection=1")) |
| 7690 | drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
| 7691 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 7692 | if (os_strstr(param, "no_offchannel_tx=1")) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 7693 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 7694 | drv->test_use_roc_tx = 1; |
| 7695 | } |
| 7696 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7697 | return 0; |
| 7698 | } |
| 7699 | |
| 7700 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7701 | static void * nl80211_global_init(void *ctx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7702 | { |
| 7703 | struct nl80211_global *global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7704 | struct netlink_config *cfg; |
| 7705 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7706 | global = os_zalloc(sizeof(*global)); |
| 7707 | if (global == NULL) |
| 7708 | return NULL; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7709 | global->ctx = ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7710 | global->ioctl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7711 | dl_list_init(&global->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7712 | global->if_add_ifindex = -1; |
| 7713 | |
| 7714 | cfg = os_zalloc(sizeof(*cfg)); |
| 7715 | if (cfg == NULL) |
| 7716 | goto err; |
| 7717 | |
| 7718 | cfg->ctx = global; |
| 7719 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; |
| 7720 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; |
| 7721 | global->netlink = netlink_init(cfg); |
| 7722 | if (global->netlink == NULL) { |
| 7723 | os_free(cfg); |
| 7724 | goto err; |
| 7725 | } |
| 7726 | |
| 7727 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
| 7728 | goto err; |
| 7729 | |
| 7730 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 7731 | if (global->ioctl_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7732 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
| 7733 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7734 | goto err; |
| 7735 | } |
| 7736 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7737 | return global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7738 | |
| 7739 | err: |
| 7740 | nl80211_global_deinit(global); |
| 7741 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7742 | } |
| 7743 | |
| 7744 | |
| 7745 | static void nl80211_global_deinit(void *priv) |
| 7746 | { |
| 7747 | struct nl80211_global *global = priv; |
| 7748 | if (global == NULL) |
| 7749 | return; |
| 7750 | if (!dl_list_empty(&global->interfaces)) { |
| 7751 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " |
| 7752 | "nl80211_global_deinit", |
| 7753 | dl_list_len(&global->interfaces)); |
| 7754 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7755 | |
| 7756 | if (global->netlink) |
| 7757 | netlink_deinit(global->netlink); |
| 7758 | |
| 7759 | nl_destroy_handles(&global->nl); |
| 7760 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7761 | if (global->nl_event) |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7762 | nl80211_destroy_eloop_handle(&global->nl_event, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7763 | |
| 7764 | nl_cb_put(global->nl_cb); |
| 7765 | |
| 7766 | if (global->ioctl_sock >= 0) |
| 7767 | close(global->ioctl_sock); |
| 7768 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7769 | os_free(global); |
| 7770 | } |
| 7771 | |
| 7772 | |
| 7773 | static const char * nl80211_get_radio_name(void *priv) |
| 7774 | { |
| 7775 | struct i802_bss *bss = priv; |
| 7776 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7777 | return drv->phyname; |
| 7778 | } |
| 7779 | |
| 7780 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7781 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, |
| 7782 | struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7783 | { |
| 7784 | struct nl_msg *msg; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7785 | const size_t PMK_MAX_LEN = 48; /* current cfg80211 limit */ |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7786 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7787 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7788 | (params->pmkid && |
| 7789 | nla_put(msg, NL80211_ATTR_PMKID, 16, params->pmkid)) || |
| 7790 | (params->bssid && |
| 7791 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) || |
| 7792 | (params->ssid_len && |
| 7793 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) || |
| 7794 | (params->fils_cache_id && |
| 7795 | nla_put(msg, NL80211_ATTR_FILS_CACHE_ID, 2, |
| 7796 | params->fils_cache_id)) || |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7797 | (params->pmk_len && params->pmk_len <= PMK_MAX_LEN && |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7798 | nla_put(msg, NL80211_ATTR_PMK, params->pmk_len, params->pmk))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7799 | nlmsg_free(msg); |
| 7800 | return -ENOBUFS; |
| 7801 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7802 | |
| 7803 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7804 | } |
| 7805 | |
| 7806 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7807 | static int nl80211_add_pmkid(void *priv, struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7808 | { |
| 7809 | struct i802_bss *bss = priv; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7810 | int ret; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7811 | |
| 7812 | if (params->bssid) |
| 7813 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, |
| 7814 | MAC2STR(params->bssid)); |
| 7815 | else if (params->fils_cache_id && params->ssid_len) { |
| 7816 | wpa_printf(MSG_DEBUG, |
| 7817 | "nl80211: Add PMKSA for cache id %02x%02x SSID %s", |
| 7818 | params->fils_cache_id[0], params->fils_cache_id[1], |
| 7819 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
| 7820 | } |
| 7821 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7822 | ret = nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, params); |
| 7823 | if (ret < 0) { |
| 7824 | wpa_printf(MSG_DEBUG, |
| 7825 | "nl80211: NL80211_CMD_SET_PMKSA failed: %d (%s)", |
| 7826 | ret, strerror(-ret)); |
| 7827 | } |
| 7828 | |
| 7829 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7830 | } |
| 7831 | |
| 7832 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7833 | static int nl80211_remove_pmkid(void *priv, struct wpa_pmkid_params *params) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7834 | { |
| 7835 | struct i802_bss *bss = priv; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7836 | int ret; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7837 | |
| 7838 | if (params->bssid) |
| 7839 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, |
| 7840 | MAC2STR(params->bssid)); |
| 7841 | else if (params->fils_cache_id && params->ssid_len) { |
| 7842 | wpa_printf(MSG_DEBUG, |
| 7843 | "nl80211: Delete PMKSA for cache id %02x%02x SSID %s", |
| 7844 | params->fils_cache_id[0], params->fils_cache_id[1], |
| 7845 | wpa_ssid_txt(params->ssid, params->ssid_len)); |
| 7846 | } |
| 7847 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 7848 | ret = nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, params); |
| 7849 | if (ret < 0) { |
| 7850 | wpa_printf(MSG_DEBUG, |
| 7851 | "nl80211: NL80211_CMD_DEL_PMKSA failed: %d (%s)", |
| 7852 | ret, strerror(-ret)); |
| 7853 | } |
| 7854 | |
| 7855 | return ret; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7856 | } |
| 7857 | |
| 7858 | |
| 7859 | static int nl80211_flush_pmkid(void *priv) |
| 7860 | { |
| 7861 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7862 | struct nl_msg *msg; |
| 7863 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7864 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 7865 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_FLUSH_PMKSA); |
| 7866 | if (!msg) |
| 7867 | return -ENOBUFS; |
| 7868 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7869 | } |
| 7870 | |
| 7871 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7872 | static void clean_survey_results(struct survey_results *survey_results) |
| 7873 | { |
| 7874 | struct freq_survey *survey, *tmp; |
| 7875 | |
| 7876 | if (dl_list_empty(&survey_results->survey_list)) |
| 7877 | return; |
| 7878 | |
| 7879 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 7880 | struct freq_survey, list) { |
| 7881 | dl_list_del(&survey->list); |
| 7882 | os_free(survey); |
| 7883 | } |
| 7884 | } |
| 7885 | |
| 7886 | |
| 7887 | static void add_survey(struct nlattr **sinfo, u32 ifidx, |
| 7888 | struct dl_list *survey_list) |
| 7889 | { |
| 7890 | struct freq_survey *survey; |
| 7891 | |
| 7892 | survey = os_zalloc(sizeof(struct freq_survey)); |
| 7893 | if (!survey) |
| 7894 | return; |
| 7895 | |
| 7896 | survey->ifidx = ifidx; |
| 7897 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 7898 | survey->filled = 0; |
| 7899 | |
| 7900 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { |
| 7901 | survey->nf = (int8_t) |
| 7902 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 7903 | survey->filled |= SURVEY_HAS_NF; |
| 7904 | } |
| 7905 | |
| 7906 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { |
| 7907 | survey->channel_time = |
| 7908 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); |
| 7909 | survey->filled |= SURVEY_HAS_CHAN_TIME; |
| 7910 | } |
| 7911 | |
| 7912 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { |
| 7913 | survey->channel_time_busy = |
| 7914 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); |
| 7915 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; |
| 7916 | } |
| 7917 | |
| 7918 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { |
| 7919 | survey->channel_time_rx = |
| 7920 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); |
| 7921 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; |
| 7922 | } |
| 7923 | |
| 7924 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { |
| 7925 | survey->channel_time_tx = |
| 7926 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); |
| 7927 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; |
| 7928 | } |
| 7929 | |
| 7930 | 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)", |
| 7931 | survey->freq, |
| 7932 | survey->nf, |
| 7933 | (unsigned long int) survey->channel_time, |
| 7934 | (unsigned long int) survey->channel_time_busy, |
| 7935 | (unsigned long int) survey->channel_time_tx, |
| 7936 | (unsigned long int) survey->channel_time_rx, |
| 7937 | survey->filled); |
| 7938 | |
| 7939 | dl_list_add_tail(survey_list, &survey->list); |
| 7940 | } |
| 7941 | |
| 7942 | |
| 7943 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, |
| 7944 | unsigned int freq_filter) |
| 7945 | { |
| 7946 | if (!freq_filter) |
| 7947 | return 1; |
| 7948 | |
| 7949 | return freq_filter == surveyed_freq; |
| 7950 | } |
| 7951 | |
| 7952 | |
| 7953 | static int survey_handler(struct nl_msg *msg, void *arg) |
| 7954 | { |
| 7955 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7956 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7957 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 7958 | struct survey_results *survey_results; |
| 7959 | u32 surveyed_freq = 0; |
| 7960 | u32 ifidx; |
| 7961 | |
| 7962 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 7963 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 7964 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 7965 | }; |
| 7966 | |
| 7967 | survey_results = (struct survey_results *) arg; |
| 7968 | |
| 7969 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7970 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7971 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 7972 | if (!tb[NL80211_ATTR_IFINDEX]) |
| 7973 | return NL_SKIP; |
| 7974 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7975 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 7976 | |
| 7977 | if (!tb[NL80211_ATTR_SURVEY_INFO]) |
| 7978 | return NL_SKIP; |
| 7979 | |
| 7980 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 7981 | tb[NL80211_ATTR_SURVEY_INFO], |
| 7982 | survey_policy)) |
| 7983 | return NL_SKIP; |
| 7984 | |
| 7985 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { |
| 7986 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); |
| 7987 | return NL_SKIP; |
| 7988 | } |
| 7989 | |
| 7990 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 7991 | |
| 7992 | if (!check_survey_ok(sinfo, surveyed_freq, |
| 7993 | survey_results->freq_filter)) |
| 7994 | return NL_SKIP; |
| 7995 | |
| 7996 | if (survey_results->freq_filter && |
| 7997 | survey_results->freq_filter != surveyed_freq) { |
| 7998 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", |
| 7999 | surveyed_freq); |
| 8000 | return NL_SKIP; |
| 8001 | } |
| 8002 | |
| 8003 | add_survey(sinfo, ifidx, &survey_results->survey_list); |
| 8004 | |
| 8005 | return NL_SKIP; |
| 8006 | } |
| 8007 | |
| 8008 | |
| 8009 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) |
| 8010 | { |
| 8011 | struct i802_bss *bss = priv; |
| 8012 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8013 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8014 | int err; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8015 | union wpa_event_data data; |
| 8016 | struct survey_results *survey_results; |
| 8017 | |
| 8018 | os_memset(&data, 0, sizeof(data)); |
| 8019 | survey_results = &data.survey_results; |
| 8020 | |
| 8021 | dl_list_init(&survey_results->survey_list); |
| 8022 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8023 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8024 | if (!msg) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8025 | return -ENOBUFS; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8026 | |
| 8027 | if (freq) |
| 8028 | data.survey_results.freq_filter = freq; |
| 8029 | |
| 8030 | do { |
| 8031 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); |
| 8032 | err = send_and_recv_msgs(drv, msg, survey_handler, |
| 8033 | survey_results); |
| 8034 | } while (err > 0); |
| 8035 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8036 | if (err) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8037 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8038 | else |
| 8039 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8040 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8041 | clean_survey_results(survey_results); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 8042 | return err; |
| 8043 | } |
| 8044 | |
| 8045 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 8046 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
| 8047 | const u8 *kck, size_t kck_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8048 | const u8 *replay_ctr) |
| 8049 | { |
| 8050 | struct i802_bss *bss = priv; |
| 8051 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8052 | struct nlattr *replay_nested; |
| 8053 | struct nl_msg *msg; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8054 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8055 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8056 | if (!drv->set_rekey_offload) |
| 8057 | return; |
| 8058 | |
| 8059 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8060 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
| 8061 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 8062 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 8063 | (kck_len && nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8064 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
| 8065 | replay_ctr)) { |
| 8066 | nl80211_nlmsg_clear(msg); |
| 8067 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8068 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8069 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8070 | |
| 8071 | nla_nest_end(msg, replay_nested); |
| 8072 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8073 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 8074 | if (ret == -EOPNOTSUPP) { |
| 8075 | wpa_printf(MSG_DEBUG, |
| 8076 | "nl80211: Driver does not support rekey offload"); |
| 8077 | drv->set_rekey_offload = 0; |
| 8078 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8079 | } |
| 8080 | |
| 8081 | |
| 8082 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
| 8083 | const u8 *addr, int qos) |
| 8084 | { |
| 8085 | /* send data frame to poll STA and check whether |
| 8086 | * this frame is ACKed */ |
| 8087 | struct { |
| 8088 | struct ieee80211_hdr hdr; |
| 8089 | u16 qos_ctl; |
| 8090 | } STRUCT_PACKED nulldata; |
| 8091 | size_t size; |
| 8092 | |
| 8093 | /* Send data frame to poll STA and check whether this frame is ACKed */ |
| 8094 | |
| 8095 | os_memset(&nulldata, 0, sizeof(nulldata)); |
| 8096 | |
| 8097 | if (qos) { |
| 8098 | nulldata.hdr.frame_control = |
| 8099 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 8100 | WLAN_FC_STYPE_QOS_NULL); |
| 8101 | size = sizeof(nulldata); |
| 8102 | } else { |
| 8103 | nulldata.hdr.frame_control = |
| 8104 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 8105 | WLAN_FC_STYPE_NULLFUNC); |
| 8106 | size = sizeof(struct ieee80211_hdr); |
| 8107 | } |
| 8108 | |
| 8109 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 8110 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 8111 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 8112 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 8113 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8114 | 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] | 8115 | 0, 0, NULL, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8116 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
| 8117 | "send poll frame"); |
| 8118 | } |
| 8119 | |
| 8120 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
| 8121 | int qos) |
| 8122 | { |
| 8123 | struct i802_bss *bss = priv; |
| 8124 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8125 | struct nl_msg *msg; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8126 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8127 | |
| 8128 | if (!drv->poll_command_supported) { |
| 8129 | nl80211_send_null_frame(bss, own_addr, addr, qos); |
| 8130 | return; |
| 8131 | } |
| 8132 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8133 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
| 8134 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 8135 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8136 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8137 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8138 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8139 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8140 | if (ret < 0) { |
| 8141 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " |
| 8142 | MACSTR " failed: ret=%d (%s)", |
| 8143 | MAC2STR(addr), ret, strerror(-ret)); |
| 8144 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8145 | } |
| 8146 | |
| 8147 | |
| 8148 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
| 8149 | { |
| 8150 | struct nl_msg *msg; |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8151 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8152 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8153 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
| 8154 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
| 8155 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { |
| 8156 | nlmsg_free(msg); |
| 8157 | return -ENOBUFS; |
| 8158 | } |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8159 | |
| 8160 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 8161 | if (ret < 0) { |
| 8162 | wpa_printf(MSG_DEBUG, |
| 8163 | "nl80211: Setting PS state %s failed: %d (%s)", |
| 8164 | enabled ? "enabled" : "disabled", |
| 8165 | ret, strerror(-ret)); |
| 8166 | } |
| 8167 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8168 | } |
| 8169 | |
| 8170 | |
| 8171 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, |
| 8172 | int ctwindow) |
| 8173 | { |
| 8174 | struct i802_bss *bss = priv; |
| 8175 | |
| 8176 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " |
| 8177 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); |
| 8178 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8179 | if (opp_ps != -1 || ctwindow != -1) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 8180 | #ifdef ANDROID_P2P |
| 8181 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8182 | #else /* ANDROID_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8183 | return -1; /* Not yet supported */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 8184 | #endif /* ANDROID_P2P */ |
| 8185 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8186 | |
| 8187 | if (legacy_ps == -1) |
| 8188 | return 0; |
| 8189 | if (legacy_ps != 0 && legacy_ps != 1) |
| 8190 | return -1; /* Not yet supported */ |
| 8191 | |
| 8192 | return nl80211_set_power_save(bss, legacy_ps); |
| 8193 | } |
| 8194 | |
| 8195 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8196 | static int nl80211_start_radar_detection(void *priv, |
| 8197 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8198 | { |
| 8199 | struct i802_bss *bss = priv; |
| 8200 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8201 | struct nl_msg *msg; |
| 8202 | int ret; |
| 8203 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 8204 | 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)", |
| 8205 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 8206 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 8207 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8208 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
| 8209 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " |
| 8210 | "detection"); |
| 8211 | return -1; |
| 8212 | } |
| 8213 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8214 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
| 8215 | nl80211_put_freq_params(msg, freq) < 0) { |
| 8216 | nlmsg_free(msg); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8217 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8218 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8219 | |
| 8220 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8221 | if (ret == 0) |
| 8222 | return 0; |
| 8223 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " |
| 8224 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 8225 | return -1; |
| 8226 | } |
| 8227 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8228 | #ifdef CONFIG_TDLS |
| 8229 | |
| 8230 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, |
| 8231 | u8 dialog_token, u16 status_code, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 8232 | u32 peer_capab, int initiator, const u8 *buf, |
| 8233 | size_t len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8234 | { |
| 8235 | struct i802_bss *bss = priv; |
| 8236 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8237 | struct nl_msg *msg; |
| 8238 | |
| 8239 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 8240 | return -EOPNOTSUPP; |
| 8241 | |
| 8242 | if (!dst) |
| 8243 | return -EINVAL; |
| 8244 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8245 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
| 8246 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 8247 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || |
| 8248 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || |
| 8249 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) |
| 8250 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8251 | if (peer_capab) { |
| 8252 | /* |
| 8253 | * The internal enum tdls_peer_capability definition is |
| 8254 | * currently identical with the nl80211 enum |
| 8255 | * nl80211_tdls_peer_capability, so no conversion is needed |
| 8256 | * here. |
| 8257 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8258 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
| 8259 | peer_capab)) |
| 8260 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 8261 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8262 | if ((initiator && |
| 8263 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || |
| 8264 | nla_put(msg, NL80211_ATTR_IE, len, buf)) |
| 8265 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8266 | |
| 8267 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8268 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8269 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8270 | nlmsg_free(msg); |
| 8271 | return -ENOBUFS; |
| 8272 | } |
| 8273 | |
| 8274 | |
| 8275 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) |
| 8276 | { |
| 8277 | struct i802_bss *bss = priv; |
| 8278 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8279 | struct nl_msg *msg; |
| 8280 | enum nl80211_tdls_operation nl80211_oper; |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8281 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8282 | |
| 8283 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 8284 | return -EOPNOTSUPP; |
| 8285 | |
| 8286 | switch (oper) { |
| 8287 | case TDLS_DISCOVERY_REQ: |
| 8288 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; |
| 8289 | break; |
| 8290 | case TDLS_SETUP: |
| 8291 | nl80211_oper = NL80211_TDLS_SETUP; |
| 8292 | break; |
| 8293 | case TDLS_TEARDOWN: |
| 8294 | nl80211_oper = NL80211_TDLS_TEARDOWN; |
| 8295 | break; |
| 8296 | case TDLS_ENABLE_LINK: |
| 8297 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; |
| 8298 | break; |
| 8299 | case TDLS_DISABLE_LINK: |
| 8300 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; |
| 8301 | break; |
| 8302 | case TDLS_ENABLE: |
| 8303 | return 0; |
| 8304 | case TDLS_DISABLE: |
| 8305 | return 0; |
| 8306 | default: |
| 8307 | return -EINVAL; |
| 8308 | } |
| 8309 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8310 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
| 8311 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
| 8312 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
| 8313 | nlmsg_free(msg); |
| 8314 | return -ENOBUFS; |
| 8315 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8316 | |
Paul Stewart | 092955c | 2017-02-06 09:13:09 -0800 | [diff] [blame] | 8317 | res = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8318 | wpa_printf(MSG_DEBUG, "nl80211: TDLS_OPER: oper=%d mac=" MACSTR |
| 8319 | " --> res=%d (%s)", nl80211_oper, MAC2STR(peer), res, |
| 8320 | strerror(-res)); |
| 8321 | return res; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8322 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8323 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8324 | |
| 8325 | static int |
| 8326 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, |
| 8327 | const struct hostapd_freq_params *params) |
| 8328 | { |
| 8329 | struct i802_bss *bss = priv; |
| 8330 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8331 | struct nl_msg *msg; |
| 8332 | int ret = -ENOBUFS; |
| 8333 | |
| 8334 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 8335 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 8336 | return -EOPNOTSUPP; |
| 8337 | |
| 8338 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR |
| 8339 | " oper_class=%u freq=%u", |
| 8340 | MAC2STR(addr), oper_class, params->freq); |
| 8341 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); |
| 8342 | if (!msg || |
| 8343 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 8344 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || |
| 8345 | (ret = nl80211_put_freq_params(msg, params))) { |
| 8346 | nlmsg_free(msg); |
| 8347 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); |
| 8348 | return ret; |
| 8349 | } |
| 8350 | |
| 8351 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8352 | } |
| 8353 | |
| 8354 | |
| 8355 | static int |
| 8356 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) |
| 8357 | { |
| 8358 | struct i802_bss *bss = priv; |
| 8359 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8360 | struct nl_msg *msg; |
| 8361 | |
| 8362 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 8363 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 8364 | return -EOPNOTSUPP; |
| 8365 | |
| 8366 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, |
| 8367 | MAC2STR(addr)); |
| 8368 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); |
| 8369 | if (!msg || |
| 8370 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 8371 | nlmsg_free(msg); |
| 8372 | wpa_printf(MSG_DEBUG, |
| 8373 | "nl80211: Could not build TDLS cancel chan switch"); |
| 8374 | return -ENOBUFS; |
| 8375 | } |
| 8376 | |
| 8377 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 8378 | } |
| 8379 | |
| 8380 | #endif /* CONFIG TDLS */ |
| 8381 | |
| 8382 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8383 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
| 8384 | enum wpa_alg alg, const u8 *addr, |
| 8385 | int key_idx, int set_tx, |
| 8386 | const u8 *seq, size_t seq_len, |
| 8387 | const u8 *key, size_t key_len) |
| 8388 | { |
| 8389 | struct i802_bss *bss = priv; |
| 8390 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, |
| 8391 | set_tx, seq, seq_len, key, key_len); |
| 8392 | } |
| 8393 | |
| 8394 | |
| 8395 | static int driver_nl80211_scan2(void *priv, |
| 8396 | struct wpa_driver_scan_params *params) |
| 8397 | { |
| 8398 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8399 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 8400 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8401 | |
| 8402 | /* |
| 8403 | * Do a vendor specific scan if possible. If only_new_results is |
| 8404 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush |
| 8405 | * cannot be achieved through a vendor scan. The below condition may |
| 8406 | * need to be modified if new scan flags are added in the future whose |
| 8407 | * functionality can only be achieved through a normal scan. |
| 8408 | */ |
| 8409 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) |
| 8410 | return wpa_driver_nl80211_vendor_scan(bss, params); |
| 8411 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8412 | return wpa_driver_nl80211_scan(bss, params); |
| 8413 | } |
| 8414 | |
| 8415 | |
| 8416 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
| 8417 | int reason_code) |
| 8418 | { |
| 8419 | struct i802_bss *bss = priv; |
| 8420 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); |
| 8421 | } |
| 8422 | |
| 8423 | |
| 8424 | static int driver_nl80211_authenticate(void *priv, |
| 8425 | struct wpa_driver_auth_params *params) |
| 8426 | { |
| 8427 | struct i802_bss *bss = priv; |
| 8428 | return wpa_driver_nl80211_authenticate(bss, params); |
| 8429 | } |
| 8430 | |
| 8431 | |
| 8432 | static void driver_nl80211_deinit(void *priv) |
| 8433 | { |
| 8434 | struct i802_bss *bss = priv; |
| 8435 | wpa_driver_nl80211_deinit(bss); |
| 8436 | } |
| 8437 | |
| 8438 | |
| 8439 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, |
| 8440 | const char *ifname) |
| 8441 | { |
| 8442 | struct i802_bss *bss = priv; |
| 8443 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 8444 | } |
| 8445 | |
| 8446 | |
| 8447 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8448 | size_t data_len, int noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8449 | unsigned int freq, |
| 8450 | const u16 *csa_offs, size_t csa_offs_len) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8451 | { |
| 8452 | struct i802_bss *bss = priv; |
| 8453 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8454 | freq, 0, 0, 0, csa_offs, |
| 8455 | csa_offs_len); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8456 | } |
| 8457 | |
| 8458 | |
| 8459 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) |
| 8460 | { |
| 8461 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8462 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8463 | } |
| 8464 | |
| 8465 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8466 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
| 8467 | const char *ifname, int vlan_id) |
| 8468 | { |
| 8469 | struct i802_bss *bss = priv; |
| 8470 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); |
| 8471 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8472 | |
| 8473 | |
| 8474 | static int driver_nl80211_read_sta_data(void *priv, |
| 8475 | struct hostap_sta_driver_data *data, |
| 8476 | const u8 *addr) |
| 8477 | { |
| 8478 | struct i802_bss *bss = priv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 8479 | |
| 8480 | os_memset(data, 0, sizeof(*data)); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8481 | return i802_read_sta_data(bss, data, addr); |
| 8482 | } |
| 8483 | |
| 8484 | |
| 8485 | static int driver_nl80211_send_action(void *priv, unsigned int freq, |
| 8486 | unsigned int wait_time, |
| 8487 | const u8 *dst, const u8 *src, |
| 8488 | const u8 *bssid, |
| 8489 | const u8 *data, size_t data_len, |
| 8490 | int no_cck) |
| 8491 | { |
| 8492 | struct i802_bss *bss = priv; |
| 8493 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, |
| 8494 | bssid, data, data_len, no_cck); |
| 8495 | } |
| 8496 | |
| 8497 | |
| 8498 | static int driver_nl80211_probe_req_report(void *priv, int report) |
| 8499 | { |
| 8500 | struct i802_bss *bss = priv; |
| 8501 | return wpa_driver_nl80211_probe_req_report(bss, report); |
| 8502 | } |
| 8503 | |
| 8504 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8505 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
| 8506 | const u8 *ies, size_t ies_len) |
| 8507 | { |
| 8508 | int ret; |
| 8509 | struct nl_msg *msg; |
| 8510 | struct i802_bss *bss = priv; |
| 8511 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8512 | u16 mdid = WPA_GET_LE16(md); |
| 8513 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8514 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8515 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
| 8516 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
| 8517 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { |
| 8518 | nlmsg_free(msg); |
| 8519 | return -ENOBUFS; |
| 8520 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8521 | |
| 8522 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8523 | if (ret) { |
| 8524 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " |
| 8525 | "err=%d (%s)", ret, strerror(-ret)); |
| 8526 | } |
| 8527 | |
| 8528 | return ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8529 | } |
| 8530 | |
| 8531 | |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 8532 | static const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8533 | { |
| 8534 | struct i802_bss *bss = priv; |
| 8535 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8536 | |
| 8537 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 8538 | return NULL; |
| 8539 | |
| 8540 | return bss->addr; |
| 8541 | } |
| 8542 | |
| 8543 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8544 | static const char * scan_state_str(enum scan_states scan_state) |
| 8545 | { |
| 8546 | switch (scan_state) { |
| 8547 | case NO_SCAN: |
| 8548 | return "NO_SCAN"; |
| 8549 | case SCAN_REQUESTED: |
| 8550 | return "SCAN_REQUESTED"; |
| 8551 | case SCAN_STARTED: |
| 8552 | return "SCAN_STARTED"; |
| 8553 | case SCAN_COMPLETED: |
| 8554 | return "SCAN_COMPLETED"; |
| 8555 | case SCAN_ABORTED: |
| 8556 | return "SCAN_ABORTED"; |
| 8557 | case SCHED_SCAN_STARTED: |
| 8558 | return "SCHED_SCAN_STARTED"; |
| 8559 | case SCHED_SCAN_STOPPED: |
| 8560 | return "SCHED_SCAN_STOPPED"; |
| 8561 | case SCHED_SCAN_RESULTS: |
| 8562 | return "SCHED_SCAN_RESULTS"; |
| 8563 | } |
| 8564 | |
| 8565 | return "??"; |
| 8566 | } |
| 8567 | |
| 8568 | |
| 8569 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) |
| 8570 | { |
| 8571 | struct i802_bss *bss = priv; |
| 8572 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8573 | int res; |
| 8574 | char *pos, *end; |
| 8575 | |
| 8576 | pos = buf; |
| 8577 | end = buf + buflen; |
| 8578 | |
| 8579 | res = os_snprintf(pos, end - pos, |
| 8580 | "ifindex=%d\n" |
| 8581 | "ifname=%s\n" |
| 8582 | "brname=%s\n" |
| 8583 | "addr=" MACSTR "\n" |
| 8584 | "freq=%d\n" |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 8585 | "%s%s%s%s%s%s", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8586 | bss->ifindex, |
| 8587 | bss->ifname, |
| 8588 | bss->brname, |
| 8589 | MAC2STR(bss->addr), |
| 8590 | bss->freq, |
| 8591 | bss->beacon_set ? "beacon_set=1\n" : "", |
| 8592 | bss->added_if_into_bridge ? |
| 8593 | "added_if_into_bridge=1\n" : "", |
Hai Shalom | c9e41a1 | 2018-07-31 14:41:42 -0700 | [diff] [blame] | 8594 | bss->already_in_bridge ? "already_in_bridge=1\n" : "", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8595 | bss->added_bridge ? "added_bridge=1\n" : "", |
| 8596 | bss->in_deinit ? "in_deinit=1\n" : "", |
| 8597 | bss->if_dynamic ? "if_dynamic=1\n" : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8598 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8599 | return pos - buf; |
| 8600 | pos += res; |
| 8601 | |
| 8602 | if (bss->wdev_id_set) { |
| 8603 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", |
| 8604 | (unsigned long long) bss->wdev_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8605 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8606 | return pos - buf; |
| 8607 | pos += res; |
| 8608 | } |
| 8609 | |
| 8610 | res = os_snprintf(pos, end - pos, |
| 8611 | "phyname=%s\n" |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8612 | "perm_addr=" MACSTR "\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8613 | "drv_ifindex=%d\n" |
| 8614 | "operstate=%d\n" |
| 8615 | "scan_state=%s\n" |
| 8616 | "auth_bssid=" MACSTR "\n" |
| 8617 | "auth_attempt_bssid=" MACSTR "\n" |
| 8618 | "bssid=" MACSTR "\n" |
| 8619 | "prev_bssid=" MACSTR "\n" |
| 8620 | "associated=%d\n" |
| 8621 | "assoc_freq=%u\n" |
| 8622 | "monitor_sock=%d\n" |
| 8623 | "monitor_ifidx=%d\n" |
| 8624 | "monitor_refcount=%d\n" |
| 8625 | "last_mgmt_freq=%u\n" |
| 8626 | "eapol_tx_sock=%d\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8627 | "%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] | 8628 | drv->phyname, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8629 | MAC2STR(drv->perm_addr), |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8630 | drv->ifindex, |
| 8631 | drv->operstate, |
| 8632 | scan_state_str(drv->scan_state), |
| 8633 | MAC2STR(drv->auth_bssid), |
| 8634 | MAC2STR(drv->auth_attempt_bssid), |
| 8635 | MAC2STR(drv->bssid), |
| 8636 | MAC2STR(drv->prev_bssid), |
| 8637 | drv->associated, |
| 8638 | drv->assoc_freq, |
| 8639 | drv->monitor_sock, |
| 8640 | drv->monitor_ifidx, |
| 8641 | drv->monitor_refcount, |
| 8642 | drv->last_mgmt_freq, |
| 8643 | drv->eapol_tx_sock, |
| 8644 | drv->ignore_if_down_event ? |
| 8645 | "ignore_if_down_event=1\n" : "", |
| 8646 | drv->scan_complete_events ? |
| 8647 | "scan_complete_events=1\n" : "", |
| 8648 | drv->disabled_11b_rates ? |
| 8649 | "disabled_11b_rates=1\n" : "", |
| 8650 | drv->pending_remain_on_chan ? |
| 8651 | "pending_remain_on_chan=1\n" : "", |
| 8652 | drv->in_interface_list ? "in_interface_list=1\n" : "", |
| 8653 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", |
| 8654 | drv->poll_command_supported ? |
| 8655 | "poll_command_supported=1\n" : "", |
| 8656 | drv->data_tx_status ? "data_tx_status=1\n" : "", |
| 8657 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", |
| 8658 | drv->retry_auth ? "retry_auth=1\n" : "", |
| 8659 | drv->use_monitor ? "use_monitor=1\n" : "", |
| 8660 | drv->ignore_next_local_disconnect ? |
| 8661 | "ignore_next_local_disconnect=1\n" : "", |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 8662 | drv->ignore_next_local_deauth ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8663 | "ignore_next_local_deauth=1\n" : ""); |
| 8664 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8665 | return pos - buf; |
| 8666 | pos += res; |
| 8667 | |
| 8668 | if (drv->has_capability) { |
| 8669 | res = os_snprintf(pos, end - pos, |
| 8670 | "capa.key_mgmt=0x%x\n" |
| 8671 | "capa.enc=0x%x\n" |
| 8672 | "capa.auth=0x%x\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8673 | "capa.flags=0x%llx\n" |
| 8674 | "capa.rrm_flags=0x%x\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8675 | "capa.max_scan_ssids=%d\n" |
| 8676 | "capa.max_sched_scan_ssids=%d\n" |
| 8677 | "capa.sched_scan_supported=%d\n" |
| 8678 | "capa.max_match_sets=%d\n" |
| 8679 | "capa.max_remain_on_chan=%u\n" |
| 8680 | "capa.max_stations=%u\n" |
| 8681 | "capa.probe_resp_offloads=0x%x\n" |
| 8682 | "capa.max_acl_mac_addrs=%u\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8683 | "capa.num_multichan_concurrent=%u\n" |
| 8684 | "capa.mac_addr_rand_sched_scan_supported=%d\n" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8685 | "capa.mac_addr_rand_scan_supported=%d\n" |
| 8686 | "capa.conc_capab=%u\n" |
| 8687 | "capa.max_conc_chan_2_4=%u\n" |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8688 | "capa.max_conc_chan_5_0=%u\n" |
| 8689 | "capa.max_sched_scan_plans=%u\n" |
| 8690 | "capa.max_sched_scan_plan_interval=%u\n" |
| 8691 | "capa.max_sched_scan_plan_iterations=%u\n", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8692 | drv->capa.key_mgmt, |
| 8693 | drv->capa.enc, |
| 8694 | drv->capa.auth, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8695 | (unsigned long long) drv->capa.flags, |
| 8696 | drv->capa.rrm_flags, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8697 | drv->capa.max_scan_ssids, |
| 8698 | drv->capa.max_sched_scan_ssids, |
| 8699 | drv->capa.sched_scan_supported, |
| 8700 | drv->capa.max_match_sets, |
| 8701 | drv->capa.max_remain_on_chan, |
| 8702 | drv->capa.max_stations, |
| 8703 | drv->capa.probe_resp_offloads, |
| 8704 | drv->capa.max_acl_mac_addrs, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8705 | drv->capa.num_multichan_concurrent, |
| 8706 | drv->capa.mac_addr_rand_sched_scan_supported, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8707 | drv->capa.mac_addr_rand_scan_supported, |
| 8708 | drv->capa.conc_capab, |
| 8709 | drv->capa.max_conc_chan_2_4, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8710 | drv->capa.max_conc_chan_5_0, |
| 8711 | drv->capa.max_sched_scan_plans, |
| 8712 | drv->capa.max_sched_scan_plan_interval, |
| 8713 | drv->capa.max_sched_scan_plan_iterations); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8714 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8715 | return pos - buf; |
| 8716 | pos += res; |
| 8717 | } |
| 8718 | |
| 8719 | return pos - buf; |
| 8720 | } |
| 8721 | |
| 8722 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8723 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
| 8724 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8725 | if ((settings->head && |
| 8726 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, |
| 8727 | settings->head_len, settings->head)) || |
| 8728 | (settings->tail && |
| 8729 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, |
| 8730 | settings->tail_len, settings->tail)) || |
| 8731 | (settings->beacon_ies && |
| 8732 | nla_put(msg, NL80211_ATTR_IE, |
| 8733 | settings->beacon_ies_len, settings->beacon_ies)) || |
| 8734 | (settings->proberesp_ies && |
| 8735 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 8736 | settings->proberesp_ies_len, settings->proberesp_ies)) || |
| 8737 | (settings->assocresp_ies && |
| 8738 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 8739 | settings->assocresp_ies_len, settings->assocresp_ies)) || |
| 8740 | (settings->probe_resp && |
| 8741 | nla_put(msg, NL80211_ATTR_PROBE_RESP, |
| 8742 | settings->probe_resp_len, settings->probe_resp))) |
| 8743 | return -ENOBUFS; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8744 | |
| 8745 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8746 | } |
| 8747 | |
| 8748 | |
| 8749 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) |
| 8750 | { |
| 8751 | struct nl_msg *msg; |
| 8752 | struct i802_bss *bss = priv; |
| 8753 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8754 | struct nlattr *beacon_csa; |
| 8755 | int ret = -ENOBUFS; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8756 | int csa_off_len = 0; |
| 8757 | int i; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8758 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 8759 | 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] | 8760 | settings->cs_count, settings->block_tx, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 8761 | settings->freq_params.freq, settings->freq_params.bandwidth, |
| 8762 | settings->freq_params.center_freq1, |
| 8763 | settings->freq_params.center_freq2); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8764 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8765 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8766 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
| 8767 | return -EOPNOTSUPP; |
| 8768 | } |
| 8769 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 8770 | if (drv->nlmode != NL80211_IFTYPE_AP && |
| 8771 | drv->nlmode != NL80211_IFTYPE_P2P_GO && |
| 8772 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8773 | return -EOPNOTSUPP; |
| 8774 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8775 | /* |
| 8776 | * Remove empty counters, assuming Probe Response and Beacon frame |
| 8777 | * counters match. This implementation assumes that there are only two |
| 8778 | * counters. |
| 8779 | */ |
| 8780 | if (settings->counter_offset_beacon[0] && |
| 8781 | !settings->counter_offset_beacon[1]) { |
| 8782 | csa_off_len = 1; |
| 8783 | } else if (settings->counter_offset_beacon[1] && |
| 8784 | !settings->counter_offset_beacon[0]) { |
| 8785 | csa_off_len = 1; |
| 8786 | settings->counter_offset_beacon[0] = |
| 8787 | settings->counter_offset_beacon[1]; |
| 8788 | settings->counter_offset_presp[0] = |
| 8789 | settings->counter_offset_presp[1]; |
| 8790 | } else if (settings->counter_offset_beacon[1] && |
| 8791 | settings->counter_offset_beacon[0]) { |
| 8792 | csa_off_len = 2; |
| 8793 | } else { |
| 8794 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); |
| 8795 | return -EINVAL; |
| 8796 | } |
| 8797 | |
| 8798 | /* Check CSA counters validity */ |
| 8799 | if (drv->capa.max_csa_counters && |
| 8800 | csa_off_len > drv->capa.max_csa_counters) { |
| 8801 | wpa_printf(MSG_ERROR, |
| 8802 | "nl80211: Too many CSA counters provided"); |
| 8803 | return -EINVAL; |
| 8804 | } |
| 8805 | |
| 8806 | if (!settings->beacon_csa.tail) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8807 | return -EINVAL; |
| 8808 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8809 | for (i = 0; i < csa_off_len; i++) { |
| 8810 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; |
| 8811 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; |
| 8812 | |
| 8813 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || |
| 8814 | (settings->beacon_csa.tail[csa_c_off_bcn] != |
| 8815 | settings->cs_count)) |
| 8816 | return -EINVAL; |
| 8817 | |
| 8818 | if (settings->beacon_csa.probe_resp && |
| 8819 | ((settings->beacon_csa.probe_resp_len <= |
| 8820 | csa_c_off_presp) || |
| 8821 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != |
| 8822 | settings->cs_count))) |
| 8823 | return -EINVAL; |
| 8824 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8825 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8826 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
| 8827 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
| 8828 | settings->cs_count) || |
| 8829 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || |
| 8830 | (settings->block_tx && |
| 8831 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8832 | goto error; |
| 8833 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8834 | /* beacon_after params */ |
| 8835 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 8836 | if (ret) |
| 8837 | goto error; |
| 8838 | |
| 8839 | /* beacon_csa params */ |
| 8840 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); |
| 8841 | if (!beacon_csa) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8842 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8843 | |
| 8844 | ret = set_beacon_data(msg, &settings->beacon_csa); |
| 8845 | if (ret) |
| 8846 | goto error; |
| 8847 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8848 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
| 8849 | csa_off_len * sizeof(u16), |
| 8850 | settings->counter_offset_beacon) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8851 | (settings->beacon_csa.probe_resp && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8852 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
| 8853 | csa_off_len * sizeof(u16), |
| 8854 | settings->counter_offset_presp))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8855 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8856 | |
| 8857 | nla_nest_end(msg, beacon_csa); |
| 8858 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8859 | if (ret) { |
| 8860 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", |
| 8861 | ret, strerror(-ret)); |
| 8862 | } |
| 8863 | return ret; |
| 8864 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8865 | fail: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8866 | ret = -ENOBUFS; |
| 8867 | error: |
| 8868 | nlmsg_free(msg); |
| 8869 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); |
| 8870 | return ret; |
| 8871 | } |
| 8872 | |
| 8873 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8874 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
| 8875 | u8 user_priority, u16 admitted_time) |
| 8876 | { |
| 8877 | struct i802_bss *bss = priv; |
| 8878 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8879 | struct nl_msg *msg; |
| 8880 | int ret; |
| 8881 | |
| 8882 | wpa_printf(MSG_DEBUG, |
| 8883 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", |
| 8884 | tsid, admitted_time, user_priority); |
| 8885 | |
| 8886 | if (!is_sta_interface(drv->nlmode)) |
| 8887 | return -ENOTSUP; |
| 8888 | |
| 8889 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
| 8890 | if (!msg || |
| 8891 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 8892 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 8893 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || |
| 8894 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { |
| 8895 | nlmsg_free(msg); |
| 8896 | return -ENOBUFS; |
| 8897 | } |
| 8898 | |
| 8899 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8900 | if (ret) |
| 8901 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", |
| 8902 | ret, strerror(-ret)); |
| 8903 | return ret; |
| 8904 | } |
| 8905 | |
| 8906 | |
| 8907 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) |
| 8908 | { |
| 8909 | struct i802_bss *bss = priv; |
| 8910 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8911 | struct nl_msg *msg; |
| 8912 | int ret; |
| 8913 | |
| 8914 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); |
| 8915 | |
| 8916 | if (!is_sta_interface(drv->nlmode)) |
| 8917 | return -ENOTSUP; |
| 8918 | |
| 8919 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
| 8920 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 8921 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 8922 | nlmsg_free(msg); |
| 8923 | return -ENOBUFS; |
| 8924 | } |
| 8925 | |
| 8926 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8927 | if (ret) |
| 8928 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", |
| 8929 | ret, strerror(-ret)); |
| 8930 | return ret; |
| 8931 | } |
| 8932 | |
| 8933 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8934 | #ifdef CONFIG_TESTING_OPTIONS |
| 8935 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) |
| 8936 | { |
| 8937 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8938 | struct wpabuf *buf = arg; |
| 8939 | |
| 8940 | if (!buf) |
| 8941 | return NL_SKIP; |
| 8942 | |
| 8943 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { |
| 8944 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); |
| 8945 | return NL_SKIP; |
| 8946 | } |
| 8947 | |
| 8948 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), |
| 8949 | genlmsg_attrlen(gnlh, 0)); |
| 8950 | |
| 8951 | return NL_SKIP; |
| 8952 | } |
| 8953 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 8954 | |
| 8955 | |
| 8956 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
| 8957 | { |
| 8958 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8959 | struct nlattr *nl_vendor_reply, *nl; |
| 8960 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8961 | struct wpabuf *buf = arg; |
| 8962 | int rem; |
| 8963 | |
| 8964 | if (!buf) |
| 8965 | return NL_SKIP; |
| 8966 | |
| 8967 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8968 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8969 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; |
| 8970 | |
| 8971 | if (!nl_vendor_reply) |
| 8972 | return NL_SKIP; |
| 8973 | |
| 8974 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { |
| 8975 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); |
| 8976 | return NL_SKIP; |
| 8977 | } |
| 8978 | |
| 8979 | nla_for_each_nested(nl, nl_vendor_reply, rem) { |
| 8980 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); |
| 8981 | } |
| 8982 | |
| 8983 | return NL_SKIP; |
| 8984 | } |
| 8985 | |
| 8986 | |
| 8987 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, |
| 8988 | unsigned int subcmd, const u8 *data, |
| 8989 | size_t data_len, struct wpabuf *buf) |
| 8990 | { |
| 8991 | struct i802_bss *bss = priv; |
| 8992 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8993 | struct nl_msg *msg; |
| 8994 | int ret; |
| 8995 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8996 | #ifdef CONFIG_TESTING_OPTIONS |
| 8997 | if (vendor_id == 0xffffffff) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8998 | msg = nlmsg_alloc(); |
| 8999 | if (!msg) |
| 9000 | return -ENOMEM; |
| 9001 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9002 | nl80211_cmd(drv, msg, 0, subcmd); |
| 9003 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < |
| 9004 | 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9005 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9006 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
| 9007 | if (ret) |
| 9008 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", |
| 9009 | ret); |
| 9010 | return ret; |
| 9011 | } |
| 9012 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 9013 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9014 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 9015 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
| 9016 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || |
| 9017 | (data && |
| 9018 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) |
| 9019 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9020 | |
| 9021 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); |
| 9022 | if (ret) |
| 9023 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", |
| 9024 | ret); |
| 9025 | return ret; |
| 9026 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9027 | fail: |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9028 | nlmsg_free(msg); |
| 9029 | return -ENOBUFS; |
| 9030 | } |
| 9031 | |
| 9032 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9033 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
| 9034 | u8 qos_map_set_len) |
| 9035 | { |
| 9036 | struct i802_bss *bss = priv; |
| 9037 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9038 | struct nl_msg *msg; |
| 9039 | int ret; |
| 9040 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9041 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
| 9042 | qos_map_set, qos_map_set_len); |
| 9043 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9044 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
| 9045 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
| 9046 | nlmsg_free(msg); |
| 9047 | return -ENOBUFS; |
| 9048 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9049 | |
| 9050 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9051 | if (ret) |
| 9052 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); |
| 9053 | |
| 9054 | return ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9055 | } |
| 9056 | |
| 9057 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9058 | static int nl80211_set_wowlan(void *priv, |
| 9059 | const struct wowlan_triggers *triggers) |
| 9060 | { |
| 9061 | struct i802_bss *bss = priv; |
| 9062 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9063 | struct nl_msg *msg; |
| 9064 | struct nlattr *wowlan_triggers; |
| 9065 | int ret; |
| 9066 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9067 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
| 9068 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 9069 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9070 | !(wowlan_triggers = nla_nest_start(msg, |
| 9071 | NL80211_ATTR_WOWLAN_TRIGGERS)) || |
| 9072 | (triggers->any && |
| 9073 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 9074 | (triggers->disconnect && |
| 9075 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 9076 | (triggers->magic_pkt && |
| 9077 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 9078 | (triggers->gtk_rekey_failure && |
| 9079 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 9080 | (triggers->eap_identity_req && |
| 9081 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 9082 | (triggers->four_way_handshake && |
| 9083 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 9084 | (triggers->rfkill_release && |
| 9085 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { |
| 9086 | nlmsg_free(msg); |
| 9087 | return -ENOBUFS; |
| 9088 | } |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9089 | |
| 9090 | nla_nest_end(msg, wowlan_triggers); |
| 9091 | |
| 9092 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9093 | if (ret) |
| 9094 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); |
| 9095 | |
| 9096 | return ret; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9097 | } |
| 9098 | |
| 9099 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9100 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9101 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
| 9102 | { |
| 9103 | struct i802_bss *bss = priv; |
| 9104 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9105 | struct nl_msg *msg; |
| 9106 | struct nlattr *params; |
| 9107 | |
| 9108 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); |
| 9109 | |
| 9110 | if (!drv->roaming_vendor_cmd_avail) { |
| 9111 | wpa_printf(MSG_DEBUG, |
| 9112 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); |
| 9113 | return -1; |
| 9114 | } |
| 9115 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9116 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9117 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9118 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9119 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || |
| 9120 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9121 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, |
| 9122 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : |
| 9123 | QCA_ROAMING_NOT_ALLOWED) || |
| 9124 | (bssid && |
| 9125 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { |
| 9126 | nlmsg_free(msg); |
| 9127 | return -1; |
| 9128 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9129 | nla_nest_end(msg, params); |
| 9130 | |
| 9131 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9132 | } |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9133 | |
| 9134 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9135 | static int nl80211_disable_fils(void *priv, int disable) |
| 9136 | { |
| 9137 | struct i802_bss *bss = priv; |
| 9138 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9139 | struct nl_msg *msg; |
| 9140 | struct nlattr *params; |
| 9141 | |
| 9142 | wpa_printf(MSG_DEBUG, "nl80211: Disable FILS=%d", disable); |
| 9143 | |
| 9144 | if (!drv->set_wifi_conf_vendor_cmd_avail) |
| 9145 | return -1; |
| 9146 | |
| 9147 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9148 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9149 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9150 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION) || |
| 9151 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9152 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_DISABLE_FILS, |
| 9153 | disable)) { |
| 9154 | nlmsg_free(msg); |
| 9155 | return -1; |
| 9156 | } |
| 9157 | nla_nest_end(msg, params); |
| 9158 | |
| 9159 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9160 | } |
| 9161 | |
| 9162 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9163 | /* Reserved QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID value for wpa_supplicant */ |
| 9164 | #define WPA_SUPPLICANT_CLIENT_ID 1 |
| 9165 | |
| 9166 | static int nl80211_set_bssid_blacklist(void *priv, unsigned int num_bssid, |
| 9167 | const u8 *bssid) |
| 9168 | { |
| 9169 | struct i802_bss *bss = priv; |
| 9170 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9171 | struct nl_msg *msg; |
| 9172 | struct nlattr *params, *nlbssids, *attr; |
| 9173 | unsigned int i; |
| 9174 | |
| 9175 | wpa_printf(MSG_DEBUG, "nl80211: Set blacklist BSSID (num=%u)", |
| 9176 | num_bssid); |
| 9177 | |
| 9178 | if (!drv->roam_vendor_cmd_avail) |
| 9179 | return -1; |
| 9180 | |
| 9181 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9182 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9183 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9184 | QCA_NL80211_VENDOR_SUBCMD_ROAM) || |
| 9185 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9186 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_SUBCMD, |
| 9187 | QCA_WLAN_VENDOR_ATTR_ROAM_SUBCMD_SET_BLACKLIST_BSSID) || |
| 9188 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_REQ_ID, |
| 9189 | WPA_SUPPLICANT_CLIENT_ID) || |
| 9190 | nla_put_u32(msg, |
| 9191 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_NUM_BSSID, |
| 9192 | num_bssid)) |
| 9193 | goto fail; |
| 9194 | |
| 9195 | nlbssids = nla_nest_start( |
| 9196 | msg, QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS); |
| 9197 | if (!nlbssids) |
| 9198 | goto fail; |
| 9199 | |
| 9200 | for (i = 0; i < num_bssid; i++) { |
| 9201 | attr = nla_nest_start(msg, i); |
| 9202 | if (!attr) |
| 9203 | goto fail; |
| 9204 | if (nla_put(msg, |
| 9205 | QCA_WLAN_VENDOR_ATTR_ROAMING_PARAM_SET_BSSID_PARAMS_BSSID, |
| 9206 | ETH_ALEN, &bssid[i * ETH_ALEN])) |
| 9207 | goto fail; |
| 9208 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%u]: " MACSTR, i, |
| 9209 | MAC2STR(&bssid[i * ETH_ALEN])); |
| 9210 | nla_nest_end(msg, attr); |
| 9211 | } |
| 9212 | nla_nest_end(msg, nlbssids); |
| 9213 | nla_nest_end(msg, params); |
| 9214 | |
| 9215 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9216 | |
| 9217 | fail: |
| 9218 | nlmsg_free(msg); |
| 9219 | return -1; |
| 9220 | } |
| 9221 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9222 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9223 | |
| 9224 | |
| 9225 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
| 9226 | { |
| 9227 | struct i802_bss *bss = priv; |
| 9228 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9229 | int new_addr = addr != NULL; |
| 9230 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9231 | if (TEST_FAIL()) |
| 9232 | return -1; |
| 9233 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9234 | if (!addr) |
| 9235 | addr = drv->perm_addr; |
| 9236 | |
| 9237 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) |
| 9238 | return -1; |
| 9239 | |
| 9240 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) |
| 9241 | { |
| 9242 | wpa_printf(MSG_DEBUG, |
| 9243 | "nl80211: failed to set_mac_addr for %s to " MACSTR, |
| 9244 | bss->ifname, MAC2STR(addr)); |
| 9245 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 9246 | 1) < 0) { |
| 9247 | wpa_printf(MSG_DEBUG, |
| 9248 | "nl80211: Could not restore interface UP after failed set_mac_addr"); |
| 9249 | } |
| 9250 | return -1; |
| 9251 | } |
| 9252 | |
| 9253 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, |
| 9254 | bss->ifname, MAC2STR(addr)); |
| 9255 | drv->addr_changed = new_addr; |
| 9256 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 9257 | |
| 9258 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) |
| 9259 | { |
| 9260 | wpa_printf(MSG_DEBUG, |
| 9261 | "nl80211: Could not restore interface UP after set_mac_addr"); |
| 9262 | } |
| 9263 | |
| 9264 | return 0; |
| 9265 | } |
| 9266 | |
| 9267 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9268 | #ifdef CONFIG_MESH |
| 9269 | |
| 9270 | static int wpa_driver_nl80211_init_mesh(void *priv) |
| 9271 | { |
| 9272 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { |
| 9273 | wpa_printf(MSG_INFO, |
| 9274 | "nl80211: Failed to set interface into mesh mode"); |
| 9275 | return -1; |
| 9276 | } |
| 9277 | return 0; |
| 9278 | } |
| 9279 | |
| 9280 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9281 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
| 9282 | size_t mesh_id_len) |
| 9283 | { |
| 9284 | if (mesh_id) { |
| 9285 | wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)", |
| 9286 | mesh_id, mesh_id_len); |
| 9287 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); |
| 9288 | } |
| 9289 | |
| 9290 | return 0; |
| 9291 | } |
| 9292 | |
| 9293 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9294 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
| 9295 | struct wpa_driver_mesh_bss_params *params) |
| 9296 | { |
| 9297 | struct nlattr *container; |
| 9298 | |
| 9299 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
| 9300 | if (!container) |
| 9301 | return -1; |
| 9302 | |
| 9303 | if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 9304 | nla_put_u8(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 9305 | params->auto_plinks)) || |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9306 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) && |
| 9307 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 9308 | params->max_peer_links)) || |
| 9309 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_RSSI_THRESHOLD) && |
| 9310 | nla_put_u32(msg, NL80211_MESHCONF_RSSI_THRESHOLD, |
| 9311 | params->rssi_threshold))) |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9312 | return -1; |
| 9313 | |
| 9314 | /* |
| 9315 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because |
| 9316 | * the timer could disconnect stations even in that case. |
| 9317 | */ |
| 9318 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) && |
| 9319 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 9320 | params->peer_link_timeout)) { |
| 9321 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); |
| 9322 | return -1; |
| 9323 | } |
| 9324 | |
| 9325 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) && |
| 9326 | nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) { |
| 9327 | wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE"); |
| 9328 | return -1; |
| 9329 | } |
| 9330 | |
| 9331 | nla_nest_end(msg, container); |
| 9332 | |
| 9333 | return 0; |
| 9334 | } |
| 9335 | |
| 9336 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9337 | static int nl80211_join_mesh(struct i802_bss *bss, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9338 | struct wpa_driver_mesh_join_params *params) |
| 9339 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9340 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9341 | struct nl_msg *msg; |
| 9342 | struct nlattr *container; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 9343 | int ret = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9344 | |
| 9345 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
| 9346 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 9347 | if (!msg || |
| 9348 | nl80211_put_freq_params(msg, ¶ms->freq) || |
| 9349 | nl80211_put_basic_rates(msg, params->basic_rates) || |
| 9350 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 9351 | nl80211_put_beacon_int(msg, params->beacon_int) || |
| 9352 | nl80211_put_dtim_period(msg, params->dtim_period)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9353 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9354 | |
| 9355 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
| 9356 | |
| 9357 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); |
| 9358 | if (!container) |
| 9359 | goto fail; |
| 9360 | |
| 9361 | if (params->ies) { |
| 9362 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); |
| 9363 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
| 9364 | params->ies)) |
| 9365 | goto fail; |
| 9366 | } |
| 9367 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ |
| 9368 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { |
| 9369 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
| 9370 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) |
| 9371 | goto fail; |
| 9372 | } |
| 9373 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
| 9374 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) |
| 9375 | goto fail; |
| 9376 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && |
| 9377 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) |
| 9378 | goto fail; |
| 9379 | nla_nest_end(msg, container); |
| 9380 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 9381 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS; |
| 9382 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT; |
| 9383 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS; |
| 9384 | if (nl80211_put_mesh_config(msg, ¶ms->conf) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9385 | goto fail; |
| 9386 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9387 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9388 | msg = NULL; |
| 9389 | if (ret) { |
| 9390 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", |
| 9391 | ret, strerror(-ret)); |
| 9392 | goto fail; |
| 9393 | } |
| 9394 | ret = 0; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 9395 | drv->assoc_freq = bss->freq = params->freq.freq; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9396 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
| 9397 | |
| 9398 | fail: |
| 9399 | nlmsg_free(msg); |
| 9400 | return ret; |
| 9401 | } |
| 9402 | |
| 9403 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 9404 | static int |
| 9405 | wpa_driver_nl80211_join_mesh(void *priv, |
| 9406 | struct wpa_driver_mesh_join_params *params) |
| 9407 | { |
| 9408 | struct i802_bss *bss = priv; |
| 9409 | int ret, timeout; |
| 9410 | |
| 9411 | timeout = params->conf.peer_link_timeout; |
| 9412 | |
| 9413 | /* Disable kernel inactivity timer */ |
| 9414 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) |
| 9415 | params->conf.peer_link_timeout = 0; |
| 9416 | |
| 9417 | ret = nl80211_join_mesh(bss, params); |
| 9418 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { |
| 9419 | wpa_printf(MSG_DEBUG, |
| 9420 | "nl80211: Mesh join retry for peer_link_timeout"); |
| 9421 | /* |
| 9422 | * Old kernel does not support setting |
| 9423 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds |
| 9424 | * into future from peer_link_timeout. |
| 9425 | */ |
| 9426 | params->conf.peer_link_timeout = timeout + 60; |
| 9427 | ret = nl80211_join_mesh(priv, params); |
| 9428 | } |
| 9429 | |
| 9430 | params->conf.peer_link_timeout = timeout; |
| 9431 | return ret; |
| 9432 | } |
| 9433 | |
| 9434 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9435 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
| 9436 | { |
| 9437 | struct i802_bss *bss = priv; |
| 9438 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9439 | struct nl_msg *msg; |
| 9440 | int ret; |
| 9441 | |
| 9442 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); |
| 9443 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
| 9444 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9445 | if (ret) { |
| 9446 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", |
| 9447 | ret, strerror(-ret)); |
| 9448 | } else { |
| 9449 | wpa_printf(MSG_DEBUG, |
| 9450 | "nl80211: mesh leave request send successfully"); |
| 9451 | } |
| 9452 | |
| 9453 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
| 9454 | NL80211_IFTYPE_STATION)) { |
| 9455 | wpa_printf(MSG_INFO, |
| 9456 | "nl80211: Failed to set interface into station mode"); |
| 9457 | } |
| 9458 | return ret; |
| 9459 | } |
| 9460 | |
| 9461 | #endif /* CONFIG_MESH */ |
| 9462 | |
| 9463 | |
| 9464 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
| 9465 | const u8 *ipaddr, int prefixlen, |
| 9466 | const u8 *addr) |
| 9467 | { |
| 9468 | #ifdef CONFIG_LIBNL3_ROUTE |
| 9469 | struct i802_bss *bss = priv; |
| 9470 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9471 | struct rtnl_neigh *rn; |
| 9472 | struct nl_addr *nl_ipaddr = NULL; |
| 9473 | struct nl_addr *nl_lladdr = NULL; |
| 9474 | int family, addrsize; |
| 9475 | int res; |
| 9476 | |
| 9477 | if (!ipaddr || prefixlen == 0 || !addr) |
| 9478 | return -EINVAL; |
| 9479 | |
| 9480 | if (bss->br_ifindex == 0) { |
| 9481 | wpa_printf(MSG_DEBUG, |
| 9482 | "nl80211: bridge must be set before adding an ip neigh to it"); |
| 9483 | return -1; |
| 9484 | } |
| 9485 | |
| 9486 | if (!drv->rtnl_sk) { |
| 9487 | wpa_printf(MSG_DEBUG, |
| 9488 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 9489 | return -1; |
| 9490 | } |
| 9491 | |
| 9492 | if (version == 4) { |
| 9493 | family = AF_INET; |
| 9494 | addrsize = 4; |
| 9495 | } else if (version == 6) { |
| 9496 | family = AF_INET6; |
| 9497 | addrsize = 16; |
| 9498 | } else { |
| 9499 | return -EINVAL; |
| 9500 | } |
| 9501 | |
| 9502 | rn = rtnl_neigh_alloc(); |
| 9503 | if (rn == NULL) |
| 9504 | return -ENOMEM; |
| 9505 | |
| 9506 | /* set the destination ip address for neigh */ |
| 9507 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 9508 | if (nl_ipaddr == NULL) { |
| 9509 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 9510 | res = -ENOMEM; |
| 9511 | goto errout; |
| 9512 | } |
| 9513 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); |
| 9514 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 9515 | if (res) { |
| 9516 | wpa_printf(MSG_DEBUG, |
| 9517 | "nl80211: neigh set destination addr failed"); |
| 9518 | goto errout; |
| 9519 | } |
| 9520 | |
| 9521 | /* set the corresponding lladdr for neigh */ |
| 9522 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); |
| 9523 | if (nl_lladdr == NULL) { |
| 9524 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); |
| 9525 | res = -ENOMEM; |
| 9526 | goto errout; |
| 9527 | } |
| 9528 | rtnl_neigh_set_lladdr(rn, nl_lladdr); |
| 9529 | |
| 9530 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 9531 | rtnl_neigh_set_state(rn, NUD_PERMANENT); |
| 9532 | |
| 9533 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); |
| 9534 | if (res) { |
| 9535 | wpa_printf(MSG_DEBUG, |
| 9536 | "nl80211: Adding bridge ip neigh failed: %s", |
| 9537 | strerror(errno)); |
| 9538 | } |
| 9539 | errout: |
| 9540 | if (nl_lladdr) |
| 9541 | nl_addr_put(nl_lladdr); |
| 9542 | if (nl_ipaddr) |
| 9543 | nl_addr_put(nl_ipaddr); |
| 9544 | if (rn) |
| 9545 | rtnl_neigh_put(rn); |
| 9546 | return res; |
| 9547 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 9548 | return -1; |
| 9549 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 9550 | } |
| 9551 | |
| 9552 | |
| 9553 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
| 9554 | const u8 *ipaddr) |
| 9555 | { |
| 9556 | #ifdef CONFIG_LIBNL3_ROUTE |
| 9557 | struct i802_bss *bss = priv; |
| 9558 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9559 | struct rtnl_neigh *rn; |
| 9560 | struct nl_addr *nl_ipaddr; |
| 9561 | int family, addrsize; |
| 9562 | int res; |
| 9563 | |
| 9564 | if (!ipaddr) |
| 9565 | return -EINVAL; |
| 9566 | |
| 9567 | if (version == 4) { |
| 9568 | family = AF_INET; |
| 9569 | addrsize = 4; |
| 9570 | } else if (version == 6) { |
| 9571 | family = AF_INET6; |
| 9572 | addrsize = 16; |
| 9573 | } else { |
| 9574 | return -EINVAL; |
| 9575 | } |
| 9576 | |
| 9577 | if (bss->br_ifindex == 0) { |
| 9578 | wpa_printf(MSG_DEBUG, |
| 9579 | "nl80211: bridge must be set to delete an ip neigh"); |
| 9580 | return -1; |
| 9581 | } |
| 9582 | |
| 9583 | if (!drv->rtnl_sk) { |
| 9584 | wpa_printf(MSG_DEBUG, |
| 9585 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 9586 | return -1; |
| 9587 | } |
| 9588 | |
| 9589 | rn = rtnl_neigh_alloc(); |
| 9590 | if (rn == NULL) |
| 9591 | return -ENOMEM; |
| 9592 | |
| 9593 | /* set the destination ip address for neigh */ |
| 9594 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 9595 | if (nl_ipaddr == NULL) { |
| 9596 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 9597 | res = -ENOMEM; |
| 9598 | goto errout; |
| 9599 | } |
| 9600 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 9601 | if (res) { |
| 9602 | wpa_printf(MSG_DEBUG, |
| 9603 | "nl80211: neigh set destination addr failed"); |
| 9604 | goto errout; |
| 9605 | } |
| 9606 | |
| 9607 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 9608 | |
| 9609 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 9610 | if (res) { |
| 9611 | wpa_printf(MSG_DEBUG, |
| 9612 | "nl80211: Deleting bridge ip neigh failed: %s", |
| 9613 | strerror(errno)); |
| 9614 | } |
| 9615 | errout: |
| 9616 | if (nl_ipaddr) |
| 9617 | nl_addr_put(nl_ipaddr); |
| 9618 | if (rn) |
| 9619 | rtnl_neigh_put(rn); |
| 9620 | return res; |
| 9621 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 9622 | return -1; |
| 9623 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 9624 | } |
| 9625 | |
| 9626 | |
| 9627 | static int linux_write_system_file(const char *path, unsigned int val) |
| 9628 | { |
| 9629 | char buf[50]; |
| 9630 | int fd, len; |
| 9631 | |
| 9632 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); |
| 9633 | if (os_snprintf_error(sizeof(buf), len)) |
| 9634 | return -1; |
| 9635 | |
| 9636 | fd = open(path, O_WRONLY); |
| 9637 | if (fd < 0) |
| 9638 | return -1; |
| 9639 | |
| 9640 | if (write(fd, buf, len) < 0) { |
| 9641 | wpa_printf(MSG_DEBUG, |
| 9642 | "nl80211: Failed to write Linux system file: %s with the value of %d", |
| 9643 | path, val); |
| 9644 | close(fd); |
| 9645 | return -1; |
| 9646 | } |
| 9647 | close(fd); |
| 9648 | |
| 9649 | return 0; |
| 9650 | } |
| 9651 | |
| 9652 | |
| 9653 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) |
| 9654 | { |
| 9655 | switch (attr) { |
| 9656 | case DRV_BR_PORT_ATTR_PROXYARP: |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 9657 | return "proxyarp_wifi"; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9658 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
| 9659 | return "hairpin_mode"; |
| 9660 | } |
| 9661 | |
| 9662 | return NULL; |
| 9663 | } |
| 9664 | |
| 9665 | |
| 9666 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, |
| 9667 | unsigned int val) |
| 9668 | { |
| 9669 | struct i802_bss *bss = priv; |
| 9670 | char path[128]; |
| 9671 | const char *attr_txt; |
| 9672 | |
| 9673 | attr_txt = drv_br_port_attr_str(attr); |
| 9674 | if (attr_txt == NULL) |
| 9675 | return -EINVAL; |
| 9676 | |
| 9677 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", |
| 9678 | bss->ifname, attr_txt); |
| 9679 | |
| 9680 | if (linux_write_system_file(path, val)) |
| 9681 | return -1; |
| 9682 | |
| 9683 | return 0; |
| 9684 | } |
| 9685 | |
| 9686 | |
| 9687 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
| 9688 | { |
| 9689 | switch (param) { |
| 9690 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 9691 | return "arp_accept"; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 9692 | default: |
| 9693 | return NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9694 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9695 | } |
| 9696 | |
| 9697 | |
| 9698 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, |
| 9699 | unsigned int val) |
| 9700 | { |
| 9701 | struct i802_bss *bss = priv; |
| 9702 | char path[128]; |
| 9703 | const char *param_txt; |
| 9704 | int ip_version = 4; |
| 9705 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 9706 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
| 9707 | os_snprintf(path, sizeof(path), |
| 9708 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", |
| 9709 | bss->brname); |
| 9710 | goto set_val; |
| 9711 | } |
| 9712 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9713 | param_txt = drv_br_net_param_str(param); |
| 9714 | if (param_txt == NULL) |
| 9715 | return -EINVAL; |
| 9716 | |
| 9717 | switch (param) { |
| 9718 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 9719 | ip_version = 4; |
| 9720 | break; |
| 9721 | default: |
| 9722 | return -EINVAL; |
| 9723 | } |
| 9724 | |
| 9725 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", |
| 9726 | ip_version, bss->brname, param_txt); |
| 9727 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 9728 | set_val: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9729 | if (linux_write_system_file(path, val)) |
| 9730 | return -1; |
| 9731 | |
| 9732 | return 0; |
| 9733 | } |
| 9734 | |
| 9735 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9736 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 9737 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9738 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
| 9739 | { |
| 9740 | switch (hw_mode) { |
| 9741 | case HOSTAPD_MODE_IEEE80211B: |
| 9742 | return QCA_ACS_MODE_IEEE80211B; |
| 9743 | case HOSTAPD_MODE_IEEE80211G: |
| 9744 | return QCA_ACS_MODE_IEEE80211G; |
| 9745 | case HOSTAPD_MODE_IEEE80211A: |
| 9746 | return QCA_ACS_MODE_IEEE80211A; |
| 9747 | case HOSTAPD_MODE_IEEE80211AD: |
| 9748 | return QCA_ACS_MODE_IEEE80211AD; |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 9749 | case HOSTAPD_MODE_IEEE80211ANY: |
| 9750 | return QCA_ACS_MODE_IEEE80211ANY; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9751 | default: |
| 9752 | return -1; |
| 9753 | } |
| 9754 | } |
| 9755 | |
| 9756 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9757 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
| 9758 | { |
| 9759 | int i, len, ret; |
| 9760 | u32 *freqs; |
| 9761 | |
| 9762 | if (!freq_list) |
| 9763 | return 0; |
| 9764 | len = int_array_len(freq_list); |
| 9765 | freqs = os_malloc(sizeof(u32) * len); |
| 9766 | if (!freqs) |
| 9767 | return -1; |
| 9768 | for (i = 0; i < len; i++) |
| 9769 | freqs[i] = freq_list[i]; |
| 9770 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, |
| 9771 | sizeof(u32) * len, freqs); |
| 9772 | os_free(freqs); |
| 9773 | return ret; |
| 9774 | } |
| 9775 | |
| 9776 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9777 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
| 9778 | { |
| 9779 | struct i802_bss *bss = priv; |
| 9780 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9781 | struct nl_msg *msg; |
| 9782 | struct nlattr *data; |
| 9783 | int ret; |
| 9784 | int mode; |
| 9785 | |
| 9786 | mode = hw_mode_to_qca_acs(params->hw_mode); |
| 9787 | if (mode < 0) |
| 9788 | return -1; |
| 9789 | |
| 9790 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9791 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9792 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9793 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || |
| 9794 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9795 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || |
| 9796 | (params->ht_enabled && |
| 9797 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || |
| 9798 | (params->ht40_enabled && |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 9799 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
| 9800 | (params->vht_enabled && |
| 9801 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || |
| 9802 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, |
| 9803 | params->ch_width) || |
| 9804 | (params->ch_list_len && |
| 9805 | 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] | 9806 | params->ch_list)) || |
| 9807 | add_acs_freq_list(msg, params->freq_list)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9808 | nlmsg_free(msg); |
| 9809 | return -ENOBUFS; |
| 9810 | } |
| 9811 | nla_nest_end(msg, data); |
| 9812 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 9813 | wpa_printf(MSG_DEBUG, |
| 9814 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u", |
| 9815 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
| 9816 | params->vht_enabled, params->ch_width, params->ch_list_len); |
| 9817 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9818 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9819 | if (ret) { |
| 9820 | wpa_printf(MSG_DEBUG, |
| 9821 | "nl80211: Failed to invoke driver ACS function: %s", |
| 9822 | strerror(errno)); |
| 9823 | } |
| 9824 | return ret; |
| 9825 | } |
| 9826 | |
| 9827 | |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 9828 | static int nl80211_set_band(void *priv, enum set_band band) |
| 9829 | { |
| 9830 | struct i802_bss *bss = priv; |
| 9831 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9832 | struct nl_msg *msg; |
| 9833 | struct nlattr *data; |
| 9834 | int ret; |
| 9835 | enum qca_set_band qca_band; |
| 9836 | |
| 9837 | if (!drv->setband_vendor_cmd_avail) |
| 9838 | return -1; |
| 9839 | |
| 9840 | switch (band) { |
| 9841 | case WPA_SETBAND_AUTO: |
| 9842 | qca_band = QCA_SETBAND_AUTO; |
| 9843 | break; |
| 9844 | case WPA_SETBAND_5G: |
| 9845 | qca_band = QCA_SETBAND_5G; |
| 9846 | break; |
| 9847 | case WPA_SETBAND_2G: |
| 9848 | qca_band = QCA_SETBAND_2G; |
| 9849 | break; |
| 9850 | default: |
| 9851 | return -1; |
| 9852 | } |
| 9853 | |
| 9854 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9855 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9856 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9857 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || |
| 9858 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9859 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) { |
| 9860 | nlmsg_free(msg); |
| 9861 | return -ENOBUFS; |
| 9862 | } |
| 9863 | nla_nest_end(msg, data); |
| 9864 | |
| 9865 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9866 | if (ret) { |
| 9867 | wpa_printf(MSG_DEBUG, |
| 9868 | "nl80211: Driver setband function failed: %s", |
| 9869 | strerror(errno)); |
| 9870 | } |
| 9871 | return ret; |
| 9872 | } |
| 9873 | |
| 9874 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9875 | struct nl80211_pcl { |
| 9876 | unsigned int num; |
| 9877 | unsigned int *freq_list; |
| 9878 | }; |
| 9879 | |
| 9880 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) |
| 9881 | { |
| 9882 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9883 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9884 | struct nl80211_pcl *param = arg; |
| 9885 | struct nlattr *nl_vend, *attr; |
| 9886 | enum qca_iface_type iface_type; |
| 9887 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 9888 | unsigned int num, max_num; |
| 9889 | u32 *freqs; |
| 9890 | |
| 9891 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9892 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9893 | |
| 9894 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; |
| 9895 | if (!nl_vend) |
| 9896 | return NL_SKIP; |
| 9897 | |
| 9898 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 9899 | nla_data(nl_vend), nla_len(nl_vend), NULL); |
| 9900 | |
| 9901 | attr = tb_vendor[ |
| 9902 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; |
| 9903 | if (!attr) { |
| 9904 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); |
| 9905 | param->num = 0; |
| 9906 | return NL_SKIP; |
| 9907 | } |
| 9908 | |
| 9909 | iface_type = (enum qca_iface_type) nla_get_u32(attr); |
| 9910 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", |
| 9911 | iface_type); |
| 9912 | |
| 9913 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; |
| 9914 | if (!attr) { |
| 9915 | wpa_printf(MSG_ERROR, |
| 9916 | "nl80211: preferred_freq_list couldn't be found"); |
| 9917 | param->num = 0; |
| 9918 | return NL_SKIP; |
| 9919 | } |
| 9920 | |
| 9921 | /* |
| 9922 | * param->num has the maximum number of entries for which there |
| 9923 | * is room in the freq_list provided by the caller. |
| 9924 | */ |
| 9925 | freqs = nla_data(attr); |
| 9926 | max_num = nla_len(attr) / sizeof(u32); |
| 9927 | if (max_num > param->num) |
| 9928 | max_num = param->num; |
| 9929 | for (num = 0; num < max_num; num++) |
| 9930 | param->freq_list[num] = freqs[num]; |
| 9931 | param->num = num; |
| 9932 | |
| 9933 | return NL_SKIP; |
| 9934 | } |
| 9935 | |
| 9936 | |
| 9937 | static int nl80211_get_pref_freq_list(void *priv, |
| 9938 | enum wpa_driver_if_type if_type, |
| 9939 | unsigned int *num, |
| 9940 | unsigned int *freq_list) |
| 9941 | { |
| 9942 | struct i802_bss *bss = priv; |
| 9943 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9944 | struct nl_msg *msg; |
| 9945 | int ret; |
| 9946 | unsigned int i; |
| 9947 | struct nlattr *params; |
| 9948 | struct nl80211_pcl param; |
| 9949 | enum qca_iface_type iface_type; |
| 9950 | |
| 9951 | if (!drv->get_pref_freq_list) |
| 9952 | return -1; |
| 9953 | |
| 9954 | switch (if_type) { |
| 9955 | case WPA_IF_STATION: |
| 9956 | iface_type = QCA_IFACE_TYPE_STA; |
| 9957 | break; |
| 9958 | case WPA_IF_AP_BSS: |
| 9959 | iface_type = QCA_IFACE_TYPE_AP; |
| 9960 | break; |
| 9961 | case WPA_IF_P2P_GO: |
| 9962 | iface_type = QCA_IFACE_TYPE_P2P_GO; |
| 9963 | break; |
| 9964 | case WPA_IF_P2P_CLIENT: |
| 9965 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; |
| 9966 | break; |
| 9967 | case WPA_IF_IBSS: |
| 9968 | iface_type = QCA_IFACE_TYPE_IBSS; |
| 9969 | break; |
| 9970 | case WPA_IF_TDLS: |
| 9971 | iface_type = QCA_IFACE_TYPE_TDLS; |
| 9972 | break; |
| 9973 | default: |
| 9974 | return -1; |
| 9975 | } |
| 9976 | |
| 9977 | param.num = *num; |
| 9978 | param.freq_list = freq_list; |
| 9979 | |
| 9980 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9981 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || |
| 9982 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9983 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9984 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || |
| 9985 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9986 | nla_put_u32(msg, |
| 9987 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, |
| 9988 | iface_type)) { |
| 9989 | wpa_printf(MSG_ERROR, |
| 9990 | "%s: err in adding vendor_cmd and vendor_data", |
| 9991 | __func__); |
| 9992 | nlmsg_free(msg); |
| 9993 | return -1; |
| 9994 | } |
| 9995 | nla_nest_end(msg, params); |
| 9996 | |
| 9997 | os_memset(freq_list, 0, *num * sizeof(freq_list[0])); |
| 9998 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m); |
| 9999 | if (ret) { |
| 10000 | wpa_printf(MSG_ERROR, |
| 10001 | "%s: err in send_and_recv_msgs", __func__); |
| 10002 | return ret; |
| 10003 | } |
| 10004 | |
| 10005 | *num = param.num; |
| 10006 | |
| 10007 | for (i = 0; i < *num; i++) { |
| 10008 | wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d", |
| 10009 | i, freq_list[i]); |
| 10010 | } |
| 10011 | |
| 10012 | return 0; |
| 10013 | } |
| 10014 | |
| 10015 | |
| 10016 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
| 10017 | { |
| 10018 | struct i802_bss *bss = priv; |
| 10019 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10020 | struct nl_msg *msg; |
| 10021 | int ret; |
| 10022 | struct nlattr *params; |
| 10023 | |
| 10024 | if (!drv->set_prob_oper_freq) |
| 10025 | return -1; |
| 10026 | |
| 10027 | wpa_printf(MSG_DEBUG, |
| 10028 | "nl80211: Set P2P probable operating freq %u for ifindex %d", |
| 10029 | freq, bss->ifindex); |
| 10030 | |
| 10031 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10032 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10033 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10034 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || |
| 10035 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 10036 | nla_put_u32(msg, |
| 10037 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, |
| 10038 | QCA_IFACE_TYPE_P2P_CLIENT) || |
| 10039 | nla_put_u32(msg, |
| 10040 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, |
| 10041 | freq)) { |
| 10042 | wpa_printf(MSG_ERROR, |
| 10043 | "%s: err in adding vendor_cmd and vendor_data", |
| 10044 | __func__); |
| 10045 | nlmsg_free(msg); |
| 10046 | return -1; |
| 10047 | } |
| 10048 | nla_nest_end(msg, params); |
| 10049 | |
| 10050 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10051 | msg = NULL; |
| 10052 | if (ret) { |
| 10053 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", |
| 10054 | __func__); |
| 10055 | return ret; |
| 10056 | } |
| 10057 | nlmsg_free(msg); |
| 10058 | return 0; |
| 10059 | } |
| 10060 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 10061 | |
| 10062 | static int nl80211_p2p_lo_start(void *priv, unsigned int freq, |
| 10063 | unsigned int period, unsigned int interval, |
| 10064 | unsigned int count, const u8 *device_types, |
| 10065 | size_t dev_types_len, |
| 10066 | const u8 *ies, size_t ies_len) |
| 10067 | { |
| 10068 | struct i802_bss *bss = priv; |
| 10069 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10070 | struct nl_msg *msg; |
| 10071 | struct nlattr *container; |
| 10072 | int ret; |
| 10073 | |
| 10074 | wpa_printf(MSG_DEBUG, |
| 10075 | "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u", |
| 10076 | freq, period, interval, count); |
| 10077 | |
| 10078 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 10079 | return -1; |
| 10080 | |
| 10081 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10082 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10083 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10084 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START)) |
| 10085 | goto fail; |
| 10086 | |
| 10087 | container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 10088 | if (!container) |
| 10089 | goto fail; |
| 10090 | |
| 10091 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL, |
| 10092 | freq) || |
| 10093 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD, |
| 10094 | period) || |
| 10095 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL, |
| 10096 | interval) || |
| 10097 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT, |
| 10098 | count) || |
| 10099 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES, |
| 10100 | dev_types_len, device_types) || |
| 10101 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE, |
| 10102 | ies_len, ies)) |
| 10103 | goto fail; |
| 10104 | |
| 10105 | nla_nest_end(msg, container); |
| 10106 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10107 | msg = NULL; |
| 10108 | if (ret) { |
| 10109 | wpa_printf(MSG_DEBUG, |
| 10110 | "nl80211: Failed to send P2P Listen offload vendor command"); |
| 10111 | goto fail; |
| 10112 | } |
| 10113 | |
| 10114 | return 0; |
| 10115 | |
| 10116 | fail: |
| 10117 | nlmsg_free(msg); |
| 10118 | return -1; |
| 10119 | } |
| 10120 | |
| 10121 | |
| 10122 | static int nl80211_p2p_lo_stop(void *priv) |
| 10123 | { |
| 10124 | struct i802_bss *bss = priv; |
| 10125 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10126 | struct nl_msg *msg; |
| 10127 | |
| 10128 | wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload"); |
| 10129 | |
| 10130 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 10131 | return -1; |
| 10132 | |
| 10133 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10134 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10135 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10136 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) { |
| 10137 | nlmsg_free(msg); |
| 10138 | return -1; |
| 10139 | } |
| 10140 | |
| 10141 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10142 | } |
| 10143 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 10144 | |
| 10145 | static int nl80211_set_tdls_mode(void *priv, int tdls_external_control) |
| 10146 | { |
| 10147 | struct i802_bss *bss = priv; |
| 10148 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10149 | struct nl_msg *msg; |
| 10150 | struct nlattr *params; |
| 10151 | int ret; |
| 10152 | u32 tdls_mode; |
| 10153 | |
| 10154 | wpa_printf(MSG_DEBUG, |
| 10155 | "nl80211: Set TDKS mode: tdls_external_control=%d", |
| 10156 | tdls_external_control); |
| 10157 | |
| 10158 | if (tdls_external_control == 1) |
| 10159 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT | |
| 10160 | QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL; |
| 10161 | else |
| 10162 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT; |
| 10163 | |
| 10164 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10165 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10166 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10167 | QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS)) |
| 10168 | goto fail; |
| 10169 | |
| 10170 | params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 10171 | if (!params) |
| 10172 | goto fail; |
| 10173 | |
| 10174 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE, |
| 10175 | tdls_mode)) |
| 10176 | goto fail; |
| 10177 | |
| 10178 | nla_nest_end(msg, params); |
| 10179 | |
| 10180 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10181 | msg = NULL; |
| 10182 | if (ret) { |
| 10183 | wpa_printf(MSG_ERROR, |
| 10184 | "nl80211: Set TDLS mode failed: ret=%d (%s)", |
| 10185 | ret, strerror(-ret)); |
| 10186 | goto fail; |
| 10187 | } |
| 10188 | return 0; |
| 10189 | fail: |
| 10190 | nlmsg_free(msg); |
| 10191 | return -1; |
| 10192 | } |
| 10193 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10194 | |
| 10195 | #ifdef CONFIG_MBO |
| 10196 | |
| 10197 | static enum mbo_transition_reject_reason |
| 10198 | nl80211_mbo_reject_reason_mapping(enum qca_wlan_btm_candidate_status status) |
| 10199 | { |
| 10200 | switch (status) { |
| 10201 | case QCA_STATUS_REJECT_EXCESSIVE_FRAME_LOSS_EXPECTED: |
| 10202 | return MBO_TRANSITION_REJECT_REASON_FRAME_LOSS; |
| 10203 | case QCA_STATUS_REJECT_EXCESSIVE_DELAY_EXPECTED: |
| 10204 | return MBO_TRANSITION_REJECT_REASON_DELAY; |
| 10205 | case QCA_STATUS_REJECT_INSUFFICIENT_QOS_CAPACITY: |
| 10206 | return MBO_TRANSITION_REJECT_REASON_QOS_CAPACITY; |
| 10207 | case QCA_STATUS_REJECT_LOW_RSSI: |
| 10208 | return MBO_TRANSITION_REJECT_REASON_RSSI; |
| 10209 | case QCA_STATUS_REJECT_HIGH_INTERFERENCE: |
| 10210 | return MBO_TRANSITION_REJECT_REASON_INTERFERENCE; |
| 10211 | case QCA_STATUS_REJECT_UNKNOWN: |
| 10212 | default: |
| 10213 | return MBO_TRANSITION_REJECT_REASON_UNSPECIFIED; |
| 10214 | } |
| 10215 | } |
| 10216 | |
| 10217 | |
| 10218 | static void nl80211_parse_btm_candidate_info(struct candidate_list *candidate, |
| 10219 | struct nlattr *tb[], int num) |
| 10220 | { |
| 10221 | enum qca_wlan_btm_candidate_status status; |
| 10222 | char buf[50]; |
| 10223 | |
| 10224 | os_memcpy(candidate->bssid, |
| 10225 | nla_data(tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID]), |
| 10226 | ETH_ALEN); |
| 10227 | |
| 10228 | status = nla_get_u32( |
| 10229 | tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]); |
| 10230 | candidate->is_accept = status == QCA_STATUS_ACCEPT; |
| 10231 | candidate->reject_reason = nl80211_mbo_reject_reason_mapping(status); |
| 10232 | |
| 10233 | if (candidate->is_accept) |
| 10234 | os_snprintf(buf, sizeof(buf), "Accepted"); |
| 10235 | else |
| 10236 | os_snprintf(buf, sizeof(buf), |
| 10237 | "Rejected, Reject_reason: %d", |
| 10238 | candidate->reject_reason); |
| 10239 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR " %s", |
| 10240 | num, MAC2STR(candidate->bssid), buf); |
| 10241 | } |
| 10242 | |
| 10243 | |
| 10244 | static int |
| 10245 | nl80211_get_bss_transition_status_handler(struct nl_msg *msg, void *arg) |
| 10246 | { |
| 10247 | struct wpa_bss_candidate_info *info = arg; |
| 10248 | struct candidate_list *candidate = info->candidates; |
| 10249 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 10250 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 10251 | struct nlattr *tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1]; |
| 10252 | static struct nla_policy policy[ |
| 10253 | QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX + 1] = { |
| 10254 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] = { |
| 10255 | .minlen = ETH_ALEN |
| 10256 | }, |
| 10257 | [QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS] = { |
| 10258 | .type = NLA_U32, |
| 10259 | }, |
| 10260 | }; |
| 10261 | struct nlattr *attr; |
| 10262 | int rem; |
| 10263 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 10264 | u8 num; |
| 10265 | |
| 10266 | num = info->num; /* number of candidates sent to driver */ |
| 10267 | info->num = 0; |
| 10268 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 10269 | genlmsg_attrlen(gnlh, 0), NULL); |
| 10270 | |
| 10271 | if (!tb_msg[NL80211_ATTR_VENDOR_DATA] || |
| 10272 | nla_parse_nested(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 10273 | tb_msg[NL80211_ATTR_VENDOR_DATA], NULL) || |
| 10274 | !tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO]) |
| 10275 | return NL_SKIP; |
| 10276 | |
| 10277 | wpa_printf(MSG_DEBUG, |
| 10278 | "nl80211: WNM Candidate list received from driver"); |
| 10279 | nla_for_each_nested(attr, |
| 10280 | tb_vendor[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO], |
| 10281 | rem) { |
| 10282 | if (info->num >= num || |
| 10283 | nla_parse_nested( |
| 10284 | tb, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_MAX, |
| 10285 | attr, policy) || |
| 10286 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID] || |
| 10287 | !tb[QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_STATUS]) |
| 10288 | break; |
| 10289 | |
| 10290 | nl80211_parse_btm_candidate_info(candidate, tb, info->num); |
| 10291 | |
| 10292 | candidate++; |
| 10293 | info->num++; |
| 10294 | } |
| 10295 | |
| 10296 | return NL_SKIP; |
| 10297 | } |
| 10298 | |
| 10299 | |
| 10300 | static struct wpa_bss_candidate_info * |
| 10301 | nl80211_get_bss_transition_status(void *priv, struct wpa_bss_trans_info *params) |
| 10302 | { |
| 10303 | struct i802_bss *bss = priv; |
| 10304 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10305 | struct nl_msg *msg; |
| 10306 | struct nlattr *attr, *attr1, *attr2; |
| 10307 | struct wpa_bss_candidate_info *info; |
| 10308 | u8 i; |
| 10309 | int ret; |
| 10310 | u8 *pos; |
| 10311 | |
| 10312 | if (!drv->fetch_bss_trans_status) |
| 10313 | return NULL; |
| 10314 | |
| 10315 | info = os_zalloc(sizeof(*info)); |
| 10316 | if (!info) |
| 10317 | return NULL; |
| 10318 | /* Allocate memory for number of candidates sent to driver */ |
| 10319 | info->candidates = os_calloc(params->n_candidates, |
| 10320 | sizeof(*info->candidates)); |
| 10321 | if (!info->candidates) { |
| 10322 | os_free(info); |
| 10323 | return NULL; |
| 10324 | } |
| 10325 | |
| 10326 | /* Copy the number of candidates being sent to driver. This is used in |
| 10327 | * nl80211_get_bss_transition_status_handler() to limit the number of |
| 10328 | * candidates that can be populated in info->candidates and will be |
| 10329 | * later overwritten with the actual number of candidates received from |
| 10330 | * the driver. |
| 10331 | */ |
| 10332 | info->num = params->n_candidates; |
| 10333 | |
| 10334 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10335 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10336 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10337 | QCA_NL80211_VENDOR_SUBCMD_FETCH_BSS_TRANSITION_STATUS)) |
| 10338 | goto fail; |
| 10339 | |
| 10340 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 10341 | if (!attr) |
| 10342 | goto fail; |
| 10343 | |
| 10344 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_BTM_MBO_TRANSITION_REASON, |
| 10345 | params->mbo_transition_reason)) |
| 10346 | goto fail; |
| 10347 | |
| 10348 | attr1 = nla_nest_start(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO); |
| 10349 | if (!attr1) |
| 10350 | goto fail; |
| 10351 | |
| 10352 | wpa_printf(MSG_DEBUG, |
| 10353 | "nl80211: WNM Candidate list info sending to driver: mbo_transition_reason: %d n_candidates: %d", |
| 10354 | params->mbo_transition_reason, params->n_candidates); |
| 10355 | pos = params->bssid; |
| 10356 | for (i = 0; i < params->n_candidates; i++) { |
| 10357 | wpa_printf(MSG_DEBUG, "nl80211: BSSID[%d]: " MACSTR, i, |
| 10358 | MAC2STR(pos)); |
| 10359 | attr2 = nla_nest_start(msg, i); |
| 10360 | if (!attr2 || |
| 10361 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_BTM_CANDIDATE_INFO_BSSID, |
| 10362 | ETH_ALEN, pos)) |
| 10363 | goto fail; |
| 10364 | pos += ETH_ALEN; |
| 10365 | nla_nest_end(msg, attr2); |
| 10366 | } |
| 10367 | |
| 10368 | nla_nest_end(msg, attr1); |
| 10369 | nla_nest_end(msg, attr); |
| 10370 | |
| 10371 | ret = send_and_recv_msgs(drv, msg, |
| 10372 | nl80211_get_bss_transition_status_handler, |
| 10373 | info); |
| 10374 | msg = NULL; |
| 10375 | if (ret) { |
| 10376 | wpa_printf(MSG_ERROR, |
| 10377 | "nl80211: WNM Get BSS transition status failed: ret=%d (%s)", |
| 10378 | ret, strerror(-ret)); |
| 10379 | goto fail; |
| 10380 | } |
| 10381 | return info; |
| 10382 | |
| 10383 | fail: |
| 10384 | nlmsg_free(msg); |
| 10385 | os_free(info->candidates); |
| 10386 | os_free(info); |
| 10387 | return NULL; |
| 10388 | } |
| 10389 | |
| 10390 | |
| 10391 | /** |
| 10392 | * nl80211_ignore_assoc_disallow - Configure driver to ignore assoc_disallow |
| 10393 | * @priv: Pointer to private driver data from wpa_driver_nl80211_init() |
| 10394 | * @ignore_assoc_disallow: 0 to not ignore, 1 to ignore |
| 10395 | * Returns: 0 on success, -1 on failure |
| 10396 | */ |
| 10397 | static int nl80211_ignore_assoc_disallow(void *priv, int ignore_disallow) |
| 10398 | { |
| 10399 | struct i802_bss *bss = priv; |
| 10400 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10401 | struct nl_msg *msg; |
| 10402 | struct nlattr *attr; |
| 10403 | int ret = -1; |
| 10404 | |
| 10405 | if (!drv->set_wifi_conf_vendor_cmd_avail) |
| 10406 | return -1; |
| 10407 | |
| 10408 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 10409 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 10410 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 10411 | QCA_NL80211_VENDOR_SUBCMD_SET_WIFI_CONFIGURATION)) |
| 10412 | goto fail; |
| 10413 | |
| 10414 | attr = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 10415 | if (!attr) |
| 10416 | goto fail; |
| 10417 | |
| 10418 | wpa_printf(MSG_DEBUG, "nl80211: Set ignore_assoc_disallow %d", |
| 10419 | ignore_disallow); |
| 10420 | if (nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_CONFIG_IGNORE_ASSOC_DISALLOWED, |
| 10421 | ignore_disallow)) |
| 10422 | goto fail; |
| 10423 | |
| 10424 | nla_nest_end(msg, attr); |
| 10425 | |
| 10426 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10427 | msg = NULL; |
| 10428 | if (ret) { |
| 10429 | wpa_printf(MSG_ERROR, |
| 10430 | "nl80211: Set ignore_assoc_disallow failed: ret=%d (%s)", |
| 10431 | ret, strerror(-ret)); |
| 10432 | goto fail; |
| 10433 | } |
| 10434 | |
| 10435 | fail: |
| 10436 | nlmsg_free(msg); |
| 10437 | return ret; |
| 10438 | } |
| 10439 | |
| 10440 | #endif /* CONFIG_MBO */ |
| 10441 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10442 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 10443 | |
| 10444 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10445 | static int nl80211_write_to_file(const char *name, unsigned int val) |
| 10446 | { |
| 10447 | int fd, len; |
| 10448 | char tmp[128]; |
| 10449 | |
| 10450 | fd = open(name, O_RDWR); |
| 10451 | if (fd < 0) { |
| 10452 | wpa_printf(MSG_ERROR, "nl80211: Failed to open %s: %s", |
| 10453 | name, strerror(errno)); |
| 10454 | return fd; |
| 10455 | } |
| 10456 | |
| 10457 | len = os_snprintf(tmp, sizeof(tmp), "%u\n", val); |
| 10458 | len = write(fd, tmp, len); |
| 10459 | if (len < 0) |
| 10460 | wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s", |
| 10461 | name, strerror(errno)); |
| 10462 | close(fd); |
| 10463 | |
| 10464 | return 0; |
| 10465 | } |
| 10466 | |
| 10467 | |
| 10468 | static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags) |
| 10469 | { |
| 10470 | struct i802_bss *bss = priv; |
| 10471 | char path[128]; |
| 10472 | int ret; |
| 10473 | |
| 10474 | wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x", |
| 10475 | filter_flags); |
| 10476 | |
| 10477 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 10478 | ret = os_snprintf(path, sizeof(path), |
| 10479 | "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast", |
| 10480 | bss->ifname); |
| 10481 | if (os_snprintf_error(sizeof(path), ret)) |
| 10482 | return -1; |
| 10483 | |
| 10484 | ret = nl80211_write_to_file(path, |
| 10485 | !!(filter_flags & |
| 10486 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 10487 | if (ret) { |
| 10488 | wpa_printf(MSG_ERROR, |
| 10489 | "nl80211: Failed to set IPv4 unicast in multicast filter"); |
| 10490 | return ret; |
| 10491 | } |
| 10492 | |
| 10493 | os_snprintf(path, sizeof(path), |
| 10494 | "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast", |
| 10495 | bss->ifname); |
| 10496 | ret = nl80211_write_to_file(path, |
| 10497 | !!(filter_flags & |
| 10498 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 10499 | |
| 10500 | if (ret) { |
| 10501 | wpa_printf(MSG_ERROR, |
| 10502 | "nl80211: Failed to set IPv6 unicast in multicast filter"); |
| 10503 | return ret; |
| 10504 | } |
| 10505 | |
| 10506 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 10507 | os_snprintf(path, sizeof(path), |
| 10508 | "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp", |
| 10509 | bss->ifname); |
| 10510 | ret = nl80211_write_to_file(path, |
| 10511 | !!(filter_flags & |
| 10512 | WPA_DATA_FRAME_FILTER_FLAG_ARP)); |
| 10513 | if (ret) { |
| 10514 | wpa_printf(MSG_ERROR, |
| 10515 | "nl80211: Failed set gratuitous ARP filter"); |
| 10516 | return ret; |
| 10517 | } |
| 10518 | |
| 10519 | /* Configure filtering of IPv6 NA frames */ |
| 10520 | os_snprintf(path, sizeof(path), |
| 10521 | "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na", |
| 10522 | bss->ifname); |
| 10523 | ret = nl80211_write_to_file(path, |
| 10524 | !!(filter_flags & |
| 10525 | WPA_DATA_FRAME_FILTER_FLAG_NA)); |
| 10526 | if (ret) { |
| 10527 | wpa_printf(MSG_ERROR, |
| 10528 | "nl80211: Failed to set unsolicited NA filter"); |
| 10529 | return ret; |
| 10530 | } |
| 10531 | |
| 10532 | return 0; |
| 10533 | } |
| 10534 | |
| 10535 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 10536 | static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type, |
| 10537 | const u8 **ext_capa, const u8 **ext_capa_mask, |
| 10538 | unsigned int *ext_capa_len) |
| 10539 | { |
| 10540 | struct i802_bss *bss = priv; |
| 10541 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10542 | enum nl80211_iftype nlmode; |
| 10543 | unsigned int i; |
| 10544 | |
| 10545 | if (!ext_capa || !ext_capa_mask || !ext_capa_len) |
| 10546 | return -1; |
| 10547 | |
| 10548 | nlmode = wpa_driver_nl80211_if_type(type); |
| 10549 | |
| 10550 | /* By default, use the per-radio values */ |
| 10551 | *ext_capa = drv->extended_capa; |
| 10552 | *ext_capa_mask = drv->extended_capa_mask; |
| 10553 | *ext_capa_len = drv->extended_capa_len; |
| 10554 | |
| 10555 | /* Replace the default value if a per-interface type value exists */ |
| 10556 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 10557 | if (nlmode == drv->iface_ext_capa[i].iftype) { |
| 10558 | *ext_capa = drv->iface_ext_capa[i].ext_capa; |
| 10559 | *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask; |
| 10560 | *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len; |
| 10561 | break; |
| 10562 | } |
| 10563 | } |
| 10564 | |
| 10565 | return 0; |
| 10566 | } |
| 10567 | |
| 10568 | |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10569 | static int nl80211_update_connection_params( |
| 10570 | void *priv, struct wpa_driver_associate_params *params, |
| 10571 | enum wpa_drv_update_connect_params_mask mask) |
| 10572 | { |
| 10573 | struct i802_bss *bss = priv; |
| 10574 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10575 | struct nl_msg *msg; |
| 10576 | int ret = -1; |
| 10577 | enum nl80211_auth_type type; |
| 10578 | |
| 10579 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_CONNECT_PARAMS); |
| 10580 | if (!msg) |
| 10581 | goto fail; |
| 10582 | |
| 10583 | wpa_printf(MSG_DEBUG, "nl80211: Update connection params (ifindex=%d)", |
| 10584 | drv->ifindex); |
| 10585 | |
| 10586 | if ((mask & WPA_DRV_UPDATE_ASSOC_IES) && params->wpa_ie) { |
| 10587 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 10588 | params->wpa_ie)) |
| 10589 | goto fail; |
| 10590 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, |
| 10591 | params->wpa_ie_len); |
| 10592 | } |
| 10593 | |
| 10594 | if (mask & WPA_DRV_UPDATE_AUTH_TYPE) { |
| 10595 | type = get_nl_auth_type(params->auth_alg); |
| 10596 | if (type == NL80211_AUTHTYPE_MAX || |
| 10597 | nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 10598 | goto fail; |
| 10599 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
| 10600 | } |
| 10601 | |
| 10602 | if ((mask & WPA_DRV_UPDATE_FILS_ERP_INFO) && |
| 10603 | nl80211_put_fils_connect_params(drv, params, msg)) |
| 10604 | goto fail; |
| 10605 | |
| 10606 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10607 | msg = NULL; |
| 10608 | if (ret) |
| 10609 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 10610 | "nl80211: Update connect params command failed: ret=%d (%s)", |
| 10611 | ret, strerror(-ret)); |
| 10612 | |
| 10613 | fail: |
| 10614 | nlmsg_free(msg); |
| 10615 | return ret; |
| 10616 | } |
| 10617 | |
| 10618 | |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10619 | static int nl80211_send_external_auth_status(void *priv, |
| 10620 | struct external_auth *params) |
| 10621 | { |
| 10622 | struct i802_bss *bss = priv; |
| 10623 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 10624 | struct nl_msg *msg = NULL; |
| 10625 | int ret = -1; |
| 10626 | |
| 10627 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 10628 | "nl80211: External auth status: %u", params->status); |
| 10629 | |
| 10630 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_EXTERNAL_AUTH); |
| 10631 | if (!msg || |
| 10632 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, params->status) || |
| 10633 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 10634 | params->ssid) || |
| 10635 | nla_put(msg, NL80211_ATTR_BSSID, ETH_ALEN, params->bssid)) |
| 10636 | goto fail; |
| 10637 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 10638 | msg = NULL; |
| 10639 | if (ret) { |
| 10640 | wpa_printf(MSG_DEBUG, |
| 10641 | "nl80211: External Auth status update failed: ret=%d (%s)", |
| 10642 | ret, strerror(-ret)); |
| 10643 | goto fail; |
| 10644 | } |
| 10645 | fail: |
| 10646 | nlmsg_free(msg); |
| 10647 | return ret; |
| 10648 | } |
| 10649 | |
| 10650 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10651 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 10652 | .name = "nl80211", |
| 10653 | .desc = "Linux nl80211/cfg80211", |
| 10654 | .get_bssid = wpa_driver_nl80211_get_bssid, |
| 10655 | .get_ssid = wpa_driver_nl80211_get_ssid, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10656 | .set_key = driver_nl80211_set_key, |
| 10657 | .scan2 = driver_nl80211_scan2, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10658 | .sched_scan = wpa_driver_nl80211_sched_scan, |
| 10659 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10660 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 10661 | .abort_scan = wpa_driver_nl80211_abort_scan, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10662 | .deauthenticate = driver_nl80211_deauthenticate, |
| 10663 | .authenticate = driver_nl80211_authenticate, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10664 | .associate = wpa_driver_nl80211_associate, |
| 10665 | .global_init = nl80211_global_init, |
| 10666 | .global_deinit = nl80211_global_deinit, |
| 10667 | .init2 = wpa_driver_nl80211_init, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10668 | .deinit = driver_nl80211_deinit, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10669 | .get_capa = wpa_driver_nl80211_get_capa, |
| 10670 | .set_operstate = wpa_driver_nl80211_set_operstate, |
| 10671 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
| 10672 | .set_country = wpa_driver_nl80211_set_country, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 10673 | .get_country = wpa_driver_nl80211_get_country, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10674 | .set_ap = wpa_driver_nl80211_set_ap, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 10675 | .set_acl = wpa_driver_nl80211_set_acl, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10676 | .if_add = wpa_driver_nl80211_if_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10677 | .if_remove = driver_nl80211_if_remove, |
| 10678 | .send_mlme = driver_nl80211_send_mlme, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10679 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10680 | .sta_add = wpa_driver_nl80211_sta_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10681 | .sta_remove = driver_nl80211_sta_remove, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10682 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
| 10683 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10684 | .hapd_init = i802_init, |
| 10685 | .hapd_deinit = i802_deinit, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10686 | .set_wds_sta = i802_set_wds_sta, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10687 | .get_seqnum = i802_get_seqnum, |
| 10688 | .flush = i802_flush, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10689 | .get_inact_sec = i802_get_inact_sec, |
| 10690 | .sta_clear_stats = i802_sta_clear_stats, |
| 10691 | .set_rts = i802_set_rts, |
| 10692 | .set_frag = i802_set_frag, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10693 | .set_tx_queue_params = i802_set_tx_queue_params, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10694 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10695 | .sta_deauth = i802_sta_deauth, |
| 10696 | .sta_disassoc = i802_sta_disassoc, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10697 | .read_sta_data = driver_nl80211_read_sta_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10698 | .set_freq = i802_set_freq, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10699 | .send_action = driver_nl80211_send_action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10700 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
| 10701 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
| 10702 | .cancel_remain_on_channel = |
| 10703 | wpa_driver_nl80211_cancel_remain_on_channel, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 10704 | .probe_req_report = driver_nl80211_probe_req_report, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10705 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 10706 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10707 | .resume = wpa_driver_nl80211_resume, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10708 | .signal_monitor = nl80211_signal_monitor, |
| 10709 | .signal_poll = nl80211_signal_poll, |
| 10710 | .send_frame = nl80211_send_frame, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10711 | .set_param = nl80211_set_param, |
| 10712 | .get_radio_name = nl80211_get_radio_name, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 10713 | .add_pmkid = nl80211_add_pmkid, |
| 10714 | .remove_pmkid = nl80211_remove_pmkid, |
| 10715 | .flush_pmkid = nl80211_flush_pmkid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10716 | .set_rekey_info = nl80211_set_rekey_info, |
| 10717 | .poll_client = nl80211_poll_client, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10718 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 10719 | .start_dfs_cac = nl80211_start_radar_detection, |
| 10720 | .stop_ap = wpa_driver_nl80211_stop_ap, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10721 | #ifdef CONFIG_TDLS |
| 10722 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, |
| 10723 | .tdls_oper = nl80211_tdls_oper, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10724 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
| 10725 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10726 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 10727 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 10728 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 10729 | .get_survey = wpa_driver_nl80211_get_survey, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 10730 | .status = wpa_driver_nl80211_status, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 10731 | .switch_channel = nl80211_switch_channel, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10732 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 10733 | .set_noa = wpa_driver_set_p2p_noa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 10734 | .get_noa = wpa_driver_get_p2p_noa, |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 10735 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 10736 | #endif /* ANDROID_P2P */ |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 10737 | #ifdef ANDROID |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 10738 | #ifndef ANDROID_LIB_STUB |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 10739 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 10740 | #endif /* !ANDROID_LIB_STUB */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 10741 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 10742 | .vendor_cmd = nl80211_vendor_cmd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 10743 | .set_qos_map = nl80211_set_qos_map, |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 10744 | .set_wowlan = nl80211_set_wowlan, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 10745 | .set_mac_addr = nl80211_set_mac_addr, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10746 | #ifdef CONFIG_MESH |
| 10747 | .init_mesh = wpa_driver_nl80211_init_mesh, |
| 10748 | .join_mesh = wpa_driver_nl80211_join_mesh, |
| 10749 | .leave_mesh = wpa_driver_nl80211_leave_mesh, |
| 10750 | #endif /* CONFIG_MESH */ |
| 10751 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
| 10752 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, |
| 10753 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
| 10754 | .br_set_net_param = wpa_driver_br_set_net_param, |
| 10755 | .add_tx_ts = nl80211_add_ts, |
| 10756 | .del_tx_ts = nl80211_del_ts, |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 10757 | .get_ifindex = nl80211_get_ifindex, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10758 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 10759 | .roaming = nl80211_roaming, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10760 | .disable_fils = nl80211_disable_fils, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 10761 | .do_acs = wpa_driver_do_acs, |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 10762 | .set_band = nl80211_set_band, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10763 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
| 10764 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 10765 | .p2p_lo_start = nl80211_p2p_lo_start, |
| 10766 | .p2p_lo_stop = nl80211_p2p_lo_stop, |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 10767 | .set_default_scan_ies = nl80211_set_default_scan_ies, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 10768 | .set_tdls_mode = nl80211_set_tdls_mode, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10769 | #ifdef CONFIG_MBO |
| 10770 | .get_bss_transition_status = nl80211_get_bss_transition_status, |
| 10771 | .ignore_assoc_disallow = nl80211_ignore_assoc_disallow, |
| 10772 | #endif /* CONFIG_MBO */ |
| 10773 | .set_bssid_blacklist = nl80211_set_bssid_blacklist, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 10774 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 10775 | .configure_data_frame_filters = nl80211_configure_data_frame_filters, |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 10776 | .get_ext_capab = nl80211_get_ext_capab, |
Dmitry Shmidt | d2986c2 | 2017-10-23 14:22:09 -0700 | [diff] [blame] | 10777 | .update_connect_params = nl80211_update_connection_params, |
Roshan Pius | 3a1667e | 2018-07-03 15:17:14 -0700 | [diff] [blame] | 10778 | .send_external_auth_status = nl80211_send_external_auth_status, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 10779 | }; |