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" |
| 32 | #include "l2_packet/l2_packet.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 33 | #include "netlink.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 34 | #include "linux_defines.h" |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 35 | #include "linux_ioctl.h" |
| 36 | #include "radiotap.h" |
| 37 | #include "radiotap_iter.h" |
| 38 | #include "rfkill.h" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 39 | #include "driver_nl80211.h" |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 40 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 41 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 42 | #ifndef CONFIG_LIBNL20 |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 43 | /* |
| 44 | * libnl 1.1 has a bug, it tries to allocate socket numbers densely |
| 45 | * but when you free a socket again it will mess up its bitmap and |
| 46 | * and use the wrong number the next time it needs a socket ID. |
| 47 | * Therefore, we wrap the handle alloc/destroy and add our own pid |
| 48 | * accounting. |
| 49 | */ |
| 50 | static uint32_t port_bitmap[32] = { 0 }; |
| 51 | |
| 52 | static struct nl_handle *nl80211_handle_alloc(void *cb) |
| 53 | { |
| 54 | struct nl_handle *handle; |
| 55 | uint32_t pid = getpid() & 0x3FFFFF; |
| 56 | int i; |
| 57 | |
| 58 | handle = nl_handle_alloc_cb(cb); |
| 59 | |
| 60 | for (i = 0; i < 1024; i++) { |
| 61 | if (port_bitmap[i / 32] & (1 << (i % 32))) |
| 62 | continue; |
| 63 | port_bitmap[i / 32] |= 1 << (i % 32); |
| 64 | pid += i << 22; |
| 65 | break; |
| 66 | } |
| 67 | |
| 68 | nl_socket_set_local_port(handle, pid); |
| 69 | |
| 70 | return handle; |
| 71 | } |
| 72 | |
| 73 | static void nl80211_handle_destroy(struct nl_handle *handle) |
| 74 | { |
| 75 | uint32_t port = nl_socket_get_local_port(handle); |
| 76 | |
| 77 | port >>= 22; |
| 78 | port_bitmap[port / 32] &= ~(1 << (port % 32)); |
| 79 | |
| 80 | nl_handle_destroy(handle); |
| 81 | } |
| 82 | #endif /* CONFIG_LIBNL20 */ |
| 83 | |
| 84 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 85 | #ifdef ANDROID |
| 86 | /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */ |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 87 | #undef nl_socket_set_nonblocking |
| 88 | #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 89 | |
Dmitry Shmidt | 5460547 | 2013-11-08 11:10:19 -0800 | [diff] [blame] | 90 | #endif /* ANDROID */ |
| 91 | |
| 92 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 93 | static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg) |
| 94 | { |
| 95 | struct nl_handle *handle; |
| 96 | |
| 97 | handle = nl80211_handle_alloc(cb); |
| 98 | if (handle == NULL) { |
| 99 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 100 | "callbacks (%s)", dbg); |
| 101 | return NULL; |
| 102 | } |
| 103 | |
| 104 | if (genl_connect(handle)) { |
| 105 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic " |
| 106 | "netlink (%s)", dbg); |
| 107 | nl80211_handle_destroy(handle); |
| 108 | return NULL; |
| 109 | } |
| 110 | |
| 111 | return handle; |
| 112 | } |
| 113 | |
| 114 | |
| 115 | static void nl_destroy_handles(struct nl_handle **handle) |
| 116 | { |
| 117 | if (*handle == NULL) |
| 118 | return; |
| 119 | nl80211_handle_destroy(*handle); |
| 120 | *handle = NULL; |
| 121 | } |
| 122 | |
| 123 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 124 | #if __WORDSIZE == 64 |
| 125 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL |
| 126 | #else |
| 127 | #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL |
| 128 | #endif |
| 129 | |
| 130 | static void nl80211_register_eloop_read(struct nl_handle **handle, |
| 131 | eloop_sock_handler handler, |
| 132 | void *eloop_data) |
| 133 | { |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 134 | #ifdef CONFIG_LIBNL20 |
| 135 | /* |
| 136 | * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB) |
| 137 | * by default. It is possible to hit that limit in some cases where |
| 138 | * operations are blocked, e.g., with a burst of Deauthentication frames |
| 139 | * to hostapd and STA entry deletion. Try to increase the buffer to make |
| 140 | * this less likely to occur. |
| 141 | */ |
| 142 | if (nl_socket_set_buffer_size(*handle, 262144, 0) < 0) { |
| 143 | wpa_printf(MSG_DEBUG, |
| 144 | "nl80211: Could not set nl_socket RX buffer size: %s", |
| 145 | strerror(errno)); |
| 146 | /* continue anyway with the default (smaller) buffer */ |
| 147 | } |
| 148 | #endif /* CONFIG_LIBNL20 */ |
| 149 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 150 | nl_socket_set_nonblocking(*handle); |
| 151 | eloop_register_read_sock(nl_socket_get_fd(*handle), handler, |
| 152 | eloop_data, *handle); |
| 153 | *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID); |
| 154 | } |
| 155 | |
| 156 | |
| 157 | static void nl80211_destroy_eloop_handle(struct nl_handle **handle) |
| 158 | { |
| 159 | *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID); |
| 160 | eloop_unregister_read_sock(nl_socket_get_fd(*handle)); |
| 161 | nl_destroy_handles(handle); |
| 162 | } |
| 163 | |
| 164 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 165 | static void nl80211_global_deinit(void *priv); |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 166 | static void nl80211_check_global(struct nl80211_global *global); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 167 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 168 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss); |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 169 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 170 | struct hostapd_freq_params *freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 171 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 172 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 173 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 174 | const u8 *set_addr, int first, |
| 175 | const char *driver_params); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 176 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 177 | unsigned int freq, unsigned int wait, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 178 | const u8 *buf, size_t buf_len, u64 *cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 179 | int no_cck, int no_ack, int offchanok, |
| 180 | const u16 *csa_offs, size_t csa_offs_len); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 181 | static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, |
| 182 | int report); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 183 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 184 | #define IFIDX_ANY -1 |
| 185 | |
| 186 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 187 | int ifidx_reason); |
| 188 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 189 | int ifidx_reason); |
| 190 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 191 | int ifidx_reason); |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 192 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 193 | static int nl80211_set_channel(struct i802_bss *bss, |
| 194 | struct hostapd_freq_params *freq, int set_chan); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 195 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 196 | int ifindex, int disabled); |
| 197 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 198 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 199 | int reset_mode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 200 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 201 | static int i802_set_iface_flags(struct i802_bss *bss, int up); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 202 | static int nl80211_set_param(void *priv, const char *param); |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 203 | #ifdef CONFIG_MESH |
| 204 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
| 205 | struct wpa_driver_mesh_bss_params *params); |
| 206 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame^] | 207 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
| 208 | int reason); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 209 | |
| 210 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 211 | /* Converts nl80211_chan_width to a common format */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 212 | enum chan_width convert2width(int width) |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 213 | { |
| 214 | switch (width) { |
| 215 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 216 | return CHAN_WIDTH_20_NOHT; |
| 217 | case NL80211_CHAN_WIDTH_20: |
| 218 | return CHAN_WIDTH_20; |
| 219 | case NL80211_CHAN_WIDTH_40: |
| 220 | return CHAN_WIDTH_40; |
| 221 | case NL80211_CHAN_WIDTH_80: |
| 222 | return CHAN_WIDTH_80; |
| 223 | case NL80211_CHAN_WIDTH_80P80: |
| 224 | return CHAN_WIDTH_80P80; |
| 225 | case NL80211_CHAN_WIDTH_160: |
| 226 | return CHAN_WIDTH_160; |
| 227 | } |
| 228 | return CHAN_WIDTH_UNKNOWN; |
| 229 | } |
| 230 | |
| 231 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 232 | int is_ap_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 233 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 234 | return nlmode == NL80211_IFTYPE_AP || |
| 235 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 239 | int is_sta_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 240 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 241 | return nlmode == NL80211_IFTYPE_STATION || |
| 242 | nlmode == NL80211_IFTYPE_P2P_CLIENT; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 246 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 247 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 248 | return nlmode == NL80211_IFTYPE_P2P_CLIENT || |
| 249 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 250 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 251 | |
| 252 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 253 | struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, |
| 254 | int ifindex) |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 255 | { |
| 256 | struct i802_bss *bss; |
| 257 | |
| 258 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 259 | if (bss->ifindex == ifindex) |
| 260 | return bss; |
| 261 | } |
| 262 | |
| 263 | return NULL; |
| 264 | } |
| 265 | |
| 266 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 267 | static int is_mesh_interface(enum nl80211_iftype nlmode) |
| 268 | { |
| 269 | return nlmode == NL80211_IFTYPE_MESH_POINT; |
| 270 | } |
| 271 | |
| 272 | |
| 273 | void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 274 | { |
| 275 | if (drv->associated) |
| 276 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); |
| 277 | drv->associated = 0; |
| 278 | os_memset(drv->bssid, 0, ETH_ALEN); |
| 279 | } |
| 280 | |
| 281 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 282 | /* nl80211 code */ |
| 283 | static int ack_handler(struct nl_msg *msg, void *arg) |
| 284 | { |
| 285 | int *err = arg; |
| 286 | *err = 0; |
| 287 | return NL_STOP; |
| 288 | } |
| 289 | |
| 290 | static int finish_handler(struct nl_msg *msg, void *arg) |
| 291 | { |
| 292 | int *ret = arg; |
| 293 | *ret = 0; |
| 294 | return NL_SKIP; |
| 295 | } |
| 296 | |
| 297 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, |
| 298 | void *arg) |
| 299 | { |
| 300 | int *ret = arg; |
| 301 | *ret = err->error; |
| 302 | return NL_SKIP; |
| 303 | } |
| 304 | |
| 305 | |
| 306 | static int no_seq_check(struct nl_msg *msg, void *arg) |
| 307 | { |
| 308 | return NL_OK; |
| 309 | } |
| 310 | |
| 311 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 312 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
| 313 | { |
| 314 | /* |
| 315 | * Clear nlmsg data, e.g., to make sure key material is not left in |
| 316 | * heap memory for unnecessarily long time. |
| 317 | */ |
| 318 | if (msg) { |
| 319 | struct nlmsghdr *hdr = nlmsg_hdr(msg); |
| 320 | void *data = nlmsg_data(hdr); |
| 321 | /* |
| 322 | * This would use nlmsg_datalen() or the older nlmsg_len() if |
| 323 | * only libnl were to maintain a stable API.. Neither will work |
| 324 | * with all released versions, so just calculate the length |
| 325 | * here. |
| 326 | */ |
| 327 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; |
| 328 | |
| 329 | os_memset(data, 0, len); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 334 | static int send_and_recv(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 335 | struct nl_handle *nl_handle, struct nl_msg *msg, |
| 336 | int (*valid_handler)(struct nl_msg *, void *), |
| 337 | void *valid_data) |
| 338 | { |
| 339 | struct nl_cb *cb; |
| 340 | int err = -ENOMEM; |
| 341 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 342 | if (!msg) |
| 343 | return -ENOMEM; |
| 344 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 345 | cb = nl_cb_clone(global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 346 | if (!cb) |
| 347 | goto out; |
| 348 | |
| 349 | err = nl_send_auto_complete(nl_handle, msg); |
| 350 | if (err < 0) |
| 351 | goto out; |
| 352 | |
| 353 | err = 1; |
| 354 | |
| 355 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); |
| 356 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
| 357 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
| 358 | |
| 359 | if (valid_handler) |
| 360 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 361 | valid_handler, valid_data); |
| 362 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 363 | while (err > 0) { |
| 364 | int res = nl_recvmsgs(nl_handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 365 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 366 | wpa_printf(MSG_INFO, |
| 367 | "nl80211: %s->nl_recvmsgs failed: %d", |
| 368 | __func__, res); |
| 369 | } |
| 370 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 371 | out: |
| 372 | nl_cb_put(cb); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 373 | if (!valid_handler && valid_data == (void *) -1) |
| 374 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 375 | nlmsg_free(msg); |
| 376 | return err; |
| 377 | } |
| 378 | |
| 379 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 380 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
| 381 | struct nl_msg *msg, |
| 382 | int (*valid_handler)(struct nl_msg *, void *), |
| 383 | void *valid_data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 384 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 385 | return send_and_recv(drv->global, drv->global->nl, msg, |
| 386 | valid_handler, valid_data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | |
| 390 | struct family_data { |
| 391 | const char *group; |
| 392 | int id; |
| 393 | }; |
| 394 | |
| 395 | |
| 396 | static int family_handler(struct nl_msg *msg, void *arg) |
| 397 | { |
| 398 | struct family_data *res = arg; |
| 399 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; |
| 400 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 401 | struct nlattr *mcgrp; |
| 402 | int i; |
| 403 | |
| 404 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 405 | genlmsg_attrlen(gnlh, 0), NULL); |
| 406 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) |
| 407 | return NL_SKIP; |
| 408 | |
| 409 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { |
| 410 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; |
| 411 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), |
| 412 | nla_len(mcgrp), NULL); |
| 413 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || |
| 414 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || |
| 415 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), |
| 416 | res->group, |
| 417 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) |
| 418 | continue; |
| 419 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); |
| 420 | break; |
| 421 | }; |
| 422 | |
| 423 | return NL_SKIP; |
| 424 | } |
| 425 | |
| 426 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 427 | static int nl_get_multicast_id(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 428 | const char *family, const char *group) |
| 429 | { |
| 430 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 431 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 432 | struct family_data res = { group, -ENOENT }; |
| 433 | |
| 434 | msg = nlmsg_alloc(); |
| 435 | if (!msg) |
| 436 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 437 | if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
| 438 | 0, 0, CTRL_CMD_GETFAMILY, 0) || |
| 439 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { |
| 440 | nlmsg_free(msg); |
| 441 | return -1; |
| 442 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 443 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 444 | ret = send_and_recv(global, global->nl, msg, family_handler, &res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 445 | if (ret == 0) |
| 446 | ret = res.id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 447 | return ret; |
| 448 | } |
| 449 | |
| 450 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 451 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
| 452 | struct nl_msg *msg, int flags, uint8_t cmd) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 453 | { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 454 | if (TEST_FAIL()) |
| 455 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 456 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
| 457 | 0, flags, cmd, 0); |
| 458 | } |
| 459 | |
| 460 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 461 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
| 462 | { |
| 463 | if (bss->wdev_id_set) |
| 464 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); |
| 465 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 466 | } |
| 467 | |
| 468 | |
| 469 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 470 | { |
| 471 | struct nl_msg *msg; |
| 472 | |
| 473 | msg = nlmsg_alloc(); |
| 474 | if (!msg) |
| 475 | return NULL; |
| 476 | |
| 477 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || |
| 478 | nl80211_set_iface_id(msg, bss) < 0) { |
| 479 | nlmsg_free(msg); |
| 480 | return NULL; |
| 481 | } |
| 482 | |
| 483 | return msg; |
| 484 | } |
| 485 | |
| 486 | |
| 487 | static struct nl_msg * |
| 488 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, |
| 489 | int flags, uint8_t cmd) |
| 490 | { |
| 491 | struct nl_msg *msg; |
| 492 | |
| 493 | msg = nlmsg_alloc(); |
| 494 | if (!msg) |
| 495 | return NULL; |
| 496 | |
| 497 | if (!nl80211_cmd(drv, msg, flags, cmd) || |
| 498 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { |
| 499 | nlmsg_free(msg); |
| 500 | return NULL; |
| 501 | } |
| 502 | |
| 503 | return msg; |
| 504 | } |
| 505 | |
| 506 | |
| 507 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, |
| 508 | uint8_t cmd) |
| 509 | { |
| 510 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); |
| 511 | } |
| 512 | |
| 513 | |
| 514 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 515 | { |
| 516 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); |
| 517 | } |
| 518 | |
| 519 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 520 | struct wiphy_idx_data { |
| 521 | int wiphy_idx; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 522 | enum nl80211_iftype nlmode; |
| 523 | u8 *macaddr; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 524 | }; |
| 525 | |
| 526 | |
| 527 | static int netdev_info_handler(struct nl_msg *msg, void *arg) |
| 528 | { |
| 529 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 530 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 531 | struct wiphy_idx_data *info = arg; |
| 532 | |
| 533 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 534 | genlmsg_attrlen(gnlh, 0), NULL); |
| 535 | |
| 536 | if (tb[NL80211_ATTR_WIPHY]) |
| 537 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 538 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 539 | if (tb[NL80211_ATTR_IFTYPE]) |
| 540 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); |
| 541 | |
| 542 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
| 543 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 544 | ETH_ALEN); |
| 545 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 546 | return NL_SKIP; |
| 547 | } |
| 548 | |
| 549 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 550 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 551 | { |
| 552 | struct nl_msg *msg; |
| 553 | struct wiphy_idx_data data = { |
| 554 | .wiphy_idx = -1, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 555 | .macaddr = NULL, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 556 | }; |
| 557 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 558 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 559 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 560 | |
| 561 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) |
| 562 | return data.wiphy_idx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 563 | return -1; |
| 564 | } |
| 565 | |
| 566 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 567 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
| 568 | { |
| 569 | struct nl_msg *msg; |
| 570 | struct wiphy_idx_data data = { |
| 571 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
| 572 | .macaddr = NULL, |
| 573 | }; |
| 574 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 575 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 576 | return NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 577 | |
| 578 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) |
| 579 | return data.nlmode; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 580 | return NL80211_IFTYPE_UNSPECIFIED; |
| 581 | } |
| 582 | |
| 583 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 584 | static int nl80211_get_macaddr(struct i802_bss *bss) |
| 585 | { |
| 586 | struct nl_msg *msg; |
| 587 | struct wiphy_idx_data data = { |
| 588 | .macaddr = bss->addr, |
| 589 | }; |
| 590 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 591 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 592 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 593 | |
| 594 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 595 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 596 | |
| 597 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 598 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
| 599 | struct nl80211_wiphy_data *w) |
| 600 | { |
| 601 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 602 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 603 | |
| 604 | msg = nlmsg_alloc(); |
| 605 | if (!msg) |
| 606 | return -1; |
| 607 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 608 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
| 609 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { |
| 610 | nlmsg_free(msg); |
| 611 | return -1; |
| 612 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 613 | |
| 614 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 615 | if (ret) { |
| 616 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " |
| 617 | "failed: ret=%d (%s)", |
| 618 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 619 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 620 | return ret; |
| 621 | } |
| 622 | |
| 623 | |
| 624 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) |
| 625 | { |
| 626 | struct nl80211_wiphy_data *w = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 627 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 628 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 629 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 630 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 631 | res = nl_recvmsgs(handle, w->nl_cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 632 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 633 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 634 | __func__, res); |
| 635 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | |
| 639 | static int process_beacon_event(struct nl_msg *msg, void *arg) |
| 640 | { |
| 641 | struct nl80211_wiphy_data *w = arg; |
| 642 | struct wpa_driver_nl80211_data *drv; |
| 643 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 644 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 645 | union wpa_event_data event; |
| 646 | |
| 647 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 648 | genlmsg_attrlen(gnlh, 0), NULL); |
| 649 | |
| 650 | if (gnlh->cmd != NL80211_CMD_FRAME) { |
| 651 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", |
| 652 | gnlh->cmd); |
| 653 | return NL_SKIP; |
| 654 | } |
| 655 | |
| 656 | if (!tb[NL80211_ATTR_FRAME]) |
| 657 | return NL_SKIP; |
| 658 | |
| 659 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, |
| 660 | wiphy_list) { |
| 661 | os_memset(&event, 0, sizeof(event)); |
| 662 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); |
| 663 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); |
| 664 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
| 665 | } |
| 666 | |
| 667 | return NL_SKIP; |
| 668 | } |
| 669 | |
| 670 | |
| 671 | static struct nl80211_wiphy_data * |
| 672 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) |
| 673 | { |
| 674 | static DEFINE_DL_LIST(nl80211_wiphys); |
| 675 | struct nl80211_wiphy_data *w; |
| 676 | int wiphy_idx, found = 0; |
| 677 | struct i802_bss *tmp_bss; |
| 678 | |
| 679 | if (bss->wiphy_data != NULL) |
| 680 | return bss->wiphy_data; |
| 681 | |
| 682 | wiphy_idx = nl80211_get_wiphy_index(bss); |
| 683 | |
| 684 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { |
| 685 | if (w->wiphy_idx == wiphy_idx) |
| 686 | goto add; |
| 687 | } |
| 688 | |
| 689 | /* alloc new one */ |
| 690 | w = os_zalloc(sizeof(*w)); |
| 691 | if (w == NULL) |
| 692 | return NULL; |
| 693 | w->wiphy_idx = wiphy_idx; |
| 694 | dl_list_init(&w->bsss); |
| 695 | dl_list_init(&w->drvs); |
| 696 | |
| 697 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 698 | if (!w->nl_cb) { |
| 699 | os_free(w); |
| 700 | return NULL; |
| 701 | } |
| 702 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL); |
| 703 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, process_beacon_event, |
| 704 | w); |
| 705 | |
| 706 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, |
| 707 | "wiphy beacons"); |
| 708 | if (w->nl_beacons == NULL) { |
| 709 | os_free(w); |
| 710 | return NULL; |
| 711 | } |
| 712 | |
| 713 | if (nl80211_register_beacons(bss->drv, w)) { |
| 714 | nl_destroy_handles(&w->nl_beacons); |
| 715 | os_free(w); |
| 716 | return NULL; |
| 717 | } |
| 718 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 719 | nl80211_register_eloop_read(&w->nl_beacons, nl80211_recv_beacons, w); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 720 | |
| 721 | dl_list_add(&nl80211_wiphys, &w->list); |
| 722 | |
| 723 | add: |
| 724 | /* drv entry for this bss already there? */ |
| 725 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 726 | if (tmp_bss->drv == bss->drv) { |
| 727 | found = 1; |
| 728 | break; |
| 729 | } |
| 730 | } |
| 731 | /* if not add it */ |
| 732 | if (!found) |
| 733 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); |
| 734 | |
| 735 | dl_list_add(&w->bsss, &bss->wiphy_list); |
| 736 | bss->wiphy_data = w; |
| 737 | return w; |
| 738 | } |
| 739 | |
| 740 | |
| 741 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) |
| 742 | { |
| 743 | struct nl80211_wiphy_data *w = bss->wiphy_data; |
| 744 | struct i802_bss *tmp_bss; |
| 745 | int found = 0; |
| 746 | |
| 747 | if (w == NULL) |
| 748 | return; |
| 749 | bss->wiphy_data = NULL; |
| 750 | dl_list_del(&bss->wiphy_list); |
| 751 | |
| 752 | /* still any for this drv present? */ |
| 753 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 754 | if (tmp_bss->drv == bss->drv) { |
| 755 | found = 1; |
| 756 | break; |
| 757 | } |
| 758 | } |
| 759 | /* if not remove it */ |
| 760 | if (!found) |
| 761 | dl_list_del(&bss->drv->wiphy_list); |
| 762 | |
| 763 | if (!dl_list_empty(&w->bsss)) |
| 764 | return; |
| 765 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 766 | nl80211_destroy_eloop_handle(&w->nl_beacons); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 767 | |
| 768 | nl_cb_put(w->nl_cb); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 769 | dl_list_del(&w->list); |
| 770 | os_free(w); |
| 771 | } |
| 772 | |
| 773 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 774 | static unsigned int nl80211_get_ifindex(void *priv) |
| 775 | { |
| 776 | struct i802_bss *bss = priv; |
| 777 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 778 | |
| 779 | return drv->ifindex; |
| 780 | } |
| 781 | |
| 782 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 783 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
| 784 | { |
| 785 | struct i802_bss *bss = priv; |
| 786 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 787 | if (!drv->associated) |
| 788 | return -1; |
| 789 | os_memcpy(bssid, drv->bssid, ETH_ALEN); |
| 790 | return 0; |
| 791 | } |
| 792 | |
| 793 | |
| 794 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
| 795 | { |
| 796 | struct i802_bss *bss = priv; |
| 797 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 798 | if (!drv->associated) |
| 799 | return -1; |
| 800 | os_memcpy(ssid, drv->ssid, drv->ssid_len); |
| 801 | return drv->ssid_len; |
| 802 | } |
| 803 | |
| 804 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 805 | static void wpa_driver_nl80211_event_newlink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 806 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 807 | int ifindex, const char *ifname) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 808 | { |
| 809 | union wpa_event_data event; |
| 810 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 811 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 812 | if (if_nametoindex(drv->first_bss->ifname) == 0) { |
| 813 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", |
| 814 | drv->first_bss->ifname); |
| 815 | return; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 816 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 817 | if (!drv->if_removed) |
| 818 | return; |
| 819 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", |
| 820 | drv->first_bss->ifname); |
| 821 | drv->if_removed = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 822 | } |
| 823 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 824 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 825 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 826 | os_strlcpy(event.interface_status.ifname, ifname, |
| 827 | sizeof(event.interface_status.ifname)); |
| 828 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 829 | if (drv) |
| 830 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 831 | else |
| 832 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 833 | &event); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | |
| 837 | static void wpa_driver_nl80211_event_dellink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 838 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 839 | int ifindex, const char *ifname) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 840 | { |
| 841 | union wpa_event_data event; |
| 842 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 843 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 844 | if (drv->if_removed) { |
| 845 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", |
| 846 | ifname); |
| 847 | return; |
| 848 | } |
| 849 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
| 850 | ifname); |
| 851 | drv->if_removed = 1; |
| 852 | } else { |
| 853 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", |
| 854 | ifname); |
| 855 | } |
| 856 | |
| 857 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 858 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 859 | os_strlcpy(event.interface_status.ifname, ifname, |
| 860 | sizeof(event.interface_status.ifname)); |
| 861 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 862 | if (drv) |
| 863 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 864 | else |
| 865 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 866 | &event); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 867 | } |
| 868 | |
| 869 | |
| 870 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
| 871 | u8 *buf, size_t len) |
| 872 | { |
| 873 | int attrlen, rta_len; |
| 874 | struct rtattr *attr; |
| 875 | |
| 876 | attrlen = len; |
| 877 | attr = (struct rtattr *) buf; |
| 878 | |
| 879 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
| 880 | while (RTA_OK(attr, attrlen)) { |
| 881 | if (attr->rta_type == IFLA_IFNAME) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 882 | if (os_strcmp(((char *) attr) + rta_len, |
| 883 | drv->first_bss->ifname) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 884 | return 1; |
| 885 | else |
| 886 | break; |
| 887 | } |
| 888 | attr = RTA_NEXT(attr, attrlen); |
| 889 | } |
| 890 | |
| 891 | return 0; |
| 892 | } |
| 893 | |
| 894 | |
| 895 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, |
| 896 | int ifindex, u8 *buf, size_t len) |
| 897 | { |
| 898 | if (drv->ifindex == ifindex) |
| 899 | return 1; |
| 900 | |
| 901 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 902 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 903 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
| 904 | "interface"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 905 | wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 906 | return 1; |
| 907 | } |
| 908 | |
| 909 | return 0; |
| 910 | } |
| 911 | |
| 912 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 913 | static struct wpa_driver_nl80211_data * |
| 914 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len) |
| 915 | { |
| 916 | struct wpa_driver_nl80211_data *drv; |
| 917 | dl_list_for_each(drv, &global->interfaces, |
| 918 | struct wpa_driver_nl80211_data, list) { |
| 919 | if (wpa_driver_nl80211_own_ifindex(drv, idx, buf, len) || |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 920 | have_ifidx(drv, idx, IFIDX_ANY)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 921 | return drv; |
| 922 | } |
| 923 | return NULL; |
| 924 | } |
| 925 | |
| 926 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 927 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
| 928 | struct ifinfomsg *ifi, |
| 929 | u8 *buf, size_t len) |
| 930 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 931 | struct nl80211_global *global = ctx; |
| 932 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 933 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 934 | struct rtattr *attr; |
| 935 | u32 brid = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 936 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 937 | char ifname[IFNAMSIZ + 1]; |
| 938 | char extra[100], *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 939 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 940 | extra[0] = '\0'; |
| 941 | pos = extra; |
| 942 | end = pos + sizeof(extra); |
| 943 | ifname[0] = '\0'; |
| 944 | |
| 945 | attrlen = len; |
| 946 | attr = (struct rtattr *) buf; |
| 947 | while (RTA_OK(attr, attrlen)) { |
| 948 | switch (attr->rta_type) { |
| 949 | case IFLA_IFNAME: |
| 950 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) |
| 951 | break; |
| 952 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 953 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 954 | break; |
| 955 | case IFLA_MASTER: |
| 956 | brid = nla_get_u32((struct nlattr *) attr); |
| 957 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 958 | break; |
| 959 | case IFLA_WIRELESS: |
| 960 | pos += os_snprintf(pos, end - pos, " wext"); |
| 961 | break; |
| 962 | case IFLA_OPERSTATE: |
| 963 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 964 | nla_get_u32((struct nlattr *) attr)); |
| 965 | break; |
| 966 | case IFLA_LINKMODE: |
| 967 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 968 | nla_get_u32((struct nlattr *) attr)); |
| 969 | break; |
| 970 | } |
| 971 | attr = RTA_NEXT(attr, attrlen); |
| 972 | } |
| 973 | extra[sizeof(extra) - 1] = '\0'; |
| 974 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 975 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 976 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 977 | ifi->ifi_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 978 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 979 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 980 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 981 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 982 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 983 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
| 984 | if (!drv) |
| 985 | goto event_newlink; |
| 986 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 987 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 988 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 989 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 990 | linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 991 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 992 | "event since interface %s is up", namebuf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 993 | drv->ignore_if_down_event = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 994 | return; |
| 995 | } |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 996 | wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", |
| 997 | namebuf, ifname); |
| 998 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 999 | wpa_printf(MSG_DEBUG, |
| 1000 | "nl80211: Not the main interface (%s) - do not indicate interface down", |
| 1001 | drv->first_bss->ifname); |
| 1002 | } else if (drv->ignore_if_down_event) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1003 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1004 | "event generated by mode change"); |
| 1005 | drv->ignore_if_down_event = 0; |
| 1006 | } else { |
| 1007 | drv->if_disabled = 1; |
| 1008 | wpa_supplicant_event(drv->ctx, |
| 1009 | EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1010 | |
| 1011 | /* |
| 1012 | * Try to get drv again, since it may be removed as |
| 1013 | * part of the EVENT_INTERFACE_DISABLED handling for |
| 1014 | * dynamic interfaces |
| 1015 | */ |
| 1016 | drv = nl80211_find_drv(global, ifi->ifi_index, |
| 1017 | buf, len); |
| 1018 | if (!drv) |
| 1019 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1020 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1021 | } |
| 1022 | |
| 1023 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1024 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1025 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1026 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1027 | "event since interface %s is down", |
| 1028 | namebuf); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1029 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1030 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1031 | "event since interface %s does not exist", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1032 | drv->first_bss->ifname); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1033 | } else if (drv->if_removed) { |
| 1034 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1035 | "event since interface %s is marked " |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1036 | "removed", drv->first_bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1037 | } else { |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1038 | struct i802_bss *bss; |
| 1039 | u8 addr[ETH_ALEN]; |
| 1040 | |
| 1041 | /* Re-read MAC address as it may have changed */ |
| 1042 | bss = get_bss_ifindex(drv, ifi->ifi_index); |
| 1043 | if (bss && |
| 1044 | linux_get_ifhwaddr(drv->global->ioctl_sock, |
| 1045 | bss->ifname, addr) < 0) { |
| 1046 | wpa_printf(MSG_DEBUG, |
| 1047 | "nl80211: %s: failed to re-read MAC address", |
| 1048 | bss->ifname); |
| 1049 | } else if (bss && |
| 1050 | os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { |
| 1051 | wpa_printf(MSG_DEBUG, |
| 1052 | "nl80211: Own MAC address on ifindex %d (%s) changed from " |
| 1053 | MACSTR " to " MACSTR, |
| 1054 | ifi->ifi_index, bss->ifname, |
| 1055 | MAC2STR(bss->addr), |
| 1056 | MAC2STR(addr)); |
| 1057 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 1058 | } |
| 1059 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1060 | wpa_printf(MSG_DEBUG, "nl80211: Interface up"); |
| 1061 | drv->if_disabled = 0; |
| 1062 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, |
| 1063 | NULL); |
| 1064 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | /* |
| 1068 | * Some drivers send the association event before the operup event--in |
| 1069 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() |
| 1070 | * fails. This will hit us when wpa_supplicant does not need to do |
| 1071 | * IEEE 802.1X authentication |
| 1072 | */ |
| 1073 | if (drv->operstate == 1 && |
| 1074 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1075 | !(ifi->ifi_flags & IFF_RUNNING)) { |
| 1076 | 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] | 1077 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1078 | -1, IF_OPER_UP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1079 | } |
| 1080 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1081 | event_newlink: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1082 | if (ifname[0]) |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1083 | wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index, |
| 1084 | ifname); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1085 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1086 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1087 | struct i802_bss *bss; |
| 1088 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1089 | /* device has been added to bridge */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1090 | if (!if_indextoname(brid, namebuf)) { |
| 1091 | wpa_printf(MSG_DEBUG, |
| 1092 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1093 | brid); |
| 1094 | return; |
| 1095 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1096 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
| 1097 | brid, namebuf); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1098 | add_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1099 | |
| 1100 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 1101 | if (os_strcmp(ifname, bss->ifname) == 0) { |
| 1102 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); |
| 1103 | break; |
| 1104 | } |
| 1105 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1106 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | |
| 1110 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
| 1111 | struct ifinfomsg *ifi, |
| 1112 | u8 *buf, size_t len) |
| 1113 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1114 | struct nl80211_global *global = ctx; |
| 1115 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1116 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1117 | struct rtattr *attr; |
| 1118 | u32 brid = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1119 | char ifname[IFNAMSIZ + 1]; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1120 | char extra[100], *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1121 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1122 | extra[0] = '\0'; |
| 1123 | pos = extra; |
| 1124 | end = pos + sizeof(extra); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1125 | ifname[0] = '\0'; |
| 1126 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1127 | attrlen = len; |
| 1128 | attr = (struct rtattr *) buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1129 | while (RTA_OK(attr, attrlen)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1130 | switch (attr->rta_type) { |
| 1131 | case IFLA_IFNAME: |
| 1132 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) |
| 1133 | break; |
| 1134 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1135 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1136 | break; |
| 1137 | case IFLA_MASTER: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1138 | brid = nla_get_u32((struct nlattr *) attr); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1139 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1140 | break; |
| 1141 | case IFLA_OPERSTATE: |
| 1142 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1143 | nla_get_u32((struct nlattr *) attr)); |
| 1144 | break; |
| 1145 | case IFLA_LINKMODE: |
| 1146 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1147 | nla_get_u32((struct nlattr *) attr)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1148 | break; |
| 1149 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1150 | attr = RTA_NEXT(attr, attrlen); |
| 1151 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1152 | extra[sizeof(extra) - 1] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1153 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1154 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1155 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1156 | ifi->ifi_flags, |
| 1157 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1158 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1159 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1160 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1161 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1162 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1163 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1164 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1165 | /* device has been removed from bridge */ |
| 1166 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1167 | |
| 1168 | if (!if_indextoname(brid, namebuf)) { |
| 1169 | wpa_printf(MSG_DEBUG, |
| 1170 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1171 | brid); |
| 1172 | } else { |
| 1173 | wpa_printf(MSG_DEBUG, |
| 1174 | "nl80211: Remove ifindex %u for bridge %s", |
| 1175 | brid, namebuf); |
| 1176 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1177 | del_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1178 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1179 | |
| 1180 | if (ifi->ifi_family != AF_BRIDGE || !brid) |
| 1181 | wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index, |
| 1182 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1186 | struct nl80211_get_assoc_freq_arg { |
| 1187 | struct wpa_driver_nl80211_data *drv; |
| 1188 | unsigned int assoc_freq; |
| 1189 | unsigned int ibss_freq; |
| 1190 | u8 assoc_bssid[ETH_ALEN]; |
| 1191 | u8 assoc_ssid[SSID_MAX_LEN]; |
| 1192 | u8 assoc_ssid_len; |
| 1193 | }; |
| 1194 | |
| 1195 | static int nl80211_get_assoc_freq_handler(struct nl_msg *msg, void *arg) |
| 1196 | { |
| 1197 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1198 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1199 | struct nlattr *bss[NL80211_BSS_MAX + 1]; |
| 1200 | static struct nla_policy bss_policy[NL80211_BSS_MAX + 1] = { |
| 1201 | [NL80211_BSS_BSSID] = { .type = NLA_UNSPEC }, |
| 1202 | [NL80211_BSS_FREQUENCY] = { .type = NLA_U32 }, |
| 1203 | [NL80211_BSS_INFORMATION_ELEMENTS] = { .type = NLA_UNSPEC }, |
| 1204 | [NL80211_BSS_STATUS] = { .type = NLA_U32 }, |
| 1205 | }; |
| 1206 | struct nl80211_get_assoc_freq_arg *ctx = arg; |
| 1207 | enum nl80211_bss_status status; |
| 1208 | |
| 1209 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1210 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1211 | if (!tb[NL80211_ATTR_BSS] || |
| 1212 | nla_parse_nested(bss, NL80211_BSS_MAX, tb[NL80211_ATTR_BSS], |
| 1213 | bss_policy) || |
| 1214 | !bss[NL80211_BSS_STATUS]) |
| 1215 | return NL_SKIP; |
| 1216 | |
| 1217 | status = nla_get_u32(bss[NL80211_BSS_STATUS]); |
| 1218 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1219 | bss[NL80211_BSS_FREQUENCY]) { |
| 1220 | ctx->assoc_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1221 | wpa_printf(MSG_DEBUG, "nl80211: Associated on %u MHz", |
| 1222 | ctx->assoc_freq); |
| 1223 | } |
| 1224 | if (status == NL80211_BSS_STATUS_IBSS_JOINED && |
| 1225 | bss[NL80211_BSS_FREQUENCY]) { |
| 1226 | ctx->ibss_freq = nla_get_u32(bss[NL80211_BSS_FREQUENCY]); |
| 1227 | wpa_printf(MSG_DEBUG, "nl80211: IBSS-joined on %u MHz", |
| 1228 | ctx->ibss_freq); |
| 1229 | } |
| 1230 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1231 | bss[NL80211_BSS_BSSID]) { |
| 1232 | os_memcpy(ctx->assoc_bssid, |
| 1233 | nla_data(bss[NL80211_BSS_BSSID]), ETH_ALEN); |
| 1234 | wpa_printf(MSG_DEBUG, "nl80211: Associated with " |
| 1235 | MACSTR, MAC2STR(ctx->assoc_bssid)); |
| 1236 | } |
| 1237 | |
| 1238 | if (status == NL80211_BSS_STATUS_ASSOCIATED && |
| 1239 | bss[NL80211_BSS_INFORMATION_ELEMENTS]) { |
| 1240 | const u8 *ie, *ssid; |
| 1241 | size_t ie_len; |
| 1242 | |
| 1243 | ie = nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1244 | ie_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); |
| 1245 | ssid = get_ie(ie, ie_len, WLAN_EID_SSID); |
| 1246 | if (ssid && ssid[1] > 0 && ssid[1] <= SSID_MAX_LEN) { |
| 1247 | ctx->assoc_ssid_len = ssid[1]; |
| 1248 | os_memcpy(ctx->assoc_ssid, ssid + 2, ssid[1]); |
| 1249 | } |
| 1250 | } |
| 1251 | |
| 1252 | return NL_SKIP; |
| 1253 | } |
| 1254 | |
| 1255 | |
| 1256 | 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] | 1257 | { |
| 1258 | struct nl_msg *msg; |
| 1259 | int ret; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1260 | struct nl80211_get_assoc_freq_arg arg; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1261 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1262 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1263 | os_memset(&arg, 0, sizeof(arg)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1264 | arg.drv = drv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 1265 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
| 1266 | &arg); |
| 1267 | if (ret == 0) { |
| 1268 | os_memcpy(ssid, arg.assoc_ssid, arg.assoc_ssid_len); |
| 1269 | return arg.assoc_ssid_len; |
| 1270 | } |
| 1271 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d (%s)", |
| 1272 | ret, strerror(-ret)); |
| 1273 | return ret; |
| 1274 | } |
| 1275 | |
| 1276 | |
| 1277 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
| 1278 | { |
| 1279 | struct nl_msg *msg; |
| 1280 | int ret; |
| 1281 | struct nl80211_get_assoc_freq_arg arg; |
| 1282 | |
| 1283 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
| 1284 | os_memset(&arg, 0, sizeof(arg)); |
| 1285 | arg.drv = drv; |
| 1286 | ret = send_and_recv_msgs(drv, msg, nl80211_get_assoc_freq_handler, |
| 1287 | &arg); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1288 | if (ret == 0) { |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1289 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
| 1290 | arg.ibss_freq : arg.assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1291 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1292 | "associated BSS from scan results: %u MHz", freq); |
| 1293 | if (freq) |
| 1294 | drv->assoc_freq = freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1295 | return drv->assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1296 | } |
| 1297 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
| 1298 | "(%s)", ret, strerror(-ret)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1299 | return drv->assoc_freq; |
| 1300 | } |
| 1301 | |
| 1302 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1303 | static int get_link_signal(struct nl_msg *msg, void *arg) |
| 1304 | { |
| 1305 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1306 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1307 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; |
| 1308 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { |
| 1309 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1310 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1311 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1312 | }; |
| 1313 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
| 1314 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 1315 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 1316 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 1317 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, |
| 1318 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 1319 | }; |
| 1320 | struct wpa_signal_info *sig_change = arg; |
| 1321 | |
| 1322 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1323 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1324 | if (!tb[NL80211_ATTR_STA_INFO] || |
| 1325 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, |
| 1326 | tb[NL80211_ATTR_STA_INFO], policy)) |
| 1327 | return NL_SKIP; |
| 1328 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) |
| 1329 | return NL_SKIP; |
| 1330 | |
| 1331 | sig_change->current_signal = |
| 1332 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); |
| 1333 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1334 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
| 1335 | sig_change->avg_signal = |
| 1336 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); |
| 1337 | else |
| 1338 | sig_change->avg_signal = 0; |
| 1339 | |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1340 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
| 1341 | sig_change->avg_beacon_signal = |
| 1342 | (s8) |
| 1343 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); |
| 1344 | else |
| 1345 | sig_change->avg_beacon_signal = 0; |
| 1346 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1347 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
| 1348 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, |
| 1349 | sinfo[NL80211_STA_INFO_TX_BITRATE], |
| 1350 | rate_policy)) { |
| 1351 | sig_change->current_txrate = 0; |
| 1352 | } else { |
| 1353 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { |
| 1354 | sig_change->current_txrate = |
| 1355 | nla_get_u16(rinfo[ |
| 1356 | NL80211_RATE_INFO_BITRATE]) * 100; |
| 1357 | } |
| 1358 | } |
| 1359 | } |
| 1360 | |
| 1361 | return NL_SKIP; |
| 1362 | } |
| 1363 | |
| 1364 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1365 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
| 1366 | struct wpa_signal_info *sig) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1367 | { |
| 1368 | struct nl_msg *msg; |
| 1369 | |
| 1370 | sig->current_signal = -9999; |
| 1371 | sig->current_txrate = 0; |
| 1372 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1373 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
| 1374 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) { |
| 1375 | nlmsg_free(msg); |
| 1376 | return -ENOBUFS; |
| 1377 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1378 | |
| 1379 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | |
| 1383 | static int get_link_noise(struct nl_msg *msg, void *arg) |
| 1384 | { |
| 1385 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1386 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1387 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 1388 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 1389 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 1390 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 1391 | }; |
| 1392 | struct wpa_signal_info *sig_change = arg; |
| 1393 | |
| 1394 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1395 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1396 | |
| 1397 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 1398 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); |
| 1399 | return NL_SKIP; |
| 1400 | } |
| 1401 | |
| 1402 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 1403 | tb[NL80211_ATTR_SURVEY_INFO], |
| 1404 | survey_policy)) { |
| 1405 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " |
| 1406 | "attributes!"); |
| 1407 | return NL_SKIP; |
| 1408 | } |
| 1409 | |
| 1410 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 1411 | return NL_SKIP; |
| 1412 | |
| 1413 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 1414 | sig_change->frequency) |
| 1415 | return NL_SKIP; |
| 1416 | |
| 1417 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 1418 | return NL_SKIP; |
| 1419 | |
| 1420 | sig_change->current_noise = |
| 1421 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 1422 | |
| 1423 | return NL_SKIP; |
| 1424 | } |
| 1425 | |
| 1426 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1427 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
| 1428 | struct wpa_signal_info *sig_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1429 | { |
| 1430 | struct nl_msg *msg; |
| 1431 | |
| 1432 | sig_change->current_noise = 9999; |
| 1433 | sig_change->frequency = drv->assoc_freq; |
| 1434 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1435 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1436 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | |
| 1440 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
| 1441 | void *handle) |
| 1442 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1443 | struct nl_cb *cb = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1444 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1445 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1446 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1447 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1448 | res = nl_recvmsgs(handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 1449 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1450 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 1451 | __func__, res); |
| 1452 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1453 | } |
| 1454 | |
| 1455 | |
| 1456 | /** |
| 1457 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain |
| 1458 | * @priv: driver_nl80211 private data |
| 1459 | * @alpha2_arg: country to which to switch to |
| 1460 | * Returns: 0 on success, -1 on failure |
| 1461 | * |
| 1462 | * This asks nl80211 to set the regulatory domain for given |
| 1463 | * country ISO / IEC alpha2. |
| 1464 | */ |
| 1465 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) |
| 1466 | { |
| 1467 | struct i802_bss *bss = priv; |
| 1468 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1469 | char alpha2[3]; |
| 1470 | struct nl_msg *msg; |
| 1471 | |
| 1472 | msg = nlmsg_alloc(); |
| 1473 | if (!msg) |
| 1474 | return -ENOMEM; |
| 1475 | |
| 1476 | alpha2[0] = alpha2_arg[0]; |
| 1477 | alpha2[1] = alpha2_arg[1]; |
| 1478 | alpha2[2] = '\0'; |
| 1479 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1480 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
| 1481 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { |
| 1482 | nlmsg_free(msg); |
| 1483 | return -EINVAL; |
| 1484 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1485 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) |
| 1486 | return -EINVAL; |
| 1487 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1488 | } |
| 1489 | |
| 1490 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1491 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
| 1492 | { |
| 1493 | char *alpha2 = arg; |
| 1494 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 1495 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1496 | |
| 1497 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1498 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1499 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { |
| 1500 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); |
| 1501 | return NL_SKIP; |
| 1502 | } |
| 1503 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); |
| 1504 | return NL_SKIP; |
| 1505 | } |
| 1506 | |
| 1507 | |
| 1508 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) |
| 1509 | { |
| 1510 | struct i802_bss *bss = priv; |
| 1511 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1512 | struct nl_msg *msg; |
| 1513 | int ret; |
| 1514 | |
| 1515 | msg = nlmsg_alloc(); |
| 1516 | if (!msg) |
| 1517 | return -ENOMEM; |
| 1518 | |
| 1519 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
| 1520 | alpha2[0] = '\0'; |
| 1521 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2); |
| 1522 | if (!alpha2[0]) |
| 1523 | ret = -1; |
| 1524 | |
| 1525 | return ret; |
| 1526 | } |
| 1527 | |
| 1528 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1529 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1530 | { |
| 1531 | int ret; |
| 1532 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1533 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1534 | if (global->nl_cb == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1535 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 1536 | "callbacks"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1537 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1538 | } |
| 1539 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1540 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
| 1541 | if (global->nl == NULL) |
| 1542 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1543 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1544 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
| 1545 | if (global->nl80211_id < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1546 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
| 1547 | "found"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1548 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1549 | } |
| 1550 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1551 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
| 1552 | if (global->nl_event == NULL) |
| 1553 | goto err; |
| 1554 | |
| 1555 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1556 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1557 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1558 | if (ret < 0) { |
| 1559 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1560 | "membership for scan events: %d (%s)", |
| 1561 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1562 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1563 | } |
| 1564 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1565 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1566 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1567 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1568 | if (ret < 0) { |
| 1569 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1570 | "membership for mlme events: %d (%s)", |
| 1571 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1572 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1573 | } |
| 1574 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1575 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1576 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1577 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1578 | if (ret < 0) { |
| 1579 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1580 | "membership for regulatory events: %d (%s)", |
| 1581 | ret, strerror(-ret)); |
| 1582 | /* Continue without regulatory events */ |
| 1583 | } |
| 1584 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1585 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
| 1586 | if (ret >= 0) |
| 1587 | ret = nl_socket_add_membership(global->nl_event, ret); |
| 1588 | if (ret < 0) { |
| 1589 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1590 | "membership for vendor events: %d (%s)", |
| 1591 | ret, strerror(-ret)); |
| 1592 | /* Continue without vendor events */ |
| 1593 | } |
| 1594 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1595 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1596 | no_seq_check, NULL); |
| 1597 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1598 | process_global_event, global); |
| 1599 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1600 | nl80211_register_eloop_read(&global->nl_event, |
| 1601 | wpa_driver_nl80211_event_receive, |
| 1602 | global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1603 | |
| 1604 | return 0; |
| 1605 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1606 | err: |
| 1607 | nl_destroy_handles(&global->nl_event); |
| 1608 | nl_destroy_handles(&global->nl); |
| 1609 | nl_cb_put(global->nl_cb); |
| 1610 | global->nl_cb = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1611 | return -1; |
| 1612 | } |
| 1613 | |
| 1614 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1615 | static void nl80211_check_global(struct nl80211_global *global) |
| 1616 | { |
| 1617 | struct nl_handle *handle; |
| 1618 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; |
| 1619 | int ret; |
| 1620 | unsigned int i; |
| 1621 | |
| 1622 | /* |
| 1623 | * Try to re-add memberships to handle case of cfg80211 getting reloaded |
| 1624 | * and all registration having been cleared. |
| 1625 | */ |
| 1626 | handle = (void *) (((intptr_t) global->nl_event) ^ |
| 1627 | ELOOP_SOCKET_INVALID); |
| 1628 | |
| 1629 | for (i = 0; groups[i]; i++) { |
| 1630 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); |
| 1631 | if (ret >= 0) |
| 1632 | ret = nl_socket_add_membership(handle, ret); |
| 1633 | if (ret < 0) { |
| 1634 | wpa_printf(MSG_INFO, |
| 1635 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", |
| 1636 | groups[i], ret, strerror(-ret)); |
| 1637 | } |
| 1638 | } |
| 1639 | } |
| 1640 | |
| 1641 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1642 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
| 1643 | { |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1644 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1645 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1646 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1647 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1648 | /* |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1649 | * rtnetlink ifdown handler will report interfaces other than the P2P |
| 1650 | * Device interface as disabled. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1651 | */ |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1652 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 1653 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1654 | } |
| 1655 | |
| 1656 | |
| 1657 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) |
| 1658 | { |
| 1659 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1660 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1661 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1662 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
| 1663 | "after rfkill unblock"); |
| 1664 | return; |
| 1665 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1666 | |
| 1667 | if (is_p2p_net_interface(drv->nlmode)) |
| 1668 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
| 1669 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1670 | /* |
| 1671 | * rtnetlink ifup handler will report interfaces other than the P2P |
| 1672 | * Device interface as enabled. |
| 1673 | */ |
| 1674 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 1675 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1676 | } |
| 1677 | |
| 1678 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1679 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
| 1680 | void *eloop_ctx, |
| 1681 | void *handle) |
| 1682 | { |
| 1683 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 1684 | u8 data[2048]; |
| 1685 | struct msghdr msg; |
| 1686 | struct iovec entry; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1687 | u8 control[512]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1688 | struct cmsghdr *cmsg; |
| 1689 | int res, found_ee = 0, found_wifi = 0, acked = 0; |
| 1690 | union wpa_event_data event; |
| 1691 | |
| 1692 | memset(&msg, 0, sizeof(msg)); |
| 1693 | msg.msg_iov = &entry; |
| 1694 | msg.msg_iovlen = 1; |
| 1695 | entry.iov_base = data; |
| 1696 | entry.iov_len = sizeof(data); |
| 1697 | msg.msg_control = &control; |
| 1698 | msg.msg_controllen = sizeof(control); |
| 1699 | |
| 1700 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); |
| 1701 | /* if error or not fitting 802.3 header, return */ |
| 1702 | if (res < 14) |
| 1703 | return; |
| 1704 | |
| 1705 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
| 1706 | { |
| 1707 | if (cmsg->cmsg_level == SOL_SOCKET && |
| 1708 | cmsg->cmsg_type == SCM_WIFI_STATUS) { |
| 1709 | int *ack; |
| 1710 | |
| 1711 | found_wifi = 1; |
| 1712 | ack = (void *)CMSG_DATA(cmsg); |
| 1713 | acked = *ack; |
| 1714 | } |
| 1715 | |
| 1716 | if (cmsg->cmsg_level == SOL_PACKET && |
| 1717 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { |
| 1718 | struct sock_extended_err *err = |
| 1719 | (struct sock_extended_err *)CMSG_DATA(cmsg); |
| 1720 | |
| 1721 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) |
| 1722 | found_ee = 1; |
| 1723 | } |
| 1724 | } |
| 1725 | |
| 1726 | if (!found_ee || !found_wifi) |
| 1727 | return; |
| 1728 | |
| 1729 | memset(&event, 0, sizeof(event)); |
| 1730 | event.eapol_tx_status.dst = data; |
| 1731 | event.eapol_tx_status.data = data + 14; |
| 1732 | event.eapol_tx_status.data_len = res - 14; |
| 1733 | event.eapol_tx_status.ack = acked; |
| 1734 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); |
| 1735 | } |
| 1736 | |
| 1737 | |
| 1738 | static int nl80211_init_bss(struct i802_bss *bss) |
| 1739 | { |
| 1740 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1741 | if (!bss->nl_cb) |
| 1742 | return -1; |
| 1743 | |
| 1744 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1745 | no_seq_check, NULL); |
| 1746 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1747 | process_bss_event, bss); |
| 1748 | |
| 1749 | return 0; |
| 1750 | } |
| 1751 | |
| 1752 | |
| 1753 | static void nl80211_destroy_bss(struct i802_bss *bss) |
| 1754 | { |
| 1755 | nl_cb_put(bss->nl_cb); |
| 1756 | bss->nl_cb = NULL; |
| 1757 | } |
| 1758 | |
| 1759 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1760 | static void |
| 1761 | wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv) |
| 1762 | { |
| 1763 | struct rfkill_config *rcfg; |
| 1764 | |
| 1765 | if (drv->rfkill) |
| 1766 | return; |
| 1767 | |
| 1768 | rcfg = os_zalloc(sizeof(*rcfg)); |
| 1769 | if (!rcfg) |
| 1770 | return; |
| 1771 | |
| 1772 | rcfg->ctx = drv; |
| 1773 | |
| 1774 | /* rfkill uses netdev sysfs for initialization. However, P2P Device is |
| 1775 | * not associated with a netdev, so use the name of some other interface |
| 1776 | * sharing the same wiphy as the P2P Device interface. |
| 1777 | * |
| 1778 | * Note: This is valid, as a P2P Device interface is always dynamically |
| 1779 | * created and is created only once another wpa_s interface was added. |
| 1780 | */ |
| 1781 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 1782 | struct nl80211_global *global = drv->global; |
| 1783 | struct wpa_driver_nl80211_data *tmp1; |
| 1784 | |
| 1785 | dl_list_for_each(tmp1, &global->interfaces, |
| 1786 | struct wpa_driver_nl80211_data, list) { |
| 1787 | if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx || |
| 1788 | !tmp1->rfkill) |
| 1789 | continue; |
| 1790 | |
| 1791 | wpa_printf(MSG_DEBUG, |
| 1792 | "nl80211: Use (%s) to initialize P2P Device rfkill", |
| 1793 | tmp1->first_bss->ifname); |
| 1794 | os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname, |
| 1795 | sizeof(rcfg->ifname)); |
| 1796 | break; |
| 1797 | } |
| 1798 | } else { |
| 1799 | os_strlcpy(rcfg->ifname, drv->first_bss->ifname, |
| 1800 | sizeof(rcfg->ifname)); |
| 1801 | } |
| 1802 | |
| 1803 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; |
| 1804 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; |
| 1805 | drv->rfkill = rfkill_init(rcfg); |
| 1806 | if (!drv->rfkill) { |
| 1807 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
| 1808 | os_free(rcfg); |
| 1809 | } |
| 1810 | } |
| 1811 | |
| 1812 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1813 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
| 1814 | void *global_priv, int hostapd, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1815 | const u8 *set_addr, |
| 1816 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1817 | { |
| 1818 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1819 | struct i802_bss *bss; |
| 1820 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1821 | if (global_priv == NULL) |
| 1822 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1823 | drv = os_zalloc(sizeof(*drv)); |
| 1824 | if (drv == NULL) |
| 1825 | return NULL; |
| 1826 | drv->global = global_priv; |
| 1827 | drv->ctx = ctx; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1828 | drv->hostapd = !!hostapd; |
| 1829 | drv->eapol_sock = -1; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1830 | |
| 1831 | /* |
| 1832 | * There is no driver capability flag for this, so assume it is |
| 1833 | * supported and disable this on first attempt to use if the driver |
| 1834 | * rejects the command due to missing support. |
| 1835 | */ |
| 1836 | drv->set_rekey_offload = 1; |
| 1837 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1838 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
| 1839 | drv->if_indices = drv->default_if_indices; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1840 | drv->if_indices_reason = drv->default_if_indices_reason; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1841 | |
| 1842 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); |
| 1843 | if (!drv->first_bss) { |
| 1844 | os_free(drv); |
| 1845 | return NULL; |
| 1846 | } |
| 1847 | bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1848 | bss->drv = drv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1849 | bss->ctx = ctx; |
| 1850 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1851 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
| 1852 | drv->monitor_ifidx = -1; |
| 1853 | drv->monitor_sock = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1854 | drv->eapol_tx_sock = -1; |
| 1855 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1856 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1857 | if (nl80211_init_bss(bss)) |
| 1858 | goto failed; |
| 1859 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1860 | 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] | 1861 | goto failed; |
| 1862 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1863 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
| 1864 | if (drv->eapol_tx_sock < 0) |
| 1865 | goto failed; |
| 1866 | |
| 1867 | if (drv->data_tx_status) { |
| 1868 | int enabled = 1; |
| 1869 | |
| 1870 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, |
| 1871 | &enabled, sizeof(enabled)) < 0) { |
| 1872 | wpa_printf(MSG_DEBUG, |
| 1873 | "nl80211: wifi status sockopt failed\n"); |
| 1874 | drv->data_tx_status = 0; |
| 1875 | if (!drv->use_monitor) |
| 1876 | drv->capa.flags &= |
| 1877 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
| 1878 | } else { |
| 1879 | eloop_register_read_sock(drv->eapol_tx_sock, |
| 1880 | wpa_driver_nl80211_handle_eapol_tx_status, |
| 1881 | drv, NULL); |
| 1882 | } |
| 1883 | } |
| 1884 | |
| 1885 | if (drv->global) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1886 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1887 | dl_list_add(&drv->global->interfaces, &drv->list); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1888 | drv->in_interface_list = 1; |
| 1889 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1890 | |
| 1891 | return bss; |
| 1892 | |
| 1893 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1894 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1895 | return NULL; |
| 1896 | } |
| 1897 | |
| 1898 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1899 | /** |
| 1900 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface |
| 1901 | * @ctx: context to be used when calling wpa_supplicant functions, |
| 1902 | * e.g., wpa_supplicant_event() |
| 1903 | * @ifname: interface name, e.g., wlan0 |
| 1904 | * @global_priv: private driver global data from global_init() |
| 1905 | * Returns: Pointer to private data, %NULL on failure |
| 1906 | */ |
| 1907 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
| 1908 | void *global_priv) |
| 1909 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1910 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
| 1911 | NULL); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1912 | } |
| 1913 | |
| 1914 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1915 | static int nl80211_register_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1916 | struct nl_handle *nl_handle, |
| 1917 | u16 type, const u8 *match, size_t match_len) |
| 1918 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1919 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1920 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1921 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1922 | char buf[30]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1923 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1924 | buf[0] = '\0'; |
| 1925 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 1926 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s", |
| 1927 | type, fc2str(type), nl_handle, buf); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1928 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1929 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) || |
| 1930 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
| 1931 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { |
| 1932 | nlmsg_free(msg); |
| 1933 | return -1; |
| 1934 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1935 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1936 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1937 | if (ret) { |
| 1938 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
| 1939 | "failed (type=%u): ret=%d (%s)", |
| 1940 | type, ret, strerror(-ret)); |
| 1941 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", |
| 1942 | match, match_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1943 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1944 | return ret; |
| 1945 | } |
| 1946 | |
| 1947 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1948 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
| 1949 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1950 | if (bss->nl_mgmt) { |
| 1951 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
| 1952 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
| 1953 | return -1; |
| 1954 | } |
| 1955 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1956 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1957 | if (bss->nl_mgmt == NULL) |
| 1958 | return -1; |
| 1959 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1960 | return 0; |
| 1961 | } |
| 1962 | |
| 1963 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1964 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
| 1965 | { |
| 1966 | nl80211_register_eloop_read(&bss->nl_mgmt, |
| 1967 | wpa_driver_nl80211_event_receive, |
| 1968 | bss->nl_cb); |
| 1969 | } |
| 1970 | |
| 1971 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1972 | static int nl80211_register_action_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1973 | const u8 *match, size_t match_len) |
| 1974 | { |
| 1975 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1976 | return nl80211_register_frame(bss, bss->nl_mgmt, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1977 | type, match, match_len); |
| 1978 | } |
| 1979 | |
| 1980 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1981 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1982 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1983 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1984 | int ret = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1985 | |
| 1986 | if (nl80211_alloc_mgmt_handle(bss)) |
| 1987 | return -1; |
| 1988 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
| 1989 | "handle %p", bss->nl_mgmt); |
| 1990 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1991 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 1992 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
| 1993 | |
| 1994 | /* register for any AUTH message */ |
| 1995 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); |
| 1996 | } |
| 1997 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1998 | #ifdef CONFIG_INTERWORKING |
| 1999 | /* QoS Map Configure */ |
| 2000 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2001 | ret = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 2002 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2003 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2004 | /* GAS Initial Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2005 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2006 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2007 | /* GAS Initial Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2008 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2009 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2010 | /* GAS Comeback Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2011 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2012 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2013 | /* GAS Comeback Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2014 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2015 | ret = -1; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 2016 | /* Protected GAS Initial Request */ |
| 2017 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) |
| 2018 | ret = -1; |
| 2019 | /* Protected GAS Initial Response */ |
| 2020 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) |
| 2021 | ret = -1; |
| 2022 | /* Protected GAS Comeback Request */ |
| 2023 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) |
| 2024 | ret = -1; |
| 2025 | /* Protected GAS Comeback Response */ |
| 2026 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) |
| 2027 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2028 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING */ |
| 2029 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2030 | /* P2P Public Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2031 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2032 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
| 2033 | 6) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2034 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2035 | /* P2P Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2036 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2037 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
| 2038 | 5) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2039 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2040 | #endif /* CONFIG_P2P */ |
| 2041 | #ifdef CONFIG_IEEE80211W |
| 2042 | /* SA Query Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2043 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2044 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2045 | #endif /* CONFIG_IEEE80211W */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2046 | #ifdef CONFIG_TDLS |
| 2047 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { |
| 2048 | /* TDLS Discovery Response */ |
| 2049 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
| 2050 | 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2051 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2052 | } |
| 2053 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2054 | #ifdef CONFIG_FST |
| 2055 | /* FST Action frames */ |
| 2056 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2057 | ret = -1; |
| 2058 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2059 | |
| 2060 | /* FT Action frames */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2061 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2062 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2063 | else |
| 2064 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | |
| 2065 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; |
| 2066 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2067 | /* WNM - BSS Transition Management Request */ |
| 2068 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2069 | ret = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 2070 | /* WNM-Sleep Mode Response */ |
| 2071 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2072 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2073 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2074 | #ifdef CONFIG_HS20 |
| 2075 | /* WNM-Notification */ |
| 2076 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2077 | ret = -1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2078 | #endif /* CONFIG_HS20 */ |
| 2079 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2080 | /* WMM-AC ADDTS Response */ |
| 2081 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) |
| 2082 | ret = -1; |
| 2083 | |
| 2084 | /* WMM-AC DELTS */ |
| 2085 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) |
| 2086 | ret = -1; |
| 2087 | |
| 2088 | /* Radio Measurement - Neighbor Report Response */ |
| 2089 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) |
| 2090 | ret = -1; |
| 2091 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2092 | /* Radio Measurement - Radio Measurement Request */ |
| 2093 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0) |
| 2094 | ret = -1; |
| 2095 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2096 | /* Radio Measurement - Link Measurement Request */ |
| 2097 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && |
| 2098 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) |
| 2099 | ret = -1; |
| 2100 | |
| 2101 | nl80211_mgmt_handle_register_eloop(bss); |
| 2102 | |
| 2103 | return ret; |
| 2104 | } |
| 2105 | |
| 2106 | |
| 2107 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
| 2108 | { |
| 2109 | int ret = 0; |
| 2110 | |
| 2111 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2112 | return -1; |
| 2113 | |
| 2114 | wpa_printf(MSG_DEBUG, |
| 2115 | "nl80211: Subscribe to mgmt frames with mesh handle %p", |
| 2116 | bss->nl_mgmt); |
| 2117 | |
| 2118 | /* Auth frames for mesh SAE */ |
| 2119 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2120 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2121 | (WLAN_FC_STYPE_AUTH << 4), |
| 2122 | NULL, 0) < 0) |
| 2123 | ret = -1; |
| 2124 | |
| 2125 | /* Mesh peering open */ |
| 2126 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) |
| 2127 | ret = -1; |
| 2128 | /* Mesh peering confirm */ |
| 2129 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) |
| 2130 | ret = -1; |
| 2131 | /* Mesh peering close */ |
| 2132 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) |
| 2133 | ret = -1; |
| 2134 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2135 | nl80211_mgmt_handle_register_eloop(bss); |
| 2136 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2137 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2138 | } |
| 2139 | |
| 2140 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2141 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
| 2142 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2143 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2144 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2145 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2146 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
| 2147 | 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] | 2148 | if (ret) { |
| 2149 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " |
| 2150 | "failed: ret=%d (%s)", |
| 2151 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2152 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2153 | return ret; |
| 2154 | } |
| 2155 | |
| 2156 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2157 | static int nl80211_action_subscribe_ap(struct i802_bss *bss) |
| 2158 | { |
| 2159 | int ret = 0; |
| 2160 | |
| 2161 | /* Public Action frames */ |
| 2162 | if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0) |
| 2163 | ret = -1; |
| 2164 | /* RRM Measurement Report */ |
| 2165 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0) |
| 2166 | ret = -1; |
| 2167 | /* RRM Neighbor Report Request */ |
| 2168 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0) |
| 2169 | ret = -1; |
| 2170 | /* FT Action frames */ |
| 2171 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
| 2172 | ret = -1; |
| 2173 | #ifdef CONFIG_IEEE80211W |
| 2174 | /* SA Query */ |
| 2175 | if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0) |
| 2176 | ret = -1; |
| 2177 | #endif /* CONFIG_IEEE80211W */ |
| 2178 | /* Protected Dual of Public Action */ |
| 2179 | if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0) |
| 2180 | ret = -1; |
| 2181 | /* WNM */ |
| 2182 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0) |
| 2183 | ret = -1; |
| 2184 | /* WMM */ |
| 2185 | if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0) |
| 2186 | ret = -1; |
| 2187 | #ifdef CONFIG_FST |
| 2188 | /* FST Action frames */ |
| 2189 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2190 | ret = -1; |
| 2191 | #endif /* CONFIG_FST */ |
| 2192 | /* Vendor-specific */ |
| 2193 | if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0) |
| 2194 | ret = -1; |
| 2195 | |
| 2196 | return ret; |
| 2197 | } |
| 2198 | |
| 2199 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2200 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
| 2201 | { |
| 2202 | static const int stypes[] = { |
| 2203 | WLAN_FC_STYPE_AUTH, |
| 2204 | WLAN_FC_STYPE_ASSOC_REQ, |
| 2205 | WLAN_FC_STYPE_REASSOC_REQ, |
| 2206 | WLAN_FC_STYPE_DISASSOC, |
| 2207 | WLAN_FC_STYPE_DEAUTH, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2208 | WLAN_FC_STYPE_PROBE_REQ, |
| 2209 | /* Beacon doesn't work as mac80211 doesn't currently allow |
| 2210 | * it, but it wouldn't really be the right thing anyway as |
| 2211 | * it isn't per interface ... maybe just dump the scan |
| 2212 | * results periodically for OLBC? |
| 2213 | */ |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2214 | /* WLAN_FC_STYPE_BEACON, */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2215 | }; |
| 2216 | unsigned int i; |
| 2217 | |
| 2218 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2219 | return -1; |
| 2220 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2221 | "handle %p", bss->nl_mgmt); |
| 2222 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2223 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2224 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2225 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2226 | (stypes[i] << 4), |
| 2227 | NULL, 0) < 0) { |
| 2228 | goto out_err; |
| 2229 | } |
| 2230 | } |
| 2231 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2232 | if (nl80211_action_subscribe_ap(bss)) |
| 2233 | goto out_err; |
| 2234 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2235 | if (nl80211_register_spurious_class3(bss)) |
| 2236 | goto out_err; |
| 2237 | |
| 2238 | if (nl80211_get_wiphy_data_ap(bss) == NULL) |
| 2239 | goto out_err; |
| 2240 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2241 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2242 | return 0; |
| 2243 | |
| 2244 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2245 | nl_destroy_handles(&bss->nl_mgmt); |
| 2246 | return -1; |
| 2247 | } |
| 2248 | |
| 2249 | |
| 2250 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
| 2251 | { |
| 2252 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2253 | return -1; |
| 2254 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2255 | "handle %p (device SME)", bss->nl_mgmt); |
| 2256 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2257 | if (nl80211_action_subscribe_ap(bss)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2258 | goto out_err; |
| 2259 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2260 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2261 | return 0; |
| 2262 | |
| 2263 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2264 | nl_destroy_handles(&bss->nl_mgmt); |
| 2265 | return -1; |
| 2266 | } |
| 2267 | |
| 2268 | |
| 2269 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
| 2270 | { |
| 2271 | if (bss->nl_mgmt == NULL) |
| 2272 | return; |
| 2273 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
| 2274 | "(%s)", bss->nl_mgmt, reason); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2275 | nl80211_destroy_eloop_handle(&bss->nl_mgmt); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2276 | |
| 2277 | nl80211_put_wiphy_data_ap(bss); |
| 2278 | } |
| 2279 | |
| 2280 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2281 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
| 2282 | { |
| 2283 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); |
| 2284 | } |
| 2285 | |
| 2286 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2287 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
| 2288 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2289 | struct nl_msg *msg; |
| 2290 | int ret; |
| 2291 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2292 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
| 2293 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2294 | |
| 2295 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", |
| 2296 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2297 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2298 | } |
| 2299 | |
| 2300 | |
| 2301 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
| 2302 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2303 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2304 | int ret; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2305 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2306 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
| 2307 | NL80211_CMD_STOP_P2P_DEVICE); |
| 2308 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2309 | |
| 2310 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
| 2311 | start ? "Start" : "Stop", |
| 2312 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2313 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2314 | return ret; |
| 2315 | } |
| 2316 | |
| 2317 | |
| 2318 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
| 2319 | { |
| 2320 | enum nl80211_iftype nlmode; |
| 2321 | |
| 2322 | nlmode = nl80211_get_ifmode(bss); |
| 2323 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2324 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, |
| 2325 | bss->ifname, up); |
| 2326 | } |
| 2327 | |
| 2328 | /* P2P Device has start/stop which is equivalent */ |
| 2329 | return nl80211_set_p2pdev(bss, up); |
| 2330 | } |
| 2331 | |
| 2332 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2333 | #ifdef CONFIG_TESTING_OPTIONS |
| 2334 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) |
| 2335 | { |
| 2336 | /* struct wpa_driver_nl80211_data *drv = arg; */ |
| 2337 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 2338 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2339 | |
| 2340 | |
| 2341 | wpa_printf(MSG_DEBUG, |
| 2342 | "nl80211: QCA vendor test command response received"); |
| 2343 | |
| 2344 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2345 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2346 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { |
| 2347 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); |
| 2348 | return NL_SKIP; |
| 2349 | } |
| 2350 | |
| 2351 | wpa_hexdump(MSG_DEBUG, |
| 2352 | "nl80211: Received QCA vendor test command response", |
| 2353 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), |
| 2354 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); |
| 2355 | |
| 2356 | return NL_SKIP; |
| 2357 | } |
| 2358 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2359 | |
| 2360 | |
| 2361 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) |
| 2362 | { |
| 2363 | #ifdef CONFIG_TESTING_OPTIONS |
| 2364 | struct nl_msg *msg; |
| 2365 | struct nlattr *params; |
| 2366 | int ret; |
| 2367 | |
| 2368 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2369 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2370 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2371 | QCA_NL80211_VENDOR_SUBCMD_TEST) || |
| 2372 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 2373 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { |
| 2374 | nlmsg_free(msg); |
| 2375 | return; |
| 2376 | } |
| 2377 | nla_nest_end(msg, params); |
| 2378 | |
| 2379 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv); |
| 2380 | wpa_printf(MSG_DEBUG, |
| 2381 | "nl80211: QCA vendor test command returned %d (%s)", |
| 2382 | ret, strerror(-ret)); |
| 2383 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2384 | } |
| 2385 | |
| 2386 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2387 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2388 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2389 | const u8 *set_addr, int first, |
| 2390 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2391 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2392 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2393 | int send_rfkill_event = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2394 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2395 | |
| 2396 | drv->ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2397 | bss->ifindex = drv->ifindex; |
| 2398 | bss->wdev_id = drv->global->if_add_wdevid; |
| 2399 | bss->wdev_id_set = drv->global->if_add_wdevid_set; |
| 2400 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2401 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
| 2402 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2403 | drv->global->if_add_wdevid_set = 0; |
| 2404 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2405 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2406 | bss->static_ap = 1; |
| 2407 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 2408 | if (first && |
| 2409 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && |
| 2410 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) |
| 2411 | drv->start_iface_up = 1; |
| 2412 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2413 | if (wpa_driver_nl80211_capa(drv)) |
| 2414 | return -1; |
| 2415 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2416 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
| 2417 | return -1; |
| 2418 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2419 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
| 2420 | bss->ifname, drv->phyname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2421 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2422 | if (set_addr && |
| 2423 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || |
| 2424 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2425 | set_addr))) |
| 2426 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2427 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2428 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2429 | drv->start_mode_ap = 1; |
| 2430 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2431 | if (drv->hostapd || bss->static_ap) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2432 | nlmode = NL80211_IFTYPE_AP; |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 2433 | else if (bss->if_dynamic || |
| 2434 | nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2435 | nlmode = nl80211_get_ifmode(bss); |
| 2436 | else |
| 2437 | nlmode = NL80211_IFTYPE_STATION; |
| 2438 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2439 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2440 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2441 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2442 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2443 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2444 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2445 | nl80211_get_macaddr(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2446 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2447 | wpa_driver_nl80211_drv_init_rfkill(drv); |
| 2448 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2449 | if (!rfkill_is_blocked(drv->rfkill)) { |
| 2450 | int ret = i802_set_iface_flags(bss, 1); |
| 2451 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2452 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
| 2453 | "interface '%s' UP", bss->ifname); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2454 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2455 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2456 | |
| 2457 | if (is_p2p_net_interface(nlmode)) |
| 2458 | nl80211_disable_11b_rates(bss->drv, |
| 2459 | bss->drv->ifindex, 1); |
| 2460 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2461 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2462 | return ret; |
| 2463 | } else { |
| 2464 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " |
| 2465 | "interface '%s' due to rfkill", bss->ifname); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2466 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 2467 | drv->if_disabled = 1; |
| 2468 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2469 | send_rfkill_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2470 | } |
| 2471 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2472 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2473 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
| 2474 | 1, IF_OPER_DORMANT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2475 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2476 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2477 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2478 | bss->addr)) |
| 2479 | return -1; |
| 2480 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); |
| 2481 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2482 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2483 | if (send_rfkill_event) { |
| 2484 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, |
| 2485 | drv, drv->ctx); |
| 2486 | } |
| 2487 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2488 | if (drv->vendor_cmd_test_avail) |
| 2489 | qca_vendor_test(drv); |
| 2490 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2491 | return 0; |
| 2492 | } |
| 2493 | |
| 2494 | |
| 2495 | static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv) |
| 2496 | { |
| 2497 | struct nl_msg *msg; |
| 2498 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2499 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
| 2500 | drv->ifindex); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2501 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2502 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2503 | } |
| 2504 | |
| 2505 | |
| 2506 | /** |
| 2507 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2508 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2509 | * |
| 2510 | * Shut down driver interface and processing of driver events. Free |
| 2511 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). |
| 2512 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2513 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2514 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2515 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2516 | unsigned int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2517 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2518 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
| 2519 | bss->ifname, drv->disabled_11b_rates); |
| 2520 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2521 | bss->in_deinit = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2522 | if (drv->data_tx_status) |
| 2523 | eloop_unregister_read_sock(drv->eapol_tx_sock); |
| 2524 | if (drv->eapol_tx_sock >= 0) |
| 2525 | close(drv->eapol_tx_sock); |
| 2526 | |
| 2527 | if (bss->nl_preq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2528 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 2529 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2530 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 2531 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2532 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2533 | "interface %s from bridge %s: %s", |
| 2534 | bss->ifname, bss->brname, strerror(errno)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2535 | if (drv->rtnl_sk) |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 2536 | nl80211_handle_destroy(drv->rtnl_sk); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2537 | } |
| 2538 | if (bss->added_bridge) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2539 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
| 2540 | 0) < 0) |
| 2541 | wpa_printf(MSG_INFO, |
| 2542 | "nl80211: Could not set bridge %s down", |
| 2543 | bss->brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2544 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2545 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2546 | "bridge %s: %s", |
| 2547 | bss->brname, strerror(errno)); |
| 2548 | } |
| 2549 | |
| 2550 | nl80211_remove_monitor_interface(drv); |
| 2551 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2552 | if (is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2553 | wpa_driver_nl80211_del_beacon(drv); |
| 2554 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2555 | if (drv->eapol_sock >= 0) { |
| 2556 | eloop_unregister_read_sock(drv->eapol_sock); |
| 2557 | close(drv->eapol_sock); |
| 2558 | } |
| 2559 | |
| 2560 | if (drv->if_indices != drv->default_if_indices) |
| 2561 | os_free(drv->if_indices); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2562 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2563 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
| 2564 | os_free(drv->if_indices_reason); |
| 2565 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2566 | if (drv->disabled_11b_rates) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2567 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 2568 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2569 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
| 2570 | IF_OPER_UP); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 2571 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2572 | rfkill_deinit(drv->rfkill); |
| 2573 | |
| 2574 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 2575 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2576 | if (!drv->start_iface_up) |
| 2577 | (void) i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2578 | |
| 2579 | if (drv->addr_changed) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2580 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 2581 | 0) < 0) { |
| 2582 | wpa_printf(MSG_DEBUG, |
| 2583 | "nl80211: Could not set interface down to restore permanent MAC address"); |
| 2584 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2585 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2586 | drv->perm_addr) < 0) { |
| 2587 | wpa_printf(MSG_DEBUG, |
| 2588 | "nl80211: Could not restore permanent MAC address"); |
| 2589 | } |
| 2590 | } |
| 2591 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2592 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2593 | if (!drv->hostapd || !drv->start_mode_ap) |
| 2594 | wpa_driver_nl80211_set_mode(bss, |
| 2595 | NL80211_IFTYPE_STATION); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2596 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2597 | } else { |
| 2598 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
| 2599 | nl80211_del_p2pdev(bss); |
| 2600 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2601 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2602 | nl80211_destroy_bss(drv->first_bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2603 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2604 | os_free(drv->filter_ssids); |
| 2605 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2606 | os_free(drv->auth_ie); |
| 2607 | |
| 2608 | if (drv->in_interface_list) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2609 | dl_list_del(&drv->list); |
| 2610 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2611 | os_free(drv->extended_capa); |
| 2612 | os_free(drv->extended_capa_mask); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2613 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 2614 | os_free(drv->iface_ext_capa[i].ext_capa); |
| 2615 | os_free(drv->iface_ext_capa[i].ext_capa_mask); |
| 2616 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2617 | os_free(drv->first_bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2618 | os_free(drv); |
| 2619 | } |
| 2620 | |
| 2621 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2622 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
| 2623 | { |
| 2624 | switch (alg) { |
| 2625 | case WPA_ALG_WEP: |
| 2626 | if (key_len == 5) |
| 2627 | return WLAN_CIPHER_SUITE_WEP40; |
| 2628 | return WLAN_CIPHER_SUITE_WEP104; |
| 2629 | case WPA_ALG_TKIP: |
| 2630 | return WLAN_CIPHER_SUITE_TKIP; |
| 2631 | case WPA_ALG_CCMP: |
| 2632 | return WLAN_CIPHER_SUITE_CCMP; |
| 2633 | case WPA_ALG_GCMP: |
| 2634 | return WLAN_CIPHER_SUITE_GCMP; |
| 2635 | case WPA_ALG_CCMP_256: |
| 2636 | return WLAN_CIPHER_SUITE_CCMP_256; |
| 2637 | case WPA_ALG_GCMP_256: |
| 2638 | return WLAN_CIPHER_SUITE_GCMP_256; |
| 2639 | case WPA_ALG_IGTK: |
| 2640 | return WLAN_CIPHER_SUITE_AES_CMAC; |
| 2641 | case WPA_ALG_BIP_GMAC_128: |
| 2642 | return WLAN_CIPHER_SUITE_BIP_GMAC_128; |
| 2643 | case WPA_ALG_BIP_GMAC_256: |
| 2644 | return WLAN_CIPHER_SUITE_BIP_GMAC_256; |
| 2645 | case WPA_ALG_BIP_CMAC_256: |
| 2646 | return WLAN_CIPHER_SUITE_BIP_CMAC_256; |
| 2647 | case WPA_ALG_SMS4: |
| 2648 | return WLAN_CIPHER_SUITE_SMS4; |
| 2649 | case WPA_ALG_KRK: |
| 2650 | return WLAN_CIPHER_SUITE_KRK; |
| 2651 | case WPA_ALG_NONE: |
| 2652 | case WPA_ALG_PMK: |
| 2653 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", |
| 2654 | alg); |
| 2655 | return 0; |
| 2656 | } |
| 2657 | |
| 2658 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", |
| 2659 | alg); |
| 2660 | return 0; |
| 2661 | } |
| 2662 | |
| 2663 | |
| 2664 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) |
| 2665 | { |
| 2666 | switch (cipher) { |
| 2667 | case WPA_CIPHER_CCMP_256: |
| 2668 | return WLAN_CIPHER_SUITE_CCMP_256; |
| 2669 | case WPA_CIPHER_GCMP_256: |
| 2670 | return WLAN_CIPHER_SUITE_GCMP_256; |
| 2671 | case WPA_CIPHER_CCMP: |
| 2672 | return WLAN_CIPHER_SUITE_CCMP; |
| 2673 | case WPA_CIPHER_GCMP: |
| 2674 | return WLAN_CIPHER_SUITE_GCMP; |
| 2675 | case WPA_CIPHER_TKIP: |
| 2676 | return WLAN_CIPHER_SUITE_TKIP; |
| 2677 | case WPA_CIPHER_WEP104: |
| 2678 | return WLAN_CIPHER_SUITE_WEP104; |
| 2679 | case WPA_CIPHER_WEP40: |
| 2680 | return WLAN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2681 | case WPA_CIPHER_GTK_NOT_USED: |
| 2682 | return WLAN_CIPHER_SUITE_NO_GROUP_ADDR; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2683 | } |
| 2684 | |
| 2685 | return 0; |
| 2686 | } |
| 2687 | |
| 2688 | |
| 2689 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], |
| 2690 | int max_suites) |
| 2691 | { |
| 2692 | int num_suites = 0; |
| 2693 | |
| 2694 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) |
| 2695 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP_256; |
| 2696 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
| 2697 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP_256; |
| 2698 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
| 2699 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP; |
| 2700 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
| 2701 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP; |
| 2702 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
| 2703 | suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP; |
| 2704 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
| 2705 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104; |
| 2706 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
| 2707 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40; |
| 2708 | |
| 2709 | return num_suites; |
| 2710 | } |
| 2711 | |
| 2712 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2713 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2714 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 2715 | const u8 *key, size_t key_len) |
| 2716 | { |
| 2717 | struct nl_msg *msg; |
| 2718 | int ret; |
| 2719 | |
| 2720 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
| 2721 | return 0; |
| 2722 | |
| 2723 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2724 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2725 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2726 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || |
| 2727 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { |
| 2728 | nl80211_nlmsg_clear(msg); |
| 2729 | nlmsg_free(msg); |
| 2730 | return -1; |
| 2731 | } |
| 2732 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 2733 | if (ret) { |
| 2734 | wpa_printf(MSG_DEBUG, |
| 2735 | "nl80211: Key management set key failed: ret=%d (%s)", |
| 2736 | ret, strerror(-ret)); |
| 2737 | } |
| 2738 | |
| 2739 | return ret; |
| 2740 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2741 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2742 | |
| 2743 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2744 | 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] | 2745 | enum wpa_alg alg, const u8 *addr, |
| 2746 | int key_idx, int set_tx, |
| 2747 | const u8 *seq, size_t seq_len, |
| 2748 | const u8 *key, size_t key_len) |
| 2749 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2750 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2751 | int ifindex; |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2752 | struct nl_msg *msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2753 | int ret; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2754 | int tdls = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2755 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2756 | /* Ignore for P2P Device */ |
| 2757 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2758 | return 0; |
| 2759 | |
| 2760 | ifindex = if_nametoindex(ifname); |
| 2761 | 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] | 2762 | "set_tx=%d seq_len=%lu key_len=%lu", |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2763 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2764 | (unsigned long) seq_len, (unsigned long) key_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2765 | #ifdef CONFIG_TDLS |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2766 | if (key_idx == -1) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2767 | key_idx = 0; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2768 | tdls = 1; |
| 2769 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2770 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2771 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2772 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2773 | if (alg == WPA_ALG_PMK && |
| 2774 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { |
| 2775 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
| 2776 | __func__); |
| 2777 | ret = issue_key_mgmt_set_key(drv, key, key_len); |
| 2778 | return ret; |
| 2779 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2780 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2781 | |
| 2782 | if (alg == WPA_ALG_NONE) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2783 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
| 2784 | if (!msg) |
| 2785 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2786 | } else { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2787 | u32 suite; |
| 2788 | |
| 2789 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 2790 | if (!suite) |
| 2791 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2792 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
| 2793 | if (!msg || |
| 2794 | nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2795 | nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, suite)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2796 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2797 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2798 | } |
| 2799 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2800 | if (seq && seq_len) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2801 | if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq)) |
| 2802 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2803 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
| 2804 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2805 | |
| 2806 | if (addr && !is_broadcast_ether_addr(addr)) { |
| 2807 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2808 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 2809 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2810 | |
| 2811 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { |
| 2812 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2813 | if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, |
| 2814 | NL80211_KEYTYPE_GROUP)) |
| 2815 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2816 | } |
| 2817 | } else if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2818 | struct nlattr *types; |
| 2819 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2820 | wpa_printf(MSG_DEBUG, " broadcast key"); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2821 | |
| 2822 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2823 | if (!types || |
| 2824 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 2825 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2826 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2827 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2828 | if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2829 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2830 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2831 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2832 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
| 2833 | ret = 0; |
| 2834 | if (ret) |
| 2835 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", |
| 2836 | ret, strerror(-ret)); |
| 2837 | |
| 2838 | /* |
| 2839 | * If we failed or don't need to set the default TX key (below), |
| 2840 | * we're done here. |
| 2841 | */ |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2842 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2843 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2844 | if (is_ap_interface(drv->nlmode) && addr && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2845 | !is_broadcast_ether_addr(addr)) |
| 2846 | return ret; |
| 2847 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2848 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
| 2849 | if (!msg || |
| 2850 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2851 | nla_put_flag(msg, (alg == WPA_ALG_IGTK || |
| 2852 | alg == WPA_ALG_BIP_GMAC_128 || |
| 2853 | alg == WPA_ALG_BIP_GMAC_256 || |
| 2854 | alg == WPA_ALG_BIP_CMAC_256) ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2855 | NL80211_ATTR_KEY_DEFAULT_MGMT : |
| 2856 | NL80211_ATTR_KEY_DEFAULT)) |
| 2857 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2858 | if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2859 | struct nlattr *types; |
| 2860 | |
| 2861 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2862 | if (!types || |
| 2863 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 2864 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2865 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2866 | } else if (addr) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2867 | struct nlattr *types; |
| 2868 | |
| 2869 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2870 | if (!types || |
| 2871 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) |
| 2872 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2873 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2874 | } |
| 2875 | |
| 2876 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 2877 | if (ret == -ENOENT) |
| 2878 | ret = 0; |
| 2879 | if (ret) |
| 2880 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " |
| 2881 | "err=%d %s)", ret, strerror(-ret)); |
| 2882 | return ret; |
| 2883 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2884 | fail: |
| 2885 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2886 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2887 | return -ENOBUFS; |
| 2888 | } |
| 2889 | |
| 2890 | |
| 2891 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
| 2892 | int key_idx, int defkey, |
| 2893 | const u8 *seq, size_t seq_len, |
| 2894 | const u8 *key, size_t key_len) |
| 2895 | { |
| 2896 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2897 | u32 suite; |
| 2898 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2899 | if (!key_attr) |
| 2900 | return -1; |
| 2901 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2902 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 2903 | if (!suite) |
| 2904 | return -1; |
| 2905 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2906 | if (defkey && alg == WPA_ALG_IGTK) { |
| 2907 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) |
| 2908 | return -1; |
| 2909 | } else if (defkey) { |
| 2910 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) |
| 2911 | return -1; |
| 2912 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2913 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2914 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2915 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2916 | (seq && seq_len && |
| 2917 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || |
| 2918 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) |
| 2919 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2920 | |
| 2921 | nla_nest_end(msg, key_attr); |
| 2922 | |
| 2923 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2924 | } |
| 2925 | |
| 2926 | |
| 2927 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
| 2928 | struct nl_msg *msg) |
| 2929 | { |
| 2930 | int i, privacy = 0; |
| 2931 | struct nlattr *nl_keys, *nl_key; |
| 2932 | |
| 2933 | for (i = 0; i < 4; i++) { |
| 2934 | if (!params->wep_key[i]) |
| 2935 | continue; |
| 2936 | privacy = 1; |
| 2937 | break; |
| 2938 | } |
| 2939 | if (params->wps == WPS_MODE_PRIVACY) |
| 2940 | privacy = 1; |
| 2941 | if (params->pairwise_suite && |
| 2942 | params->pairwise_suite != WPA_CIPHER_NONE) |
| 2943 | privacy = 1; |
| 2944 | |
| 2945 | if (!privacy) |
| 2946 | return 0; |
| 2947 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2948 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 2949 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2950 | |
| 2951 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); |
| 2952 | if (!nl_keys) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2953 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2954 | |
| 2955 | for (i = 0; i < 4; i++) { |
| 2956 | if (!params->wep_key[i]) |
| 2957 | continue; |
| 2958 | |
| 2959 | nl_key = nla_nest_start(msg, i); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2960 | if (!nl_key || |
| 2961 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], |
| 2962 | params->wep_key[i]) || |
| 2963 | nla_put_u32(msg, NL80211_KEY_CIPHER, |
| 2964 | params->wep_key_len[i] == 5 ? |
| 2965 | WLAN_CIPHER_SUITE_WEP40 : |
| 2966 | WLAN_CIPHER_SUITE_WEP104) || |
| 2967 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
| 2968 | (i == params->wep_tx_keyidx && |
| 2969 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) |
| 2970 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2971 | |
| 2972 | nla_nest_end(msg, nl_key); |
| 2973 | } |
| 2974 | nla_nest_end(msg, nl_keys); |
| 2975 | |
| 2976 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2977 | } |
| 2978 | |
| 2979 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2980 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 2981 | const u8 *addr, int cmd, u16 reason_code, |
| 2982 | int local_state_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2983 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2984 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2985 | struct nl_msg *msg; |
| 2986 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2987 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
| 2988 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
| 2989 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 2990 | (local_state_change && |
| 2991 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { |
| 2992 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2993 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2994 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2995 | |
| 2996 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2997 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2998 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 2999 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", |
| 3000 | reason_code, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3001 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3002 | return ret; |
| 3003 | } |
| 3004 | |
| 3005 | |
| 3006 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3007 | int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3008 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3009 | int ret; |
| 3010 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3011 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3012 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3013 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 3014 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
| 3015 | reason_code, 0); |
| 3016 | /* |
| 3017 | * For locally generated disconnect, supplicant already generates a |
| 3018 | * DEAUTH event, so ignore the event from NL80211. |
| 3019 | */ |
| 3020 | drv->ignore_next_local_disconnect = ret == 0; |
| 3021 | |
| 3022 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3023 | } |
| 3024 | |
| 3025 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3026 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
| 3027 | const u8 *addr, int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3028 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3029 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3030 | int ret; |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3031 | |
| 3032 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3033 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3034 | return nl80211_leave_ibss(drv, 1); |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 3035 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3036 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3037 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3038 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
| 3039 | __func__, MAC2STR(addr), reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3040 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 3041 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
| 3042 | reason_code, 0); |
| 3043 | /* |
| 3044 | * For locally generated deauthenticate, supplicant already generates a |
| 3045 | * DEAUTH event, so ignore the event from NL80211. |
| 3046 | */ |
| 3047 | drv->ignore_next_local_deauth = ret == 0; |
| 3048 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3049 | } |
| 3050 | |
| 3051 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3052 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
| 3053 | struct wpa_driver_auth_params *params) |
| 3054 | { |
| 3055 | int i; |
| 3056 | |
| 3057 | drv->auth_freq = params->freq; |
| 3058 | drv->auth_alg = params->auth_alg; |
| 3059 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; |
| 3060 | drv->auth_local_state_change = params->local_state_change; |
| 3061 | drv->auth_p2p = params->p2p; |
| 3062 | |
| 3063 | if (params->bssid) |
| 3064 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); |
| 3065 | else |
| 3066 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); |
| 3067 | |
| 3068 | if (params->ssid) { |
| 3069 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); |
| 3070 | drv->auth_ssid_len = params->ssid_len; |
| 3071 | } else |
| 3072 | drv->auth_ssid_len = 0; |
| 3073 | |
| 3074 | |
| 3075 | os_free(drv->auth_ie); |
| 3076 | drv->auth_ie = NULL; |
| 3077 | drv->auth_ie_len = 0; |
| 3078 | if (params->ie) { |
| 3079 | drv->auth_ie = os_malloc(params->ie_len); |
| 3080 | if (drv->auth_ie) { |
| 3081 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); |
| 3082 | drv->auth_ie_len = params->ie_len; |
| 3083 | } |
| 3084 | } |
| 3085 | |
| 3086 | for (i = 0; i < 4; i++) { |
| 3087 | if (params->wep_key[i] && params->wep_key_len[i] && |
| 3088 | params->wep_key_len[i] <= 16) { |
| 3089 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], |
| 3090 | params->wep_key_len[i]); |
| 3091 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; |
| 3092 | } else |
| 3093 | drv->auth_wep_key_len[i] = 0; |
| 3094 | } |
| 3095 | } |
| 3096 | |
| 3097 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3098 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
| 3099 | { |
| 3100 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3101 | |
| 3102 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) |
| 3103 | return; |
| 3104 | |
| 3105 | /* |
| 3106 | * Looks like we failed to unmask 11b rates previously. This could |
| 3107 | * happen, e.g., if the interface was down at the point in time when a |
| 3108 | * P2P group was terminated. |
| 3109 | */ |
| 3110 | wpa_printf(MSG_DEBUG, |
| 3111 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", |
| 3112 | bss->ifname); |
| 3113 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 3114 | } |
| 3115 | |
| 3116 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3117 | static int wpa_driver_nl80211_authenticate( |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3118 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3119 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3120 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3121 | int ret = -1, i; |
| 3122 | struct nl_msg *msg; |
| 3123 | enum nl80211_auth_type type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3124 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3125 | int count = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3126 | int is_retry; |
| 3127 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3128 | nl80211_unmask_11b_rates(bss); |
| 3129 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3130 | is_retry = drv->retry_auth; |
| 3131 | drv->retry_auth = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3132 | drv->ignore_deauth_event = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3133 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3134 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3135 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3136 | if (params->bssid) |
| 3137 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 3138 | else |
| 3139 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3140 | /* FIX: IBSS mode */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3141 | nlmode = params->p2p ? |
| 3142 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 3143 | if (drv->nlmode != nlmode && |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3144 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3145 | return -1; |
| 3146 | |
| 3147 | retry: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3148 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
| 3149 | drv->ifindex); |
| 3150 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3151 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
| 3152 | if (!msg) |
| 3153 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3154 | |
| 3155 | for (i = 0; i < 4; i++) { |
| 3156 | if (!params->wep_key[i]) |
| 3157 | continue; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3158 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3159 | NULL, i, |
| 3160 | i == params->wep_tx_keyidx, NULL, 0, |
| 3161 | params->wep_key[i], |
| 3162 | params->wep_key_len[i]); |
| 3163 | if (params->wep_tx_keyidx != i) |
| 3164 | continue; |
| 3165 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3166 | params->wep_key[i], params->wep_key_len[i])) |
| 3167 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3168 | } |
| 3169 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3170 | if (params->bssid) { |
| 3171 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 3172 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3173 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 3174 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3175 | } |
| 3176 | if (params->freq) { |
| 3177 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3178 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
| 3179 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3180 | } |
| 3181 | if (params->ssid) { |
| 3182 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 3183 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3184 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 3185 | params->ssid)) |
| 3186 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3187 | } |
| 3188 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3189 | if (params->ie && |
| 3190 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) |
| 3191 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3192 | if (params->auth_data) { |
| 3193 | wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data, |
| 3194 | params->auth_data_len); |
| 3195 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len, |
| 3196 | params->auth_data)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3197 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3198 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3199 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 3200 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 3201 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 3202 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 3203 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 3204 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 3205 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 3206 | type = NL80211_AUTHTYPE_FT; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3207 | else if (params->auth_alg & WPA_AUTH_ALG_SAE) |
| 3208 | type = NL80211_AUTHTYPE_SAE; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 3209 | else if (params->auth_alg & WPA_AUTH_ALG_FILS) |
| 3210 | type = NL80211_AUTHTYPE_FILS_SK; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3211 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3212 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3213 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3214 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 3215 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3216 | if (params->local_state_change) { |
| 3217 | wpa_printf(MSG_DEBUG, " * Local state change only"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3218 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
| 3219 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3220 | } |
| 3221 | |
| 3222 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3223 | msg = NULL; |
| 3224 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3225 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 3226 | "nl80211: MLME command failed (auth): ret=%d (%s)", |
| 3227 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3228 | count++; |
| 3229 | if (ret == -EALREADY && count == 1 && params->bssid && |
| 3230 | !params->local_state_change) { |
| 3231 | /* |
| 3232 | * mac80211 does not currently accept new |
| 3233 | * authentication if we are already authenticated. As a |
| 3234 | * workaround, force deauthentication and try again. |
| 3235 | */ |
| 3236 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " |
| 3237 | "after forced deauthentication"); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3238 | drv->ignore_deauth_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3239 | wpa_driver_nl80211_deauthenticate( |
| 3240 | bss, params->bssid, |
| 3241 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 3242 | nlmsg_free(msg); |
| 3243 | goto retry; |
| 3244 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3245 | |
| 3246 | if (ret == -ENOENT && params->freq && !is_retry) { |
| 3247 | /* |
| 3248 | * cfg80211 has likely expired the BSS entry even |
| 3249 | * though it was previously available in our internal |
| 3250 | * BSS table. To recover quickly, start a single |
| 3251 | * channel scan on the specified channel. |
| 3252 | */ |
| 3253 | struct wpa_driver_scan_params scan; |
| 3254 | int freqs[2]; |
| 3255 | |
| 3256 | os_memset(&scan, 0, sizeof(scan)); |
| 3257 | scan.num_ssids = 1; |
| 3258 | if (params->ssid) { |
| 3259 | scan.ssids[0].ssid = params->ssid; |
| 3260 | scan.ssids[0].ssid_len = params->ssid_len; |
| 3261 | } |
| 3262 | freqs[0] = params->freq; |
| 3263 | freqs[1] = 0; |
| 3264 | scan.freqs = freqs; |
| 3265 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " |
| 3266 | "channel scan to refresh cfg80211 BSS " |
| 3267 | "entry"); |
| 3268 | ret = wpa_driver_nl80211_scan(bss, &scan); |
| 3269 | if (ret == 0) { |
| 3270 | nl80211_copy_auth_params(drv, params); |
| 3271 | drv->scan_for_auth = 1; |
| 3272 | } |
| 3273 | } else if (is_retry) { |
| 3274 | /* |
| 3275 | * Need to indicate this with an event since the return |
| 3276 | * value from the retry is not delivered to core code. |
| 3277 | */ |
| 3278 | union wpa_event_data event; |
| 3279 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " |
| 3280 | "failed"); |
| 3281 | os_memset(&event, 0, sizeof(event)); |
| 3282 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, |
| 3283 | ETH_ALEN); |
| 3284 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, |
| 3285 | &event); |
| 3286 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3287 | } else { |
| 3288 | wpa_printf(MSG_DEBUG, |
| 3289 | "nl80211: Authentication request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3290 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3291 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3292 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3293 | nlmsg_free(msg); |
| 3294 | return ret; |
| 3295 | } |
| 3296 | |
| 3297 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3298 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3299 | { |
| 3300 | struct wpa_driver_auth_params params; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3301 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3302 | int i; |
| 3303 | |
| 3304 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); |
| 3305 | |
| 3306 | os_memset(¶ms, 0, sizeof(params)); |
| 3307 | params.freq = drv->auth_freq; |
| 3308 | params.auth_alg = drv->auth_alg; |
| 3309 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; |
| 3310 | params.local_state_change = drv->auth_local_state_change; |
| 3311 | params.p2p = drv->auth_p2p; |
| 3312 | |
| 3313 | if (!is_zero_ether_addr(drv->auth_bssid_)) |
| 3314 | params.bssid = drv->auth_bssid_; |
| 3315 | |
| 3316 | if (drv->auth_ssid_len) { |
| 3317 | params.ssid = drv->auth_ssid; |
| 3318 | params.ssid_len = drv->auth_ssid_len; |
| 3319 | } |
| 3320 | |
| 3321 | params.ie = drv->auth_ie; |
| 3322 | params.ie_len = drv->auth_ie_len; |
| 3323 | |
| 3324 | for (i = 0; i < 4; i++) { |
| 3325 | if (drv->auth_wep_key_len[i]) { |
| 3326 | params.wep_key[i] = drv->auth_wep_key[i]; |
| 3327 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; |
| 3328 | } |
| 3329 | } |
| 3330 | |
| 3331 | drv->retry_auth = 1; |
| 3332 | return wpa_driver_nl80211_authenticate(bss, ¶ms); |
| 3333 | } |
| 3334 | |
| 3335 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3336 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
| 3337 | const void *data, size_t len, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3338 | int encrypt, int noack, |
| 3339 | unsigned int freq, int no_cck, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3340 | int offchanok, unsigned int wait_time, |
| 3341 | const u16 *csa_offs, |
| 3342 | size_t csa_offs_len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3343 | { |
| 3344 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3345 | u64 cookie; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3346 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3347 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 3348 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3349 | freq = nl80211_get_assoc_freq(drv); |
| 3350 | wpa_printf(MSG_DEBUG, |
| 3351 | "nl80211: send_frame - Use assoc_freq=%u for IBSS", |
| 3352 | freq); |
| 3353 | } |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3354 | if (freq == 0) { |
| 3355 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", |
| 3356 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3357 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3358 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3359 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3360 | if (drv->use_monitor) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3361 | 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] | 3362 | freq, bss->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3363 | return nl80211_send_monitor(drv, data, len, encrypt, noack); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3364 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3365 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3366 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3367 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3368 | &cookie, no_cck, noack, offchanok, |
| 3369 | csa_offs, csa_offs_len); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3370 | if (res == 0 && !noack) { |
| 3371 | const struct ieee80211_mgmt *mgmt; |
| 3372 | u16 fc; |
| 3373 | |
| 3374 | mgmt = (const struct ieee80211_mgmt *) data; |
| 3375 | fc = le_to_host16(mgmt->frame_control); |
| 3376 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3377 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { |
| 3378 | wpa_printf(MSG_MSGDUMP, |
| 3379 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", |
| 3380 | (long long unsigned int) |
| 3381 | drv->send_action_cookie, |
| 3382 | (long long unsigned int) cookie); |
| 3383 | drv->send_action_cookie = cookie; |
| 3384 | } |
| 3385 | } |
| 3386 | |
| 3387 | return res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3388 | } |
| 3389 | |
| 3390 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3391 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
| 3392 | size_t data_len, int noack, |
| 3393 | unsigned int freq, int no_cck, |
| 3394 | int offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3395 | unsigned int wait_time, |
| 3396 | const u16 *csa_offs, |
| 3397 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3398 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3399 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3400 | struct ieee80211_mgmt *mgmt; |
| 3401 | int encrypt = 1; |
| 3402 | u16 fc; |
| 3403 | |
| 3404 | mgmt = (struct ieee80211_mgmt *) data; |
| 3405 | fc = le_to_host16(mgmt->frame_control); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 3406 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR |
| 3407 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d", |
| 3408 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, |
| 3409 | fc, fc2str(fc), drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3410 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3411 | if ((is_sta_interface(drv->nlmode) || |
| 3412 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3413 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3414 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { |
| 3415 | /* |
| 3416 | * The use of last_mgmt_freq is a bit of a hack, |
| 3417 | * but it works due to the single-threaded nature |
| 3418 | * of wpa_supplicant. |
| 3419 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3420 | if (freq == 0) { |
| 3421 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", |
| 3422 | drv->last_mgmt_freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3423 | freq = drv->last_mgmt_freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3424 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3425 | return nl80211_send_frame_cmd(bss, freq, 0, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3426 | data, data_len, NULL, 1, noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3427 | 1, csa_offs, csa_offs_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3428 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3429 | |
| 3430 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3431 | if (freq == 0) { |
| 3432 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", |
| 3433 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3434 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3435 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3436 | return nl80211_send_frame_cmd(bss, freq, |
| 3437 | (int) freq == bss->freq ? 0 : |
| 3438 | wait_time, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3439 | data, data_len, |
| 3440 | &drv->send_action_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3441 | no_cck, noack, offchanok, |
| 3442 | csa_offs, csa_offs_len); |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 3443 | } |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 3444 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3445 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3446 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 3447 | /* |
| 3448 | * Only one of the authentication frame types is encrypted. |
| 3449 | * In order for static WEP encryption to work properly (i.e., |
| 3450 | * to not encrypt the frame), we need to tell mac80211 about |
| 3451 | * the frames that must not be encrypted. |
| 3452 | */ |
| 3453 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 3454 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); |
| 3455 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
| 3456 | encrypt = 0; |
| 3457 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3458 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3459 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3460 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3461 | noack, freq, no_cck, offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3462 | wait_time, csa_offs, |
| 3463 | csa_offs_len); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3464 | } |
| 3465 | |
| 3466 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3467 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
| 3468 | { |
| 3469 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 3470 | u8 rates_len = 0; |
| 3471 | int i; |
| 3472 | |
| 3473 | if (!basic_rates) |
| 3474 | return 0; |
| 3475 | |
| 3476 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) |
| 3477 | rates[rates_len++] = basic_rates[i] / 5; |
| 3478 | |
| 3479 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); |
| 3480 | } |
| 3481 | |
| 3482 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3483 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
| 3484 | int slot, int ht_opmode, int ap_isolate, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3485 | const int *basic_rates) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3486 | { |
| 3487 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3488 | struct nl_msg *msg; |
| 3489 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3490 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
| 3491 | (cts >= 0 && |
| 3492 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || |
| 3493 | (preamble >= 0 && |
| 3494 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || |
| 3495 | (slot >= 0 && |
| 3496 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || |
| 3497 | (ht_opmode >= 0 && |
| 3498 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || |
| 3499 | (ap_isolate >= 0 && |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3500 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
| 3501 | nl80211_put_basic_rates(msg, basic_rates)) { |
| 3502 | nlmsg_free(msg); |
| 3503 | return -ENOBUFS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3504 | } |
| 3505 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3506 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3507 | } |
| 3508 | |
| 3509 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3510 | static int wpa_driver_nl80211_set_acl(void *priv, |
| 3511 | struct hostapd_acl_params *params) |
| 3512 | { |
| 3513 | struct i802_bss *bss = priv; |
| 3514 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3515 | struct nl_msg *msg; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3516 | struct nl_msg *acl; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3517 | unsigned int i; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3518 | int ret; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3519 | |
| 3520 | if (!(drv->capa.max_acl_mac_addrs)) |
| 3521 | return -ENOTSUP; |
| 3522 | |
| 3523 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) |
| 3524 | return -ENOTSUP; |
| 3525 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3526 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
| 3527 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); |
| 3528 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3529 | acl = nlmsg_alloc(); |
| 3530 | if (!acl) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3531 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3532 | for (i = 0; i < params->num_mac_acl; i++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3533 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { |
| 3534 | nlmsg_free(acl); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3535 | return -ENOMEM; |
| 3536 | } |
| 3537 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3538 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3539 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
| 3540 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
| 3541 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : |
| 3542 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || |
| 3543 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
| 3544 | nlmsg_free(msg); |
| 3545 | nlmsg_free(acl); |
| 3546 | return -ENOMEM; |
| 3547 | } |
| 3548 | nlmsg_free(acl); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3549 | |
| 3550 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3551 | if (ret) { |
| 3552 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", |
| 3553 | ret, strerror(-ret)); |
| 3554 | } |
| 3555 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3556 | return ret; |
| 3557 | } |
| 3558 | |
| 3559 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3560 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
| 3561 | { |
| 3562 | if (beacon_int > 0) { |
| 3563 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); |
| 3564 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 3565 | beacon_int); |
| 3566 | } |
| 3567 | |
| 3568 | return 0; |
| 3569 | } |
| 3570 | |
| 3571 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3572 | static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period) |
| 3573 | { |
| 3574 | if (dtim_period > 0) { |
| 3575 | wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period); |
| 3576 | return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); |
| 3577 | } |
| 3578 | |
| 3579 | return 0; |
| 3580 | } |
| 3581 | |
| 3582 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3583 | #ifdef CONFIG_MESH |
| 3584 | static int nl80211_set_mesh_config(void *priv, |
| 3585 | struct wpa_driver_mesh_bss_params *params) |
| 3586 | { |
| 3587 | struct i802_bss *bss = priv; |
| 3588 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3589 | struct nl_msg *msg; |
| 3590 | int ret; |
| 3591 | |
| 3592 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG); |
| 3593 | if (!msg) |
| 3594 | return -1; |
| 3595 | |
| 3596 | ret = nl80211_put_mesh_config(msg, params); |
| 3597 | if (ret < 0) { |
| 3598 | nlmsg_free(msg); |
| 3599 | return ret; |
| 3600 | } |
| 3601 | |
| 3602 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3603 | if (ret) { |
| 3604 | wpa_printf(MSG_ERROR, |
| 3605 | "nl80211: Mesh config set failed: %d (%s)", |
| 3606 | ret, strerror(-ret)); |
| 3607 | return ret; |
| 3608 | } |
| 3609 | return 0; |
| 3610 | } |
| 3611 | #endif /* CONFIG_MESH */ |
| 3612 | |
| 3613 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3614 | static int nl80211_put_beacon_rate(struct nl_msg *msg, const u64 flags, |
| 3615 | struct wpa_driver_ap_params *params) |
| 3616 | { |
| 3617 | struct nlattr *bands, *band; |
| 3618 | struct nl80211_txrate_vht vht_rate; |
| 3619 | |
| 3620 | if (!params->freq || |
| 3621 | (params->beacon_rate == 0 && |
| 3622 | params->rate_type == BEACON_RATE_LEGACY)) |
| 3623 | return 0; |
| 3624 | |
| 3625 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 3626 | if (!bands) |
| 3627 | return -1; |
| 3628 | |
| 3629 | switch (params->freq->mode) { |
| 3630 | case HOSTAPD_MODE_IEEE80211B: |
| 3631 | case HOSTAPD_MODE_IEEE80211G: |
| 3632 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
| 3633 | break; |
| 3634 | case HOSTAPD_MODE_IEEE80211A: |
| 3635 | band = nla_nest_start(msg, NL80211_BAND_5GHZ); |
| 3636 | break; |
| 3637 | case HOSTAPD_MODE_IEEE80211AD: |
| 3638 | band = nla_nest_start(msg, NL80211_BAND_60GHZ); |
| 3639 | break; |
| 3640 | default: |
| 3641 | return 0; |
| 3642 | } |
| 3643 | |
| 3644 | if (!band) |
| 3645 | return -1; |
| 3646 | |
| 3647 | os_memset(&vht_rate, 0, sizeof(vht_rate)); |
| 3648 | |
| 3649 | switch (params->rate_type) { |
| 3650 | case BEACON_RATE_LEGACY: |
| 3651 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_LEGACY)) { |
| 3652 | wpa_printf(MSG_INFO, |
| 3653 | "nl80211: Driver does not support setting Beacon frame rate (legacy)"); |
| 3654 | return -1; |
| 3655 | } |
| 3656 | |
| 3657 | if (nla_put_u8(msg, NL80211_TXRATE_LEGACY, |
| 3658 | (u8) params->beacon_rate / 5) || |
| 3659 | nla_put(msg, NL80211_TXRATE_HT, 0, NULL) || |
| 3660 | (params->freq->vht_enabled && |
| 3661 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 3662 | &vht_rate))) |
| 3663 | return -1; |
| 3664 | |
| 3665 | wpa_printf(MSG_DEBUG, " * beacon_rate = legacy:%u (* 100 kbps)", |
| 3666 | params->beacon_rate); |
| 3667 | break; |
| 3668 | case BEACON_RATE_HT: |
| 3669 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_HT)) { |
| 3670 | wpa_printf(MSG_INFO, |
| 3671 | "nl80211: Driver does not support setting Beacon frame rate (HT)"); |
| 3672 | return -1; |
| 3673 | } |
| 3674 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL) || |
| 3675 | nla_put_u8(msg, NL80211_TXRATE_HT, params->beacon_rate) || |
| 3676 | (params->freq->vht_enabled && |
| 3677 | nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 3678 | &vht_rate))) |
| 3679 | return -1; |
| 3680 | wpa_printf(MSG_DEBUG, " * beacon_rate = HT-MCS %u", |
| 3681 | params->beacon_rate); |
| 3682 | break; |
| 3683 | case BEACON_RATE_VHT: |
| 3684 | if (!(flags & WPA_DRIVER_FLAGS_BEACON_RATE_VHT)) { |
| 3685 | wpa_printf(MSG_INFO, |
| 3686 | "nl80211: Driver does not support setting Beacon frame rate (VHT)"); |
| 3687 | return -1; |
| 3688 | } |
| 3689 | vht_rate.mcs[0] = BIT(params->beacon_rate); |
| 3690 | if (nla_put(msg, NL80211_TXRATE_LEGACY, 0, NULL)) |
| 3691 | return -1; |
| 3692 | if (nla_put(msg, NL80211_TXRATE_HT, 0, NULL)) |
| 3693 | return -1; |
| 3694 | if (nla_put(msg, NL80211_TXRATE_VHT, sizeof(vht_rate), |
| 3695 | &vht_rate)) |
| 3696 | return -1; |
| 3697 | wpa_printf(MSG_DEBUG, " * beacon_rate = VHT-MCS %u", |
| 3698 | params->beacon_rate); |
| 3699 | break; |
| 3700 | } |
| 3701 | |
| 3702 | nla_nest_end(msg, band); |
| 3703 | nla_nest_end(msg, bands); |
| 3704 | |
| 3705 | return 0; |
| 3706 | } |
| 3707 | |
| 3708 | |
| 3709 | static int nl80211_set_multicast_to_unicast(struct i802_bss *bss, |
| 3710 | int multicast_to_unicast) |
| 3711 | { |
| 3712 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3713 | struct nl_msg *msg; |
| 3714 | int ret; |
| 3715 | |
| 3716 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_MULTICAST_TO_UNICAST); |
| 3717 | if (!msg || |
| 3718 | (multicast_to_unicast && |
| 3719 | nla_put_flag(msg, NL80211_ATTR_MULTICAST_TO_UNICAST_ENABLED))) { |
| 3720 | wpa_printf(MSG_ERROR, |
| 3721 | "nl80211: Failed to build NL80211_CMD_SET_MULTICAST_TO_UNICAST msg for %s", |
| 3722 | bss->ifname); |
| 3723 | nlmsg_free(msg); |
| 3724 | return -ENOBUFS; |
| 3725 | } |
| 3726 | |
| 3727 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3728 | |
| 3729 | switch (ret) { |
| 3730 | case 0: |
| 3731 | wpa_printf(MSG_DEBUG, |
| 3732 | "nl80211: multicast to unicast %s on interface %s", |
| 3733 | multicast_to_unicast ? "enabled" : "disabled", |
| 3734 | bss->ifname); |
| 3735 | break; |
| 3736 | case -EOPNOTSUPP: |
| 3737 | if (!multicast_to_unicast) |
| 3738 | break; |
| 3739 | wpa_printf(MSG_INFO, |
| 3740 | "nl80211: multicast to unicast not supported on interface %s", |
| 3741 | bss->ifname); |
| 3742 | break; |
| 3743 | default: |
| 3744 | wpa_printf(MSG_ERROR, |
| 3745 | "nl80211: %s multicast to unicast failed with %d (%s) on interface %s", |
| 3746 | multicast_to_unicast ? "enabling" : "disabling", |
| 3747 | ret, strerror(-ret), bss->ifname); |
| 3748 | break; |
| 3749 | } |
| 3750 | |
| 3751 | return ret; |
| 3752 | } |
| 3753 | |
| 3754 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3755 | static int wpa_driver_nl80211_set_ap(void *priv, |
| 3756 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3757 | { |
| 3758 | struct i802_bss *bss = priv; |
| 3759 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3760 | struct nl_msg *msg; |
| 3761 | u8 cmd = NL80211_CMD_NEW_BEACON; |
| 3762 | int ret; |
| 3763 | int beacon_set; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3764 | int num_suites; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3765 | int smps_mode; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3766 | u32 suites[10], suite; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3767 | u32 ver; |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3768 | #ifdef CONFIG_MESH |
| 3769 | struct wpa_driver_mesh_bss_params mesh_params; |
| 3770 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3771 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3772 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3773 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3774 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
| 3775 | beacon_set); |
| 3776 | if (beacon_set) |
| 3777 | cmd = NL80211_CMD_SET_BEACON; |
| 3778 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3779 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
| 3780 | params->head, params->head_len); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3781 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
| 3782 | params->tail, params->tail_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3783 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3784 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3785 | wpa_printf(MSG_DEBUG, "nl80211: beacon_rate=%u", params->beacon_rate); |
| 3786 | wpa_printf(MSG_DEBUG, "nl80211: rate_type=%d", params->rate_type); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3787 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3788 | wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid", |
| 3789 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3790 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 3791 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
| 3792 | params->head) || |
| 3793 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, |
| 3794 | params->tail) || |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3795 | nl80211_put_beacon_int(msg, params->beacon_int) || |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3796 | nl80211_put_beacon_rate(msg, drv->capa.flags, params) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3797 | nl80211_put_dtim_period(msg, params->dtim_period) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3798 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 3799 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3800 | if (params->proberesp && params->proberesp_len) { |
| 3801 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", |
| 3802 | params->proberesp, params->proberesp_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3803 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
| 3804 | params->proberesp)) |
| 3805 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3806 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3807 | switch (params->hide_ssid) { |
| 3808 | case NO_SSID_HIDING: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3809 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3810 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3811 | NL80211_HIDDEN_SSID_NOT_IN_USE)) |
| 3812 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3813 | break; |
| 3814 | case HIDDEN_SSID_ZERO_LEN: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3815 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3816 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3817 | NL80211_HIDDEN_SSID_ZERO_LEN)) |
| 3818 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3819 | break; |
| 3820 | case HIDDEN_SSID_ZERO_CONTENTS: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3821 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3822 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3823 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) |
| 3824 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3825 | break; |
| 3826 | } |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3827 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3828 | if (params->privacy && |
| 3829 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 3830 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3831 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3832 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
| 3833 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { |
| 3834 | /* Leave out the attribute */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3835 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
| 3836 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 3837 | NL80211_AUTHTYPE_SHARED_KEY)) |
| 3838 | goto fail; |
| 3839 | } else { |
| 3840 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 3841 | NL80211_AUTHTYPE_OPEN_SYSTEM)) |
| 3842 | goto fail; |
| 3843 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3844 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3845 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3846 | ver = 0; |
| 3847 | if (params->wpa_version & WPA_PROTO_WPA) |
| 3848 | ver |= NL80211_WPA_VERSION_1; |
| 3849 | if (params->wpa_version & WPA_PROTO_RSN) |
| 3850 | ver |= NL80211_WPA_VERSION_2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3851 | if (ver && |
| 3852 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 3853 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3854 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3855 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
| 3856 | params->key_mgmt_suites); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3857 | num_suites = 0; |
| 3858 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) |
| 3859 | suites[num_suites++] = WLAN_AKM_SUITE_8021X; |
| 3860 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) |
| 3861 | suites[num_suites++] = WLAN_AKM_SUITE_PSK; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3862 | if (num_suites && |
| 3863 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), |
| 3864 | suites)) |
| 3865 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3866 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3867 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3868 | (!params->pairwise_ciphers || |
| 3869 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) && |
| 3870 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 3871 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3872 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3873 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3874 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
| 3875 | params->pairwise_ciphers); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3876 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
| 3877 | suites, ARRAY_SIZE(suites)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3878 | if (num_suites && |
| 3879 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 3880 | num_suites * sizeof(u32), suites)) |
| 3881 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3882 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3883 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
| 3884 | params->group_cipher); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3885 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3886 | if (suite && |
| 3887 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) |
| 3888 | goto fail; |
| 3889 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3890 | if (params->ht_opmode != -1) { |
| 3891 | switch (params->smps_mode) { |
| 3892 | case HT_CAP_INFO_SMPS_DYNAMIC: |
| 3893 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic"); |
| 3894 | smps_mode = NL80211_SMPS_DYNAMIC; |
| 3895 | break; |
| 3896 | case HT_CAP_INFO_SMPS_STATIC: |
| 3897 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static"); |
| 3898 | smps_mode = NL80211_SMPS_STATIC; |
| 3899 | break; |
| 3900 | default: |
| 3901 | /* invalid - fallback to smps off */ |
| 3902 | case HT_CAP_INFO_SMPS_DISABLED: |
| 3903 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off"); |
| 3904 | smps_mode = NL80211_SMPS_OFF; |
| 3905 | break; |
| 3906 | } |
| 3907 | if (nla_put_u32(msg, NL80211_ATTR_SMPS_MODE, smps_mode)) |
| 3908 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3909 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3910 | |
| 3911 | if (params->beacon_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3912 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
| 3913 | params->beacon_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3914 | if (nla_put(msg, NL80211_ATTR_IE, |
| 3915 | wpabuf_len(params->beacon_ies), |
| 3916 | wpabuf_head(params->beacon_ies))) |
| 3917 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3918 | } |
| 3919 | if (params->proberesp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3920 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
| 3921 | params->proberesp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3922 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 3923 | wpabuf_len(params->proberesp_ies), |
| 3924 | wpabuf_head(params->proberesp_ies))) |
| 3925 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3926 | } |
| 3927 | if (params->assocresp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3928 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
| 3929 | params->assocresp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3930 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 3931 | wpabuf_len(params->assocresp_ies), |
| 3932 | wpabuf_head(params->assocresp_ies))) |
| 3933 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3934 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3935 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3936 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3937 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
| 3938 | params->ap_max_inactivity); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3939 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
| 3940 | params->ap_max_inactivity)) |
| 3941 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3942 | } |
| 3943 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3944 | #ifdef CONFIG_P2P |
| 3945 | if (params->p2p_go_ctwindow > 0) { |
| 3946 | if (drv->p2p_go_ctwindow_supported) { |
| 3947 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", |
| 3948 | params->p2p_go_ctwindow); |
| 3949 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, |
| 3950 | params->p2p_go_ctwindow)) |
| 3951 | goto fail; |
| 3952 | } else { |
| 3953 | wpa_printf(MSG_INFO, |
| 3954 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); |
| 3955 | } |
| 3956 | } |
| 3957 | #endif /* CONFIG_P2P */ |
| 3958 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3959 | if (params->pbss) { |
| 3960 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); |
| 3961 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 3962 | goto fail; |
| 3963 | } |
| 3964 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3965 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3966 | if (ret) { |
| 3967 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", |
| 3968 | ret, strerror(-ret)); |
| 3969 | } else { |
| 3970 | bss->beacon_set = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3971 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
| 3972 | params->short_slot_time, params->ht_opmode, |
| 3973 | params->isolate, params->basic_rates); |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 3974 | nl80211_set_multicast_to_unicast(bss, |
| 3975 | params->multicast_to_unicast); |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3976 | if (beacon_set && params->freq && |
| 3977 | params->freq->bandwidth != bss->bandwidth) { |
| 3978 | wpa_printf(MSG_DEBUG, |
| 3979 | "nl80211: Update BSS %s bandwidth: %d -> %d", |
| 3980 | bss->ifname, bss->bandwidth, |
| 3981 | params->freq->bandwidth); |
| 3982 | ret = nl80211_set_channel(bss, params->freq, 1); |
| 3983 | if (ret) { |
| 3984 | wpa_printf(MSG_DEBUG, |
| 3985 | "nl80211: Frequency set failed: %d (%s)", |
| 3986 | ret, strerror(-ret)); |
| 3987 | } else { |
| 3988 | wpa_printf(MSG_DEBUG, |
| 3989 | "nl80211: Frequency set succeeded for ht2040 coex"); |
| 3990 | bss->bandwidth = params->freq->bandwidth; |
| 3991 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3992 | } else if (!beacon_set && params->freq) { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3993 | /* |
| 3994 | * cfg80211 updates the driver on frequence change in AP |
| 3995 | * mode only at the point when beaconing is started, so |
| 3996 | * set the initial value here. |
| 3997 | */ |
| 3998 | bss->bandwidth = params->freq->bandwidth; |
| 3999 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4000 | } |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4001 | |
| 4002 | #ifdef CONFIG_MESH |
| 4003 | if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) { |
| 4004 | os_memset(&mesh_params, 0, sizeof(mesh_params)); |
| 4005 | mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE; |
| 4006 | mesh_params.ht_opmode = params->ht_opmode; |
| 4007 | ret = nl80211_set_mesh_config(priv, &mesh_params); |
| 4008 | if (ret < 0) |
| 4009 | return ret; |
| 4010 | } |
| 4011 | #endif /* CONFIG_MESH */ |
| 4012 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4013 | return ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4014 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4015 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4016 | return -ENOBUFS; |
| 4017 | } |
| 4018 | |
| 4019 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4020 | static int nl80211_put_freq_params(struct nl_msg *msg, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4021 | const struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4022 | { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4023 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4024 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
| 4025 | return -ENOBUFS; |
| 4026 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4027 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
| 4028 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); |
| 4029 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4030 | if (freq->vht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4031 | enum nl80211_chan_width cw; |
| 4032 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4033 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4034 | switch (freq->bandwidth) { |
| 4035 | case 20: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4036 | cw = NL80211_CHAN_WIDTH_20; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4037 | break; |
| 4038 | case 40: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4039 | cw = NL80211_CHAN_WIDTH_40; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4040 | break; |
| 4041 | case 80: |
| 4042 | if (freq->center_freq2) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4043 | cw = NL80211_CHAN_WIDTH_80P80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4044 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4045 | cw = NL80211_CHAN_WIDTH_80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4046 | break; |
| 4047 | case 160: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4048 | cw = NL80211_CHAN_WIDTH_160; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4049 | break; |
| 4050 | default: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4051 | return -EINVAL; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4052 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4053 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4054 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
| 4055 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", |
| 4056 | freq->center_freq1); |
| 4057 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", |
| 4058 | freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4059 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
| 4060 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, |
| 4061 | freq->center_freq1) || |
| 4062 | (freq->center_freq2 && |
| 4063 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 4064 | freq->center_freq2))) |
| 4065 | return -ENOBUFS; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4066 | } else if (freq->ht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4067 | enum nl80211_channel_type ct; |
| 4068 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4069 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
| 4070 | freq->sec_channel_offset); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4071 | switch (freq->sec_channel_offset) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4072 | case -1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4073 | ct = NL80211_CHAN_HT40MINUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4074 | break; |
| 4075 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4076 | ct = NL80211_CHAN_HT40PLUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4077 | break; |
| 4078 | default: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4079 | ct = NL80211_CHAN_HT20; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4080 | break; |
| 4081 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4082 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4083 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4084 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
| 4085 | return -ENOBUFS; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4086 | } else { |
| 4087 | wpa_printf(MSG_DEBUG, " * channel_type=%d", |
| 4088 | NL80211_CHAN_NO_HT); |
| 4089 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 4090 | NL80211_CHAN_NO_HT)) |
| 4091 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4092 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4093 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4094 | } |
| 4095 | |
| 4096 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 4097 | static int nl80211_set_channel(struct i802_bss *bss, |
| 4098 | struct hostapd_freq_params *freq, int set_chan) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4099 | { |
| 4100 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4101 | struct nl_msg *msg; |
| 4102 | int ret; |
| 4103 | |
| 4104 | wpa_printf(MSG_DEBUG, |
| 4105 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
| 4106 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 4107 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4108 | |
| 4109 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
| 4110 | NL80211_CMD_SET_WIPHY); |
| 4111 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { |
| 4112 | nlmsg_free(msg); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 4113 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4114 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4115 | |
| 4116 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4117 | if (ret == 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4118 | bss->freq = freq->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4119 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4120 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4121 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4122 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4123 | return -1; |
| 4124 | } |
| 4125 | |
| 4126 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4127 | static u32 sta_flags_nl80211(int flags) |
| 4128 | { |
| 4129 | u32 f = 0; |
| 4130 | |
| 4131 | if (flags & WPA_STA_AUTHORIZED) |
| 4132 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 4133 | if (flags & WPA_STA_WMM) |
| 4134 | f |= BIT(NL80211_STA_FLAG_WME); |
| 4135 | if (flags & WPA_STA_SHORT_PREAMBLE) |
| 4136 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
| 4137 | if (flags & WPA_STA_MFP) |
| 4138 | f |= BIT(NL80211_STA_FLAG_MFP); |
| 4139 | if (flags & WPA_STA_TDLS_PEER) |
| 4140 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4141 | if (flags & WPA_STA_AUTHENTICATED) |
| 4142 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4143 | if (flags & WPA_STA_ASSOCIATED) |
| 4144 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4145 | |
| 4146 | return f; |
| 4147 | } |
| 4148 | |
| 4149 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4150 | #ifdef CONFIG_MESH |
| 4151 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) |
| 4152 | { |
| 4153 | switch (state) { |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4154 | case PLINK_IDLE: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4155 | return NL80211_PLINK_LISTEN; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4156 | case PLINK_OPN_SNT: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4157 | return NL80211_PLINK_OPN_SNT; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4158 | case PLINK_OPN_RCVD: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4159 | return NL80211_PLINK_OPN_RCVD; |
| 4160 | case PLINK_CNF_RCVD: |
| 4161 | return NL80211_PLINK_CNF_RCVD; |
| 4162 | case PLINK_ESTAB: |
| 4163 | return NL80211_PLINK_ESTAB; |
| 4164 | case PLINK_HOLDING: |
| 4165 | return NL80211_PLINK_HOLDING; |
| 4166 | case PLINK_BLOCKED: |
| 4167 | return NL80211_PLINK_BLOCKED; |
| 4168 | default: |
| 4169 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", |
| 4170 | state); |
| 4171 | } |
| 4172 | return -1; |
| 4173 | } |
| 4174 | #endif /* CONFIG_MESH */ |
| 4175 | |
| 4176 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4177 | static int wpa_driver_nl80211_sta_add(void *priv, |
| 4178 | struct hostapd_sta_add_params *params) |
| 4179 | { |
| 4180 | struct i802_bss *bss = priv; |
| 4181 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4182 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4183 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4184 | int ret = -ENOBUFS; |
| 4185 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4186 | if ((params->flags & WPA_STA_TDLS_PEER) && |
| 4187 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 4188 | return -EOPNOTSUPP; |
| 4189 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4190 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
| 4191 | params->set ? "Set" : "Add", MAC2STR(params->addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4192 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
| 4193 | NL80211_CMD_NEW_STATION); |
| 4194 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) |
| 4195 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4196 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4197 | /* |
| 4198 | * Set the below properties only in one of the following cases: |
| 4199 | * 1. New station is added, already associated. |
| 4200 | * 2. Set WPA_STA_TDLS_PEER station. |
| 4201 | * 3. Set an already added unassociated station, if driver supports |
| 4202 | * full AP client state. (Set these properties after station became |
| 4203 | * associated will be rejected by the driver). |
| 4204 | */ |
| 4205 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
| 4206 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 4207 | (params->flags & WPA_STA_ASSOCIATED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4208 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
| 4209 | params->supp_rates, params->supp_rates_len); |
| 4210 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
| 4211 | params->capability); |
| 4212 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, |
| 4213 | params->supp_rates_len, params->supp_rates) || |
| 4214 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, |
| 4215 | params->capability)) |
| 4216 | goto fail; |
| 4217 | |
| 4218 | if (params->ht_capabilities) { |
| 4219 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
| 4220 | (u8 *) params->ht_capabilities, |
| 4221 | sizeof(*params->ht_capabilities)); |
| 4222 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
| 4223 | sizeof(*params->ht_capabilities), |
| 4224 | params->ht_capabilities)) |
| 4225 | goto fail; |
| 4226 | } |
| 4227 | |
| 4228 | if (params->vht_capabilities) { |
| 4229 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
| 4230 | (u8 *) params->vht_capabilities, |
| 4231 | sizeof(*params->vht_capabilities)); |
| 4232 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
| 4233 | sizeof(*params->vht_capabilities), |
| 4234 | params->vht_capabilities)) |
| 4235 | goto fail; |
| 4236 | } |
| 4237 | |
| 4238 | if (params->ext_capab) { |
| 4239 | wpa_hexdump(MSG_DEBUG, " * ext_capab", |
| 4240 | params->ext_capab, params->ext_capab_len); |
| 4241 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
| 4242 | params->ext_capab_len, params->ext_capab)) |
| 4243 | goto fail; |
| 4244 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4245 | |
| 4246 | if (is_ap_interface(drv->nlmode) && |
| 4247 | nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS, |
| 4248 | params->support_p2p_ps ? |
| 4249 | NL80211_P2P_PS_SUPPORTED : |
| 4250 | NL80211_P2P_PS_UNSUPPORTED)) |
| 4251 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4252 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4253 | if (!params->set) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4254 | if (params->aid) { |
| 4255 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4256 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
| 4257 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4258 | } else { |
| 4259 | /* |
| 4260 | * cfg80211 validates that AID is non-zero, so we have |
| 4261 | * to make this a non-zero value for the TDLS case where |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4262 | * a dummy STA entry is used for now and for a station |
| 4263 | * that is still not associated. |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4264 | */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4265 | wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)", |
| 4266 | (params->flags & WPA_STA_TDLS_PEER) ? |
| 4267 | "TDLS" : "UNASSOC_STA"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4268 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
| 4269 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4270 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4271 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 4272 | params->listen_interval); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4273 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 4274 | params->listen_interval)) |
| 4275 | goto fail; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4276 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
| 4277 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4278 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
| 4279 | goto fail; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4280 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 4281 | (params->flags & WPA_STA_ASSOCIATED)) { |
| 4282 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
| 4283 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 4284 | params->listen_interval); |
| 4285 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || |
| 4286 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 4287 | params->listen_interval)) |
| 4288 | goto fail; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4289 | } |
| 4290 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 4291 | if (params->vht_opmode_enabled) { |
| 4292 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4293 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
| 4294 | params->vht_opmode)) |
| 4295 | goto fail; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4296 | } |
| 4297 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4298 | if (params->supp_channels) { |
| 4299 | wpa_hexdump(MSG_DEBUG, " * supported channels", |
| 4300 | params->supp_channels, params->supp_channels_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4301 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
| 4302 | params->supp_channels_len, params->supp_channels)) |
| 4303 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4304 | } |
| 4305 | |
| 4306 | if (params->supp_oper_classes) { |
| 4307 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", |
| 4308 | params->supp_oper_classes, |
| 4309 | params->supp_oper_classes_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4310 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
| 4311 | params->supp_oper_classes_len, |
| 4312 | params->supp_oper_classes)) |
| 4313 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4314 | } |
| 4315 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4316 | os_memset(&upd, 0, sizeof(upd)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4317 | upd.set = sta_flags_nl80211(params->flags); |
| 4318 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4319 | |
| 4320 | /* |
| 4321 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH |
| 4322 | * flags, as nl80211 driver moves a new station, by default, into |
| 4323 | * associated state. |
| 4324 | * |
| 4325 | * On the other hand, if the driver supports that feature and the |
| 4326 | * station is added in unauthenticated state, set the |
| 4327 | * authenticated/associated bits in the mask to prevent moving this |
| 4328 | * station to associated state before it is actually associated. |
| 4329 | * |
| 4330 | * This is irrelevant for mesh mode where the station is added to the |
| 4331 | * driver as authenticated already, and ASSOCIATED isn't part of the |
| 4332 | * nl80211 API. |
| 4333 | */ |
| 4334 | if (!is_mesh_interface(drv->nlmode)) { |
| 4335 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { |
| 4336 | wpa_printf(MSG_DEBUG, |
| 4337 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); |
| 4338 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4339 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); |
| 4340 | } else if (!params->set && |
| 4341 | !(params->flags & WPA_STA_TDLS_PEER)) { |
| 4342 | if (!(params->flags & WPA_STA_AUTHENTICATED)) |
| 4343 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
| 4344 | if (!(params->flags & WPA_STA_ASSOCIATED)) |
| 4345 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 4346 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4347 | #ifdef CONFIG_MESH |
| 4348 | } else { |
| 4349 | if (params->plink_state == PLINK_ESTAB && params->peer_aid) { |
| 4350 | ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID, |
| 4351 | params->peer_aid); |
| 4352 | if (ret) |
| 4353 | goto fail; |
| 4354 | } |
| 4355 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4356 | } |
| 4357 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4358 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
| 4359 | upd.set, upd.mask); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4360 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 4361 | goto fail; |
| 4362 | |
| 4363 | #ifdef CONFIG_MESH |
| 4364 | if (params->plink_state && |
| 4365 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, |
| 4366 | sta_plink_state_nl80211(params->plink_state))) |
| 4367 | goto fail; |
| 4368 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4369 | |
| 4370 | if (params->flags & WPA_STA_WMM) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4371 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 4372 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4373 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4374 | if (!wme || |
| 4375 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 4376 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || |
| 4377 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, |
| 4378 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
| 4379 | WMM_QOSINFO_STA_SP_MASK)) |
| 4380 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4381 | nla_nest_end(msg, wme); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4382 | } |
| 4383 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4384 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4385 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4386 | if (ret) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4387 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
| 4388 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, |
| 4389 | strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4390 | if (ret == -EEXIST) |
| 4391 | ret = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4392 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4393 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4394 | return ret; |
| 4395 | } |
| 4396 | |
| 4397 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4398 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
| 4399 | { |
| 4400 | #ifdef CONFIG_LIBNL3_ROUTE |
| 4401 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4402 | struct rtnl_neigh *rn; |
| 4403 | struct nl_addr *nl_addr; |
| 4404 | int err; |
| 4405 | |
| 4406 | rn = rtnl_neigh_alloc(); |
| 4407 | if (!rn) |
| 4408 | return; |
| 4409 | |
| 4410 | rtnl_neigh_set_family(rn, AF_BRIDGE); |
| 4411 | rtnl_neigh_set_ifindex(rn, bss->ifindex); |
| 4412 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); |
| 4413 | if (!nl_addr) { |
| 4414 | rtnl_neigh_put(rn); |
| 4415 | return; |
| 4416 | } |
| 4417 | rtnl_neigh_set_lladdr(rn, nl_addr); |
| 4418 | |
| 4419 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 4420 | if (err < 0) { |
| 4421 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " |
| 4422 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), |
| 4423 | bss->ifindex, nl_geterror(err)); |
| 4424 | } else { |
| 4425 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " |
| 4426 | MACSTR, MAC2STR(addr)); |
| 4427 | } |
| 4428 | |
| 4429 | nl_addr_put(nl_addr); |
| 4430 | rtnl_neigh_put(rn); |
| 4431 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 4432 | } |
| 4433 | |
| 4434 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4435 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
| 4436 | int deauth, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4437 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4438 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4439 | struct nl_msg *msg; |
| 4440 | int ret; |
| 4441 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4442 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
| 4443 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 4444 | (deauth == 0 && |
| 4445 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 4446 | WLAN_FC_STYPE_DISASSOC)) || |
| 4447 | (deauth == 1 && |
| 4448 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 4449 | WLAN_FC_STYPE_DEAUTH)) || |
| 4450 | (reason_code && |
| 4451 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { |
| 4452 | nlmsg_free(msg); |
| 4453 | return -ENOBUFS; |
| 4454 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4455 | |
| 4456 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 4457 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
| 4458 | " --> %d (%s)", |
| 4459 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4460 | |
| 4461 | if (drv->rtnl_sk) |
| 4462 | rtnl_neigh_delete_fdb_entry(bss, addr); |
| 4463 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4464 | if (ret == -ENOENT) |
| 4465 | return 0; |
| 4466 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4467 | } |
| 4468 | |
| 4469 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4470 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4471 | { |
| 4472 | struct nl_msg *msg; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4473 | struct wpa_driver_nl80211_data *drv2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4474 | |
| 4475 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
| 4476 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4477 | /* stop listening for EAPOL on this interface */ |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4478 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 4479 | struct wpa_driver_nl80211_data, list) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4480 | { |
| 4481 | del_ifidx(drv2, ifidx, IFIDX_ANY); |
| 4482 | /* Remove all bridges learned for this iface */ |
| 4483 | del_ifidx(drv2, IFIDX_ANY, ifidx); |
| 4484 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4485 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4486 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4487 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 4488 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4489 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
| 4490 | } |
| 4491 | |
| 4492 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 4493 | const char * nl80211_iftype_str(enum nl80211_iftype mode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4494 | { |
| 4495 | switch (mode) { |
| 4496 | case NL80211_IFTYPE_ADHOC: |
| 4497 | return "ADHOC"; |
| 4498 | case NL80211_IFTYPE_STATION: |
| 4499 | return "STATION"; |
| 4500 | case NL80211_IFTYPE_AP: |
| 4501 | return "AP"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 4502 | case NL80211_IFTYPE_AP_VLAN: |
| 4503 | return "AP_VLAN"; |
| 4504 | case NL80211_IFTYPE_WDS: |
| 4505 | return "WDS"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4506 | case NL80211_IFTYPE_MONITOR: |
| 4507 | return "MONITOR"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 4508 | case NL80211_IFTYPE_MESH_POINT: |
| 4509 | return "MESH_POINT"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4510 | case NL80211_IFTYPE_P2P_CLIENT: |
| 4511 | return "P2P_CLIENT"; |
| 4512 | case NL80211_IFTYPE_P2P_GO: |
| 4513 | return "P2P_GO"; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4514 | case NL80211_IFTYPE_P2P_DEVICE: |
| 4515 | return "P2P_DEVICE"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4516 | default: |
| 4517 | return "unknown"; |
| 4518 | } |
| 4519 | } |
| 4520 | |
| 4521 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4522 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
| 4523 | const char *ifname, |
| 4524 | enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4525 | const u8 *addr, int wds, |
| 4526 | int (*handler)(struct nl_msg *, void *), |
| 4527 | void *arg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4528 | { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4529 | struct nl_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4530 | int ifidx; |
| 4531 | int ret = -ENOBUFS; |
| 4532 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4533 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
| 4534 | iftype, nl80211_iftype_str(iftype)); |
| 4535 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4536 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
| 4537 | if (!msg || |
| 4538 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
| 4539 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) |
| 4540 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4541 | |
| 4542 | if (iftype == NL80211_IFTYPE_MONITOR) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4543 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4544 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4545 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4546 | if (!flags || |
| 4547 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) |
| 4548 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4549 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4550 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4551 | } else if (wds) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4552 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
| 4553 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4554 | } |
| 4555 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4556 | /* |
| 4557 | * Tell cfg80211 that the interface belongs to the socket that created |
| 4558 | * it, and the interface should be deleted when the socket is closed. |
| 4559 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4560 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 4561 | goto fail; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4562 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4563 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4564 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4565 | if (ret) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4566 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4567 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4568 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
| 4569 | ifname, ret, strerror(-ret)); |
| 4570 | return ret; |
| 4571 | } |
| 4572 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4573 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
| 4574 | return 0; |
| 4575 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4576 | ifidx = if_nametoindex(ifname); |
| 4577 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
| 4578 | ifname, ifidx); |
| 4579 | |
| 4580 | if (ifidx <= 0) |
| 4581 | return -1; |
| 4582 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4583 | /* |
| 4584 | * Some virtual interfaces need to process EAPOL packets and events on |
| 4585 | * the parent interface. This is used mainly with hostapd. |
| 4586 | */ |
| 4587 | if (drv->hostapd || |
| 4588 | iftype == NL80211_IFTYPE_AP_VLAN || |
| 4589 | iftype == NL80211_IFTYPE_WDS || |
| 4590 | iftype == NL80211_IFTYPE_MONITOR) { |
| 4591 | /* start listening for EAPOL on this interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4592 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4593 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4594 | |
| 4595 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4596 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4597 | nl80211_remove_iface(drv, ifidx); |
| 4598 | return -1; |
| 4599 | } |
| 4600 | |
| 4601 | return ifidx; |
| 4602 | } |
| 4603 | |
| 4604 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4605 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
| 4606 | const char *ifname, enum nl80211_iftype iftype, |
| 4607 | const u8 *addr, int wds, |
| 4608 | int (*handler)(struct nl_msg *, void *), |
| 4609 | void *arg, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4610 | { |
| 4611 | int ret; |
| 4612 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4613 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
| 4614 | arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4615 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4616 | /* if error occurred and interface exists already */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4617 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4618 | if (use_existing) { |
| 4619 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", |
| 4620 | ifname); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 4621 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
| 4622 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4623 | addr) < 0 && |
| 4624 | (linux_set_iface_flags(drv->global->ioctl_sock, |
| 4625 | ifname, 0) < 0 || |
| 4626 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4627 | addr) < 0 || |
| 4628 | linux_set_iface_flags(drv->global->ioctl_sock, |
| 4629 | ifname, 1) < 0)) |
| 4630 | return -1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4631 | return -ENFILE; |
| 4632 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4633 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
| 4634 | |
| 4635 | /* Try to remove the interface that was already there. */ |
| 4636 | nl80211_remove_iface(drv, if_nametoindex(ifname)); |
| 4637 | |
| 4638 | /* Try to create the interface again */ |
| 4639 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4640 | wds, handler, arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4641 | } |
| 4642 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4643 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
| 4644 | wpa_printf(MSG_DEBUG, |
| 4645 | "nl80211: Interface %s created for P2P - disable 11b rates", |
| 4646 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4647 | nl80211_disable_11b_rates(drv, ret, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4648 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4649 | |
| 4650 | return ret; |
| 4651 | } |
| 4652 | |
| 4653 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4654 | static int nl80211_setup_ap(struct i802_bss *bss) |
| 4655 | { |
| 4656 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4657 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4658 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 4659 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4660 | |
| 4661 | /* |
| 4662 | * Disable Probe Request reporting unless we need it in this way for |
| 4663 | * devices that include the AP SME, in the other case (unless using |
| 4664 | * monitor iface) we'll get it through the nl_mgmt socket instead. |
| 4665 | */ |
| 4666 | if (!drv->device_ap_sme) |
| 4667 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4668 | |
| 4669 | if (!drv->device_ap_sme && !drv->use_monitor) |
| 4670 | if (nl80211_mgmt_subscribe_ap(bss)) |
| 4671 | return -1; |
| 4672 | |
| 4673 | if (drv->device_ap_sme && !drv->use_monitor) |
| 4674 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4675 | wpa_printf(MSG_DEBUG, |
| 4676 | "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] | 4677 | |
| 4678 | if (!drv->device_ap_sme && drv->use_monitor && |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 4679 | nl80211_create_monitor_interface(drv) && |
| 4680 | !drv->device_ap_sme) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4681 | return -1; |
| 4682 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4683 | if (drv->device_ap_sme && |
| 4684 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { |
| 4685 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " |
| 4686 | "Probe Request frame reporting in AP mode"); |
| 4687 | /* Try to survive without this */ |
| 4688 | } |
| 4689 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4690 | return 0; |
| 4691 | } |
| 4692 | |
| 4693 | |
| 4694 | static void nl80211_teardown_ap(struct i802_bss *bss) |
| 4695 | { |
| 4696 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4697 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4698 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 4699 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4700 | if (drv->device_ap_sme) { |
| 4701 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4702 | if (!drv->use_monitor) |
| 4703 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); |
| 4704 | } else if (drv->use_monitor) |
| 4705 | nl80211_remove_monitor_interface(drv); |
| 4706 | else |
| 4707 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
| 4708 | |
| 4709 | bss->beacon_set = 0; |
| 4710 | } |
| 4711 | |
| 4712 | |
| 4713 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
| 4714 | const u8 *addr, const u8 *data, |
| 4715 | size_t data_len) |
| 4716 | { |
| 4717 | struct sockaddr_ll ll; |
| 4718 | int ret; |
| 4719 | |
| 4720 | if (bss->drv->eapol_tx_sock < 0) { |
| 4721 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); |
| 4722 | return -1; |
| 4723 | } |
| 4724 | |
| 4725 | os_memset(&ll, 0, sizeof(ll)); |
| 4726 | ll.sll_family = AF_PACKET; |
| 4727 | ll.sll_ifindex = bss->ifindex; |
| 4728 | ll.sll_protocol = htons(ETH_P_PAE); |
| 4729 | ll.sll_halen = ETH_ALEN; |
| 4730 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); |
| 4731 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, |
| 4732 | (struct sockaddr *) &ll, sizeof(ll)); |
| 4733 | if (ret < 0) |
| 4734 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", |
| 4735 | strerror(errno)); |
| 4736 | |
| 4737 | return ret; |
| 4738 | } |
| 4739 | |
| 4740 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4741 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 4742 | |
| 4743 | static int wpa_driver_nl80211_hapd_send_eapol( |
| 4744 | void *priv, const u8 *addr, const u8 *data, |
| 4745 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
| 4746 | { |
| 4747 | struct i802_bss *bss = priv; |
| 4748 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4749 | struct ieee80211_hdr *hdr; |
| 4750 | size_t len; |
| 4751 | u8 *pos; |
| 4752 | int res; |
| 4753 | int qos = flags & WPA_STA_WMM; |
Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 4754 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4755 | if (drv->device_ap_sme || !drv->use_monitor) |
| 4756 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
| 4757 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4758 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
| 4759 | data_len; |
| 4760 | hdr = os_zalloc(len); |
| 4761 | if (hdr == NULL) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4762 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
| 4763 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4764 | return -1; |
| 4765 | } |
| 4766 | |
| 4767 | hdr->frame_control = |
| 4768 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); |
| 4769 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 4770 | if (encrypt) |
| 4771 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); |
| 4772 | if (qos) { |
| 4773 | hdr->frame_control |= |
| 4774 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); |
| 4775 | } |
| 4776 | |
| 4777 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 4778 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 4779 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 4780 | pos = (u8 *) (hdr + 1); |
| 4781 | |
| 4782 | if (qos) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 4783 | /* Set highest priority in QoS header */ |
| 4784 | pos[0] = 7; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4785 | pos[1] = 0; |
| 4786 | pos += 2; |
| 4787 | } |
| 4788 | |
| 4789 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); |
| 4790 | pos += sizeof(rfc1042_header); |
| 4791 | WPA_PUT_BE16(pos, ETH_P_PAE); |
| 4792 | pos += 2; |
| 4793 | memcpy(pos, data, data_len); |
| 4794 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4795 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4796 | 0, 0, 0, 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4797 | if (res < 0) { |
| 4798 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " |
| 4799 | "failed: %d (%s)", |
| 4800 | (unsigned long) len, errno, strerror(errno)); |
| 4801 | } |
| 4802 | os_free(hdr); |
| 4803 | |
| 4804 | return res; |
| 4805 | } |
| 4806 | |
| 4807 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4808 | 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] | 4809 | unsigned int total_flags, |
| 4810 | unsigned int flags_or, |
| 4811 | unsigned int flags_and) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4812 | { |
| 4813 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4814 | struct nl_msg *msg; |
| 4815 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4816 | struct nl80211_sta_flag_update upd; |
| 4817 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4818 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
| 4819 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", |
| 4820 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, |
| 4821 | !!(total_flags & WPA_STA_AUTHORIZED)); |
| 4822 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4823 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 4824 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 4825 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4826 | |
| 4827 | /* |
| 4828 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This |
| 4829 | * can be removed eventually. |
| 4830 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4831 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4832 | if (!flags || |
| 4833 | ((total_flags & WPA_STA_AUTHORIZED) && |
| 4834 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || |
| 4835 | ((total_flags & WPA_STA_WMM) && |
| 4836 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || |
| 4837 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && |
| 4838 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || |
| 4839 | ((total_flags & WPA_STA_MFP) && |
| 4840 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || |
| 4841 | ((total_flags & WPA_STA_TDLS_PEER) && |
| 4842 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) |
| 4843 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4844 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4845 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4846 | |
| 4847 | os_memset(&upd, 0, sizeof(upd)); |
| 4848 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); |
| 4849 | upd.set = sta_flags_nl80211(flags_or); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4850 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 4851 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4852 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4853 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 4854 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4855 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4856 | return -ENOBUFS; |
| 4857 | } |
| 4858 | |
| 4859 | |
| 4860 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
| 4861 | struct wpa_driver_associate_params *params) |
| 4862 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4863 | enum nl80211_iftype nlmode, old_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4864 | |
| 4865 | if (params->p2p) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4866 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
| 4867 | "group (GO)"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4868 | nlmode = NL80211_IFTYPE_P2P_GO; |
| 4869 | } else |
| 4870 | nlmode = NL80211_IFTYPE_AP; |
| 4871 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4872 | old_mode = drv->nlmode; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4873 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4874 | nl80211_remove_monitor_interface(drv); |
| 4875 | return -1; |
| 4876 | } |
| 4877 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4878 | if (params->freq.freq && |
| 4879 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4880 | if (old_mode != nlmode) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4881 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4882 | nl80211_remove_monitor_interface(drv); |
| 4883 | return -1; |
| 4884 | } |
| 4885 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4886 | return 0; |
| 4887 | } |
| 4888 | |
| 4889 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4890 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 4891 | int reset_mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4892 | { |
| 4893 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4894 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4895 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4896 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4897 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4898 | if (ret) { |
| 4899 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " |
| 4900 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4901 | } else { |
| 4902 | wpa_printf(MSG_DEBUG, |
| 4903 | "nl80211: Leave IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4904 | } |
| 4905 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4906 | if (reset_mode && |
| 4907 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4908 | NL80211_IFTYPE_STATION)) { |
| 4909 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 4910 | "station mode"); |
| 4911 | } |
| 4912 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4913 | return ret; |
| 4914 | } |
| 4915 | |
| 4916 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4917 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
| 4918 | struct wpa_driver_associate_params *params) |
| 4919 | { |
| 4920 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) |
| 4921 | return -1; |
| 4922 | |
| 4923 | if (params->htcaps && params->htcaps_mask) { |
| 4924 | int sz = sizeof(struct ieee80211_ht_capabilities); |
| 4925 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); |
| 4926 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", |
| 4927 | params->htcaps_mask, sz); |
| 4928 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, |
| 4929 | params->htcaps) || |
| 4930 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 4931 | params->htcaps_mask)) |
| 4932 | return -1; |
| 4933 | } |
| 4934 | |
| 4935 | #ifdef CONFIG_VHT_OVERRIDES |
| 4936 | if (params->disable_vht) { |
| 4937 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
| 4938 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) |
| 4939 | return -1; |
| 4940 | } |
| 4941 | |
| 4942 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 4943 | int sz = sizeof(struct ieee80211_vht_capabilities); |
| 4944 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); |
| 4945 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", |
| 4946 | params->vhtcaps_mask, sz); |
| 4947 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, |
| 4948 | params->vhtcaps) || |
| 4949 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 4950 | params->vhtcaps_mask)) |
| 4951 | return -1; |
| 4952 | } |
| 4953 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 4954 | |
| 4955 | return 0; |
| 4956 | } |
| 4957 | |
| 4958 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4959 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
| 4960 | struct wpa_driver_associate_params *params) |
| 4961 | { |
| 4962 | struct nl_msg *msg; |
| 4963 | int ret = -1; |
| 4964 | int count = 0; |
| 4965 | |
| 4966 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); |
| 4967 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4968 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4969 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 4970 | "IBSS mode"); |
| 4971 | return -1; |
| 4972 | } |
| 4973 | |
| 4974 | retry: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4975 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
| 4976 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
| 4977 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4978 | |
| 4979 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 4980 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4981 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 4982 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4983 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 4984 | drv->ssid_len = params->ssid_len; |
| 4985 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4986 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
| 4987 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4988 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4989 | |
| 4990 | ret = nl80211_set_conn_keys(params, msg); |
| 4991 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4992 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4993 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4994 | if (params->bssid && params->fixed_bssid) { |
| 4995 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, |
| 4996 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4997 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 4998 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4999 | } |
| 5000 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 5001 | if (params->fixed_freq) { |
| 5002 | wpa_printf(MSG_DEBUG, " * fixed_freq"); |
| 5003 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) |
| 5004 | goto fail; |
| 5005 | } |
| 5006 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5007 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 5008 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 5009 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
| 5010 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5011 | wpa_printf(MSG_DEBUG, " * control port"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5012 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 5013 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 5014 | } |
| 5015 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5016 | if (params->wpa_ie) { |
| 5017 | wpa_hexdump(MSG_DEBUG, |
| 5018 | " * Extra IEs for Beacon/Probe Response frames", |
| 5019 | params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5020 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 5021 | params->wpa_ie)) |
| 5022 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5023 | } |
| 5024 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 5025 | ret = nl80211_ht_vht_overrides(msg, params); |
| 5026 | if (ret < 0) |
| 5027 | goto fail; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5028 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5029 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5030 | msg = NULL; |
| 5031 | if (ret) { |
| 5032 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", |
| 5033 | ret, strerror(-ret)); |
| 5034 | count++; |
| 5035 | if (ret == -EALREADY && count == 1) { |
| 5036 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " |
| 5037 | "forced leave"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5038 | nl80211_leave_ibss(drv, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5039 | nlmsg_free(msg); |
| 5040 | goto retry; |
| 5041 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5042 | } else { |
| 5043 | wpa_printf(MSG_DEBUG, |
| 5044 | "nl80211: Join IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5045 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5046 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5047 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5048 | nlmsg_free(msg); |
| 5049 | return ret; |
| 5050 | } |
| 5051 | |
| 5052 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5053 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
| 5054 | struct wpa_driver_associate_params *params, |
| 5055 | struct nl_msg *msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5056 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5057 | if (params->bssid) { |
| 5058 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 5059 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5060 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 5061 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5062 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5063 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5064 | if (params->bssid_hint) { |
| 5065 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, |
| 5066 | MAC2STR(params->bssid_hint)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5067 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
| 5068 | params->bssid_hint)) |
| 5069 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5070 | } |
| 5071 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5072 | if (params->freq.freq) { |
| 5073 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5074 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 5075 | params->freq.freq)) |
| 5076 | return -1; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5077 | drv->assoc_freq = params->freq.freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5078 | } else |
| 5079 | drv->assoc_freq = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5080 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5081 | if (params->freq_hint) { |
| 5082 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5083 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
| 5084 | params->freq_hint)) |
| 5085 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 5086 | } |
| 5087 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5088 | if (params->bg_scan_period >= 0) { |
| 5089 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 5090 | params->bg_scan_period); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5091 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 5092 | params->bg_scan_period)) |
| 5093 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5094 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5095 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5096 | if (params->ssid) { |
| 5097 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 5098 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5099 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 5100 | params->ssid)) |
| 5101 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5102 | if (params->ssid_len > sizeof(drv->ssid)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5103 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5104 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 5105 | drv->ssid_len = params->ssid_len; |
| 5106 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5107 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5108 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5109 | if (params->wpa_ie && |
| 5110 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) |
| 5111 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5112 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5113 | if (params->wpa_proto) { |
| 5114 | enum nl80211_wpa_versions ver = 0; |
| 5115 | |
| 5116 | if (params->wpa_proto & WPA_PROTO_WPA) |
| 5117 | ver |= NL80211_WPA_VERSION_1; |
| 5118 | if (params->wpa_proto & WPA_PROTO_RSN) |
| 5119 | ver |= NL80211_WPA_VERSION_2; |
| 5120 | |
| 5121 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5122 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 5123 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5124 | } |
| 5125 | |
| 5126 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
| 5127 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
| 5128 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5129 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 5130 | cipher)) |
| 5131 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5132 | } |
| 5133 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 5134 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
| 5135 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { |
| 5136 | /* |
| 5137 | * This is likely to work even though many drivers do not |
| 5138 | * advertise support for operations without GTK. |
| 5139 | */ |
| 5140 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); |
| 5141 | } else if (params->group_suite != WPA_CIPHER_NONE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5142 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
| 5143 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5144 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
| 5145 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5146 | } |
| 5147 | |
| 5148 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 5149 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 5150 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || |
| 5151 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5152 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5153 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
| 5154 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5155 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5156 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
| 5157 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5158 | int mgmt = WLAN_AKM_SUITE_PSK; |
| 5159 | |
| 5160 | switch (params->key_mgmt_suite) { |
| 5161 | case WPA_KEY_MGMT_CCKM: |
| 5162 | mgmt = WLAN_AKM_SUITE_CCKM; |
| 5163 | break; |
| 5164 | case WPA_KEY_MGMT_IEEE8021X: |
| 5165 | mgmt = WLAN_AKM_SUITE_8021X; |
| 5166 | break; |
| 5167 | case WPA_KEY_MGMT_FT_IEEE8021X: |
| 5168 | mgmt = WLAN_AKM_SUITE_FT_8021X; |
| 5169 | break; |
| 5170 | case WPA_KEY_MGMT_FT_PSK: |
| 5171 | mgmt = WLAN_AKM_SUITE_FT_PSK; |
| 5172 | break; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 5173 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
| 5174 | mgmt = WLAN_AKM_SUITE_8021X_SHA256; |
| 5175 | break; |
| 5176 | case WPA_KEY_MGMT_PSK_SHA256: |
| 5177 | mgmt = WLAN_AKM_SUITE_PSK_SHA256; |
| 5178 | break; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5179 | case WPA_KEY_MGMT_OSEN: |
| 5180 | mgmt = WLAN_AKM_SUITE_OSEN; |
| 5181 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5182 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
| 5183 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B; |
| 5184 | break; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 5185 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
| 5186 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B_192; |
| 5187 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5188 | case WPA_KEY_MGMT_PSK: |
| 5189 | default: |
| 5190 | mgmt = WLAN_AKM_SUITE_PSK; |
| 5191 | break; |
| 5192 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 5193 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5194 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
| 5195 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5196 | } |
| 5197 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5198 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 5199 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5200 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 5201 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 5202 | (params->pairwise_suite == WPA_CIPHER_NONE || |
| 5203 | params->pairwise_suite == WPA_CIPHER_WEP104 || |
| 5204 | params->pairwise_suite == WPA_CIPHER_WEP40) && |
| 5205 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 5206 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
| 5207 | return -1; |
| 5208 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5209 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 5210 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 5211 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5212 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5213 | if (params->rrm_used) { |
| 5214 | u32 drv_rrm_flags = drv->capa.rrm_flags; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 5215 | if ((!((drv_rrm_flags & |
| 5216 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && |
| 5217 | (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && |
| 5218 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5219 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
| 5220 | return -1; |
| 5221 | } |
| 5222 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5223 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5224 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5225 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5226 | if (params->p2p) |
| 5227 | wpa_printf(MSG_DEBUG, " * P2P group"); |
| 5228 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5229 | if (params->pbss) { |
| 5230 | wpa_printf(MSG_DEBUG, " * PBSS"); |
| 5231 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 5232 | return -1; |
| 5233 | } |
| 5234 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 5235 | drv->connect_reassoc = 0; |
| 5236 | if (params->prev_bssid) { |
| 5237 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, |
| 5238 | MAC2STR(params->prev_bssid)); |
| 5239 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
| 5240 | params->prev_bssid)) |
| 5241 | return -1; |
| 5242 | drv->connect_reassoc = 1; |
| 5243 | } |
| 5244 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5245 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5246 | } |
| 5247 | |
| 5248 | |
| 5249 | static int wpa_driver_nl80211_try_connect( |
| 5250 | struct wpa_driver_nl80211_data *drv, |
| 5251 | struct wpa_driver_associate_params *params) |
| 5252 | { |
| 5253 | struct nl_msg *msg; |
| 5254 | enum nl80211_auth_type type; |
| 5255 | int ret; |
| 5256 | int algs; |
| 5257 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5258 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5259 | if (params->req_key_mgmt_offload && params->psk && |
| 5260 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 5261 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
| 5262 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { |
| 5263 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); |
| 5264 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); |
| 5265 | if (ret) |
| 5266 | return ret; |
| 5267 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5268 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5269 | |
| 5270 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
| 5271 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5272 | if (!msg) |
| 5273 | return -1; |
| 5274 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5275 | ret = nl80211_connect_common(drv, params, msg); |
| 5276 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5277 | goto fail; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5278 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5279 | algs = 0; |
| 5280 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 5281 | algs++; |
| 5282 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 5283 | algs++; |
| 5284 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 5285 | algs++; |
| 5286 | if (algs > 1) { |
| 5287 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " |
| 5288 | "selection"); |
| 5289 | goto skip_auth_type; |
| 5290 | } |
| 5291 | |
| 5292 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 5293 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 5294 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 5295 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 5296 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 5297 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 5298 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 5299 | type = NL80211_AUTHTYPE_FT; |
| 5300 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5301 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5302 | |
| 5303 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5304 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 5305 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5306 | |
| 5307 | skip_auth_type: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5308 | ret = nl80211_set_conn_keys(params, msg); |
| 5309 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5310 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5311 | |
| 5312 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5313 | msg = NULL; |
| 5314 | if (ret) { |
| 5315 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " |
| 5316 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5317 | } else { |
| 5318 | wpa_printf(MSG_DEBUG, |
| 5319 | "nl80211: Connect request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5320 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5321 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5322 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5323 | nlmsg_free(msg); |
| 5324 | return ret; |
| 5325 | |
| 5326 | } |
| 5327 | |
| 5328 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5329 | static int wpa_driver_nl80211_connect( |
| 5330 | struct wpa_driver_nl80211_data *drv, |
| 5331 | struct wpa_driver_associate_params *params) |
| 5332 | { |
Jithu Jance | a7c60b4 | 2014-12-03 18:54:40 +0530 | [diff] [blame] | 5333 | int ret; |
| 5334 | |
| 5335 | /* Store the connection attempted bssid for future use */ |
| 5336 | if (params->bssid) |
| 5337 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 5338 | else |
| 5339 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
| 5340 | |
| 5341 | ret = wpa_driver_nl80211_try_connect(drv, params); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5342 | if (ret == -EALREADY) { |
| 5343 | /* |
| 5344 | * cfg80211 does not currently accept new connections if |
| 5345 | * we are already connected. As a workaround, force |
| 5346 | * disconnection and try again. |
| 5347 | */ |
| 5348 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " |
| 5349 | "disconnecting before reassociation " |
| 5350 | "attempt"); |
| 5351 | if (wpa_driver_nl80211_disconnect( |
| 5352 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) |
| 5353 | return -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5354 | ret = wpa_driver_nl80211_try_connect(drv, params); |
| 5355 | } |
| 5356 | return ret; |
| 5357 | } |
| 5358 | |
| 5359 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5360 | static int wpa_driver_nl80211_associate( |
| 5361 | void *priv, struct wpa_driver_associate_params *params) |
| 5362 | { |
| 5363 | struct i802_bss *bss = priv; |
| 5364 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5365 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5366 | struct nl_msg *msg; |
| 5367 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5368 | nl80211_unmask_11b_rates(bss); |
| 5369 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5370 | if (params->mode == IEEE80211_MODE_AP) |
| 5371 | return wpa_driver_nl80211_ap(drv, params); |
| 5372 | |
| 5373 | if (params->mode == IEEE80211_MODE_IBSS) |
| 5374 | return wpa_driver_nl80211_ibss(drv, params); |
| 5375 | |
| 5376 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5377 | enum nl80211_iftype nlmode = params->p2p ? |
| 5378 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 5379 | |
| 5380 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5381 | return -1; |
| 5382 | return wpa_driver_nl80211_connect(drv, params); |
| 5383 | } |
| 5384 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5385 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5386 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5387 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
| 5388 | drv->ifindex); |
| 5389 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5390 | if (!msg) |
| 5391 | return -1; |
| 5392 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5393 | ret = nl80211_connect_common(drv, params, msg); |
| 5394 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5395 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5396 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 5397 | if (params->fils_kek) { |
| 5398 | wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)", |
| 5399 | (unsigned int) params->fils_kek_len); |
| 5400 | if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len, |
| 5401 | params->fils_kek)) |
| 5402 | goto fail; |
| 5403 | } |
| 5404 | if (params->fils_nonces) { |
| 5405 | wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)", |
| 5406 | params->fils_nonces, |
| 5407 | params->fils_nonces_len); |
| 5408 | if (nla_put(msg, NL80211_ATTR_FILS_NONCES, |
| 5409 | params->fils_nonces_len, params->fils_nonces)) |
| 5410 | goto fail; |
| 5411 | } |
| 5412 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5413 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5414 | msg = NULL; |
| 5415 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5416 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 5417 | "nl80211: MLME command failed (assoc): ret=%d (%s)", |
| 5418 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5419 | nl80211_dump_scan(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5420 | } else { |
| 5421 | wpa_printf(MSG_DEBUG, |
| 5422 | "nl80211: Association request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5423 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5424 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5425 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5426 | nlmsg_free(msg); |
| 5427 | return ret; |
| 5428 | } |
| 5429 | |
| 5430 | |
| 5431 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5432 | int ifindex, enum nl80211_iftype mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5433 | { |
| 5434 | struct nl_msg *msg; |
| 5435 | int ret = -ENOBUFS; |
| 5436 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5437 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
| 5438 | ifindex, mode, nl80211_iftype_str(mode)); |
| 5439 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5440 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 5441 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) |
| 5442 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5443 | |
| 5444 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5445 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5446 | if (!ret) |
| 5447 | return 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5448 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5449 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5450 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
| 5451 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); |
| 5452 | return ret; |
| 5453 | } |
| 5454 | |
| 5455 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5456 | static int wpa_driver_nl80211_set_mode_impl( |
| 5457 | struct i802_bss *bss, |
| 5458 | enum nl80211_iftype nlmode, |
| 5459 | struct hostapd_freq_params *desired_freq_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5460 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5461 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5462 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5463 | int i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5464 | int was_ap = is_ap_interface(drv->nlmode); |
| 5465 | int res; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5466 | int mode_switch_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5467 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5468 | if (TEST_FAIL()) |
| 5469 | return -1; |
| 5470 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5471 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 5472 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) |
| 5473 | mode_switch_res = 0; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5474 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5475 | if (mode_switch_res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5476 | drv->nlmode = nlmode; |
| 5477 | ret = 0; |
| 5478 | goto done; |
| 5479 | } |
| 5480 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5481 | if (mode_switch_res == -ENODEV) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5482 | return -1; |
| 5483 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5484 | if (nlmode == drv->nlmode) { |
| 5485 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
| 5486 | "requested mode - ignore error"); |
| 5487 | ret = 0; |
| 5488 | goto done; /* Already in the requested mode */ |
| 5489 | } |
| 5490 | |
| 5491 | /* mac80211 doesn't allow mode changes while the device is up, so |
| 5492 | * take the device down, try to set the mode again, and bring the |
| 5493 | * device back up. |
| 5494 | */ |
| 5495 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
| 5496 | "interface down"); |
| 5497 | for (i = 0; i < 10; i++) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5498 | res = i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5499 | if (res == -EACCES || res == -ENODEV) |
| 5500 | break; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5501 | if (res != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5502 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
| 5503 | "interface down"); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5504 | os_sleep(0, 100000); |
| 5505 | continue; |
| 5506 | } |
| 5507 | |
| 5508 | /* |
| 5509 | * Setting the mode will fail for some drivers if the phy is |
| 5510 | * on a frequency that the mode is disallowed in. |
| 5511 | */ |
| 5512 | if (desired_freq_params) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5513 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5514 | if (res) { |
| 5515 | wpa_printf(MSG_DEBUG, |
| 5516 | "nl80211: Failed to set frequency on interface"); |
| 5517 | } |
| 5518 | } |
| 5519 | |
| 5520 | /* Try to set the mode again while the interface is down */ |
| 5521 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 5522 | if (mode_switch_res == -EBUSY) { |
| 5523 | wpa_printf(MSG_DEBUG, |
| 5524 | "nl80211: Delaying mode set while interface going down"); |
| 5525 | os_sleep(0, 100000); |
| 5526 | continue; |
| 5527 | } |
| 5528 | ret = mode_switch_res; |
| 5529 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5530 | } |
| 5531 | |
| 5532 | if (!ret) { |
| 5533 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " |
| 5534 | "interface is down"); |
| 5535 | drv->nlmode = nlmode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5536 | drv->ignore_if_down_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5537 | } |
| 5538 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5539 | /* Bring the interface back up */ |
| 5540 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); |
| 5541 | if (res != 0) { |
| 5542 | wpa_printf(MSG_DEBUG, |
| 5543 | "nl80211: Failed to set interface up after switching mode"); |
| 5544 | ret = -1; |
| 5545 | } |
| 5546 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5547 | done: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5548 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5549 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " |
| 5550 | "from %d failed", nlmode, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5551 | return ret; |
| 5552 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5553 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5554 | if (is_p2p_net_interface(nlmode)) { |
| 5555 | wpa_printf(MSG_DEBUG, |
| 5556 | "nl80211: Interface %s mode change to P2P - disable 11b rates", |
| 5557 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5558 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5559 | } else if (drv->disabled_11b_rates) { |
| 5560 | wpa_printf(MSG_DEBUG, |
| 5561 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", |
| 5562 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5563 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5564 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5565 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5566 | if (is_ap_interface(nlmode)) { |
| 5567 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
| 5568 | /* Setup additional AP mode functionality if needed */ |
| 5569 | if (nl80211_setup_ap(bss)) |
| 5570 | return -1; |
| 5571 | } else if (was_ap) { |
| 5572 | /* Remove additional AP mode functionality */ |
| 5573 | nl80211_teardown_ap(bss); |
| 5574 | } else { |
| 5575 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
| 5576 | } |
| 5577 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5578 | if (is_mesh_interface(nlmode) && |
| 5579 | nl80211_mgmt_subscribe_mesh(bss)) |
| 5580 | return -1; |
| 5581 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5582 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5583 | !is_mesh_interface(nlmode) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5584 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 5585 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " |
| 5586 | "frame processing - ignore for now"); |
| 5587 | |
| 5588 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5589 | } |
| 5590 | |
| 5591 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5592 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 5593 | enum nl80211_iftype nlmode) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5594 | { |
| 5595 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); |
| 5596 | } |
| 5597 | |
| 5598 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5599 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 5600 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5601 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5602 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5603 | freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5604 | } |
| 5605 | |
| 5606 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5607 | static int wpa_driver_nl80211_get_capa(void *priv, |
| 5608 | struct wpa_driver_capa *capa) |
| 5609 | { |
| 5610 | struct i802_bss *bss = priv; |
| 5611 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 5612 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5613 | if (!drv->has_capability) |
| 5614 | return -1; |
| 5615 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5616 | if (drv->extended_capa && drv->extended_capa_mask) { |
| 5617 | capa->extended_capa = drv->extended_capa; |
| 5618 | capa->extended_capa_mask = drv->extended_capa_mask; |
| 5619 | capa->extended_capa_len = drv->extended_capa_len; |
| 5620 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5621 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5622 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5623 | } |
| 5624 | |
| 5625 | |
| 5626 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) |
| 5627 | { |
| 5628 | struct i802_bss *bss = priv; |
| 5629 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5630 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5631 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
| 5632 | bss->ifname, drv->operstate, state, |
| 5633 | state ? "UP" : "DORMANT"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5634 | drv->operstate = state; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5635 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5636 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
| 5637 | } |
| 5638 | |
| 5639 | |
| 5640 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) |
| 5641 | { |
| 5642 | struct i802_bss *bss = priv; |
| 5643 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5644 | struct nl_msg *msg; |
| 5645 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5646 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5647 | |
| 5648 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { |
| 5649 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); |
| 5650 | return 0; |
| 5651 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5652 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5653 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
| 5654 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); |
| 5655 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5656 | os_memset(&upd, 0, sizeof(upd)); |
| 5657 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 5658 | if (authorized) |
| 5659 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5660 | |
| 5661 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5662 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
| 5663 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { |
| 5664 | nlmsg_free(msg); |
| 5665 | return -ENOBUFS; |
| 5666 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5667 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5668 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5669 | if (!ret) |
| 5670 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5671 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
| 5672 | ret, strerror(-ret)); |
| 5673 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5674 | } |
| 5675 | |
| 5676 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5677 | /* Set kernel driver on given frequency (MHz) */ |
| 5678 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5679 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5680 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5681 | return nl80211_set_channel(bss, freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5682 | } |
| 5683 | |
| 5684 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5685 | static inline int min_int(int a, int b) |
| 5686 | { |
| 5687 | if (a < b) |
| 5688 | return a; |
| 5689 | return b; |
| 5690 | } |
| 5691 | |
| 5692 | |
| 5693 | static int get_key_handler(struct nl_msg *msg, void *arg) |
| 5694 | { |
| 5695 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5696 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5697 | |
| 5698 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5699 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5700 | |
| 5701 | /* |
| 5702 | * TODO: validate the key index and mac address! |
| 5703 | * Otherwise, there's a race condition as soon as |
| 5704 | * the kernel starts sending key notifications. |
| 5705 | */ |
| 5706 | |
| 5707 | if (tb[NL80211_ATTR_KEY_SEQ]) |
| 5708 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 5709 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); |
| 5710 | return NL_SKIP; |
| 5711 | } |
| 5712 | |
| 5713 | |
| 5714 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, |
| 5715 | int idx, u8 *seq) |
| 5716 | { |
| 5717 | struct i802_bss *bss = priv; |
| 5718 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5719 | struct nl_msg *msg; |
| 5720 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5721 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
| 5722 | NL80211_CMD_GET_KEY); |
| 5723 | if (!msg || |
| 5724 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 5725 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
| 5726 | nlmsg_free(msg); |
| 5727 | return -ENOBUFS; |
| 5728 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5729 | |
| 5730 | memset(seq, 0, 6); |
| 5731 | |
| 5732 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5733 | } |
| 5734 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5735 | |
| 5736 | static int i802_set_rts(void *priv, int rts) |
| 5737 | { |
| 5738 | struct i802_bss *bss = priv; |
| 5739 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5740 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5741 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5742 | u32 val; |
| 5743 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5744 | if (rts >= 2347) |
| 5745 | val = (u32) -1; |
| 5746 | else |
| 5747 | val = rts; |
| 5748 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5749 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 5750 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
| 5751 | nlmsg_free(msg); |
| 5752 | return -ENOBUFS; |
| 5753 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5754 | |
| 5755 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5756 | if (!ret) |
| 5757 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5758 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
| 5759 | "%d (%s)", rts, ret, strerror(-ret)); |
| 5760 | return ret; |
| 5761 | } |
| 5762 | |
| 5763 | |
| 5764 | static int i802_set_frag(void *priv, int frag) |
| 5765 | { |
| 5766 | struct i802_bss *bss = priv; |
| 5767 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5768 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5769 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5770 | u32 val; |
| 5771 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5772 | if (frag >= 2346) |
| 5773 | val = (u32) -1; |
| 5774 | else |
| 5775 | val = frag; |
| 5776 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5777 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 5778 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
| 5779 | nlmsg_free(msg); |
| 5780 | return -ENOBUFS; |
| 5781 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5782 | |
| 5783 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5784 | if (!ret) |
| 5785 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5786 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
| 5787 | "%d: %d (%s)", frag, ret, strerror(-ret)); |
| 5788 | return ret; |
| 5789 | } |
| 5790 | |
| 5791 | |
| 5792 | static int i802_flush(void *priv) |
| 5793 | { |
| 5794 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5795 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5796 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5797 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5798 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
| 5799 | bss->ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5800 | |
| 5801 | /* |
| 5802 | * XXX: FIX! this needs to flush all VLANs too |
| 5803 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5804 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
| 5805 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5806 | if (res) { |
| 5807 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " |
| 5808 | "(%s)", res, strerror(-res)); |
| 5809 | } |
| 5810 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5811 | } |
| 5812 | |
| 5813 | |
| 5814 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
| 5815 | { |
| 5816 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5817 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5818 | struct hostap_sta_driver_data *data = arg; |
| 5819 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; |
| 5820 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
| 5821 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, |
| 5822 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, |
| 5823 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, |
| 5824 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
| 5825 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 5826 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5827 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
| 5828 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5829 | }; |
| 5830 | |
| 5831 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5832 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5833 | |
| 5834 | /* |
| 5835 | * TODO: validate the interface and mac address! |
| 5836 | * Otherwise, there's a race condition as soon as |
| 5837 | * the kernel starts sending station notifications. |
| 5838 | */ |
| 5839 | |
| 5840 | if (!tb[NL80211_ATTR_STA_INFO]) { |
| 5841 | wpa_printf(MSG_DEBUG, "sta stats missing!"); |
| 5842 | return NL_SKIP; |
| 5843 | } |
| 5844 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, |
| 5845 | tb[NL80211_ATTR_STA_INFO], |
| 5846 | stats_policy)) { |
| 5847 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); |
| 5848 | return NL_SKIP; |
| 5849 | } |
| 5850 | |
| 5851 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) |
| 5852 | data->inactive_msec = |
| 5853 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5854 | /* For backwards compatibility, fetch the 32-bit counters first. */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5855 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
| 5856 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); |
| 5857 | if (stats[NL80211_STA_INFO_TX_BYTES]) |
| 5858 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5859 | if (stats[NL80211_STA_INFO_RX_BYTES64] && |
| 5860 | stats[NL80211_STA_INFO_TX_BYTES64]) { |
| 5861 | /* |
| 5862 | * The driver supports 64-bit counters, so use them to override |
| 5863 | * the 32-bit values. |
| 5864 | */ |
| 5865 | data->rx_bytes = |
| 5866 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); |
| 5867 | data->tx_bytes = |
| 5868 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); |
| 5869 | data->bytes_64bit = 1; |
| 5870 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5871 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
| 5872 | data->rx_packets = |
| 5873 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); |
| 5874 | if (stats[NL80211_STA_INFO_TX_PACKETS]) |
| 5875 | data->tx_packets = |
| 5876 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 5877 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
| 5878 | data->tx_retry_failed = |
| 5879 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5880 | |
| 5881 | return NL_SKIP; |
| 5882 | } |
| 5883 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5884 | static int i802_read_sta_data(struct i802_bss *bss, |
| 5885 | struct hostap_sta_driver_data *data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5886 | const u8 *addr) |
| 5887 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5888 | struct nl_msg *msg; |
| 5889 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5890 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
| 5891 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 5892 | nlmsg_free(msg); |
| 5893 | return -ENOBUFS; |
| 5894 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5895 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5896 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5897 | } |
| 5898 | |
| 5899 | |
| 5900 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
| 5901 | int cw_min, int cw_max, int burst_time) |
| 5902 | { |
| 5903 | struct i802_bss *bss = priv; |
| 5904 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5905 | struct nl_msg *msg; |
| 5906 | struct nlattr *txq, *params; |
| 5907 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5908 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5909 | if (!msg) |
| 5910 | return -1; |
| 5911 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5912 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
| 5913 | if (!txq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5914 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5915 | |
| 5916 | /* We are only sending parameters for a single TXQ at a time */ |
| 5917 | params = nla_nest_start(msg, 1); |
| 5918 | if (!params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5919 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5920 | |
| 5921 | switch (queue) { |
| 5922 | case 0: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5923 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
| 5924 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5925 | break; |
| 5926 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5927 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
| 5928 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5929 | break; |
| 5930 | case 2: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5931 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
| 5932 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5933 | break; |
| 5934 | case 3: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5935 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
| 5936 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5937 | break; |
| 5938 | } |
| 5939 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
| 5940 | * 32 usec, so need to convert the value here. */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5941 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
| 5942 | (burst_time * 100 + 16) / 32) || |
| 5943 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || |
| 5944 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || |
| 5945 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) |
| 5946 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5947 | |
| 5948 | nla_nest_end(msg, params); |
| 5949 | |
| 5950 | nla_nest_end(msg, txq); |
| 5951 | |
| 5952 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 5953 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5954 | msg = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5955 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5956 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5957 | return -1; |
| 5958 | } |
| 5959 | |
| 5960 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5961 | 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] | 5962 | const char *ifname, int vlan_id) |
| 5963 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5964 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5965 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5966 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5967 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5968 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
| 5969 | ", ifname=%s[%d], vlan_id=%d)", |
| 5970 | bss->ifname, if_nametoindex(bss->ifname), |
| 5971 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5972 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5973 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 5974 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { |
| 5975 | nlmsg_free(msg); |
| 5976 | return -ENOBUFS; |
| 5977 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5978 | |
| 5979 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5980 | if (ret < 0) { |
| 5981 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" |
| 5982 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", |
| 5983 | MAC2STR(addr), ifname, vlan_id, ret, |
| 5984 | strerror(-ret)); |
| 5985 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5986 | return ret; |
| 5987 | } |
| 5988 | |
| 5989 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5990 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
| 5991 | { |
| 5992 | struct hostap_sta_driver_data data; |
| 5993 | int ret; |
| 5994 | |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 5995 | os_memset(&data, 0, sizeof(data)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5996 | data.inactive_msec = (unsigned long) -1; |
| 5997 | ret = i802_read_sta_data(priv, &data, addr); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5998 | if (ret == -ENOENT) |
| 5999 | return -ENOENT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6000 | if (ret || data.inactive_msec == (unsigned long) -1) |
| 6001 | return -1; |
| 6002 | return data.inactive_msec / 1000; |
| 6003 | } |
| 6004 | |
| 6005 | |
| 6006 | static int i802_sta_clear_stats(void *priv, const u8 *addr) |
| 6007 | { |
| 6008 | #if 0 |
| 6009 | /* TODO */ |
| 6010 | #endif |
| 6011 | return 0; |
| 6012 | } |
| 6013 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6014 | |
| 6015 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
| 6016 | int reason) |
| 6017 | { |
| 6018 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6019 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6020 | struct ieee80211_mgmt mgmt; |
Dmitry Shmidt | 2933359 | 2017-01-09 12:27:11 -0800 | [diff] [blame^] | 6021 | u8 channel; |
| 6022 | |
| 6023 | if (ieee80211_freq_to_chan(bss->freq, &channel) == |
| 6024 | HOSTAPD_MODE_IEEE80211AD) { |
| 6025 | /* Deauthentication is not used in DMG/IEEE 802.11ad; |
| 6026 | * disassociate the STA instead. */ |
| 6027 | return i802_sta_disassoc(priv, own_addr, addr, reason); |
| 6028 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6029 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6030 | if (is_mesh_interface(drv->nlmode)) |
| 6031 | return -1; |
| 6032 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6033 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6034 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6035 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6036 | memset(&mgmt, 0, sizeof(mgmt)); |
| 6037 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 6038 | WLAN_FC_STYPE_DEAUTH); |
| 6039 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 6040 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 6041 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 6042 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
| 6043 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 6044 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6045 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6046 | 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6047 | } |
| 6048 | |
| 6049 | |
| 6050 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
| 6051 | int reason) |
| 6052 | { |
| 6053 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6054 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6055 | struct ieee80211_mgmt mgmt; |
| 6056 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6057 | if (is_mesh_interface(drv->nlmode)) |
| 6058 | return -1; |
| 6059 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6060 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6061 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6062 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6063 | memset(&mgmt, 0, sizeof(mgmt)); |
| 6064 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 6065 | WLAN_FC_STYPE_DISASSOC); |
| 6066 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 6067 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 6068 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 6069 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
| 6070 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 6071 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6072 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6073 | 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6074 | } |
| 6075 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6076 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6077 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
| 6078 | { |
| 6079 | char buf[200], *pos, *end; |
| 6080 | int i, res; |
| 6081 | |
| 6082 | pos = buf; |
| 6083 | end = pos + sizeof(buf); |
| 6084 | |
| 6085 | for (i = 0; i < drv->num_if_indices; i++) { |
| 6086 | if (!drv->if_indices[i]) |
| 6087 | continue; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6088 | res = os_snprintf(pos, end - pos, " %d(%d)", |
| 6089 | drv->if_indices[i], |
| 6090 | drv->if_indices_reason[i]); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6091 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6092 | break; |
| 6093 | pos += res; |
| 6094 | } |
| 6095 | *pos = '\0'; |
| 6096 | |
| 6097 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", |
| 6098 | drv->num_if_indices, buf); |
| 6099 | } |
| 6100 | |
| 6101 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6102 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 6103 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6104 | { |
| 6105 | int i; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6106 | int *old, *old_reason; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6107 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6108 | wpa_printf(MSG_DEBUG, |
| 6109 | "nl80211: Add own interface ifindex %d (ifidx_reason %d)", |
| 6110 | ifidx, ifidx_reason); |
| 6111 | if (have_ifidx(drv, ifidx, ifidx_reason)) { |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6112 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
| 6113 | ifidx); |
| 6114 | return; |
| 6115 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6116 | for (i = 0; i < drv->num_if_indices; i++) { |
| 6117 | if (drv->if_indices[i] == 0) { |
| 6118 | drv->if_indices[i] = ifidx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6119 | drv->if_indices_reason[i] = ifidx_reason; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6120 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6121 | return; |
| 6122 | } |
| 6123 | } |
| 6124 | |
| 6125 | if (drv->if_indices != drv->default_if_indices) |
| 6126 | old = drv->if_indices; |
| 6127 | else |
| 6128 | old = NULL; |
| 6129 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6130 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
| 6131 | old_reason = drv->if_indices_reason; |
| 6132 | else |
| 6133 | old_reason = NULL; |
| 6134 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6135 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
| 6136 | sizeof(int)); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6137 | drv->if_indices_reason = os_realloc_array(old_reason, |
| 6138 | drv->num_if_indices + 1, |
| 6139 | sizeof(int)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6140 | if (!drv->if_indices) { |
| 6141 | if (!old) |
| 6142 | drv->if_indices = drv->default_if_indices; |
| 6143 | else |
| 6144 | drv->if_indices = old; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6145 | } |
| 6146 | if (!drv->if_indices_reason) { |
| 6147 | if (!old_reason) |
| 6148 | drv->if_indices_reason = drv->default_if_indices_reason; |
| 6149 | else |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 6150 | drv->if_indices_reason = old_reason; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6151 | } |
| 6152 | if (!drv->if_indices || !drv->if_indices_reason) { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6153 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
| 6154 | "interfaces"); |
| 6155 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); |
| 6156 | return; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6157 | } |
| 6158 | if (!old) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6159 | os_memcpy(drv->if_indices, drv->default_if_indices, |
| 6160 | sizeof(drv->default_if_indices)); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6161 | if (!old_reason) |
| 6162 | os_memcpy(drv->if_indices_reason, |
| 6163 | drv->default_if_indices_reason, |
| 6164 | sizeof(drv->default_if_indices_reason)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6165 | drv->if_indices[drv->num_if_indices] = ifidx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6166 | drv->if_indices_reason[drv->num_if_indices] = ifidx_reason; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6167 | drv->num_if_indices++; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6168 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6169 | } |
| 6170 | |
| 6171 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6172 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 6173 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6174 | { |
| 6175 | int i; |
| 6176 | |
| 6177 | for (i = 0; i < drv->num_if_indices; i++) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6178 | if ((drv->if_indices[i] == ifidx || ifidx == IFIDX_ANY) && |
| 6179 | (drv->if_indices_reason[i] == ifidx_reason || |
| 6180 | ifidx_reason == IFIDX_ANY)) { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6181 | drv->if_indices[i] = 0; |
| 6182 | break; |
| 6183 | } |
| 6184 | } |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6185 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6186 | } |
| 6187 | |
| 6188 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6189 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 6190 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6191 | { |
| 6192 | int i; |
| 6193 | |
| 6194 | for (i = 0; i < drv->num_if_indices; i++) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6195 | if (drv->if_indices[i] == ifidx && |
| 6196 | (drv->if_indices_reason[i] == ifidx_reason || |
| 6197 | ifidx_reason == IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6198 | return 1; |
| 6199 | |
| 6200 | return 0; |
| 6201 | } |
| 6202 | |
| 6203 | |
| 6204 | 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] | 6205 | const char *bridge_ifname, char *ifname_wds) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6206 | { |
| 6207 | struct i802_bss *bss = priv; |
| 6208 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6209 | char name[IFNAMSIZ + 1]; |
| 6210 | |
| 6211 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6212 | if (ifname_wds) |
| 6213 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); |
| 6214 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6215 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
| 6216 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); |
| 6217 | if (val) { |
| 6218 | if (!if_nametoindex(name)) { |
| 6219 | if (nl80211_create_iface(drv, name, |
| 6220 | NL80211_IFTYPE_AP_VLAN, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6221 | bss->addr, 1, NULL, NULL, 0) < |
| 6222 | 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6223 | return -1; |
| 6224 | if (bridge_ifname && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6225 | linux_br_add_if(drv->global->ioctl_sock, |
| 6226 | bridge_ifname, name) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6227 | return -1; |
| 6228 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6229 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
| 6230 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " |
| 6231 | "interface %s up", name); |
| 6232 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6233 | return i802_set_sta_vlan(priv, addr, name, 0); |
| 6234 | } else { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6235 | if (bridge_ifname) |
| 6236 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, |
| 6237 | name); |
| 6238 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6239 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 6240 | nl80211_remove_iface(drv, if_nametoindex(name)); |
| 6241 | return 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6242 | } |
| 6243 | } |
| 6244 | |
| 6245 | |
| 6246 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
| 6247 | { |
| 6248 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 6249 | struct sockaddr_ll lladdr; |
| 6250 | unsigned char buf[3000]; |
| 6251 | int len; |
| 6252 | socklen_t fromlen = sizeof(lladdr); |
| 6253 | |
| 6254 | len = recvfrom(sock, buf, sizeof(buf), 0, |
| 6255 | (struct sockaddr *)&lladdr, &fromlen); |
| 6256 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6257 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
| 6258 | strerror(errno)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6259 | return; |
| 6260 | } |
| 6261 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6262 | if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6263 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
| 6264 | } |
| 6265 | |
| 6266 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6267 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
| 6268 | struct i802_bss *bss, |
| 6269 | const char *brname, const char *ifname) |
| 6270 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6271 | int br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6272 | char in_br[IFNAMSIZ]; |
| 6273 | |
| 6274 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6275 | br_ifindex = if_nametoindex(brname); |
| 6276 | if (br_ifindex == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6277 | /* |
| 6278 | * Bridge was configured, but the bridge device does |
| 6279 | * not exist. Try to add it now. |
| 6280 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6281 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6282 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
| 6283 | "bridge interface %s: %s", |
| 6284 | brname, strerror(errno)); |
| 6285 | return -1; |
| 6286 | } |
| 6287 | bss->added_bridge = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6288 | br_ifindex = if_nametoindex(brname); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6289 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6290 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6291 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6292 | |
| 6293 | if (linux_br_get(in_br, ifname) == 0) { |
| 6294 | if (os_strcmp(in_br, brname) == 0) |
| 6295 | return 0; /* already in the bridge */ |
| 6296 | |
| 6297 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " |
| 6298 | "bridge %s", ifname, in_br); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6299 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
| 6300 | 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6301 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
| 6302 | "remove interface %s from bridge " |
| 6303 | "%s: %s", |
| 6304 | ifname, brname, strerror(errno)); |
| 6305 | return -1; |
| 6306 | } |
| 6307 | } |
| 6308 | |
| 6309 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", |
| 6310 | ifname, brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6311 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6312 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
| 6313 | "into bridge %s: %s", |
| 6314 | ifname, brname, strerror(errno)); |
| 6315 | return -1; |
| 6316 | } |
| 6317 | bss->added_if_into_bridge = 1; |
| 6318 | |
| 6319 | return 0; |
| 6320 | } |
| 6321 | |
| 6322 | |
| 6323 | static void *i802_init(struct hostapd_data *hapd, |
| 6324 | struct wpa_init_params *params) |
| 6325 | { |
| 6326 | struct wpa_driver_nl80211_data *drv; |
| 6327 | struct i802_bss *bss; |
| 6328 | size_t i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6329 | char master_ifname[IFNAMSIZ]; |
| 6330 | int ifindex, br_ifindex = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6331 | int br_added = 0; |
| 6332 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 6333 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
| 6334 | params->global_priv, 1, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6335 | params->bssid, params->driver_params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6336 | if (bss == NULL) |
| 6337 | return NULL; |
| 6338 | |
| 6339 | drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6340 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6341 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6342 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6343 | params->ifname, master_ifname); |
| 6344 | br_ifindex = if_nametoindex(master_ifname); |
| 6345 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 6346 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && |
| 6347 | linux_master_get(master_ifname, params->ifname) == 0) { |
| 6348 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", |
| 6349 | params->ifname, master_ifname); |
| 6350 | /* start listening for EAPOL on the master interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6351 | add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6352 | |
| 6353 | /* check if master itself is under bridge */ |
| 6354 | if (linux_br_get(master_ifname, master_ifname) == 0) { |
| 6355 | wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s", |
| 6356 | master_ifname); |
| 6357 | br_ifindex = if_nametoindex(master_ifname); |
| 6358 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 6359 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6360 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6361 | master_ifname[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6362 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6363 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6364 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6365 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6366 | for (i = 0; i < params->num_bridge; i++) { |
| 6367 | if (params->bridge[i]) { |
| 6368 | ifindex = if_nametoindex(params->bridge[i]); |
| 6369 | if (ifindex) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6370 | add_ifidx(drv, ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6371 | if (ifindex == br_ifindex) |
| 6372 | br_added = 1; |
| 6373 | } |
| 6374 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6375 | |
| 6376 | /* start listening for EAPOL on the default AP interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6377 | add_ifidx(drv, drv->ifindex, IFIDX_ANY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6378 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6379 | if (params->num_bridge && params->bridge[0]) { |
| 6380 | if (i802_check_bridge(drv, bss, params->bridge[0], |
| 6381 | params->ifname) < 0) |
| 6382 | goto failed; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6383 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6384 | br_added = 1; |
| 6385 | } |
| 6386 | |
| 6387 | if (!br_added && br_ifindex && |
| 6388 | (params->num_bridge == 0 || !params->bridge[0])) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6389 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6390 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6391 | #ifdef CONFIG_LIBNL3_ROUTE |
| 6392 | if (bss->added_if_into_bridge) { |
| 6393 | drv->rtnl_sk = nl_socket_alloc(); |
| 6394 | if (drv->rtnl_sk == NULL) { |
| 6395 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); |
| 6396 | goto failed; |
| 6397 | } |
| 6398 | |
| 6399 | if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) { |
| 6400 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", |
| 6401 | strerror(errno)); |
| 6402 | goto failed; |
| 6403 | } |
| 6404 | } |
| 6405 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 6406 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6407 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
| 6408 | if (drv->eapol_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6409 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
| 6410 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6411 | goto failed; |
| 6412 | } |
| 6413 | |
| 6414 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) |
| 6415 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6416 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6417 | goto failed; |
| 6418 | } |
| 6419 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6420 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 6421 | params->own_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6422 | goto failed; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6423 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6424 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6425 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
| 6426 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6427 | return bss; |
| 6428 | |
| 6429 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6430 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6431 | return NULL; |
| 6432 | } |
| 6433 | |
| 6434 | |
| 6435 | static void i802_deinit(void *priv) |
| 6436 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6437 | struct i802_bss *bss = priv; |
| 6438 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6439 | } |
| 6440 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6441 | |
| 6442 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
| 6443 | enum wpa_driver_if_type type) |
| 6444 | { |
| 6445 | switch (type) { |
| 6446 | case WPA_IF_STATION: |
| 6447 | return NL80211_IFTYPE_STATION; |
| 6448 | case WPA_IF_P2P_CLIENT: |
| 6449 | case WPA_IF_P2P_GROUP: |
| 6450 | return NL80211_IFTYPE_P2P_CLIENT; |
| 6451 | case WPA_IF_AP_VLAN: |
| 6452 | return NL80211_IFTYPE_AP_VLAN; |
| 6453 | case WPA_IF_AP_BSS: |
| 6454 | return NL80211_IFTYPE_AP; |
| 6455 | case WPA_IF_P2P_GO: |
| 6456 | return NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6457 | case WPA_IF_P2P_DEVICE: |
| 6458 | return NL80211_IFTYPE_P2P_DEVICE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6459 | case WPA_IF_MESH: |
| 6460 | return NL80211_IFTYPE_MESH_POINT; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6461 | default: |
| 6462 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6463 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6464 | } |
| 6465 | |
| 6466 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6467 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
| 6468 | { |
| 6469 | struct wpa_driver_nl80211_data *drv; |
| 6470 | dl_list_for_each(drv, &global->interfaces, |
| 6471 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6472 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6473 | return 1; |
| 6474 | } |
| 6475 | return 0; |
| 6476 | } |
| 6477 | |
| 6478 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6479 | 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] | 6480 | { |
| 6481 | unsigned int idx; |
| 6482 | |
| 6483 | if (!drv->global) |
| 6484 | return -1; |
| 6485 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6486 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6487 | for (idx = 0; idx < 64; idx++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6488 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6489 | new_addr[0] ^= idx << 2; |
| 6490 | if (!nl80211_addr_in_use(drv->global, new_addr)) |
| 6491 | break; |
| 6492 | } |
| 6493 | if (idx == 64) |
| 6494 | return -1; |
| 6495 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6496 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6497 | MACSTR, MAC2STR(new_addr)); |
| 6498 | |
| 6499 | return 0; |
| 6500 | } |
| 6501 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6502 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6503 | struct wdev_info { |
| 6504 | u64 wdev_id; |
| 6505 | int wdev_id_set; |
| 6506 | u8 macaddr[ETH_ALEN]; |
| 6507 | }; |
| 6508 | |
| 6509 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) |
| 6510 | { |
| 6511 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6512 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6513 | struct wdev_info *wi = arg; |
| 6514 | |
| 6515 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6516 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6517 | if (tb[NL80211_ATTR_WDEV]) { |
| 6518 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 6519 | wi->wdev_id_set = 1; |
| 6520 | } |
| 6521 | |
| 6522 | if (tb[NL80211_ATTR_MAC]) |
| 6523 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 6524 | ETH_ALEN); |
| 6525 | |
| 6526 | return NL_SKIP; |
| 6527 | } |
| 6528 | |
| 6529 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6530 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
| 6531 | const char *ifname, const u8 *addr, |
| 6532 | void *bss_ctx, void **drv_priv, |
| 6533 | char *force_ifname, u8 *if_addr, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6534 | const char *bridge, int use_existing, |
| 6535 | int setup_ap) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6536 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6537 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6538 | struct i802_bss *bss = priv; |
| 6539 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6540 | int ifidx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6541 | int added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6542 | |
| 6543 | if (addr) |
| 6544 | os_memcpy(if_addr, addr, ETH_ALEN); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6545 | nlmode = wpa_driver_nl80211_if_type(type); |
| 6546 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 6547 | struct wdev_info p2pdev_info; |
| 6548 | |
| 6549 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); |
| 6550 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
| 6551 | 0, nl80211_wdev_handler, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6552 | &p2pdev_info, use_existing); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6553 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
| 6554 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
| 6555 | ifname); |
| 6556 | return -1; |
| 6557 | } |
| 6558 | |
| 6559 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; |
| 6560 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; |
| 6561 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) |
| 6562 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); |
| 6563 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", |
| 6564 | ifname, |
| 6565 | (long long unsigned int) p2pdev_info.wdev_id); |
| 6566 | } else { |
| 6567 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6568 | 0, NULL, NULL, use_existing); |
| 6569 | if (use_existing && ifidx == -ENFILE) { |
| 6570 | added = 0; |
| 6571 | ifidx = if_nametoindex(ifname); |
| 6572 | } else if (ifidx < 0) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6573 | return -1; |
| 6574 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6575 | } |
| 6576 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6577 | if (!addr) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6578 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6579 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
| 6580 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6581 | ifname, if_addr) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6582 | if (added) |
| 6583 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6584 | return -1; |
| 6585 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6586 | } |
| 6587 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6588 | if (!addr && |
| 6589 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6590 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
| 6591 | type == WPA_IF_STATION)) { |
| 6592 | /* Enforce unique address */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6593 | u8 new_addr[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6594 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6595 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6596 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6597 | if (added) |
| 6598 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6599 | return -1; |
| 6600 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6601 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6602 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6603 | "for interface %s type %d", ifname, type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6604 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6605 | if (added) |
| 6606 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6607 | return -1; |
| 6608 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6609 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6610 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6611 | if (added) |
| 6612 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6613 | return -1; |
| 6614 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6615 | } |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6616 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6617 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6618 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6619 | if (type == WPA_IF_AP_BSS && setup_ap) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6620 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
| 6621 | if (new_bss == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6622 | if (added) |
| 6623 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6624 | return -1; |
| 6625 | } |
| 6626 | |
| 6627 | if (bridge && |
| 6628 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { |
| 6629 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " |
| 6630 | "interface %s to a bridge %s", |
| 6631 | ifname, bridge); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6632 | if (added) |
| 6633 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6634 | os_free(new_bss); |
| 6635 | return -1; |
| 6636 | } |
| 6637 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6638 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
| 6639 | { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6640 | if (added) |
| 6641 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6642 | os_free(new_bss); |
| 6643 | return -1; |
| 6644 | } |
| 6645 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6646 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6647 | new_bss->ifindex = ifidx; |
| 6648 | new_bss->drv = drv; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6649 | new_bss->next = drv->first_bss->next; |
| 6650 | new_bss->freq = drv->first_bss->freq; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6651 | new_bss->ctx = bss_ctx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6652 | new_bss->added_if = added; |
| 6653 | drv->first_bss->next = new_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6654 | if (drv_priv) |
| 6655 | *drv_priv = new_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6656 | nl80211_init_bss(new_bss); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6657 | |
| 6658 | /* Subscribe management frames for this WPA_IF_AP_BSS */ |
| 6659 | if (nl80211_setup_ap(new_bss)) |
| 6660 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6661 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6662 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6663 | if (drv->global) |
| 6664 | drv->global->if_add_ifindex = ifidx; |
| 6665 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6666 | /* |
| 6667 | * Some virtual interfaces need to process EAPOL packets and events on |
| 6668 | * the parent interface. This is used mainly with hostapd. |
| 6669 | */ |
| 6670 | if (ifidx > 0 && |
| 6671 | (drv->hostapd || |
| 6672 | nlmode == NL80211_IFTYPE_AP_VLAN || |
| 6673 | nlmode == NL80211_IFTYPE_WDS || |
| 6674 | nlmode == NL80211_IFTYPE_MONITOR)) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6675 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6676 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6677 | return 0; |
| 6678 | } |
| 6679 | |
| 6680 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6681 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6682 | enum wpa_driver_if_type type, |
| 6683 | const char *ifname) |
| 6684 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6685 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6686 | int ifindex = if_nametoindex(ifname); |
| 6687 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6688 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
| 6689 | __func__, type, ifname, ifindex, bss->added_if); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 6690 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 6691 | nl80211_remove_iface(drv, ifindex); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 6692 | else if (ifindex > 0 && !bss->added_if) { |
| 6693 | struct wpa_driver_nl80211_data *drv2; |
| 6694 | dl_list_for_each(drv2, &drv->global->interfaces, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6695 | struct wpa_driver_nl80211_data, list) { |
| 6696 | del_ifidx(drv2, ifindex, IFIDX_ANY); |
| 6697 | del_ifidx(drv2, IFIDX_ANY, ifindex); |
| 6698 | } |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 6699 | } |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6700 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6701 | if (type != WPA_IF_AP_BSS) |
| 6702 | return 0; |
| 6703 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6704 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6705 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 6706 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6707 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 6708 | "interface %s from bridge %s: %s", |
| 6709 | bss->ifname, bss->brname, strerror(errno)); |
| 6710 | } |
| 6711 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6712 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6713 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 6714 | "bridge %s: %s", |
| 6715 | bss->brname, strerror(errno)); |
| 6716 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6717 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6718 | if (bss != drv->first_bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6719 | struct i802_bss *tbss; |
| 6720 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6721 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
| 6722 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6723 | if (tbss->next == bss) { |
| 6724 | tbss->next = bss->next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6725 | /* Unsubscribe management frames */ |
| 6726 | nl80211_teardown_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6727 | nl80211_destroy_bss(bss); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6728 | if (!bss->added_if) |
| 6729 | i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6730 | os_free(bss); |
| 6731 | bss = NULL; |
| 6732 | break; |
| 6733 | } |
| 6734 | } |
| 6735 | if (bss) |
| 6736 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " |
| 6737 | "BSS %p in the list", __func__, bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6738 | } else { |
| 6739 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
| 6740 | nl80211_teardown_ap(bss); |
| 6741 | if (!bss->added_if && !drv->first_bss->next) |
| 6742 | wpa_driver_nl80211_del_beacon(drv); |
| 6743 | nl80211_destroy_bss(bss); |
| 6744 | if (!bss->added_if) |
| 6745 | i802_set_iface_flags(bss, 0); |
| 6746 | if (drv->first_bss->next) { |
| 6747 | drv->first_bss = drv->first_bss->next; |
| 6748 | drv->ctx = drv->first_bss->ctx; |
| 6749 | os_free(bss); |
| 6750 | } else { |
| 6751 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); |
| 6752 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6753 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6754 | |
| 6755 | return 0; |
| 6756 | } |
| 6757 | |
| 6758 | |
| 6759 | static int cookie_handler(struct nl_msg *msg, void *arg) |
| 6760 | { |
| 6761 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6762 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6763 | u64 *cookie = arg; |
| 6764 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6765 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6766 | if (tb[NL80211_ATTR_COOKIE]) |
| 6767 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 6768 | return NL_SKIP; |
| 6769 | } |
| 6770 | |
| 6771 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6772 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6773 | unsigned int freq, unsigned int wait, |
| 6774 | const u8 *buf, size_t buf_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6775 | u64 *cookie_out, int no_cck, int no_ack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6776 | int offchanok, const u16 *csa_offs, |
| 6777 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6778 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6779 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6780 | struct nl_msg *msg; |
| 6781 | u64 cookie; |
| 6782 | int ret = -1; |
| 6783 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6784 | 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] | 6785 | "no_ack=%d offchanok=%d", |
| 6786 | freq, wait, no_cck, no_ack, offchanok); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6787 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6788 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6789 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
| 6790 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 6791 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || |
| 6792 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 6793 | drv->test_use_roc_tx) && |
| 6794 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || |
| 6795 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || |
| 6796 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6797 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
| 6798 | csa_offs_len * sizeof(u16), csa_offs)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6799 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
| 6800 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6801 | |
| 6802 | cookie = 0; |
| 6803 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 6804 | msg = NULL; |
| 6805 | if (ret) { |
| 6806 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6807 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
| 6808 | freq, wait); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6809 | } else { |
| 6810 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " |
| 6811 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
| 6812 | (long long unsigned int) cookie); |
| 6813 | |
| 6814 | if (cookie_out) |
| 6815 | *cookie_out = no_ack ? (u64) -1 : cookie; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6816 | |
| 6817 | if (drv->num_send_action_cookies == MAX_SEND_ACTION_COOKIES) { |
| 6818 | wpa_printf(MSG_DEBUG, |
| 6819 | "nl80211: Drop oldest pending send action cookie 0x%llx", |
| 6820 | (long long unsigned int) |
| 6821 | drv->send_action_cookies[0]); |
| 6822 | os_memmove(&drv->send_action_cookies[0], |
| 6823 | &drv->send_action_cookies[1], |
| 6824 | (MAX_SEND_ACTION_COOKIES - 1) * |
| 6825 | sizeof(u64)); |
| 6826 | drv->num_send_action_cookies--; |
| 6827 | } |
| 6828 | drv->send_action_cookies[drv->num_send_action_cookies] = cookie; |
| 6829 | drv->num_send_action_cookies++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6830 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6831 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6832 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6833 | nlmsg_free(msg); |
| 6834 | return ret; |
| 6835 | } |
| 6836 | |
| 6837 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6838 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
| 6839 | unsigned int freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6840 | unsigned int wait_time, |
| 6841 | const u8 *dst, const u8 *src, |
| 6842 | const u8 *bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6843 | const u8 *data, size_t data_len, |
| 6844 | int no_cck) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6845 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6846 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6847 | int ret = -1; |
| 6848 | u8 *buf; |
| 6849 | struct ieee80211_hdr *hdr; |
| 6850 | |
| 6851 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6852 | "freq=%u MHz wait=%d ms no_cck=%d)", |
| 6853 | drv->ifindex, freq, wait_time, no_cck); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6854 | |
| 6855 | buf = os_zalloc(24 + data_len); |
| 6856 | if (buf == NULL) |
| 6857 | return ret; |
| 6858 | os_memcpy(buf + 24, data, data_len); |
| 6859 | hdr = (struct ieee80211_hdr *) buf; |
| 6860 | hdr->frame_control = |
| 6861 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); |
| 6862 | os_memcpy(hdr->addr1, dst, ETH_ALEN); |
| 6863 | os_memcpy(hdr->addr2, src, ETH_ALEN); |
| 6864 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); |
| 6865 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6866 | if (is_ap_interface(drv->nlmode) && |
| 6867 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 6868 | (int) freq == bss->freq || drv->device_ap_sme || |
| 6869 | !drv->use_monitor)) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6870 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
| 6871 | 0, freq, no_cck, 1, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6872 | wait_time, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6873 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6874 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6875 | 24 + data_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6876 | &drv->send_action_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6877 | no_cck, 0, 1, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6878 | |
| 6879 | os_free(buf); |
| 6880 | return ret; |
| 6881 | } |
| 6882 | |
| 6883 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6884 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6885 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6886 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6887 | struct nl_msg *msg; |
| 6888 | int ret; |
| 6889 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 6890 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6891 | (long long unsigned int) cookie); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6892 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6893 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6894 | nlmsg_free(msg); |
| 6895 | return; |
| 6896 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6897 | |
| 6898 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6899 | if (ret) |
| 6900 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " |
| 6901 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6902 | } |
| 6903 | |
| 6904 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6905 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
| 6906 | { |
| 6907 | struct i802_bss *bss = priv; |
| 6908 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6909 | unsigned int i; |
| 6910 | u64 cookie; |
| 6911 | |
| 6912 | /* Cancel the last pending TX cookie */ |
| 6913 | nl80211_frame_wait_cancel(bss, drv->send_action_cookie); |
| 6914 | |
| 6915 | /* |
| 6916 | * Cancel the other pending TX cookies, if any. This is needed since |
| 6917 | * the driver may keep a list of all pending offchannel TX operations |
| 6918 | * and free up the radio only once they have expired or cancelled. |
| 6919 | */ |
| 6920 | for (i = drv->num_send_action_cookies; i > 0; i--) { |
| 6921 | cookie = drv->send_action_cookies[i - 1]; |
| 6922 | if (cookie != drv->send_action_cookie) |
| 6923 | nl80211_frame_wait_cancel(bss, cookie); |
| 6924 | } |
| 6925 | drv->num_send_action_cookies = 0; |
| 6926 | } |
| 6927 | |
| 6928 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6929 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
| 6930 | unsigned int duration) |
| 6931 | { |
| 6932 | struct i802_bss *bss = priv; |
| 6933 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6934 | struct nl_msg *msg; |
| 6935 | int ret; |
| 6936 | u64 cookie; |
| 6937 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6938 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
| 6939 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 6940 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { |
| 6941 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6942 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6943 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6944 | |
| 6945 | cookie = 0; |
| 6946 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 6947 | if (ret == 0) { |
| 6948 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " |
| 6949 | "0x%llx for freq=%u MHz duration=%u", |
| 6950 | (long long unsigned int) cookie, freq, duration); |
| 6951 | drv->remain_on_chan_cookie = cookie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6952 | drv->pending_remain_on_chan = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6953 | return 0; |
| 6954 | } |
| 6955 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " |
| 6956 | "(freq=%d duration=%u): %d (%s)", |
| 6957 | freq, duration, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6958 | return -1; |
| 6959 | } |
| 6960 | |
| 6961 | |
| 6962 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) |
| 6963 | { |
| 6964 | struct i802_bss *bss = priv; |
| 6965 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6966 | struct nl_msg *msg; |
| 6967 | int ret; |
| 6968 | |
| 6969 | if (!drv->pending_remain_on_chan) { |
| 6970 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " |
| 6971 | "to cancel"); |
| 6972 | return -1; |
| 6973 | } |
| 6974 | |
| 6975 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " |
| 6976 | "0x%llx", |
| 6977 | (long long unsigned int) drv->remain_on_chan_cookie); |
| 6978 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6979 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
| 6980 | if (!msg || |
| 6981 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
| 6982 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6983 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6984 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6985 | |
| 6986 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6987 | if (ret == 0) |
| 6988 | return 0; |
| 6989 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " |
| 6990 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6991 | return -1; |
| 6992 | } |
| 6993 | |
| 6994 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6995 | 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] | 6996 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6997 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6998 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6999 | if (!report) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7000 | if (bss->nl_preq && drv->device_ap_sme && |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 7001 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
| 7002 | !bss->static_ap) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7003 | /* |
| 7004 | * Do not disable Probe Request reporting that was |
| 7005 | * enabled in nl80211_setup_ap(). |
| 7006 | */ |
| 7007 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " |
| 7008 | "Probe Request reporting nl_preq=%p while " |
| 7009 | "in AP mode", bss->nl_preq); |
| 7010 | } else if (bss->nl_preq) { |
| 7011 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
| 7012 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7013 | nl80211_destroy_eloop_handle(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7014 | } |
| 7015 | return 0; |
| 7016 | } |
| 7017 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7018 | if (bss->nl_preq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7019 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7020 | "already on! nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7021 | return 0; |
| 7022 | } |
| 7023 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7024 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
| 7025 | if (bss->nl_preq == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7026 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7027 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
| 7028 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7029 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7030 | if (nl80211_register_frame(bss, bss->nl_preq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7031 | (WLAN_FC_TYPE_MGMT << 2) | |
| 7032 | (WLAN_FC_STYPE_PROBE_REQ << 4), |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7033 | NULL, 0) < 0) |
| 7034 | goto out_err; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 7035 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7036 | nl80211_register_eloop_read(&bss->nl_preq, |
| 7037 | wpa_driver_nl80211_event_receive, |
| 7038 | bss->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7039 | |
| 7040 | return 0; |
| 7041 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7042 | out_err: |
| 7043 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7044 | return -1; |
| 7045 | } |
| 7046 | |
| 7047 | |
| 7048 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 7049 | int ifindex, int disabled) |
| 7050 | { |
| 7051 | struct nl_msg *msg; |
| 7052 | struct nlattr *bands, *band; |
| 7053 | int ret; |
| 7054 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7055 | wpa_printf(MSG_DEBUG, |
| 7056 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", |
| 7057 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : |
| 7058 | "no NL80211_TXRATE_LEGACY constraint"); |
| 7059 | |
| 7060 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
| 7061 | NL80211_CMD_SET_TX_BITRATE_MASK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7062 | if (!msg) |
| 7063 | return -1; |
| 7064 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7065 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 7066 | if (!bands) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7067 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7068 | |
| 7069 | /* |
| 7070 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything |
| 7071 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS |
| 7072 | * rates. All 5 GHz rates are left enabled. |
| 7073 | */ |
| 7074 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7075 | if (!band || |
| 7076 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, |
| 7077 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) |
| 7078 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7079 | nla_nest_end(msg, band); |
| 7080 | |
| 7081 | nla_nest_end(msg, bands); |
| 7082 | |
| 7083 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7084 | if (ret) { |
| 7085 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " |
| 7086 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 7087 | } else |
| 7088 | drv->disabled_11b_rates = disabled; |
| 7089 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7090 | return ret; |
| 7091 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7092 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7093 | nlmsg_free(msg); |
| 7094 | return -1; |
| 7095 | } |
| 7096 | |
| 7097 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7098 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
| 7099 | { |
| 7100 | struct i802_bss *bss = priv; |
| 7101 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7102 | if (!is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7103 | return -1; |
| 7104 | wpa_driver_nl80211_del_beacon(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7105 | bss->beacon_set = 0; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7106 | |
| 7107 | /* |
| 7108 | * If the P2P GO interface was dynamically added, then it is |
| 7109 | * possible that the interface change to station is not possible. |
| 7110 | */ |
| 7111 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) |
| 7112 | return 0; |
| 7113 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7114 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7115 | } |
| 7116 | |
| 7117 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7118 | static int wpa_driver_nl80211_stop_ap(void *priv) |
| 7119 | { |
| 7120 | struct i802_bss *bss = priv; |
| 7121 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7122 | if (!is_ap_interface(drv->nlmode)) |
| 7123 | return -1; |
| 7124 | wpa_driver_nl80211_del_beacon(drv); |
| 7125 | bss->beacon_set = 0; |
| 7126 | return 0; |
| 7127 | } |
| 7128 | |
| 7129 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7130 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
| 7131 | { |
| 7132 | struct i802_bss *bss = priv; |
| 7133 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7134 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) |
| 7135 | return -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7136 | |
| 7137 | /* |
| 7138 | * If the P2P Client interface was dynamically added, then it is |
| 7139 | * possible that the interface change to station is not possible. |
| 7140 | */ |
| 7141 | if (bss->if_dynamic) |
| 7142 | return 0; |
| 7143 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 7144 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
| 7145 | } |
| 7146 | |
| 7147 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7148 | static void wpa_driver_nl80211_resume(void *priv) |
| 7149 | { |
| 7150 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7151 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7152 | |
| 7153 | if (i802_set_iface_flags(bss, 1)) |
| 7154 | 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] | 7155 | |
| 7156 | if (is_p2p_net_interface(nlmode)) |
| 7157 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7158 | } |
| 7159 | |
| 7160 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7161 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
| 7162 | { |
| 7163 | struct i802_bss *bss = priv; |
| 7164 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7165 | struct nl_msg *msg; |
| 7166 | struct nlattr *cqm; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7167 | |
| 7168 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " |
| 7169 | "hysteresis=%d", threshold, hysteresis); |
| 7170 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7171 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
| 7172 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
| 7173 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || |
| 7174 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { |
| 7175 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7176 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7177 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 7178 | nla_nest_end(msg, cqm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7179 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7180 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7181 | } |
| 7182 | |
| 7183 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7184 | static int get_channel_width(struct nl_msg *msg, void *arg) |
| 7185 | { |
| 7186 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7187 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7188 | struct wpa_signal_info *sig_change = arg; |
| 7189 | |
| 7190 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7191 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7192 | |
| 7193 | sig_change->center_frq1 = -1; |
| 7194 | sig_change->center_frq2 = -1; |
| 7195 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 7196 | |
| 7197 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 7198 | sig_change->chanwidth = convert2width( |
| 7199 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 7200 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 7201 | sig_change->center_frq1 = |
| 7202 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 7203 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 7204 | sig_change->center_frq2 = |
| 7205 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 7206 | } |
| 7207 | |
| 7208 | return NL_SKIP; |
| 7209 | } |
| 7210 | |
| 7211 | |
| 7212 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, |
| 7213 | struct wpa_signal_info *sig) |
| 7214 | { |
| 7215 | struct nl_msg *msg; |
| 7216 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7217 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7218 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7219 | } |
| 7220 | |
| 7221 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7222 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
| 7223 | { |
| 7224 | struct i802_bss *bss = priv; |
| 7225 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7226 | int res; |
| 7227 | |
| 7228 | os_memset(si, 0, sizeof(*si)); |
| 7229 | res = nl80211_get_link_signal(drv, si); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7230 | if (res) { |
| 7231 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && |
| 7232 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
| 7233 | return res; |
| 7234 | si->current_signal = 0; |
| 7235 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7236 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7237 | res = nl80211_get_channel_width(drv, si); |
| 7238 | if (res != 0) |
| 7239 | return res; |
| 7240 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7241 | return nl80211_get_link_noise(drv, si); |
| 7242 | } |
| 7243 | |
| 7244 | |
| 7245 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
| 7246 | int encrypt) |
| 7247 | { |
| 7248 | struct i802_bss *bss = priv; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7249 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7250 | 0, 0, 0, 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7251 | } |
| 7252 | |
| 7253 | |
| 7254 | static int nl80211_set_param(void *priv, const char *param) |
| 7255 | { |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 7256 | struct i802_bss *bss = priv; |
| 7257 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7258 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7259 | if (param == NULL) |
| 7260 | return 0; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7261 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7262 | |
| 7263 | #ifdef CONFIG_P2P |
| 7264 | if (os_strstr(param, "use_p2p_group_interface=1")) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7265 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 7266 | "interface"); |
| 7267 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 7268 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 7269 | } |
| 7270 | #endif /* CONFIG_P2P */ |
| 7271 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 7272 | if (os_strstr(param, "use_monitor=1")) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7273 | drv->use_monitor = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7274 | |
| 7275 | if (os_strstr(param, "force_connect_cmd=1")) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7276 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7277 | drv->force_connect_cmd = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7278 | } |
| 7279 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 7280 | if (os_strstr(param, "force_bss_selection=1")) |
| 7281 | drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
| 7282 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 7283 | if (os_strstr(param, "no_offchannel_tx=1")) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 7284 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 7285 | drv->test_use_roc_tx = 1; |
| 7286 | } |
| 7287 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7288 | return 0; |
| 7289 | } |
| 7290 | |
| 7291 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7292 | static void * nl80211_global_init(void *ctx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7293 | { |
| 7294 | struct nl80211_global *global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7295 | struct netlink_config *cfg; |
| 7296 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7297 | global = os_zalloc(sizeof(*global)); |
| 7298 | if (global == NULL) |
| 7299 | return NULL; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7300 | global->ctx = ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7301 | global->ioctl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7302 | dl_list_init(&global->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7303 | global->if_add_ifindex = -1; |
| 7304 | |
| 7305 | cfg = os_zalloc(sizeof(*cfg)); |
| 7306 | if (cfg == NULL) |
| 7307 | goto err; |
| 7308 | |
| 7309 | cfg->ctx = global; |
| 7310 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; |
| 7311 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; |
| 7312 | global->netlink = netlink_init(cfg); |
| 7313 | if (global->netlink == NULL) { |
| 7314 | os_free(cfg); |
| 7315 | goto err; |
| 7316 | } |
| 7317 | |
| 7318 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
| 7319 | goto err; |
| 7320 | |
| 7321 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 7322 | if (global->ioctl_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7323 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
| 7324 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7325 | goto err; |
| 7326 | } |
| 7327 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7328 | return global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7329 | |
| 7330 | err: |
| 7331 | nl80211_global_deinit(global); |
| 7332 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7333 | } |
| 7334 | |
| 7335 | |
| 7336 | static void nl80211_global_deinit(void *priv) |
| 7337 | { |
| 7338 | struct nl80211_global *global = priv; |
| 7339 | if (global == NULL) |
| 7340 | return; |
| 7341 | if (!dl_list_empty(&global->interfaces)) { |
| 7342 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " |
| 7343 | "nl80211_global_deinit", |
| 7344 | dl_list_len(&global->interfaces)); |
| 7345 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7346 | |
| 7347 | if (global->netlink) |
| 7348 | netlink_deinit(global->netlink); |
| 7349 | |
| 7350 | nl_destroy_handles(&global->nl); |
| 7351 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7352 | if (global->nl_event) |
| 7353 | nl80211_destroy_eloop_handle(&global->nl_event); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7354 | |
| 7355 | nl_cb_put(global->nl_cb); |
| 7356 | |
| 7357 | if (global->ioctl_sock >= 0) |
| 7358 | close(global->ioctl_sock); |
| 7359 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7360 | os_free(global); |
| 7361 | } |
| 7362 | |
| 7363 | |
| 7364 | static const char * nl80211_get_radio_name(void *priv) |
| 7365 | { |
| 7366 | struct i802_bss *bss = priv; |
| 7367 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7368 | return drv->phyname; |
| 7369 | } |
| 7370 | |
| 7371 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7372 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid, |
| 7373 | const u8 *pmkid) |
| 7374 | { |
| 7375 | struct nl_msg *msg; |
| 7376 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7377 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 7378 | (pmkid && nla_put(msg, NL80211_ATTR_PMKID, 16, pmkid)) || |
| 7379 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))) { |
| 7380 | nlmsg_free(msg); |
| 7381 | return -ENOBUFS; |
| 7382 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7383 | |
| 7384 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7385 | } |
| 7386 | |
| 7387 | |
| 7388 | static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 7389 | { |
| 7390 | struct i802_bss *bss = priv; |
| 7391 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid)); |
| 7392 | return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid); |
| 7393 | } |
| 7394 | |
| 7395 | |
| 7396 | static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 7397 | { |
| 7398 | struct i802_bss *bss = priv; |
| 7399 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, |
| 7400 | MAC2STR(bssid)); |
| 7401 | return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid); |
| 7402 | } |
| 7403 | |
| 7404 | |
| 7405 | static int nl80211_flush_pmkid(void *priv) |
| 7406 | { |
| 7407 | struct i802_bss *bss = priv; |
| 7408 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
| 7409 | return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL); |
| 7410 | } |
| 7411 | |
| 7412 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7413 | static void clean_survey_results(struct survey_results *survey_results) |
| 7414 | { |
| 7415 | struct freq_survey *survey, *tmp; |
| 7416 | |
| 7417 | if (dl_list_empty(&survey_results->survey_list)) |
| 7418 | return; |
| 7419 | |
| 7420 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 7421 | struct freq_survey, list) { |
| 7422 | dl_list_del(&survey->list); |
| 7423 | os_free(survey); |
| 7424 | } |
| 7425 | } |
| 7426 | |
| 7427 | |
| 7428 | static void add_survey(struct nlattr **sinfo, u32 ifidx, |
| 7429 | struct dl_list *survey_list) |
| 7430 | { |
| 7431 | struct freq_survey *survey; |
| 7432 | |
| 7433 | survey = os_zalloc(sizeof(struct freq_survey)); |
| 7434 | if (!survey) |
| 7435 | return; |
| 7436 | |
| 7437 | survey->ifidx = ifidx; |
| 7438 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 7439 | survey->filled = 0; |
| 7440 | |
| 7441 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { |
| 7442 | survey->nf = (int8_t) |
| 7443 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 7444 | survey->filled |= SURVEY_HAS_NF; |
| 7445 | } |
| 7446 | |
| 7447 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { |
| 7448 | survey->channel_time = |
| 7449 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); |
| 7450 | survey->filled |= SURVEY_HAS_CHAN_TIME; |
| 7451 | } |
| 7452 | |
| 7453 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { |
| 7454 | survey->channel_time_busy = |
| 7455 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); |
| 7456 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; |
| 7457 | } |
| 7458 | |
| 7459 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { |
| 7460 | survey->channel_time_rx = |
| 7461 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); |
| 7462 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; |
| 7463 | } |
| 7464 | |
| 7465 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { |
| 7466 | survey->channel_time_tx = |
| 7467 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); |
| 7468 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; |
| 7469 | } |
| 7470 | |
| 7471 | 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)", |
| 7472 | survey->freq, |
| 7473 | survey->nf, |
| 7474 | (unsigned long int) survey->channel_time, |
| 7475 | (unsigned long int) survey->channel_time_busy, |
| 7476 | (unsigned long int) survey->channel_time_tx, |
| 7477 | (unsigned long int) survey->channel_time_rx, |
| 7478 | survey->filled); |
| 7479 | |
| 7480 | dl_list_add_tail(survey_list, &survey->list); |
| 7481 | } |
| 7482 | |
| 7483 | |
| 7484 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, |
| 7485 | unsigned int freq_filter) |
| 7486 | { |
| 7487 | if (!freq_filter) |
| 7488 | return 1; |
| 7489 | |
| 7490 | return freq_filter == surveyed_freq; |
| 7491 | } |
| 7492 | |
| 7493 | |
| 7494 | static int survey_handler(struct nl_msg *msg, void *arg) |
| 7495 | { |
| 7496 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7497 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7498 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 7499 | struct survey_results *survey_results; |
| 7500 | u32 surveyed_freq = 0; |
| 7501 | u32 ifidx; |
| 7502 | |
| 7503 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 7504 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 7505 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 7506 | }; |
| 7507 | |
| 7508 | survey_results = (struct survey_results *) arg; |
| 7509 | |
| 7510 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7511 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7512 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 7513 | if (!tb[NL80211_ATTR_IFINDEX]) |
| 7514 | return NL_SKIP; |
| 7515 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7516 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 7517 | |
| 7518 | if (!tb[NL80211_ATTR_SURVEY_INFO]) |
| 7519 | return NL_SKIP; |
| 7520 | |
| 7521 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 7522 | tb[NL80211_ATTR_SURVEY_INFO], |
| 7523 | survey_policy)) |
| 7524 | return NL_SKIP; |
| 7525 | |
| 7526 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { |
| 7527 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); |
| 7528 | return NL_SKIP; |
| 7529 | } |
| 7530 | |
| 7531 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 7532 | |
| 7533 | if (!check_survey_ok(sinfo, surveyed_freq, |
| 7534 | survey_results->freq_filter)) |
| 7535 | return NL_SKIP; |
| 7536 | |
| 7537 | if (survey_results->freq_filter && |
| 7538 | survey_results->freq_filter != surveyed_freq) { |
| 7539 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", |
| 7540 | surveyed_freq); |
| 7541 | return NL_SKIP; |
| 7542 | } |
| 7543 | |
| 7544 | add_survey(sinfo, ifidx, &survey_results->survey_list); |
| 7545 | |
| 7546 | return NL_SKIP; |
| 7547 | } |
| 7548 | |
| 7549 | |
| 7550 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) |
| 7551 | { |
| 7552 | struct i802_bss *bss = priv; |
| 7553 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7554 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7555 | int err; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7556 | union wpa_event_data data; |
| 7557 | struct survey_results *survey_results; |
| 7558 | |
| 7559 | os_memset(&data, 0, sizeof(data)); |
| 7560 | survey_results = &data.survey_results; |
| 7561 | |
| 7562 | dl_list_init(&survey_results->survey_list); |
| 7563 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7564 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7565 | if (!msg) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7566 | return -ENOBUFS; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7567 | |
| 7568 | if (freq) |
| 7569 | data.survey_results.freq_filter = freq; |
| 7570 | |
| 7571 | do { |
| 7572 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); |
| 7573 | err = send_and_recv_msgs(drv, msg, survey_handler, |
| 7574 | survey_results); |
| 7575 | } while (err > 0); |
| 7576 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7577 | if (err) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7578 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7579 | else |
| 7580 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7581 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7582 | clean_survey_results(survey_results); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7583 | return err; |
| 7584 | } |
| 7585 | |
| 7586 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 7587 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
| 7588 | const u8 *kck, size_t kck_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7589 | const u8 *replay_ctr) |
| 7590 | { |
| 7591 | struct i802_bss *bss = priv; |
| 7592 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7593 | struct nlattr *replay_nested; |
| 7594 | struct nl_msg *msg; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 7595 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7596 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 7597 | if (!drv->set_rekey_offload) |
| 7598 | return; |
| 7599 | |
| 7600 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7601 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
| 7602 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 7603 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
| 7604 | nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7605 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
| 7606 | replay_ctr)) { |
| 7607 | nl80211_nlmsg_clear(msg); |
| 7608 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7609 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7610 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7611 | |
| 7612 | nla_nest_end(msg, replay_nested); |
| 7613 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 7614 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 7615 | if (ret == -EOPNOTSUPP) { |
| 7616 | wpa_printf(MSG_DEBUG, |
| 7617 | "nl80211: Driver does not support rekey offload"); |
| 7618 | drv->set_rekey_offload = 0; |
| 7619 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7620 | } |
| 7621 | |
| 7622 | |
| 7623 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
| 7624 | const u8 *addr, int qos) |
| 7625 | { |
| 7626 | /* send data frame to poll STA and check whether |
| 7627 | * this frame is ACKed */ |
| 7628 | struct { |
| 7629 | struct ieee80211_hdr hdr; |
| 7630 | u16 qos_ctl; |
| 7631 | } STRUCT_PACKED nulldata; |
| 7632 | size_t size; |
| 7633 | |
| 7634 | /* Send data frame to poll STA and check whether this frame is ACKed */ |
| 7635 | |
| 7636 | os_memset(&nulldata, 0, sizeof(nulldata)); |
| 7637 | |
| 7638 | if (qos) { |
| 7639 | nulldata.hdr.frame_control = |
| 7640 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 7641 | WLAN_FC_STYPE_QOS_NULL); |
| 7642 | size = sizeof(nulldata); |
| 7643 | } else { |
| 7644 | nulldata.hdr.frame_control = |
| 7645 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 7646 | WLAN_FC_STYPE_NULLFUNC); |
| 7647 | size = sizeof(struct ieee80211_hdr); |
| 7648 | } |
| 7649 | |
| 7650 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 7651 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 7652 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 7653 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 7654 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7655 | 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] | 7656 | 0, 0, NULL, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7657 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
| 7658 | "send poll frame"); |
| 7659 | } |
| 7660 | |
| 7661 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
| 7662 | int qos) |
| 7663 | { |
| 7664 | struct i802_bss *bss = priv; |
| 7665 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7666 | struct nl_msg *msg; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 7667 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7668 | |
| 7669 | if (!drv->poll_command_supported) { |
| 7670 | nl80211_send_null_frame(bss, own_addr, addr, qos); |
| 7671 | return; |
| 7672 | } |
| 7673 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7674 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
| 7675 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 7676 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7677 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7678 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7679 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 7680 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7681 | if (ret < 0) { |
| 7682 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " |
| 7683 | MACSTR " failed: ret=%d (%s)", |
| 7684 | MAC2STR(addr), ret, strerror(-ret)); |
| 7685 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7686 | } |
| 7687 | |
| 7688 | |
| 7689 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
| 7690 | { |
| 7691 | struct nl_msg *msg; |
| 7692 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7693 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
| 7694 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
| 7695 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { |
| 7696 | nlmsg_free(msg); |
| 7697 | return -ENOBUFS; |
| 7698 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7699 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7700 | } |
| 7701 | |
| 7702 | |
| 7703 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, |
| 7704 | int ctwindow) |
| 7705 | { |
| 7706 | struct i802_bss *bss = priv; |
| 7707 | |
| 7708 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " |
| 7709 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); |
| 7710 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 7711 | if (opp_ps != -1 || ctwindow != -1) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7712 | #ifdef ANDROID_P2P |
| 7713 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 7714 | #else /* ANDROID_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7715 | return -1; /* Not yet supported */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 7716 | #endif /* ANDROID_P2P */ |
| 7717 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7718 | |
| 7719 | if (legacy_ps == -1) |
| 7720 | return 0; |
| 7721 | if (legacy_ps != 0 && legacy_ps != 1) |
| 7722 | return -1; /* Not yet supported */ |
| 7723 | |
| 7724 | return nl80211_set_power_save(bss, legacy_ps); |
| 7725 | } |
| 7726 | |
| 7727 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7728 | static int nl80211_start_radar_detection(void *priv, |
| 7729 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7730 | { |
| 7731 | struct i802_bss *bss = priv; |
| 7732 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7733 | struct nl_msg *msg; |
| 7734 | int ret; |
| 7735 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7736 | 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)", |
| 7737 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 7738 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 7739 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7740 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
| 7741 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " |
| 7742 | "detection"); |
| 7743 | return -1; |
| 7744 | } |
| 7745 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7746 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
| 7747 | nl80211_put_freq_params(msg, freq) < 0) { |
| 7748 | nlmsg_free(msg); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7749 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7750 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7751 | |
| 7752 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7753 | if (ret == 0) |
| 7754 | return 0; |
| 7755 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " |
| 7756 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7757 | return -1; |
| 7758 | } |
| 7759 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7760 | #ifdef CONFIG_TDLS |
| 7761 | |
| 7762 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, |
| 7763 | u8 dialog_token, u16 status_code, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 7764 | u32 peer_capab, int initiator, const u8 *buf, |
| 7765 | size_t len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7766 | { |
| 7767 | struct i802_bss *bss = priv; |
| 7768 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7769 | struct nl_msg *msg; |
| 7770 | |
| 7771 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 7772 | return -EOPNOTSUPP; |
| 7773 | |
| 7774 | if (!dst) |
| 7775 | return -EINVAL; |
| 7776 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7777 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
| 7778 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 7779 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || |
| 7780 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || |
| 7781 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) |
| 7782 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7783 | if (peer_capab) { |
| 7784 | /* |
| 7785 | * The internal enum tdls_peer_capability definition is |
| 7786 | * currently identical with the nl80211 enum |
| 7787 | * nl80211_tdls_peer_capability, so no conversion is needed |
| 7788 | * here. |
| 7789 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7790 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
| 7791 | peer_capab)) |
| 7792 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7793 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7794 | if ((initiator && |
| 7795 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || |
| 7796 | nla_put(msg, NL80211_ATTR_IE, len, buf)) |
| 7797 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7798 | |
| 7799 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7800 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7801 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7802 | nlmsg_free(msg); |
| 7803 | return -ENOBUFS; |
| 7804 | } |
| 7805 | |
| 7806 | |
| 7807 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) |
| 7808 | { |
| 7809 | struct i802_bss *bss = priv; |
| 7810 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7811 | struct nl_msg *msg; |
| 7812 | enum nl80211_tdls_operation nl80211_oper; |
| 7813 | |
| 7814 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 7815 | return -EOPNOTSUPP; |
| 7816 | |
| 7817 | switch (oper) { |
| 7818 | case TDLS_DISCOVERY_REQ: |
| 7819 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; |
| 7820 | break; |
| 7821 | case TDLS_SETUP: |
| 7822 | nl80211_oper = NL80211_TDLS_SETUP; |
| 7823 | break; |
| 7824 | case TDLS_TEARDOWN: |
| 7825 | nl80211_oper = NL80211_TDLS_TEARDOWN; |
| 7826 | break; |
| 7827 | case TDLS_ENABLE_LINK: |
| 7828 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; |
| 7829 | break; |
| 7830 | case TDLS_DISABLE_LINK: |
| 7831 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; |
| 7832 | break; |
| 7833 | case TDLS_ENABLE: |
| 7834 | return 0; |
| 7835 | case TDLS_DISABLE: |
| 7836 | return 0; |
| 7837 | default: |
| 7838 | return -EINVAL; |
| 7839 | } |
| 7840 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7841 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
| 7842 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
| 7843 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
| 7844 | nlmsg_free(msg); |
| 7845 | return -ENOBUFS; |
| 7846 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7847 | |
| 7848 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7849 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7850 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7851 | |
| 7852 | static int |
| 7853 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, |
| 7854 | const struct hostapd_freq_params *params) |
| 7855 | { |
| 7856 | struct i802_bss *bss = priv; |
| 7857 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7858 | struct nl_msg *msg; |
| 7859 | int ret = -ENOBUFS; |
| 7860 | |
| 7861 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 7862 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 7863 | return -EOPNOTSUPP; |
| 7864 | |
| 7865 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR |
| 7866 | " oper_class=%u freq=%u", |
| 7867 | MAC2STR(addr), oper_class, params->freq); |
| 7868 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); |
| 7869 | if (!msg || |
| 7870 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 7871 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || |
| 7872 | (ret = nl80211_put_freq_params(msg, params))) { |
| 7873 | nlmsg_free(msg); |
| 7874 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); |
| 7875 | return ret; |
| 7876 | } |
| 7877 | |
| 7878 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7879 | } |
| 7880 | |
| 7881 | |
| 7882 | static int |
| 7883 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) |
| 7884 | { |
| 7885 | struct i802_bss *bss = priv; |
| 7886 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7887 | struct nl_msg *msg; |
| 7888 | |
| 7889 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 7890 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 7891 | return -EOPNOTSUPP; |
| 7892 | |
| 7893 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, |
| 7894 | MAC2STR(addr)); |
| 7895 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); |
| 7896 | if (!msg || |
| 7897 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 7898 | nlmsg_free(msg); |
| 7899 | wpa_printf(MSG_DEBUG, |
| 7900 | "nl80211: Could not build TDLS cancel chan switch"); |
| 7901 | return -ENOBUFS; |
| 7902 | } |
| 7903 | |
| 7904 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7905 | } |
| 7906 | |
| 7907 | #endif /* CONFIG TDLS */ |
| 7908 | |
| 7909 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7910 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
| 7911 | enum wpa_alg alg, const u8 *addr, |
| 7912 | int key_idx, int set_tx, |
| 7913 | const u8 *seq, size_t seq_len, |
| 7914 | const u8 *key, size_t key_len) |
| 7915 | { |
| 7916 | struct i802_bss *bss = priv; |
| 7917 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, |
| 7918 | set_tx, seq, seq_len, key, key_len); |
| 7919 | } |
| 7920 | |
| 7921 | |
| 7922 | static int driver_nl80211_scan2(void *priv, |
| 7923 | struct wpa_driver_scan_params *params) |
| 7924 | { |
| 7925 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7926 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 7927 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7928 | |
| 7929 | /* |
| 7930 | * Do a vendor specific scan if possible. If only_new_results is |
| 7931 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush |
| 7932 | * cannot be achieved through a vendor scan. The below condition may |
| 7933 | * need to be modified if new scan flags are added in the future whose |
| 7934 | * functionality can only be achieved through a normal scan. |
| 7935 | */ |
| 7936 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) |
| 7937 | return wpa_driver_nl80211_vendor_scan(bss, params); |
| 7938 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7939 | return wpa_driver_nl80211_scan(bss, params); |
| 7940 | } |
| 7941 | |
| 7942 | |
| 7943 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
| 7944 | int reason_code) |
| 7945 | { |
| 7946 | struct i802_bss *bss = priv; |
| 7947 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); |
| 7948 | } |
| 7949 | |
| 7950 | |
| 7951 | static int driver_nl80211_authenticate(void *priv, |
| 7952 | struct wpa_driver_auth_params *params) |
| 7953 | { |
| 7954 | struct i802_bss *bss = priv; |
| 7955 | return wpa_driver_nl80211_authenticate(bss, params); |
| 7956 | } |
| 7957 | |
| 7958 | |
| 7959 | static void driver_nl80211_deinit(void *priv) |
| 7960 | { |
| 7961 | struct i802_bss *bss = priv; |
| 7962 | wpa_driver_nl80211_deinit(bss); |
| 7963 | } |
| 7964 | |
| 7965 | |
| 7966 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, |
| 7967 | const char *ifname) |
| 7968 | { |
| 7969 | struct i802_bss *bss = priv; |
| 7970 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 7971 | } |
| 7972 | |
| 7973 | |
| 7974 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 7975 | size_t data_len, int noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7976 | unsigned int freq, |
| 7977 | const u16 *csa_offs, size_t csa_offs_len) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7978 | { |
| 7979 | struct i802_bss *bss = priv; |
| 7980 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7981 | freq, 0, 0, 0, csa_offs, |
| 7982 | csa_offs_len); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7983 | } |
| 7984 | |
| 7985 | |
| 7986 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) |
| 7987 | { |
| 7988 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7989 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7990 | } |
| 7991 | |
| 7992 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7993 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
| 7994 | const char *ifname, int vlan_id) |
| 7995 | { |
| 7996 | struct i802_bss *bss = priv; |
| 7997 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); |
| 7998 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7999 | |
| 8000 | |
| 8001 | static int driver_nl80211_read_sta_data(void *priv, |
| 8002 | struct hostap_sta_driver_data *data, |
| 8003 | const u8 *addr) |
| 8004 | { |
| 8005 | struct i802_bss *bss = priv; |
Dmitry Shmidt | abb90a3 | 2016-12-05 15:34:39 -0800 | [diff] [blame] | 8006 | |
| 8007 | os_memset(data, 0, sizeof(*data)); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 8008 | return i802_read_sta_data(bss, data, addr); |
| 8009 | } |
| 8010 | |
| 8011 | |
| 8012 | static int driver_nl80211_send_action(void *priv, unsigned int freq, |
| 8013 | unsigned int wait_time, |
| 8014 | const u8 *dst, const u8 *src, |
| 8015 | const u8 *bssid, |
| 8016 | const u8 *data, size_t data_len, |
| 8017 | int no_cck) |
| 8018 | { |
| 8019 | struct i802_bss *bss = priv; |
| 8020 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, |
| 8021 | bssid, data, data_len, no_cck); |
| 8022 | } |
| 8023 | |
| 8024 | |
| 8025 | static int driver_nl80211_probe_req_report(void *priv, int report) |
| 8026 | { |
| 8027 | struct i802_bss *bss = priv; |
| 8028 | return wpa_driver_nl80211_probe_req_report(bss, report); |
| 8029 | } |
| 8030 | |
| 8031 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8032 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
| 8033 | const u8 *ies, size_t ies_len) |
| 8034 | { |
| 8035 | int ret; |
| 8036 | struct nl_msg *msg; |
| 8037 | struct i802_bss *bss = priv; |
| 8038 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8039 | u16 mdid = WPA_GET_LE16(md); |
| 8040 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8041 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8042 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
| 8043 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
| 8044 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { |
| 8045 | nlmsg_free(msg); |
| 8046 | return -ENOBUFS; |
| 8047 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8048 | |
| 8049 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8050 | if (ret) { |
| 8051 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " |
| 8052 | "err=%d (%s)", ret, strerror(-ret)); |
| 8053 | } |
| 8054 | |
| 8055 | return ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 8056 | } |
| 8057 | |
| 8058 | |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 8059 | static const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 8060 | { |
| 8061 | struct i802_bss *bss = priv; |
| 8062 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8063 | |
| 8064 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 8065 | return NULL; |
| 8066 | |
| 8067 | return bss->addr; |
| 8068 | } |
| 8069 | |
| 8070 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8071 | static const char * scan_state_str(enum scan_states scan_state) |
| 8072 | { |
| 8073 | switch (scan_state) { |
| 8074 | case NO_SCAN: |
| 8075 | return "NO_SCAN"; |
| 8076 | case SCAN_REQUESTED: |
| 8077 | return "SCAN_REQUESTED"; |
| 8078 | case SCAN_STARTED: |
| 8079 | return "SCAN_STARTED"; |
| 8080 | case SCAN_COMPLETED: |
| 8081 | return "SCAN_COMPLETED"; |
| 8082 | case SCAN_ABORTED: |
| 8083 | return "SCAN_ABORTED"; |
| 8084 | case SCHED_SCAN_STARTED: |
| 8085 | return "SCHED_SCAN_STARTED"; |
| 8086 | case SCHED_SCAN_STOPPED: |
| 8087 | return "SCHED_SCAN_STOPPED"; |
| 8088 | case SCHED_SCAN_RESULTS: |
| 8089 | return "SCHED_SCAN_RESULTS"; |
| 8090 | } |
| 8091 | |
| 8092 | return "??"; |
| 8093 | } |
| 8094 | |
| 8095 | |
| 8096 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) |
| 8097 | { |
| 8098 | struct i802_bss *bss = priv; |
| 8099 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8100 | int res; |
| 8101 | char *pos, *end; |
| 8102 | |
| 8103 | pos = buf; |
| 8104 | end = buf + buflen; |
| 8105 | |
| 8106 | res = os_snprintf(pos, end - pos, |
| 8107 | "ifindex=%d\n" |
| 8108 | "ifname=%s\n" |
| 8109 | "brname=%s\n" |
| 8110 | "addr=" MACSTR "\n" |
| 8111 | "freq=%d\n" |
| 8112 | "%s%s%s%s%s", |
| 8113 | bss->ifindex, |
| 8114 | bss->ifname, |
| 8115 | bss->brname, |
| 8116 | MAC2STR(bss->addr), |
| 8117 | bss->freq, |
| 8118 | bss->beacon_set ? "beacon_set=1\n" : "", |
| 8119 | bss->added_if_into_bridge ? |
| 8120 | "added_if_into_bridge=1\n" : "", |
| 8121 | bss->added_bridge ? "added_bridge=1\n" : "", |
| 8122 | bss->in_deinit ? "in_deinit=1\n" : "", |
| 8123 | bss->if_dynamic ? "if_dynamic=1\n" : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8124 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8125 | return pos - buf; |
| 8126 | pos += res; |
| 8127 | |
| 8128 | if (bss->wdev_id_set) { |
| 8129 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", |
| 8130 | (unsigned long long) bss->wdev_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8131 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8132 | return pos - buf; |
| 8133 | pos += res; |
| 8134 | } |
| 8135 | |
| 8136 | res = os_snprintf(pos, end - pos, |
| 8137 | "phyname=%s\n" |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8138 | "perm_addr=" MACSTR "\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8139 | "drv_ifindex=%d\n" |
| 8140 | "operstate=%d\n" |
| 8141 | "scan_state=%s\n" |
| 8142 | "auth_bssid=" MACSTR "\n" |
| 8143 | "auth_attempt_bssid=" MACSTR "\n" |
| 8144 | "bssid=" MACSTR "\n" |
| 8145 | "prev_bssid=" MACSTR "\n" |
| 8146 | "associated=%d\n" |
| 8147 | "assoc_freq=%u\n" |
| 8148 | "monitor_sock=%d\n" |
| 8149 | "monitor_ifidx=%d\n" |
| 8150 | "monitor_refcount=%d\n" |
| 8151 | "last_mgmt_freq=%u\n" |
| 8152 | "eapol_tx_sock=%d\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8153 | "%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] | 8154 | drv->phyname, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8155 | MAC2STR(drv->perm_addr), |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8156 | drv->ifindex, |
| 8157 | drv->operstate, |
| 8158 | scan_state_str(drv->scan_state), |
| 8159 | MAC2STR(drv->auth_bssid), |
| 8160 | MAC2STR(drv->auth_attempt_bssid), |
| 8161 | MAC2STR(drv->bssid), |
| 8162 | MAC2STR(drv->prev_bssid), |
| 8163 | drv->associated, |
| 8164 | drv->assoc_freq, |
| 8165 | drv->monitor_sock, |
| 8166 | drv->monitor_ifidx, |
| 8167 | drv->monitor_refcount, |
| 8168 | drv->last_mgmt_freq, |
| 8169 | drv->eapol_tx_sock, |
| 8170 | drv->ignore_if_down_event ? |
| 8171 | "ignore_if_down_event=1\n" : "", |
| 8172 | drv->scan_complete_events ? |
| 8173 | "scan_complete_events=1\n" : "", |
| 8174 | drv->disabled_11b_rates ? |
| 8175 | "disabled_11b_rates=1\n" : "", |
| 8176 | drv->pending_remain_on_chan ? |
| 8177 | "pending_remain_on_chan=1\n" : "", |
| 8178 | drv->in_interface_list ? "in_interface_list=1\n" : "", |
| 8179 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", |
| 8180 | drv->poll_command_supported ? |
| 8181 | "poll_command_supported=1\n" : "", |
| 8182 | drv->data_tx_status ? "data_tx_status=1\n" : "", |
| 8183 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", |
| 8184 | drv->retry_auth ? "retry_auth=1\n" : "", |
| 8185 | drv->use_monitor ? "use_monitor=1\n" : "", |
| 8186 | drv->ignore_next_local_disconnect ? |
| 8187 | "ignore_next_local_disconnect=1\n" : "", |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 8188 | drv->ignore_next_local_deauth ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8189 | "ignore_next_local_deauth=1\n" : ""); |
| 8190 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8191 | return pos - buf; |
| 8192 | pos += res; |
| 8193 | |
| 8194 | if (drv->has_capability) { |
| 8195 | res = os_snprintf(pos, end - pos, |
| 8196 | "capa.key_mgmt=0x%x\n" |
| 8197 | "capa.enc=0x%x\n" |
| 8198 | "capa.auth=0x%x\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8199 | "capa.flags=0x%llx\n" |
| 8200 | "capa.rrm_flags=0x%x\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8201 | "capa.max_scan_ssids=%d\n" |
| 8202 | "capa.max_sched_scan_ssids=%d\n" |
| 8203 | "capa.sched_scan_supported=%d\n" |
| 8204 | "capa.max_match_sets=%d\n" |
| 8205 | "capa.max_remain_on_chan=%u\n" |
| 8206 | "capa.max_stations=%u\n" |
| 8207 | "capa.probe_resp_offloads=0x%x\n" |
| 8208 | "capa.max_acl_mac_addrs=%u\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8209 | "capa.num_multichan_concurrent=%u\n" |
| 8210 | "capa.mac_addr_rand_sched_scan_supported=%d\n" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8211 | "capa.mac_addr_rand_scan_supported=%d\n" |
| 8212 | "capa.conc_capab=%u\n" |
| 8213 | "capa.max_conc_chan_2_4=%u\n" |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8214 | "capa.max_conc_chan_5_0=%u\n" |
| 8215 | "capa.max_sched_scan_plans=%u\n" |
| 8216 | "capa.max_sched_scan_plan_interval=%u\n" |
| 8217 | "capa.max_sched_scan_plan_iterations=%u\n", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8218 | drv->capa.key_mgmt, |
| 8219 | drv->capa.enc, |
| 8220 | drv->capa.auth, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8221 | (unsigned long long) drv->capa.flags, |
| 8222 | drv->capa.rrm_flags, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8223 | drv->capa.max_scan_ssids, |
| 8224 | drv->capa.max_sched_scan_ssids, |
| 8225 | drv->capa.sched_scan_supported, |
| 8226 | drv->capa.max_match_sets, |
| 8227 | drv->capa.max_remain_on_chan, |
| 8228 | drv->capa.max_stations, |
| 8229 | drv->capa.probe_resp_offloads, |
| 8230 | drv->capa.max_acl_mac_addrs, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8231 | drv->capa.num_multichan_concurrent, |
| 8232 | drv->capa.mac_addr_rand_sched_scan_supported, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8233 | drv->capa.mac_addr_rand_scan_supported, |
| 8234 | drv->capa.conc_capab, |
| 8235 | drv->capa.max_conc_chan_2_4, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 8236 | drv->capa.max_conc_chan_5_0, |
| 8237 | drv->capa.max_sched_scan_plans, |
| 8238 | drv->capa.max_sched_scan_plan_interval, |
| 8239 | drv->capa.max_sched_scan_plan_iterations); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8240 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 8241 | return pos - buf; |
| 8242 | pos += res; |
| 8243 | } |
| 8244 | |
| 8245 | return pos - buf; |
| 8246 | } |
| 8247 | |
| 8248 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8249 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
| 8250 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8251 | if ((settings->head && |
| 8252 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, |
| 8253 | settings->head_len, settings->head)) || |
| 8254 | (settings->tail && |
| 8255 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, |
| 8256 | settings->tail_len, settings->tail)) || |
| 8257 | (settings->beacon_ies && |
| 8258 | nla_put(msg, NL80211_ATTR_IE, |
| 8259 | settings->beacon_ies_len, settings->beacon_ies)) || |
| 8260 | (settings->proberesp_ies && |
| 8261 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 8262 | settings->proberesp_ies_len, settings->proberesp_ies)) || |
| 8263 | (settings->assocresp_ies && |
| 8264 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 8265 | settings->assocresp_ies_len, settings->assocresp_ies)) || |
| 8266 | (settings->probe_resp && |
| 8267 | nla_put(msg, NL80211_ATTR_PROBE_RESP, |
| 8268 | settings->probe_resp_len, settings->probe_resp))) |
| 8269 | return -ENOBUFS; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8270 | |
| 8271 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8272 | } |
| 8273 | |
| 8274 | |
| 8275 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) |
| 8276 | { |
| 8277 | struct nl_msg *msg; |
| 8278 | struct i802_bss *bss = priv; |
| 8279 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8280 | struct nlattr *beacon_csa; |
| 8281 | int ret = -ENOBUFS; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8282 | int csa_off_len = 0; |
| 8283 | int i; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8284 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 8285 | 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] | 8286 | settings->cs_count, settings->block_tx, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 8287 | settings->freq_params.freq, settings->freq_params.bandwidth, |
| 8288 | settings->freq_params.center_freq1, |
| 8289 | settings->freq_params.center_freq2); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8290 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8291 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8292 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
| 8293 | return -EOPNOTSUPP; |
| 8294 | } |
| 8295 | |
| 8296 | if ((drv->nlmode != NL80211_IFTYPE_AP) && |
| 8297 | (drv->nlmode != NL80211_IFTYPE_P2P_GO)) |
| 8298 | return -EOPNOTSUPP; |
| 8299 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8300 | /* |
| 8301 | * Remove empty counters, assuming Probe Response and Beacon frame |
| 8302 | * counters match. This implementation assumes that there are only two |
| 8303 | * counters. |
| 8304 | */ |
| 8305 | if (settings->counter_offset_beacon[0] && |
| 8306 | !settings->counter_offset_beacon[1]) { |
| 8307 | csa_off_len = 1; |
| 8308 | } else if (settings->counter_offset_beacon[1] && |
| 8309 | !settings->counter_offset_beacon[0]) { |
| 8310 | csa_off_len = 1; |
| 8311 | settings->counter_offset_beacon[0] = |
| 8312 | settings->counter_offset_beacon[1]; |
| 8313 | settings->counter_offset_presp[0] = |
| 8314 | settings->counter_offset_presp[1]; |
| 8315 | } else if (settings->counter_offset_beacon[1] && |
| 8316 | settings->counter_offset_beacon[0]) { |
| 8317 | csa_off_len = 2; |
| 8318 | } else { |
| 8319 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); |
| 8320 | return -EINVAL; |
| 8321 | } |
| 8322 | |
| 8323 | /* Check CSA counters validity */ |
| 8324 | if (drv->capa.max_csa_counters && |
| 8325 | csa_off_len > drv->capa.max_csa_counters) { |
| 8326 | wpa_printf(MSG_ERROR, |
| 8327 | "nl80211: Too many CSA counters provided"); |
| 8328 | return -EINVAL; |
| 8329 | } |
| 8330 | |
| 8331 | if (!settings->beacon_csa.tail) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8332 | return -EINVAL; |
| 8333 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8334 | for (i = 0; i < csa_off_len; i++) { |
| 8335 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; |
| 8336 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; |
| 8337 | |
| 8338 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || |
| 8339 | (settings->beacon_csa.tail[csa_c_off_bcn] != |
| 8340 | settings->cs_count)) |
| 8341 | return -EINVAL; |
| 8342 | |
| 8343 | if (settings->beacon_csa.probe_resp && |
| 8344 | ((settings->beacon_csa.probe_resp_len <= |
| 8345 | csa_c_off_presp) || |
| 8346 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != |
| 8347 | settings->cs_count))) |
| 8348 | return -EINVAL; |
| 8349 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8350 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8351 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
| 8352 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
| 8353 | settings->cs_count) || |
| 8354 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || |
| 8355 | (settings->block_tx && |
| 8356 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8357 | goto error; |
| 8358 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8359 | /* beacon_after params */ |
| 8360 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 8361 | if (ret) |
| 8362 | goto error; |
| 8363 | |
| 8364 | /* beacon_csa params */ |
| 8365 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); |
| 8366 | if (!beacon_csa) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8367 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8368 | |
| 8369 | ret = set_beacon_data(msg, &settings->beacon_csa); |
| 8370 | if (ret) |
| 8371 | goto error; |
| 8372 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8373 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
| 8374 | csa_off_len * sizeof(u16), |
| 8375 | settings->counter_offset_beacon) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8376 | (settings->beacon_csa.probe_resp && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8377 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
| 8378 | csa_off_len * sizeof(u16), |
| 8379 | settings->counter_offset_presp))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8380 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8381 | |
| 8382 | nla_nest_end(msg, beacon_csa); |
| 8383 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8384 | if (ret) { |
| 8385 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", |
| 8386 | ret, strerror(-ret)); |
| 8387 | } |
| 8388 | return ret; |
| 8389 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8390 | fail: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8391 | ret = -ENOBUFS; |
| 8392 | error: |
| 8393 | nlmsg_free(msg); |
| 8394 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); |
| 8395 | return ret; |
| 8396 | } |
| 8397 | |
| 8398 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8399 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
| 8400 | u8 user_priority, u16 admitted_time) |
| 8401 | { |
| 8402 | struct i802_bss *bss = priv; |
| 8403 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8404 | struct nl_msg *msg; |
| 8405 | int ret; |
| 8406 | |
| 8407 | wpa_printf(MSG_DEBUG, |
| 8408 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", |
| 8409 | tsid, admitted_time, user_priority); |
| 8410 | |
| 8411 | if (!is_sta_interface(drv->nlmode)) |
| 8412 | return -ENOTSUP; |
| 8413 | |
| 8414 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
| 8415 | if (!msg || |
| 8416 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 8417 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 8418 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || |
| 8419 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { |
| 8420 | nlmsg_free(msg); |
| 8421 | return -ENOBUFS; |
| 8422 | } |
| 8423 | |
| 8424 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8425 | if (ret) |
| 8426 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", |
| 8427 | ret, strerror(-ret)); |
| 8428 | return ret; |
| 8429 | } |
| 8430 | |
| 8431 | |
| 8432 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) |
| 8433 | { |
| 8434 | struct i802_bss *bss = priv; |
| 8435 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8436 | struct nl_msg *msg; |
| 8437 | int ret; |
| 8438 | |
| 8439 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); |
| 8440 | |
| 8441 | if (!is_sta_interface(drv->nlmode)) |
| 8442 | return -ENOTSUP; |
| 8443 | |
| 8444 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
| 8445 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 8446 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 8447 | nlmsg_free(msg); |
| 8448 | return -ENOBUFS; |
| 8449 | } |
| 8450 | |
| 8451 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8452 | if (ret) |
| 8453 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", |
| 8454 | ret, strerror(-ret)); |
| 8455 | return ret; |
| 8456 | } |
| 8457 | |
| 8458 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8459 | #ifdef CONFIG_TESTING_OPTIONS |
| 8460 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) |
| 8461 | { |
| 8462 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8463 | struct wpabuf *buf = arg; |
| 8464 | |
| 8465 | if (!buf) |
| 8466 | return NL_SKIP; |
| 8467 | |
| 8468 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { |
| 8469 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); |
| 8470 | return NL_SKIP; |
| 8471 | } |
| 8472 | |
| 8473 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), |
| 8474 | genlmsg_attrlen(gnlh, 0)); |
| 8475 | |
| 8476 | return NL_SKIP; |
| 8477 | } |
| 8478 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 8479 | |
| 8480 | |
| 8481 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
| 8482 | { |
| 8483 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8484 | struct nlattr *nl_vendor_reply, *nl; |
| 8485 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8486 | struct wpabuf *buf = arg; |
| 8487 | int rem; |
| 8488 | |
| 8489 | if (!buf) |
| 8490 | return NL_SKIP; |
| 8491 | |
| 8492 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8493 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8494 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; |
| 8495 | |
| 8496 | if (!nl_vendor_reply) |
| 8497 | return NL_SKIP; |
| 8498 | |
| 8499 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { |
| 8500 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); |
| 8501 | return NL_SKIP; |
| 8502 | } |
| 8503 | |
| 8504 | nla_for_each_nested(nl, nl_vendor_reply, rem) { |
| 8505 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); |
| 8506 | } |
| 8507 | |
| 8508 | return NL_SKIP; |
| 8509 | } |
| 8510 | |
| 8511 | |
| 8512 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, |
| 8513 | unsigned int subcmd, const u8 *data, |
| 8514 | size_t data_len, struct wpabuf *buf) |
| 8515 | { |
| 8516 | struct i802_bss *bss = priv; |
| 8517 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8518 | struct nl_msg *msg; |
| 8519 | int ret; |
| 8520 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8521 | #ifdef CONFIG_TESTING_OPTIONS |
| 8522 | if (vendor_id == 0xffffffff) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8523 | msg = nlmsg_alloc(); |
| 8524 | if (!msg) |
| 8525 | return -ENOMEM; |
| 8526 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8527 | nl80211_cmd(drv, msg, 0, subcmd); |
| 8528 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < |
| 8529 | 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8530 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8531 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
| 8532 | if (ret) |
| 8533 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", |
| 8534 | ret); |
| 8535 | return ret; |
| 8536 | } |
| 8537 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 8538 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8539 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 8540 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
| 8541 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || |
| 8542 | (data && |
| 8543 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) |
| 8544 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8545 | |
| 8546 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); |
| 8547 | if (ret) |
| 8548 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", |
| 8549 | ret); |
| 8550 | return ret; |
| 8551 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8552 | fail: |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8553 | nlmsg_free(msg); |
| 8554 | return -ENOBUFS; |
| 8555 | } |
| 8556 | |
| 8557 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8558 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
| 8559 | u8 qos_map_set_len) |
| 8560 | { |
| 8561 | struct i802_bss *bss = priv; |
| 8562 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8563 | struct nl_msg *msg; |
| 8564 | int ret; |
| 8565 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8566 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
| 8567 | qos_map_set, qos_map_set_len); |
| 8568 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8569 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
| 8570 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
| 8571 | nlmsg_free(msg); |
| 8572 | return -ENOBUFS; |
| 8573 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8574 | |
| 8575 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8576 | if (ret) |
| 8577 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); |
| 8578 | |
| 8579 | return ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8580 | } |
| 8581 | |
| 8582 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8583 | static int nl80211_set_wowlan(void *priv, |
| 8584 | const struct wowlan_triggers *triggers) |
| 8585 | { |
| 8586 | struct i802_bss *bss = priv; |
| 8587 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8588 | struct nl_msg *msg; |
| 8589 | struct nlattr *wowlan_triggers; |
| 8590 | int ret; |
| 8591 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8592 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
| 8593 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8594 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8595 | !(wowlan_triggers = nla_nest_start(msg, |
| 8596 | NL80211_ATTR_WOWLAN_TRIGGERS)) || |
| 8597 | (triggers->any && |
| 8598 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 8599 | (triggers->disconnect && |
| 8600 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 8601 | (triggers->magic_pkt && |
| 8602 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 8603 | (triggers->gtk_rekey_failure && |
| 8604 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 8605 | (triggers->eap_identity_req && |
| 8606 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 8607 | (triggers->four_way_handshake && |
| 8608 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 8609 | (triggers->rfkill_release && |
| 8610 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { |
| 8611 | nlmsg_free(msg); |
| 8612 | return -ENOBUFS; |
| 8613 | } |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8614 | |
| 8615 | nla_nest_end(msg, wowlan_triggers); |
| 8616 | |
| 8617 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8618 | if (ret) |
| 8619 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); |
| 8620 | |
| 8621 | return ret; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8622 | } |
| 8623 | |
| 8624 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8625 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8626 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
| 8627 | { |
| 8628 | struct i802_bss *bss = priv; |
| 8629 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8630 | struct nl_msg *msg; |
| 8631 | struct nlattr *params; |
| 8632 | |
| 8633 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); |
| 8634 | |
| 8635 | if (!drv->roaming_vendor_cmd_avail) { |
| 8636 | wpa_printf(MSG_DEBUG, |
| 8637 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); |
| 8638 | return -1; |
| 8639 | } |
| 8640 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8641 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 8642 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8643 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8644 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || |
| 8645 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8646 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, |
| 8647 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : |
| 8648 | QCA_ROAMING_NOT_ALLOWED) || |
| 8649 | (bssid && |
| 8650 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { |
| 8651 | nlmsg_free(msg); |
| 8652 | return -1; |
| 8653 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8654 | nla_nest_end(msg, params); |
| 8655 | |
| 8656 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8657 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8658 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8659 | |
| 8660 | |
| 8661 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
| 8662 | { |
| 8663 | struct i802_bss *bss = priv; |
| 8664 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8665 | int new_addr = addr != NULL; |
| 8666 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 8667 | if (TEST_FAIL()) |
| 8668 | return -1; |
| 8669 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8670 | if (!addr) |
| 8671 | addr = drv->perm_addr; |
| 8672 | |
| 8673 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) |
| 8674 | return -1; |
| 8675 | |
| 8676 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) |
| 8677 | { |
| 8678 | wpa_printf(MSG_DEBUG, |
| 8679 | "nl80211: failed to set_mac_addr for %s to " MACSTR, |
| 8680 | bss->ifname, MAC2STR(addr)); |
| 8681 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 8682 | 1) < 0) { |
| 8683 | wpa_printf(MSG_DEBUG, |
| 8684 | "nl80211: Could not restore interface UP after failed set_mac_addr"); |
| 8685 | } |
| 8686 | return -1; |
| 8687 | } |
| 8688 | |
| 8689 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, |
| 8690 | bss->ifname, MAC2STR(addr)); |
| 8691 | drv->addr_changed = new_addr; |
| 8692 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 8693 | |
| 8694 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) |
| 8695 | { |
| 8696 | wpa_printf(MSG_DEBUG, |
| 8697 | "nl80211: Could not restore interface UP after set_mac_addr"); |
| 8698 | } |
| 8699 | |
| 8700 | return 0; |
| 8701 | } |
| 8702 | |
| 8703 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8704 | #ifdef CONFIG_MESH |
| 8705 | |
| 8706 | static int wpa_driver_nl80211_init_mesh(void *priv) |
| 8707 | { |
| 8708 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { |
| 8709 | wpa_printf(MSG_INFO, |
| 8710 | "nl80211: Failed to set interface into mesh mode"); |
| 8711 | return -1; |
| 8712 | } |
| 8713 | return 0; |
| 8714 | } |
| 8715 | |
| 8716 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8717 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
| 8718 | size_t mesh_id_len) |
| 8719 | { |
| 8720 | if (mesh_id) { |
| 8721 | wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)", |
| 8722 | mesh_id, mesh_id_len); |
| 8723 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); |
| 8724 | } |
| 8725 | |
| 8726 | return 0; |
| 8727 | } |
| 8728 | |
| 8729 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 8730 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
| 8731 | struct wpa_driver_mesh_bss_params *params) |
| 8732 | { |
| 8733 | struct nlattr *container; |
| 8734 | |
| 8735 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
| 8736 | if (!container) |
| 8737 | return -1; |
| 8738 | |
| 8739 | if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
| 8740 | nla_put_u32(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 8741 | params->auto_plinks)) || |
| 8742 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) && |
| 8743 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 8744 | params->max_peer_links))) |
| 8745 | return -1; |
| 8746 | |
| 8747 | /* |
| 8748 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because |
| 8749 | * the timer could disconnect stations even in that case. |
| 8750 | */ |
| 8751 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) && |
| 8752 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 8753 | params->peer_link_timeout)) { |
| 8754 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); |
| 8755 | return -1; |
| 8756 | } |
| 8757 | |
| 8758 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) && |
| 8759 | nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) { |
| 8760 | wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE"); |
| 8761 | return -1; |
| 8762 | } |
| 8763 | |
| 8764 | nla_nest_end(msg, container); |
| 8765 | |
| 8766 | return 0; |
| 8767 | } |
| 8768 | |
| 8769 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8770 | static int nl80211_join_mesh(struct i802_bss *bss, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8771 | struct wpa_driver_mesh_join_params *params) |
| 8772 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8773 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8774 | struct nl_msg *msg; |
| 8775 | struct nlattr *container; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8776 | int ret = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8777 | |
| 8778 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
| 8779 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8780 | if (!msg || |
| 8781 | nl80211_put_freq_params(msg, ¶ms->freq) || |
| 8782 | nl80211_put_basic_rates(msg, params->basic_rates) || |
| 8783 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 8784 | nl80211_put_beacon_int(msg, params->beacon_int) || |
| 8785 | nl80211_put_dtim_period(msg, params->dtim_period)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8786 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8787 | |
| 8788 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
| 8789 | |
| 8790 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); |
| 8791 | if (!container) |
| 8792 | goto fail; |
| 8793 | |
| 8794 | if (params->ies) { |
| 8795 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); |
| 8796 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
| 8797 | params->ies)) |
| 8798 | goto fail; |
| 8799 | } |
| 8800 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ |
| 8801 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { |
| 8802 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
| 8803 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) |
| 8804 | goto fail; |
| 8805 | } |
| 8806 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
| 8807 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) |
| 8808 | goto fail; |
| 8809 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && |
| 8810 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) |
| 8811 | goto fail; |
| 8812 | nla_nest_end(msg, container); |
| 8813 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 8814 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS; |
| 8815 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT; |
| 8816 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS; |
| 8817 | if (nl80211_put_mesh_config(msg, ¶ms->conf) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8818 | goto fail; |
| 8819 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8820 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8821 | msg = NULL; |
| 8822 | if (ret) { |
| 8823 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", |
| 8824 | ret, strerror(-ret)); |
| 8825 | goto fail; |
| 8826 | } |
| 8827 | ret = 0; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 8828 | drv->assoc_freq = bss->freq = params->freq.freq; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8829 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
| 8830 | |
| 8831 | fail: |
| 8832 | nlmsg_free(msg); |
| 8833 | return ret; |
| 8834 | } |
| 8835 | |
| 8836 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8837 | static int |
| 8838 | wpa_driver_nl80211_join_mesh(void *priv, |
| 8839 | struct wpa_driver_mesh_join_params *params) |
| 8840 | { |
| 8841 | struct i802_bss *bss = priv; |
| 8842 | int ret, timeout; |
| 8843 | |
| 8844 | timeout = params->conf.peer_link_timeout; |
| 8845 | |
| 8846 | /* Disable kernel inactivity timer */ |
| 8847 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) |
| 8848 | params->conf.peer_link_timeout = 0; |
| 8849 | |
| 8850 | ret = nl80211_join_mesh(bss, params); |
| 8851 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { |
| 8852 | wpa_printf(MSG_DEBUG, |
| 8853 | "nl80211: Mesh join retry for peer_link_timeout"); |
| 8854 | /* |
| 8855 | * Old kernel does not support setting |
| 8856 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds |
| 8857 | * into future from peer_link_timeout. |
| 8858 | */ |
| 8859 | params->conf.peer_link_timeout = timeout + 60; |
| 8860 | ret = nl80211_join_mesh(priv, params); |
| 8861 | } |
| 8862 | |
| 8863 | params->conf.peer_link_timeout = timeout; |
| 8864 | return ret; |
| 8865 | } |
| 8866 | |
| 8867 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8868 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
| 8869 | { |
| 8870 | struct i802_bss *bss = priv; |
| 8871 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8872 | struct nl_msg *msg; |
| 8873 | int ret; |
| 8874 | |
| 8875 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); |
| 8876 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
| 8877 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8878 | if (ret) { |
| 8879 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", |
| 8880 | ret, strerror(-ret)); |
| 8881 | } else { |
| 8882 | wpa_printf(MSG_DEBUG, |
| 8883 | "nl80211: mesh leave request send successfully"); |
| 8884 | } |
| 8885 | |
| 8886 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
| 8887 | NL80211_IFTYPE_STATION)) { |
| 8888 | wpa_printf(MSG_INFO, |
| 8889 | "nl80211: Failed to set interface into station mode"); |
| 8890 | } |
| 8891 | return ret; |
| 8892 | } |
| 8893 | |
| 8894 | #endif /* CONFIG_MESH */ |
| 8895 | |
| 8896 | |
| 8897 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
| 8898 | const u8 *ipaddr, int prefixlen, |
| 8899 | const u8 *addr) |
| 8900 | { |
| 8901 | #ifdef CONFIG_LIBNL3_ROUTE |
| 8902 | struct i802_bss *bss = priv; |
| 8903 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8904 | struct rtnl_neigh *rn; |
| 8905 | struct nl_addr *nl_ipaddr = NULL; |
| 8906 | struct nl_addr *nl_lladdr = NULL; |
| 8907 | int family, addrsize; |
| 8908 | int res; |
| 8909 | |
| 8910 | if (!ipaddr || prefixlen == 0 || !addr) |
| 8911 | return -EINVAL; |
| 8912 | |
| 8913 | if (bss->br_ifindex == 0) { |
| 8914 | wpa_printf(MSG_DEBUG, |
| 8915 | "nl80211: bridge must be set before adding an ip neigh to it"); |
| 8916 | return -1; |
| 8917 | } |
| 8918 | |
| 8919 | if (!drv->rtnl_sk) { |
| 8920 | wpa_printf(MSG_DEBUG, |
| 8921 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 8922 | return -1; |
| 8923 | } |
| 8924 | |
| 8925 | if (version == 4) { |
| 8926 | family = AF_INET; |
| 8927 | addrsize = 4; |
| 8928 | } else if (version == 6) { |
| 8929 | family = AF_INET6; |
| 8930 | addrsize = 16; |
| 8931 | } else { |
| 8932 | return -EINVAL; |
| 8933 | } |
| 8934 | |
| 8935 | rn = rtnl_neigh_alloc(); |
| 8936 | if (rn == NULL) |
| 8937 | return -ENOMEM; |
| 8938 | |
| 8939 | /* set the destination ip address for neigh */ |
| 8940 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 8941 | if (nl_ipaddr == NULL) { |
| 8942 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 8943 | res = -ENOMEM; |
| 8944 | goto errout; |
| 8945 | } |
| 8946 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); |
| 8947 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 8948 | if (res) { |
| 8949 | wpa_printf(MSG_DEBUG, |
| 8950 | "nl80211: neigh set destination addr failed"); |
| 8951 | goto errout; |
| 8952 | } |
| 8953 | |
| 8954 | /* set the corresponding lladdr for neigh */ |
| 8955 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); |
| 8956 | if (nl_lladdr == NULL) { |
| 8957 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); |
| 8958 | res = -ENOMEM; |
| 8959 | goto errout; |
| 8960 | } |
| 8961 | rtnl_neigh_set_lladdr(rn, nl_lladdr); |
| 8962 | |
| 8963 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 8964 | rtnl_neigh_set_state(rn, NUD_PERMANENT); |
| 8965 | |
| 8966 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); |
| 8967 | if (res) { |
| 8968 | wpa_printf(MSG_DEBUG, |
| 8969 | "nl80211: Adding bridge ip neigh failed: %s", |
| 8970 | strerror(errno)); |
| 8971 | } |
| 8972 | errout: |
| 8973 | if (nl_lladdr) |
| 8974 | nl_addr_put(nl_lladdr); |
| 8975 | if (nl_ipaddr) |
| 8976 | nl_addr_put(nl_ipaddr); |
| 8977 | if (rn) |
| 8978 | rtnl_neigh_put(rn); |
| 8979 | return res; |
| 8980 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 8981 | return -1; |
| 8982 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 8983 | } |
| 8984 | |
| 8985 | |
| 8986 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
| 8987 | const u8 *ipaddr) |
| 8988 | { |
| 8989 | #ifdef CONFIG_LIBNL3_ROUTE |
| 8990 | struct i802_bss *bss = priv; |
| 8991 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8992 | struct rtnl_neigh *rn; |
| 8993 | struct nl_addr *nl_ipaddr; |
| 8994 | int family, addrsize; |
| 8995 | int res; |
| 8996 | |
| 8997 | if (!ipaddr) |
| 8998 | return -EINVAL; |
| 8999 | |
| 9000 | if (version == 4) { |
| 9001 | family = AF_INET; |
| 9002 | addrsize = 4; |
| 9003 | } else if (version == 6) { |
| 9004 | family = AF_INET6; |
| 9005 | addrsize = 16; |
| 9006 | } else { |
| 9007 | return -EINVAL; |
| 9008 | } |
| 9009 | |
| 9010 | if (bss->br_ifindex == 0) { |
| 9011 | wpa_printf(MSG_DEBUG, |
| 9012 | "nl80211: bridge must be set to delete an ip neigh"); |
| 9013 | return -1; |
| 9014 | } |
| 9015 | |
| 9016 | if (!drv->rtnl_sk) { |
| 9017 | wpa_printf(MSG_DEBUG, |
| 9018 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 9019 | return -1; |
| 9020 | } |
| 9021 | |
| 9022 | rn = rtnl_neigh_alloc(); |
| 9023 | if (rn == NULL) |
| 9024 | return -ENOMEM; |
| 9025 | |
| 9026 | /* set the destination ip address for neigh */ |
| 9027 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 9028 | if (nl_ipaddr == NULL) { |
| 9029 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 9030 | res = -ENOMEM; |
| 9031 | goto errout; |
| 9032 | } |
| 9033 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 9034 | if (res) { |
| 9035 | wpa_printf(MSG_DEBUG, |
| 9036 | "nl80211: neigh set destination addr failed"); |
| 9037 | goto errout; |
| 9038 | } |
| 9039 | |
| 9040 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 9041 | |
| 9042 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 9043 | if (res) { |
| 9044 | wpa_printf(MSG_DEBUG, |
| 9045 | "nl80211: Deleting bridge ip neigh failed: %s", |
| 9046 | strerror(errno)); |
| 9047 | } |
| 9048 | errout: |
| 9049 | if (nl_ipaddr) |
| 9050 | nl_addr_put(nl_ipaddr); |
| 9051 | if (rn) |
| 9052 | rtnl_neigh_put(rn); |
| 9053 | return res; |
| 9054 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 9055 | return -1; |
| 9056 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 9057 | } |
| 9058 | |
| 9059 | |
| 9060 | static int linux_write_system_file(const char *path, unsigned int val) |
| 9061 | { |
| 9062 | char buf[50]; |
| 9063 | int fd, len; |
| 9064 | |
| 9065 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); |
| 9066 | if (os_snprintf_error(sizeof(buf), len)) |
| 9067 | return -1; |
| 9068 | |
| 9069 | fd = open(path, O_WRONLY); |
| 9070 | if (fd < 0) |
| 9071 | return -1; |
| 9072 | |
| 9073 | if (write(fd, buf, len) < 0) { |
| 9074 | wpa_printf(MSG_DEBUG, |
| 9075 | "nl80211: Failed to write Linux system file: %s with the value of %d", |
| 9076 | path, val); |
| 9077 | close(fd); |
| 9078 | return -1; |
| 9079 | } |
| 9080 | close(fd); |
| 9081 | |
| 9082 | return 0; |
| 9083 | } |
| 9084 | |
| 9085 | |
| 9086 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) |
| 9087 | { |
| 9088 | switch (attr) { |
| 9089 | case DRV_BR_PORT_ATTR_PROXYARP: |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 9090 | return "proxyarp_wifi"; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9091 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
| 9092 | return "hairpin_mode"; |
| 9093 | } |
| 9094 | |
| 9095 | return NULL; |
| 9096 | } |
| 9097 | |
| 9098 | |
| 9099 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, |
| 9100 | unsigned int val) |
| 9101 | { |
| 9102 | struct i802_bss *bss = priv; |
| 9103 | char path[128]; |
| 9104 | const char *attr_txt; |
| 9105 | |
| 9106 | attr_txt = drv_br_port_attr_str(attr); |
| 9107 | if (attr_txt == NULL) |
| 9108 | return -EINVAL; |
| 9109 | |
| 9110 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", |
| 9111 | bss->ifname, attr_txt); |
| 9112 | |
| 9113 | if (linux_write_system_file(path, val)) |
| 9114 | return -1; |
| 9115 | |
| 9116 | return 0; |
| 9117 | } |
| 9118 | |
| 9119 | |
| 9120 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
| 9121 | { |
| 9122 | switch (param) { |
| 9123 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 9124 | return "arp_accept"; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 9125 | default: |
| 9126 | return NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9127 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9128 | } |
| 9129 | |
| 9130 | |
| 9131 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, |
| 9132 | unsigned int val) |
| 9133 | { |
| 9134 | struct i802_bss *bss = priv; |
| 9135 | char path[128]; |
| 9136 | const char *param_txt; |
| 9137 | int ip_version = 4; |
| 9138 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 9139 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
| 9140 | os_snprintf(path, sizeof(path), |
| 9141 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", |
| 9142 | bss->brname); |
| 9143 | goto set_val; |
| 9144 | } |
| 9145 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9146 | param_txt = drv_br_net_param_str(param); |
| 9147 | if (param_txt == NULL) |
| 9148 | return -EINVAL; |
| 9149 | |
| 9150 | switch (param) { |
| 9151 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 9152 | ip_version = 4; |
| 9153 | break; |
| 9154 | default: |
| 9155 | return -EINVAL; |
| 9156 | } |
| 9157 | |
| 9158 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", |
| 9159 | ip_version, bss->brname, param_txt); |
| 9160 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 9161 | set_val: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9162 | if (linux_write_system_file(path, val)) |
| 9163 | return -1; |
| 9164 | |
| 9165 | return 0; |
| 9166 | } |
| 9167 | |
| 9168 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9169 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 9170 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9171 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
| 9172 | { |
| 9173 | switch (hw_mode) { |
| 9174 | case HOSTAPD_MODE_IEEE80211B: |
| 9175 | return QCA_ACS_MODE_IEEE80211B; |
| 9176 | case HOSTAPD_MODE_IEEE80211G: |
| 9177 | return QCA_ACS_MODE_IEEE80211G; |
| 9178 | case HOSTAPD_MODE_IEEE80211A: |
| 9179 | return QCA_ACS_MODE_IEEE80211A; |
| 9180 | case HOSTAPD_MODE_IEEE80211AD: |
| 9181 | return QCA_ACS_MODE_IEEE80211AD; |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 9182 | case HOSTAPD_MODE_IEEE80211ANY: |
| 9183 | return QCA_ACS_MODE_IEEE80211ANY; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9184 | default: |
| 9185 | return -1; |
| 9186 | } |
| 9187 | } |
| 9188 | |
| 9189 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9190 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
| 9191 | { |
| 9192 | int i, len, ret; |
| 9193 | u32 *freqs; |
| 9194 | |
| 9195 | if (!freq_list) |
| 9196 | return 0; |
| 9197 | len = int_array_len(freq_list); |
| 9198 | freqs = os_malloc(sizeof(u32) * len); |
| 9199 | if (!freqs) |
| 9200 | return -1; |
| 9201 | for (i = 0; i < len; i++) |
| 9202 | freqs[i] = freq_list[i]; |
| 9203 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, |
| 9204 | sizeof(u32) * len, freqs); |
| 9205 | os_free(freqs); |
| 9206 | return ret; |
| 9207 | } |
| 9208 | |
| 9209 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9210 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
| 9211 | { |
| 9212 | struct i802_bss *bss = priv; |
| 9213 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9214 | struct nl_msg *msg; |
| 9215 | struct nlattr *data; |
| 9216 | int ret; |
| 9217 | int mode; |
| 9218 | |
| 9219 | mode = hw_mode_to_qca_acs(params->hw_mode); |
| 9220 | if (mode < 0) |
| 9221 | return -1; |
| 9222 | |
| 9223 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9224 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9225 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9226 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || |
| 9227 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9228 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || |
| 9229 | (params->ht_enabled && |
| 9230 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || |
| 9231 | (params->ht40_enabled && |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 9232 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
| 9233 | (params->vht_enabled && |
| 9234 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || |
| 9235 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, |
| 9236 | params->ch_width) || |
| 9237 | (params->ch_list_len && |
| 9238 | 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] | 9239 | params->ch_list)) || |
| 9240 | add_acs_freq_list(msg, params->freq_list)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9241 | nlmsg_free(msg); |
| 9242 | return -ENOBUFS; |
| 9243 | } |
| 9244 | nla_nest_end(msg, data); |
| 9245 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 9246 | wpa_printf(MSG_DEBUG, |
| 9247 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u", |
| 9248 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
| 9249 | params->vht_enabled, params->ch_width, params->ch_list_len); |
| 9250 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9251 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9252 | if (ret) { |
| 9253 | wpa_printf(MSG_DEBUG, |
| 9254 | "nl80211: Failed to invoke driver ACS function: %s", |
| 9255 | strerror(errno)); |
| 9256 | } |
| 9257 | return ret; |
| 9258 | } |
| 9259 | |
| 9260 | |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 9261 | static int nl80211_set_band(void *priv, enum set_band band) |
| 9262 | { |
| 9263 | struct i802_bss *bss = priv; |
| 9264 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9265 | struct nl_msg *msg; |
| 9266 | struct nlattr *data; |
| 9267 | int ret; |
| 9268 | enum qca_set_band qca_band; |
| 9269 | |
| 9270 | if (!drv->setband_vendor_cmd_avail) |
| 9271 | return -1; |
| 9272 | |
| 9273 | switch (band) { |
| 9274 | case WPA_SETBAND_AUTO: |
| 9275 | qca_band = QCA_SETBAND_AUTO; |
| 9276 | break; |
| 9277 | case WPA_SETBAND_5G: |
| 9278 | qca_band = QCA_SETBAND_5G; |
| 9279 | break; |
| 9280 | case WPA_SETBAND_2G: |
| 9281 | qca_band = QCA_SETBAND_2G; |
| 9282 | break; |
| 9283 | default: |
| 9284 | return -1; |
| 9285 | } |
| 9286 | |
| 9287 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9288 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9289 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9290 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || |
| 9291 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9292 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) { |
| 9293 | nlmsg_free(msg); |
| 9294 | return -ENOBUFS; |
| 9295 | } |
| 9296 | nla_nest_end(msg, data); |
| 9297 | |
| 9298 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9299 | if (ret) { |
| 9300 | wpa_printf(MSG_DEBUG, |
| 9301 | "nl80211: Driver setband function failed: %s", |
| 9302 | strerror(errno)); |
| 9303 | } |
| 9304 | return ret; |
| 9305 | } |
| 9306 | |
| 9307 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9308 | struct nl80211_pcl { |
| 9309 | unsigned int num; |
| 9310 | unsigned int *freq_list; |
| 9311 | }; |
| 9312 | |
| 9313 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) |
| 9314 | { |
| 9315 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9316 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9317 | struct nl80211_pcl *param = arg; |
| 9318 | struct nlattr *nl_vend, *attr; |
| 9319 | enum qca_iface_type iface_type; |
| 9320 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 9321 | unsigned int num, max_num; |
| 9322 | u32 *freqs; |
| 9323 | |
| 9324 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9325 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9326 | |
| 9327 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; |
| 9328 | if (!nl_vend) |
| 9329 | return NL_SKIP; |
| 9330 | |
| 9331 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 9332 | nla_data(nl_vend), nla_len(nl_vend), NULL); |
| 9333 | |
| 9334 | attr = tb_vendor[ |
| 9335 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; |
| 9336 | if (!attr) { |
| 9337 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); |
| 9338 | param->num = 0; |
| 9339 | return NL_SKIP; |
| 9340 | } |
| 9341 | |
| 9342 | iface_type = (enum qca_iface_type) nla_get_u32(attr); |
| 9343 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", |
| 9344 | iface_type); |
| 9345 | |
| 9346 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; |
| 9347 | if (!attr) { |
| 9348 | wpa_printf(MSG_ERROR, |
| 9349 | "nl80211: preferred_freq_list couldn't be found"); |
| 9350 | param->num = 0; |
| 9351 | return NL_SKIP; |
| 9352 | } |
| 9353 | |
| 9354 | /* |
| 9355 | * param->num has the maximum number of entries for which there |
| 9356 | * is room in the freq_list provided by the caller. |
| 9357 | */ |
| 9358 | freqs = nla_data(attr); |
| 9359 | max_num = nla_len(attr) / sizeof(u32); |
| 9360 | if (max_num > param->num) |
| 9361 | max_num = param->num; |
| 9362 | for (num = 0; num < max_num; num++) |
| 9363 | param->freq_list[num] = freqs[num]; |
| 9364 | param->num = num; |
| 9365 | |
| 9366 | return NL_SKIP; |
| 9367 | } |
| 9368 | |
| 9369 | |
| 9370 | static int nl80211_get_pref_freq_list(void *priv, |
| 9371 | enum wpa_driver_if_type if_type, |
| 9372 | unsigned int *num, |
| 9373 | unsigned int *freq_list) |
| 9374 | { |
| 9375 | struct i802_bss *bss = priv; |
| 9376 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9377 | struct nl_msg *msg; |
| 9378 | int ret; |
| 9379 | unsigned int i; |
| 9380 | struct nlattr *params; |
| 9381 | struct nl80211_pcl param; |
| 9382 | enum qca_iface_type iface_type; |
| 9383 | |
| 9384 | if (!drv->get_pref_freq_list) |
| 9385 | return -1; |
| 9386 | |
| 9387 | switch (if_type) { |
| 9388 | case WPA_IF_STATION: |
| 9389 | iface_type = QCA_IFACE_TYPE_STA; |
| 9390 | break; |
| 9391 | case WPA_IF_AP_BSS: |
| 9392 | iface_type = QCA_IFACE_TYPE_AP; |
| 9393 | break; |
| 9394 | case WPA_IF_P2P_GO: |
| 9395 | iface_type = QCA_IFACE_TYPE_P2P_GO; |
| 9396 | break; |
| 9397 | case WPA_IF_P2P_CLIENT: |
| 9398 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; |
| 9399 | break; |
| 9400 | case WPA_IF_IBSS: |
| 9401 | iface_type = QCA_IFACE_TYPE_IBSS; |
| 9402 | break; |
| 9403 | case WPA_IF_TDLS: |
| 9404 | iface_type = QCA_IFACE_TYPE_TDLS; |
| 9405 | break; |
| 9406 | default: |
| 9407 | return -1; |
| 9408 | } |
| 9409 | |
| 9410 | param.num = *num; |
| 9411 | param.freq_list = freq_list; |
| 9412 | |
| 9413 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9414 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || |
| 9415 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9416 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9417 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || |
| 9418 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9419 | nla_put_u32(msg, |
| 9420 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, |
| 9421 | iface_type)) { |
| 9422 | wpa_printf(MSG_ERROR, |
| 9423 | "%s: err in adding vendor_cmd and vendor_data", |
| 9424 | __func__); |
| 9425 | nlmsg_free(msg); |
| 9426 | return -1; |
| 9427 | } |
| 9428 | nla_nest_end(msg, params); |
| 9429 | |
| 9430 | os_memset(freq_list, 0, *num * sizeof(freq_list[0])); |
| 9431 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m); |
| 9432 | if (ret) { |
| 9433 | wpa_printf(MSG_ERROR, |
| 9434 | "%s: err in send_and_recv_msgs", __func__); |
| 9435 | return ret; |
| 9436 | } |
| 9437 | |
| 9438 | *num = param.num; |
| 9439 | |
| 9440 | for (i = 0; i < *num; i++) { |
| 9441 | wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d", |
| 9442 | i, freq_list[i]); |
| 9443 | } |
| 9444 | |
| 9445 | return 0; |
| 9446 | } |
| 9447 | |
| 9448 | |
| 9449 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
| 9450 | { |
| 9451 | struct i802_bss *bss = priv; |
| 9452 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9453 | struct nl_msg *msg; |
| 9454 | int ret; |
| 9455 | struct nlattr *params; |
| 9456 | |
| 9457 | if (!drv->set_prob_oper_freq) |
| 9458 | return -1; |
| 9459 | |
| 9460 | wpa_printf(MSG_DEBUG, |
| 9461 | "nl80211: Set P2P probable operating freq %u for ifindex %d", |
| 9462 | freq, bss->ifindex); |
| 9463 | |
| 9464 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9465 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9466 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9467 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || |
| 9468 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9469 | nla_put_u32(msg, |
| 9470 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, |
| 9471 | QCA_IFACE_TYPE_P2P_CLIENT) || |
| 9472 | nla_put_u32(msg, |
| 9473 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, |
| 9474 | freq)) { |
| 9475 | wpa_printf(MSG_ERROR, |
| 9476 | "%s: err in adding vendor_cmd and vendor_data", |
| 9477 | __func__); |
| 9478 | nlmsg_free(msg); |
| 9479 | return -1; |
| 9480 | } |
| 9481 | nla_nest_end(msg, params); |
| 9482 | |
| 9483 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9484 | msg = NULL; |
| 9485 | if (ret) { |
| 9486 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", |
| 9487 | __func__); |
| 9488 | return ret; |
| 9489 | } |
| 9490 | nlmsg_free(msg); |
| 9491 | return 0; |
| 9492 | } |
| 9493 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 9494 | |
| 9495 | static int nl80211_p2p_lo_start(void *priv, unsigned int freq, |
| 9496 | unsigned int period, unsigned int interval, |
| 9497 | unsigned int count, const u8 *device_types, |
| 9498 | size_t dev_types_len, |
| 9499 | const u8 *ies, size_t ies_len) |
| 9500 | { |
| 9501 | struct i802_bss *bss = priv; |
| 9502 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9503 | struct nl_msg *msg; |
| 9504 | struct nlattr *container; |
| 9505 | int ret; |
| 9506 | |
| 9507 | wpa_printf(MSG_DEBUG, |
| 9508 | "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u", |
| 9509 | freq, period, interval, count); |
| 9510 | |
| 9511 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 9512 | return -1; |
| 9513 | |
| 9514 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9515 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9516 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9517 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START)) |
| 9518 | goto fail; |
| 9519 | |
| 9520 | container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 9521 | if (!container) |
| 9522 | goto fail; |
| 9523 | |
| 9524 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL, |
| 9525 | freq) || |
| 9526 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD, |
| 9527 | period) || |
| 9528 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL, |
| 9529 | interval) || |
| 9530 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT, |
| 9531 | count) || |
| 9532 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES, |
| 9533 | dev_types_len, device_types) || |
| 9534 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE, |
| 9535 | ies_len, ies)) |
| 9536 | goto fail; |
| 9537 | |
| 9538 | nla_nest_end(msg, container); |
| 9539 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9540 | msg = NULL; |
| 9541 | if (ret) { |
| 9542 | wpa_printf(MSG_DEBUG, |
| 9543 | "nl80211: Failed to send P2P Listen offload vendor command"); |
| 9544 | goto fail; |
| 9545 | } |
| 9546 | |
| 9547 | return 0; |
| 9548 | |
| 9549 | fail: |
| 9550 | nlmsg_free(msg); |
| 9551 | return -1; |
| 9552 | } |
| 9553 | |
| 9554 | |
| 9555 | static int nl80211_p2p_lo_stop(void *priv) |
| 9556 | { |
| 9557 | struct i802_bss *bss = priv; |
| 9558 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9559 | struct nl_msg *msg; |
| 9560 | |
| 9561 | wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload"); |
| 9562 | |
| 9563 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 9564 | return -1; |
| 9565 | |
| 9566 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9567 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9568 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9569 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) { |
| 9570 | nlmsg_free(msg); |
| 9571 | return -1; |
| 9572 | } |
| 9573 | |
| 9574 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9575 | } |
| 9576 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 9577 | |
| 9578 | static int nl80211_set_tdls_mode(void *priv, int tdls_external_control) |
| 9579 | { |
| 9580 | struct i802_bss *bss = priv; |
| 9581 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9582 | struct nl_msg *msg; |
| 9583 | struct nlattr *params; |
| 9584 | int ret; |
| 9585 | u32 tdls_mode; |
| 9586 | |
| 9587 | wpa_printf(MSG_DEBUG, |
| 9588 | "nl80211: Set TDKS mode: tdls_external_control=%d", |
| 9589 | tdls_external_control); |
| 9590 | |
| 9591 | if (tdls_external_control == 1) |
| 9592 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT | |
| 9593 | QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL; |
| 9594 | else |
| 9595 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT; |
| 9596 | |
| 9597 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9598 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9599 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9600 | QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS)) |
| 9601 | goto fail; |
| 9602 | |
| 9603 | params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 9604 | if (!params) |
| 9605 | goto fail; |
| 9606 | |
| 9607 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE, |
| 9608 | tdls_mode)) |
| 9609 | goto fail; |
| 9610 | |
| 9611 | nla_nest_end(msg, params); |
| 9612 | |
| 9613 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9614 | msg = NULL; |
| 9615 | if (ret) { |
| 9616 | wpa_printf(MSG_ERROR, |
| 9617 | "nl80211: Set TDLS mode failed: ret=%d (%s)", |
| 9618 | ret, strerror(-ret)); |
| 9619 | goto fail; |
| 9620 | } |
| 9621 | return 0; |
| 9622 | fail: |
| 9623 | nlmsg_free(msg); |
| 9624 | return -1; |
| 9625 | } |
| 9626 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9627 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 9628 | |
| 9629 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9630 | static int nl80211_write_to_file(const char *name, unsigned int val) |
| 9631 | { |
| 9632 | int fd, len; |
| 9633 | char tmp[128]; |
| 9634 | |
| 9635 | fd = open(name, O_RDWR); |
| 9636 | if (fd < 0) { |
| 9637 | wpa_printf(MSG_ERROR, "nl80211: Failed to open %s: %s", |
| 9638 | name, strerror(errno)); |
| 9639 | return fd; |
| 9640 | } |
| 9641 | |
| 9642 | len = os_snprintf(tmp, sizeof(tmp), "%u\n", val); |
| 9643 | len = write(fd, tmp, len); |
| 9644 | if (len < 0) |
| 9645 | wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s", |
| 9646 | name, strerror(errno)); |
| 9647 | close(fd); |
| 9648 | |
| 9649 | return 0; |
| 9650 | } |
| 9651 | |
| 9652 | |
| 9653 | static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags) |
| 9654 | { |
| 9655 | struct i802_bss *bss = priv; |
| 9656 | char path[128]; |
| 9657 | int ret; |
| 9658 | |
| 9659 | wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x", |
| 9660 | filter_flags); |
| 9661 | |
| 9662 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 9663 | ret = os_snprintf(path, sizeof(path), |
| 9664 | "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast", |
| 9665 | bss->ifname); |
| 9666 | if (os_snprintf_error(sizeof(path), ret)) |
| 9667 | return -1; |
| 9668 | |
| 9669 | ret = nl80211_write_to_file(path, |
| 9670 | !!(filter_flags & |
| 9671 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 9672 | if (ret) { |
| 9673 | wpa_printf(MSG_ERROR, |
| 9674 | "nl80211: Failed to set IPv4 unicast in multicast filter"); |
| 9675 | return ret; |
| 9676 | } |
| 9677 | |
| 9678 | os_snprintf(path, sizeof(path), |
| 9679 | "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast", |
| 9680 | bss->ifname); |
| 9681 | ret = nl80211_write_to_file(path, |
| 9682 | !!(filter_flags & |
| 9683 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 9684 | |
| 9685 | if (ret) { |
| 9686 | wpa_printf(MSG_ERROR, |
| 9687 | "nl80211: Failed to set IPv6 unicast in multicast filter"); |
| 9688 | return ret; |
| 9689 | } |
| 9690 | |
| 9691 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 9692 | os_snprintf(path, sizeof(path), |
| 9693 | "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp", |
| 9694 | bss->ifname); |
| 9695 | ret = nl80211_write_to_file(path, |
| 9696 | !!(filter_flags & |
| 9697 | WPA_DATA_FRAME_FILTER_FLAG_ARP)); |
| 9698 | if (ret) { |
| 9699 | wpa_printf(MSG_ERROR, |
| 9700 | "nl80211: Failed set gratuitous ARP filter"); |
| 9701 | return ret; |
| 9702 | } |
| 9703 | |
| 9704 | /* Configure filtering of IPv6 NA frames */ |
| 9705 | os_snprintf(path, sizeof(path), |
| 9706 | "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na", |
| 9707 | bss->ifname); |
| 9708 | ret = nl80211_write_to_file(path, |
| 9709 | !!(filter_flags & |
| 9710 | WPA_DATA_FRAME_FILTER_FLAG_NA)); |
| 9711 | if (ret) { |
| 9712 | wpa_printf(MSG_ERROR, |
| 9713 | "nl80211: Failed to set unsolicited NA filter"); |
| 9714 | return ret; |
| 9715 | } |
| 9716 | |
| 9717 | return 0; |
| 9718 | } |
| 9719 | |
| 9720 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 9721 | static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type, |
| 9722 | const u8 **ext_capa, const u8 **ext_capa_mask, |
| 9723 | unsigned int *ext_capa_len) |
| 9724 | { |
| 9725 | struct i802_bss *bss = priv; |
| 9726 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9727 | enum nl80211_iftype nlmode; |
| 9728 | unsigned int i; |
| 9729 | |
| 9730 | if (!ext_capa || !ext_capa_mask || !ext_capa_len) |
| 9731 | return -1; |
| 9732 | |
| 9733 | nlmode = wpa_driver_nl80211_if_type(type); |
| 9734 | |
| 9735 | /* By default, use the per-radio values */ |
| 9736 | *ext_capa = drv->extended_capa; |
| 9737 | *ext_capa_mask = drv->extended_capa_mask; |
| 9738 | *ext_capa_len = drv->extended_capa_len; |
| 9739 | |
| 9740 | /* Replace the default value if a per-interface type value exists */ |
| 9741 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 9742 | if (nlmode == drv->iface_ext_capa[i].iftype) { |
| 9743 | *ext_capa = drv->iface_ext_capa[i].ext_capa; |
| 9744 | *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask; |
| 9745 | *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len; |
| 9746 | break; |
| 9747 | } |
| 9748 | } |
| 9749 | |
| 9750 | return 0; |
| 9751 | } |
| 9752 | |
| 9753 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9754 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 9755 | .name = "nl80211", |
| 9756 | .desc = "Linux nl80211/cfg80211", |
| 9757 | .get_bssid = wpa_driver_nl80211_get_bssid, |
| 9758 | .get_ssid = wpa_driver_nl80211_get_ssid, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9759 | .set_key = driver_nl80211_set_key, |
| 9760 | .scan2 = driver_nl80211_scan2, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9761 | .sched_scan = wpa_driver_nl80211_sched_scan, |
| 9762 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9763 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9764 | .abort_scan = wpa_driver_nl80211_abort_scan, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9765 | .deauthenticate = driver_nl80211_deauthenticate, |
| 9766 | .authenticate = driver_nl80211_authenticate, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9767 | .associate = wpa_driver_nl80211_associate, |
| 9768 | .global_init = nl80211_global_init, |
| 9769 | .global_deinit = nl80211_global_deinit, |
| 9770 | .init2 = wpa_driver_nl80211_init, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9771 | .deinit = driver_nl80211_deinit, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9772 | .get_capa = wpa_driver_nl80211_get_capa, |
| 9773 | .set_operstate = wpa_driver_nl80211_set_operstate, |
| 9774 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
| 9775 | .set_country = wpa_driver_nl80211_set_country, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9776 | .get_country = wpa_driver_nl80211_get_country, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9777 | .set_ap = wpa_driver_nl80211_set_ap, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 9778 | .set_acl = wpa_driver_nl80211_set_acl, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9779 | .if_add = wpa_driver_nl80211_if_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9780 | .if_remove = driver_nl80211_if_remove, |
| 9781 | .send_mlme = driver_nl80211_send_mlme, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9782 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9783 | .sta_add = wpa_driver_nl80211_sta_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9784 | .sta_remove = driver_nl80211_sta_remove, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9785 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
| 9786 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9787 | .hapd_init = i802_init, |
| 9788 | .hapd_deinit = i802_deinit, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9789 | .set_wds_sta = i802_set_wds_sta, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9790 | .get_seqnum = i802_get_seqnum, |
| 9791 | .flush = i802_flush, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9792 | .get_inact_sec = i802_get_inact_sec, |
| 9793 | .sta_clear_stats = i802_sta_clear_stats, |
| 9794 | .set_rts = i802_set_rts, |
| 9795 | .set_frag = i802_set_frag, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9796 | .set_tx_queue_params = i802_set_tx_queue_params, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9797 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9798 | .sta_deauth = i802_sta_deauth, |
| 9799 | .sta_disassoc = i802_sta_disassoc, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9800 | .read_sta_data = driver_nl80211_read_sta_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9801 | .set_freq = i802_set_freq, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9802 | .send_action = driver_nl80211_send_action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9803 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
| 9804 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
| 9805 | .cancel_remain_on_channel = |
| 9806 | wpa_driver_nl80211_cancel_remain_on_channel, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9807 | .probe_req_report = driver_nl80211_probe_req_report, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9808 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9809 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9810 | .resume = wpa_driver_nl80211_resume, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9811 | .signal_monitor = nl80211_signal_monitor, |
| 9812 | .signal_poll = nl80211_signal_poll, |
| 9813 | .send_frame = nl80211_send_frame, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9814 | .set_param = nl80211_set_param, |
| 9815 | .get_radio_name = nl80211_get_radio_name, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9816 | .add_pmkid = nl80211_add_pmkid, |
| 9817 | .remove_pmkid = nl80211_remove_pmkid, |
| 9818 | .flush_pmkid = nl80211_flush_pmkid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9819 | .set_rekey_info = nl80211_set_rekey_info, |
| 9820 | .poll_client = nl80211_poll_client, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9821 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9822 | .start_dfs_cac = nl80211_start_radar_detection, |
| 9823 | .stop_ap = wpa_driver_nl80211_stop_ap, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9824 | #ifdef CONFIG_TDLS |
| 9825 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, |
| 9826 | .tdls_oper = nl80211_tdls_oper, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9827 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
| 9828 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9829 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 9830 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9831 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9832 | .get_survey = wpa_driver_nl80211_get_survey, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9833 | .status = wpa_driver_nl80211_status, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9834 | .switch_channel = nl80211_switch_channel, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9835 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 9836 | .set_noa = wpa_driver_set_p2p_noa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9837 | .get_noa = wpa_driver_get_p2p_noa, |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 9838 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 9839 | #endif /* ANDROID_P2P */ |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 9840 | #ifdef ANDROID |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 9841 | #ifndef ANDROID_LIB_STUB |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 9842 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 9843 | #endif /* !ANDROID_LIB_STUB */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 9844 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9845 | .vendor_cmd = nl80211_vendor_cmd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9846 | .set_qos_map = nl80211_set_qos_map, |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9847 | .set_wowlan = nl80211_set_wowlan, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9848 | .set_mac_addr = nl80211_set_mac_addr, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9849 | #ifdef CONFIG_MESH |
| 9850 | .init_mesh = wpa_driver_nl80211_init_mesh, |
| 9851 | .join_mesh = wpa_driver_nl80211_join_mesh, |
| 9852 | .leave_mesh = wpa_driver_nl80211_leave_mesh, |
| 9853 | #endif /* CONFIG_MESH */ |
| 9854 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
| 9855 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, |
| 9856 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
| 9857 | .br_set_net_param = wpa_driver_br_set_net_param, |
| 9858 | .add_tx_ts = nl80211_add_ts, |
| 9859 | .del_tx_ts = nl80211_del_ts, |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 9860 | .get_ifindex = nl80211_get_ifindex, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9861 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 9862 | .roaming = nl80211_roaming, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9863 | .do_acs = wpa_driver_do_acs, |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 9864 | .set_band = nl80211_set_band, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9865 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
| 9866 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 9867 | .p2p_lo_start = nl80211_p2p_lo_start, |
| 9868 | .p2p_lo_stop = nl80211_p2p_lo_stop, |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 9869 | .set_default_scan_ies = nl80211_set_default_scan_ies, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame] | 9870 | .set_tdls_mode = nl80211_set_tdls_mode, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9871 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9872 | .configure_data_frame_filters = nl80211_configure_data_frame_filters, |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 9873 | .get_ext_capab = nl80211_get_ext_capab, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9874 | }; |