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 | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 207 | |
| 208 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 209 | /* Converts nl80211_chan_width to a common format */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 210 | enum chan_width convert2width(int width) |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 211 | { |
| 212 | switch (width) { |
| 213 | case NL80211_CHAN_WIDTH_20_NOHT: |
| 214 | return CHAN_WIDTH_20_NOHT; |
| 215 | case NL80211_CHAN_WIDTH_20: |
| 216 | return CHAN_WIDTH_20; |
| 217 | case NL80211_CHAN_WIDTH_40: |
| 218 | return CHAN_WIDTH_40; |
| 219 | case NL80211_CHAN_WIDTH_80: |
| 220 | return CHAN_WIDTH_80; |
| 221 | case NL80211_CHAN_WIDTH_80P80: |
| 222 | return CHAN_WIDTH_80P80; |
| 223 | case NL80211_CHAN_WIDTH_160: |
| 224 | return CHAN_WIDTH_160; |
| 225 | } |
| 226 | return CHAN_WIDTH_UNKNOWN; |
| 227 | } |
| 228 | |
| 229 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 230 | int is_ap_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 231 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 232 | return nlmode == NL80211_IFTYPE_AP || |
| 233 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 237 | int is_sta_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 238 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 239 | return nlmode == NL80211_IFTYPE_STATION || |
| 240 | nlmode == NL80211_IFTYPE_P2P_CLIENT; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 244 | static int is_p2p_net_interface(enum nl80211_iftype nlmode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 245 | { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 246 | return nlmode == NL80211_IFTYPE_P2P_CLIENT || |
| 247 | nlmode == NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 248 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 249 | |
| 250 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 251 | struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv, |
| 252 | int ifindex) |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 253 | { |
| 254 | struct i802_bss *bss; |
| 255 | |
| 256 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 257 | if (bss->ifindex == ifindex) |
| 258 | return bss; |
| 259 | } |
| 260 | |
| 261 | return NULL; |
| 262 | } |
| 263 | |
| 264 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 265 | static int is_mesh_interface(enum nl80211_iftype nlmode) |
| 266 | { |
| 267 | return nlmode == NL80211_IFTYPE_MESH_POINT; |
| 268 | } |
| 269 | |
| 270 | |
| 271 | void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 272 | { |
| 273 | if (drv->associated) |
| 274 | os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN); |
| 275 | drv->associated = 0; |
| 276 | os_memset(drv->bssid, 0, ETH_ALEN); |
| 277 | } |
| 278 | |
| 279 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 280 | /* nl80211 code */ |
| 281 | static int ack_handler(struct nl_msg *msg, void *arg) |
| 282 | { |
| 283 | int *err = arg; |
| 284 | *err = 0; |
| 285 | return NL_STOP; |
| 286 | } |
| 287 | |
| 288 | static int finish_handler(struct nl_msg *msg, void *arg) |
| 289 | { |
| 290 | int *ret = arg; |
| 291 | *ret = 0; |
| 292 | return NL_SKIP; |
| 293 | } |
| 294 | |
| 295 | static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err, |
| 296 | void *arg) |
| 297 | { |
| 298 | int *ret = arg; |
| 299 | *ret = err->error; |
| 300 | return NL_SKIP; |
| 301 | } |
| 302 | |
| 303 | |
| 304 | static int no_seq_check(struct nl_msg *msg, void *arg) |
| 305 | { |
| 306 | return NL_OK; |
| 307 | } |
| 308 | |
| 309 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 310 | static void nl80211_nlmsg_clear(struct nl_msg *msg) |
| 311 | { |
| 312 | /* |
| 313 | * Clear nlmsg data, e.g., to make sure key material is not left in |
| 314 | * heap memory for unnecessarily long time. |
| 315 | */ |
| 316 | if (msg) { |
| 317 | struct nlmsghdr *hdr = nlmsg_hdr(msg); |
| 318 | void *data = nlmsg_data(hdr); |
| 319 | /* |
| 320 | * This would use nlmsg_datalen() or the older nlmsg_len() if |
| 321 | * only libnl were to maintain a stable API.. Neither will work |
| 322 | * with all released versions, so just calculate the length |
| 323 | * here. |
| 324 | */ |
| 325 | int len = hdr->nlmsg_len - NLMSG_HDRLEN; |
| 326 | |
| 327 | os_memset(data, 0, len); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 332 | static int send_and_recv(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 333 | struct nl_handle *nl_handle, struct nl_msg *msg, |
| 334 | int (*valid_handler)(struct nl_msg *, void *), |
| 335 | void *valid_data) |
| 336 | { |
| 337 | struct nl_cb *cb; |
| 338 | int err = -ENOMEM; |
| 339 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 340 | if (!msg) |
| 341 | return -ENOMEM; |
| 342 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 343 | cb = nl_cb_clone(global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 344 | if (!cb) |
| 345 | goto out; |
| 346 | |
| 347 | err = nl_send_auto_complete(nl_handle, msg); |
| 348 | if (err < 0) |
| 349 | goto out; |
| 350 | |
| 351 | err = 1; |
| 352 | |
| 353 | nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err); |
| 354 | nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err); |
| 355 | nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err); |
| 356 | |
| 357 | if (valid_handler) |
| 358 | nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 359 | valid_handler, valid_data); |
| 360 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 361 | while (err > 0) { |
| 362 | int res = nl_recvmsgs(nl_handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 363 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 364 | wpa_printf(MSG_INFO, |
| 365 | "nl80211: %s->nl_recvmsgs failed: %d", |
| 366 | __func__, res); |
| 367 | } |
| 368 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 369 | out: |
| 370 | nl_cb_put(cb); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 371 | if (!valid_handler && valid_data == (void *) -1) |
| 372 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 373 | nlmsg_free(msg); |
| 374 | return err; |
| 375 | } |
| 376 | |
| 377 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 378 | int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv, |
| 379 | struct nl_msg *msg, |
| 380 | int (*valid_handler)(struct nl_msg *, void *), |
| 381 | void *valid_data) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 382 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 383 | return send_and_recv(drv->global, drv->global->nl, msg, |
| 384 | valid_handler, valid_data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | |
| 388 | struct family_data { |
| 389 | const char *group; |
| 390 | int id; |
| 391 | }; |
| 392 | |
| 393 | |
| 394 | static int family_handler(struct nl_msg *msg, void *arg) |
| 395 | { |
| 396 | struct family_data *res = arg; |
| 397 | struct nlattr *tb[CTRL_ATTR_MAX + 1]; |
| 398 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 399 | struct nlattr *mcgrp; |
| 400 | int i; |
| 401 | |
| 402 | nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 403 | genlmsg_attrlen(gnlh, 0), NULL); |
| 404 | if (!tb[CTRL_ATTR_MCAST_GROUPS]) |
| 405 | return NL_SKIP; |
| 406 | |
| 407 | nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) { |
| 408 | struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1]; |
| 409 | nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp), |
| 410 | nla_len(mcgrp), NULL); |
| 411 | if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] || |
| 412 | !tb2[CTRL_ATTR_MCAST_GRP_ID] || |
| 413 | os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]), |
| 414 | res->group, |
| 415 | nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0) |
| 416 | continue; |
| 417 | res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]); |
| 418 | break; |
| 419 | }; |
| 420 | |
| 421 | return NL_SKIP; |
| 422 | } |
| 423 | |
| 424 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 425 | static int nl_get_multicast_id(struct nl80211_global *global, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 426 | const char *family, const char *group) |
| 427 | { |
| 428 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 429 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 430 | struct family_data res = { group, -ENOENT }; |
| 431 | |
| 432 | msg = nlmsg_alloc(); |
| 433 | if (!msg) |
| 434 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 435 | if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"), |
| 436 | 0, 0, CTRL_CMD_GETFAMILY, 0) || |
| 437 | nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) { |
| 438 | nlmsg_free(msg); |
| 439 | return -1; |
| 440 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 441 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 442 | ret = send_and_recv(global, global->nl, msg, family_handler, &res); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 443 | if (ret == 0) |
| 444 | ret = res.id; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 445 | return ret; |
| 446 | } |
| 447 | |
| 448 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 449 | void * nl80211_cmd(struct wpa_driver_nl80211_data *drv, |
| 450 | struct nl_msg *msg, int flags, uint8_t cmd) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 451 | { |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 452 | if (TEST_FAIL()) |
| 453 | return NULL; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 454 | return genlmsg_put(msg, 0, 0, drv->global->nl80211_id, |
| 455 | 0, flags, cmd, 0); |
| 456 | } |
| 457 | |
| 458 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 459 | static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss) |
| 460 | { |
| 461 | if (bss->wdev_id_set) |
| 462 | return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id); |
| 463 | return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex); |
| 464 | } |
| 465 | |
| 466 | |
| 467 | struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 468 | { |
| 469 | struct nl_msg *msg; |
| 470 | |
| 471 | msg = nlmsg_alloc(); |
| 472 | if (!msg) |
| 473 | return NULL; |
| 474 | |
| 475 | if (!nl80211_cmd(bss->drv, msg, flags, cmd) || |
| 476 | nl80211_set_iface_id(msg, bss) < 0) { |
| 477 | nlmsg_free(msg); |
| 478 | return NULL; |
| 479 | } |
| 480 | |
| 481 | return msg; |
| 482 | } |
| 483 | |
| 484 | |
| 485 | static struct nl_msg * |
| 486 | nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex, |
| 487 | int flags, uint8_t cmd) |
| 488 | { |
| 489 | struct nl_msg *msg; |
| 490 | |
| 491 | msg = nlmsg_alloc(); |
| 492 | if (!msg) |
| 493 | return NULL; |
| 494 | |
| 495 | if (!nl80211_cmd(drv, msg, flags, cmd) || |
| 496 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) { |
| 497 | nlmsg_free(msg); |
| 498 | return NULL; |
| 499 | } |
| 500 | |
| 501 | return msg; |
| 502 | } |
| 503 | |
| 504 | |
| 505 | struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags, |
| 506 | uint8_t cmd) |
| 507 | { |
| 508 | return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd); |
| 509 | } |
| 510 | |
| 511 | |
| 512 | struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd) |
| 513 | { |
| 514 | return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd); |
| 515 | } |
| 516 | |
| 517 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 518 | struct wiphy_idx_data { |
| 519 | int wiphy_idx; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 520 | enum nl80211_iftype nlmode; |
| 521 | u8 *macaddr; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 522 | }; |
| 523 | |
| 524 | |
| 525 | static int netdev_info_handler(struct nl_msg *msg, void *arg) |
| 526 | { |
| 527 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 528 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 529 | struct wiphy_idx_data *info = arg; |
| 530 | |
| 531 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 532 | genlmsg_attrlen(gnlh, 0), NULL); |
| 533 | |
| 534 | if (tb[NL80211_ATTR_WIPHY]) |
| 535 | info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]); |
| 536 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 537 | if (tb[NL80211_ATTR_IFTYPE]) |
| 538 | info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]); |
| 539 | |
| 540 | if (tb[NL80211_ATTR_MAC] && info->macaddr) |
| 541 | os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 542 | ETH_ALEN); |
| 543 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 544 | return NL_SKIP; |
| 545 | } |
| 546 | |
| 547 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 548 | int nl80211_get_wiphy_index(struct i802_bss *bss) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 549 | { |
| 550 | struct nl_msg *msg; |
| 551 | struct wiphy_idx_data data = { |
| 552 | .wiphy_idx = -1, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 553 | .macaddr = NULL, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 554 | }; |
| 555 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 556 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 557 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 558 | |
| 559 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) |
| 560 | return data.wiphy_idx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 561 | return -1; |
| 562 | } |
| 563 | |
| 564 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 565 | static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss) |
| 566 | { |
| 567 | struct nl_msg *msg; |
| 568 | struct wiphy_idx_data data = { |
| 569 | .nlmode = NL80211_IFTYPE_UNSPECIFIED, |
| 570 | .macaddr = NULL, |
| 571 | }; |
| 572 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 573 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 574 | return NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 575 | |
| 576 | if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0) |
| 577 | return data.nlmode; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 578 | return NL80211_IFTYPE_UNSPECIFIED; |
| 579 | } |
| 580 | |
| 581 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 582 | static int nl80211_get_macaddr(struct i802_bss *bss) |
| 583 | { |
| 584 | struct nl_msg *msg; |
| 585 | struct wiphy_idx_data data = { |
| 586 | .macaddr = bss->addr, |
| 587 | }; |
| 588 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 589 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE))) |
| 590 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 591 | |
| 592 | return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 593 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 594 | |
| 595 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 596 | static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv, |
| 597 | struct nl80211_wiphy_data *w) |
| 598 | { |
| 599 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 600 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 601 | |
| 602 | msg = nlmsg_alloc(); |
| 603 | if (!msg) |
| 604 | return -1; |
| 605 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 606 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) || |
| 607 | nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) { |
| 608 | nlmsg_free(msg); |
| 609 | return -1; |
| 610 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 611 | |
| 612 | ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 613 | if (ret) { |
| 614 | wpa_printf(MSG_DEBUG, "nl80211: Register beacons command " |
| 615 | "failed: ret=%d (%s)", |
| 616 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 617 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 618 | return ret; |
| 619 | } |
| 620 | |
| 621 | |
| 622 | static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle) |
| 623 | { |
| 624 | struct nl80211_wiphy_data *w = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 625 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 626 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 627 | wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 628 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 629 | res = nl_recvmsgs(handle, w->nl_cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 630 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 631 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 632 | __func__, res); |
| 633 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 634 | } |
| 635 | |
| 636 | |
| 637 | static int process_beacon_event(struct nl_msg *msg, void *arg) |
| 638 | { |
| 639 | struct nl80211_wiphy_data *w = arg; |
| 640 | struct wpa_driver_nl80211_data *drv; |
| 641 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 642 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 643 | union wpa_event_data event; |
| 644 | |
| 645 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 646 | genlmsg_attrlen(gnlh, 0), NULL); |
| 647 | |
| 648 | if (gnlh->cmd != NL80211_CMD_FRAME) { |
| 649 | wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)", |
| 650 | gnlh->cmd); |
| 651 | return NL_SKIP; |
| 652 | } |
| 653 | |
| 654 | if (!tb[NL80211_ATTR_FRAME]) |
| 655 | return NL_SKIP; |
| 656 | |
| 657 | dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data, |
| 658 | wiphy_list) { |
| 659 | os_memset(&event, 0, sizeof(event)); |
| 660 | event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]); |
| 661 | event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]); |
| 662 | wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event); |
| 663 | } |
| 664 | |
| 665 | return NL_SKIP; |
| 666 | } |
| 667 | |
| 668 | |
| 669 | static struct nl80211_wiphy_data * |
| 670 | nl80211_get_wiphy_data_ap(struct i802_bss *bss) |
| 671 | { |
| 672 | static DEFINE_DL_LIST(nl80211_wiphys); |
| 673 | struct nl80211_wiphy_data *w; |
| 674 | int wiphy_idx, found = 0; |
| 675 | struct i802_bss *tmp_bss; |
| 676 | |
| 677 | if (bss->wiphy_data != NULL) |
| 678 | return bss->wiphy_data; |
| 679 | |
| 680 | wiphy_idx = nl80211_get_wiphy_index(bss); |
| 681 | |
| 682 | dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) { |
| 683 | if (w->wiphy_idx == wiphy_idx) |
| 684 | goto add; |
| 685 | } |
| 686 | |
| 687 | /* alloc new one */ |
| 688 | w = os_zalloc(sizeof(*w)); |
| 689 | if (w == NULL) |
| 690 | return NULL; |
| 691 | w->wiphy_idx = wiphy_idx; |
| 692 | dl_list_init(&w->bsss); |
| 693 | dl_list_init(&w->drvs); |
| 694 | |
| 695 | w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 696 | if (!w->nl_cb) { |
| 697 | os_free(w); |
| 698 | return NULL; |
| 699 | } |
| 700 | nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL); |
| 701 | nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, process_beacon_event, |
| 702 | w); |
| 703 | |
| 704 | w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb, |
| 705 | "wiphy beacons"); |
| 706 | if (w->nl_beacons == NULL) { |
| 707 | os_free(w); |
| 708 | return NULL; |
| 709 | } |
| 710 | |
| 711 | if (nl80211_register_beacons(bss->drv, w)) { |
| 712 | nl_destroy_handles(&w->nl_beacons); |
| 713 | os_free(w); |
| 714 | return NULL; |
| 715 | } |
| 716 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 717 | nl80211_register_eloop_read(&w->nl_beacons, nl80211_recv_beacons, w); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 718 | |
| 719 | dl_list_add(&nl80211_wiphys, &w->list); |
| 720 | |
| 721 | add: |
| 722 | /* drv entry for this bss already there? */ |
| 723 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 724 | if (tmp_bss->drv == bss->drv) { |
| 725 | found = 1; |
| 726 | break; |
| 727 | } |
| 728 | } |
| 729 | /* if not add it */ |
| 730 | if (!found) |
| 731 | dl_list_add(&w->drvs, &bss->drv->wiphy_list); |
| 732 | |
| 733 | dl_list_add(&w->bsss, &bss->wiphy_list); |
| 734 | bss->wiphy_data = w; |
| 735 | return w; |
| 736 | } |
| 737 | |
| 738 | |
| 739 | static void nl80211_put_wiphy_data_ap(struct i802_bss *bss) |
| 740 | { |
| 741 | struct nl80211_wiphy_data *w = bss->wiphy_data; |
| 742 | struct i802_bss *tmp_bss; |
| 743 | int found = 0; |
| 744 | |
| 745 | if (w == NULL) |
| 746 | return; |
| 747 | bss->wiphy_data = NULL; |
| 748 | dl_list_del(&bss->wiphy_list); |
| 749 | |
| 750 | /* still any for this drv present? */ |
| 751 | dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) { |
| 752 | if (tmp_bss->drv == bss->drv) { |
| 753 | found = 1; |
| 754 | break; |
| 755 | } |
| 756 | } |
| 757 | /* if not remove it */ |
| 758 | if (!found) |
| 759 | dl_list_del(&bss->drv->wiphy_list); |
| 760 | |
| 761 | if (!dl_list_empty(&w->bsss)) |
| 762 | return; |
| 763 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 764 | nl80211_destroy_eloop_handle(&w->nl_beacons); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 765 | |
| 766 | nl_cb_put(w->nl_cb); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 767 | dl_list_del(&w->list); |
| 768 | os_free(w); |
| 769 | } |
| 770 | |
| 771 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 772 | static unsigned int nl80211_get_ifindex(void *priv) |
| 773 | { |
| 774 | struct i802_bss *bss = priv; |
| 775 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 776 | |
| 777 | return drv->ifindex; |
| 778 | } |
| 779 | |
| 780 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 781 | static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid) |
| 782 | { |
| 783 | struct i802_bss *bss = priv; |
| 784 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 785 | if (!drv->associated) |
| 786 | return -1; |
| 787 | os_memcpy(bssid, drv->bssid, ETH_ALEN); |
| 788 | return 0; |
| 789 | } |
| 790 | |
| 791 | |
| 792 | static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid) |
| 793 | { |
| 794 | struct i802_bss *bss = priv; |
| 795 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 796 | if (!drv->associated) |
| 797 | return -1; |
| 798 | os_memcpy(ssid, drv->ssid, drv->ssid_len); |
| 799 | return drv->ssid_len; |
| 800 | } |
| 801 | |
| 802 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 803 | static void wpa_driver_nl80211_event_newlink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 804 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 805 | int ifindex, const char *ifname) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 806 | { |
| 807 | union wpa_event_data event; |
| 808 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 809 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 810 | if (if_nametoindex(drv->first_bss->ifname) == 0) { |
| 811 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK", |
| 812 | drv->first_bss->ifname); |
| 813 | return; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 814 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 815 | if (!drv->if_removed) |
| 816 | return; |
| 817 | wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event", |
| 818 | drv->first_bss->ifname); |
| 819 | drv->if_removed = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 820 | } |
| 821 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 822 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 823 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 824 | os_strlcpy(event.interface_status.ifname, ifname, |
| 825 | sizeof(event.interface_status.ifname)); |
| 826 | event.interface_status.ievent = EVENT_INTERFACE_ADDED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 827 | if (drv) |
| 828 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 829 | else |
| 830 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 831 | &event); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | |
| 835 | static void wpa_driver_nl80211_event_dellink( |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 836 | struct nl80211_global *global, struct wpa_driver_nl80211_data *drv, |
| 837 | int ifindex, const char *ifname) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 838 | { |
| 839 | union wpa_event_data event; |
| 840 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 841 | if (drv && os_strcmp(drv->first_bss->ifname, ifname) == 0) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 842 | if (drv->if_removed) { |
| 843 | wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s", |
| 844 | ifname); |
| 845 | return; |
| 846 | } |
| 847 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1", |
| 848 | ifname); |
| 849 | drv->if_removed = 1; |
| 850 | } else { |
| 851 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed", |
| 852 | ifname); |
| 853 | } |
| 854 | |
| 855 | os_memset(&event, 0, sizeof(event)); |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 856 | event.interface_status.ifindex = ifindex; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 857 | os_strlcpy(event.interface_status.ifname, ifname, |
| 858 | sizeof(event.interface_status.ifname)); |
| 859 | event.interface_status.ievent = EVENT_INTERFACE_REMOVED; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 860 | if (drv) |
| 861 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event); |
| 862 | else |
| 863 | wpa_supplicant_event_global(global->ctx, EVENT_INTERFACE_STATUS, |
| 864 | &event); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 865 | } |
| 866 | |
| 867 | |
| 868 | static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv, |
| 869 | u8 *buf, size_t len) |
| 870 | { |
| 871 | int attrlen, rta_len; |
| 872 | struct rtattr *attr; |
| 873 | |
| 874 | attrlen = len; |
| 875 | attr = (struct rtattr *) buf; |
| 876 | |
| 877 | rta_len = RTA_ALIGN(sizeof(struct rtattr)); |
| 878 | while (RTA_OK(attr, attrlen)) { |
| 879 | if (attr->rta_type == IFLA_IFNAME) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 880 | if (os_strcmp(((char *) attr) + rta_len, |
| 881 | drv->first_bss->ifname) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 882 | return 1; |
| 883 | else |
| 884 | break; |
| 885 | } |
| 886 | attr = RTA_NEXT(attr, attrlen); |
| 887 | } |
| 888 | |
| 889 | return 0; |
| 890 | } |
| 891 | |
| 892 | |
| 893 | static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv, |
| 894 | int ifindex, u8 *buf, size_t len) |
| 895 | { |
| 896 | if (drv->ifindex == ifindex) |
| 897 | return 1; |
| 898 | |
| 899 | if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 900 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 901 | wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed " |
| 902 | "interface"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 903 | wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 904 | return 1; |
| 905 | } |
| 906 | |
| 907 | return 0; |
| 908 | } |
| 909 | |
| 910 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 911 | static struct wpa_driver_nl80211_data * |
| 912 | nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len) |
| 913 | { |
| 914 | struct wpa_driver_nl80211_data *drv; |
| 915 | dl_list_for_each(drv, &global->interfaces, |
| 916 | struct wpa_driver_nl80211_data, list) { |
| 917 | if (wpa_driver_nl80211_own_ifindex(drv, idx, buf, len) || |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 918 | have_ifidx(drv, idx, IFIDX_ANY)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 919 | return drv; |
| 920 | } |
| 921 | return NULL; |
| 922 | } |
| 923 | |
| 924 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 925 | static void wpa_driver_nl80211_event_rtm_newlink(void *ctx, |
| 926 | struct ifinfomsg *ifi, |
| 927 | u8 *buf, size_t len) |
| 928 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 929 | struct nl80211_global *global = ctx; |
| 930 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 931 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 932 | struct rtattr *attr; |
| 933 | u32 brid = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 934 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 935 | char ifname[IFNAMSIZ + 1]; |
| 936 | char extra[100], *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 937 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 938 | extra[0] = '\0'; |
| 939 | pos = extra; |
| 940 | end = pos + sizeof(extra); |
| 941 | ifname[0] = '\0'; |
| 942 | |
| 943 | attrlen = len; |
| 944 | attr = (struct rtattr *) buf; |
| 945 | while (RTA_OK(attr, attrlen)) { |
| 946 | switch (attr->rta_type) { |
| 947 | case IFLA_IFNAME: |
| 948 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) |
| 949 | break; |
| 950 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 951 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 952 | break; |
| 953 | case IFLA_MASTER: |
| 954 | brid = nla_get_u32((struct nlattr *) attr); |
| 955 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 956 | break; |
| 957 | case IFLA_WIRELESS: |
| 958 | pos += os_snprintf(pos, end - pos, " wext"); |
| 959 | break; |
| 960 | case IFLA_OPERSTATE: |
| 961 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 962 | nla_get_u32((struct nlattr *) attr)); |
| 963 | break; |
| 964 | case IFLA_LINKMODE: |
| 965 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 966 | nla_get_u32((struct nlattr *) attr)); |
| 967 | break; |
| 968 | } |
| 969 | attr = RTA_NEXT(attr, attrlen); |
| 970 | } |
| 971 | extra[sizeof(extra) - 1] = '\0'; |
| 972 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 973 | wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 974 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 975 | ifi->ifi_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 976 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 977 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 978 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 979 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 980 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 981 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
| 982 | if (!drv) |
| 983 | goto event_newlink; |
| 984 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 985 | if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 986 | namebuf[0] = '\0'; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 987 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 988 | linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 989 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 990 | "event since interface %s is up", namebuf); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 991 | drv->ignore_if_down_event = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 992 | return; |
| 993 | } |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 994 | wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)", |
| 995 | namebuf, ifname); |
| 996 | if (os_strcmp(drv->first_bss->ifname, ifname) != 0) { |
| 997 | wpa_printf(MSG_DEBUG, |
| 998 | "nl80211: Not the main interface (%s) - do not indicate interface down", |
| 999 | drv->first_bss->ifname); |
| 1000 | } else if (drv->ignore_if_down_event) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1001 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down " |
| 1002 | "event generated by mode change"); |
| 1003 | drv->ignore_if_down_event = 0; |
| 1004 | } else { |
| 1005 | drv->if_disabled = 1; |
| 1006 | wpa_supplicant_event(drv->ctx, |
| 1007 | EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 1008 | |
| 1009 | /* |
| 1010 | * Try to get drv again, since it may be removed as |
| 1011 | * part of the EVENT_INTERFACE_DISABLED handling for |
| 1012 | * dynamic interfaces |
| 1013 | */ |
| 1014 | drv = nl80211_find_drv(global, ifi->ifi_index, |
| 1015 | buf, len); |
| 1016 | if (!drv) |
| 1017 | return; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1018 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1019 | } |
| 1020 | |
| 1021 | if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1022 | if (if_indextoname(ifi->ifi_index, namebuf) && |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1023 | linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1024 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1025 | "event since interface %s is down", |
| 1026 | namebuf); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1027 | } else if (if_nametoindex(drv->first_bss->ifname) == 0) { |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1028 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1029 | "event since interface %s does not exist", |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1030 | drv->first_bss->ifname); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1031 | } else if (drv->if_removed) { |
| 1032 | wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up " |
| 1033 | "event since interface %s is marked " |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1034 | "removed", drv->first_bss->ifname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1035 | } else { |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 1036 | struct i802_bss *bss; |
| 1037 | u8 addr[ETH_ALEN]; |
| 1038 | |
| 1039 | /* Re-read MAC address as it may have changed */ |
| 1040 | bss = get_bss_ifindex(drv, ifi->ifi_index); |
| 1041 | if (bss && |
| 1042 | linux_get_ifhwaddr(drv->global->ioctl_sock, |
| 1043 | bss->ifname, addr) < 0) { |
| 1044 | wpa_printf(MSG_DEBUG, |
| 1045 | "nl80211: %s: failed to re-read MAC address", |
| 1046 | bss->ifname); |
| 1047 | } else if (bss && |
| 1048 | os_memcmp(addr, bss->addr, ETH_ALEN) != 0) { |
| 1049 | wpa_printf(MSG_DEBUG, |
| 1050 | "nl80211: Own MAC address on ifindex %d (%s) changed from " |
| 1051 | MACSTR " to " MACSTR, |
| 1052 | ifi->ifi_index, bss->ifname, |
| 1053 | MAC2STR(bss->addr), |
| 1054 | MAC2STR(addr)); |
| 1055 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 1056 | } |
| 1057 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1058 | wpa_printf(MSG_DEBUG, "nl80211: Interface up"); |
| 1059 | drv->if_disabled = 0; |
| 1060 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, |
| 1061 | NULL); |
| 1062 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | /* |
| 1066 | * Some drivers send the association event before the operup event--in |
| 1067 | * this case, lifting operstate in wpa_driver_nl80211_set_operstate() |
| 1068 | * fails. This will hit us when wpa_supplicant does not need to do |
| 1069 | * IEEE 802.1X authentication |
| 1070 | */ |
| 1071 | if (drv->operstate == 1 && |
| 1072 | (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP && |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1073 | !(ifi->ifi_flags & IFF_RUNNING)) { |
| 1074 | 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] | 1075 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1076 | -1, IF_OPER_UP); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1079 | event_newlink: |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1080 | if (ifname[0]) |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1081 | wpa_driver_nl80211_event_newlink(global, drv, ifi->ifi_index, |
| 1082 | ifname); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1083 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1084 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1085 | struct i802_bss *bss; |
| 1086 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1087 | /* device has been added to bridge */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1088 | if (!if_indextoname(brid, namebuf)) { |
| 1089 | wpa_printf(MSG_DEBUG, |
| 1090 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1091 | brid); |
| 1092 | return; |
| 1093 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1094 | wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s", |
| 1095 | brid, namebuf); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1096 | add_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1097 | |
| 1098 | for (bss = drv->first_bss; bss; bss = bss->next) { |
| 1099 | if (os_strcmp(ifname, bss->ifname) == 0) { |
| 1100 | os_strlcpy(bss->brname, namebuf, IFNAMSIZ); |
| 1101 | break; |
| 1102 | } |
| 1103 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1104 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1105 | } |
| 1106 | |
| 1107 | |
| 1108 | static void wpa_driver_nl80211_event_rtm_dellink(void *ctx, |
| 1109 | struct ifinfomsg *ifi, |
| 1110 | u8 *buf, size_t len) |
| 1111 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1112 | struct nl80211_global *global = ctx; |
| 1113 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1114 | int attrlen; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1115 | struct rtattr *attr; |
| 1116 | u32 brid = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1117 | char ifname[IFNAMSIZ + 1]; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1118 | char extra[100], *pos, *end; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1119 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1120 | extra[0] = '\0'; |
| 1121 | pos = extra; |
| 1122 | end = pos + sizeof(extra); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1123 | ifname[0] = '\0'; |
| 1124 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1125 | attrlen = len; |
| 1126 | attr = (struct rtattr *) buf; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1127 | while (RTA_OK(attr, attrlen)) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1128 | switch (attr->rta_type) { |
| 1129 | case IFLA_IFNAME: |
| 1130 | if (RTA_PAYLOAD(attr) >= IFNAMSIZ) |
| 1131 | break; |
| 1132 | os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr)); |
| 1133 | ifname[RTA_PAYLOAD(attr)] = '\0'; |
| 1134 | break; |
| 1135 | case IFLA_MASTER: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1136 | brid = nla_get_u32((struct nlattr *) attr); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1137 | pos += os_snprintf(pos, end - pos, " master=%u", brid); |
| 1138 | break; |
| 1139 | case IFLA_OPERSTATE: |
| 1140 | pos += os_snprintf(pos, end - pos, " operstate=%u", |
| 1141 | nla_get_u32((struct nlattr *) attr)); |
| 1142 | break; |
| 1143 | case IFLA_LINKMODE: |
| 1144 | pos += os_snprintf(pos, end - pos, " linkmode=%u", |
| 1145 | nla_get_u32((struct nlattr *) attr)); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1146 | break; |
| 1147 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1148 | attr = RTA_NEXT(attr, attrlen); |
| 1149 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1150 | extra[sizeof(extra) - 1] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1151 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1152 | wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)", |
| 1153 | ifi->ifi_index, ifname, extra, ifi->ifi_family, |
| 1154 | ifi->ifi_flags, |
| 1155 | (ifi->ifi_flags & IFF_UP) ? "[UP]" : "", |
| 1156 | (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "", |
| 1157 | (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "", |
| 1158 | (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : ""); |
| 1159 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1160 | drv = nl80211_find_drv(global, ifi->ifi_index, buf, len); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1161 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1162 | if (ifi->ifi_family == AF_BRIDGE && brid && drv) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1163 | /* device has been removed from bridge */ |
| 1164 | char namebuf[IFNAMSIZ]; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1165 | |
| 1166 | if (!if_indextoname(brid, namebuf)) { |
| 1167 | wpa_printf(MSG_DEBUG, |
| 1168 | "nl80211: Could not find bridge ifname for ifindex %u", |
| 1169 | brid); |
| 1170 | } else { |
| 1171 | wpa_printf(MSG_DEBUG, |
| 1172 | "nl80211: Remove ifindex %u for bridge %s", |
| 1173 | brid, namebuf); |
| 1174 | } |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1175 | del_ifidx(drv, brid, ifi->ifi_index); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1176 | } |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 1177 | |
| 1178 | if (ifi->ifi_family != AF_BRIDGE || !brid) |
| 1179 | wpa_driver_nl80211_event_dellink(global, drv, ifi->ifi_index, |
| 1180 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1181 | } |
| 1182 | |
| 1183 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1184 | unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv) |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1185 | { |
| 1186 | struct nl_msg *msg; |
| 1187 | int ret; |
| 1188 | struct nl80211_bss_info_arg arg; |
| 1189 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1190 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1191 | os_memset(&arg, 0, sizeof(arg)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1192 | arg.drv = drv; |
| 1193 | ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1194 | if (ret == 0) { |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1195 | unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ? |
| 1196 | arg.ibss_freq : arg.assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1197 | wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the " |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 1198 | "associated BSS from scan results: %u MHz", freq); |
| 1199 | if (freq) |
| 1200 | drv->assoc_freq = freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 1201 | return drv->assoc_freq; |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1202 | } |
| 1203 | wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d " |
| 1204 | "(%s)", ret, strerror(-ret)); |
Jouni Malinen | 87fd279 | 2011-05-16 18:35:42 +0300 | [diff] [blame] | 1205 | return drv->assoc_freq; |
| 1206 | } |
| 1207 | |
| 1208 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1209 | static int get_link_signal(struct nl_msg *msg, void *arg) |
| 1210 | { |
| 1211 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1212 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1213 | struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1]; |
| 1214 | static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = { |
| 1215 | [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 }, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1216 | [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1217 | [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1218 | }; |
| 1219 | struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1]; |
| 1220 | static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = { |
| 1221 | [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 }, |
| 1222 | [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 }, |
| 1223 | [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG }, |
| 1224 | [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG }, |
| 1225 | }; |
| 1226 | struct wpa_signal_info *sig_change = arg; |
| 1227 | |
| 1228 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1229 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1230 | if (!tb[NL80211_ATTR_STA_INFO] || |
| 1231 | nla_parse_nested(sinfo, NL80211_STA_INFO_MAX, |
| 1232 | tb[NL80211_ATTR_STA_INFO], policy)) |
| 1233 | return NL_SKIP; |
| 1234 | if (!sinfo[NL80211_STA_INFO_SIGNAL]) |
| 1235 | return NL_SKIP; |
| 1236 | |
| 1237 | sig_change->current_signal = |
| 1238 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]); |
| 1239 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 1240 | if (sinfo[NL80211_STA_INFO_SIGNAL_AVG]) |
| 1241 | sig_change->avg_signal = |
| 1242 | (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]); |
| 1243 | else |
| 1244 | sig_change->avg_signal = 0; |
| 1245 | |
Dmitry Shmidt | f73259c | 2015-03-17 11:00:54 -0700 | [diff] [blame] | 1246 | if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]) |
| 1247 | sig_change->avg_beacon_signal = |
| 1248 | (s8) |
| 1249 | nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]); |
| 1250 | else |
| 1251 | sig_change->avg_beacon_signal = 0; |
| 1252 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1253 | if (sinfo[NL80211_STA_INFO_TX_BITRATE]) { |
| 1254 | if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX, |
| 1255 | sinfo[NL80211_STA_INFO_TX_BITRATE], |
| 1256 | rate_policy)) { |
| 1257 | sig_change->current_txrate = 0; |
| 1258 | } else { |
| 1259 | if (rinfo[NL80211_RATE_INFO_BITRATE]) { |
| 1260 | sig_change->current_txrate = |
| 1261 | nla_get_u16(rinfo[ |
| 1262 | NL80211_RATE_INFO_BITRATE]) * 100; |
| 1263 | } |
| 1264 | } |
| 1265 | } |
| 1266 | |
| 1267 | return NL_SKIP; |
| 1268 | } |
| 1269 | |
| 1270 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1271 | int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv, |
| 1272 | struct wpa_signal_info *sig) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1273 | { |
| 1274 | struct nl_msg *msg; |
| 1275 | |
| 1276 | sig->current_signal = -9999; |
| 1277 | sig->current_txrate = 0; |
| 1278 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1279 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) || |
| 1280 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) { |
| 1281 | nlmsg_free(msg); |
| 1282 | return -ENOBUFS; |
| 1283 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1284 | |
| 1285 | return send_and_recv_msgs(drv, msg, get_link_signal, sig); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | |
| 1289 | static int get_link_noise(struct nl_msg *msg, void *arg) |
| 1290 | { |
| 1291 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 1292 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1293 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 1294 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 1295 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 1296 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 1297 | }; |
| 1298 | struct wpa_signal_info *sig_change = arg; |
| 1299 | |
| 1300 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1301 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1302 | |
| 1303 | if (!tb[NL80211_ATTR_SURVEY_INFO]) { |
| 1304 | wpa_printf(MSG_DEBUG, "nl80211: survey data missing!"); |
| 1305 | return NL_SKIP; |
| 1306 | } |
| 1307 | |
| 1308 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 1309 | tb[NL80211_ATTR_SURVEY_INFO], |
| 1310 | survey_policy)) { |
| 1311 | wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested " |
| 1312 | "attributes!"); |
| 1313 | return NL_SKIP; |
| 1314 | } |
| 1315 | |
| 1316 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) |
| 1317 | return NL_SKIP; |
| 1318 | |
| 1319 | if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) != |
| 1320 | sig_change->frequency) |
| 1321 | return NL_SKIP; |
| 1322 | |
| 1323 | if (!sinfo[NL80211_SURVEY_INFO_NOISE]) |
| 1324 | return NL_SKIP; |
| 1325 | |
| 1326 | sig_change->current_noise = |
| 1327 | (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 1328 | |
| 1329 | return NL_SKIP; |
| 1330 | } |
| 1331 | |
| 1332 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1333 | int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv, |
| 1334 | struct wpa_signal_info *sig_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1335 | { |
| 1336 | struct nl_msg *msg; |
| 1337 | |
| 1338 | sig_change->current_noise = 9999; |
| 1339 | sig_change->frequency = drv->assoc_freq; |
| 1340 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1341 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1342 | return send_and_recv_msgs(drv, msg, get_link_noise, sig_change); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | |
| 1346 | static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx, |
| 1347 | void *handle) |
| 1348 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1349 | struct nl_cb *cb = eloop_ctx; |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1350 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1351 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 1352 | wpa_printf(MSG_MSGDUMP, "nl80211: Event message available"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1353 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1354 | res = nl_recvmsgs(handle, cb); |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 1355 | if (res < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1356 | wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d", |
| 1357 | __func__, res); |
| 1358 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1359 | } |
| 1360 | |
| 1361 | |
| 1362 | /** |
| 1363 | * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain |
| 1364 | * @priv: driver_nl80211 private data |
| 1365 | * @alpha2_arg: country to which to switch to |
| 1366 | * Returns: 0 on success, -1 on failure |
| 1367 | * |
| 1368 | * This asks nl80211 to set the regulatory domain for given |
| 1369 | * country ISO / IEC alpha2. |
| 1370 | */ |
| 1371 | static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg) |
| 1372 | { |
| 1373 | struct i802_bss *bss = priv; |
| 1374 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1375 | char alpha2[3]; |
| 1376 | struct nl_msg *msg; |
| 1377 | |
| 1378 | msg = nlmsg_alloc(); |
| 1379 | if (!msg) |
| 1380 | return -ENOMEM; |
| 1381 | |
| 1382 | alpha2[0] = alpha2_arg[0]; |
| 1383 | alpha2[1] = alpha2_arg[1]; |
| 1384 | alpha2[2] = '\0'; |
| 1385 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1386 | if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) || |
| 1387 | nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) { |
| 1388 | nlmsg_free(msg); |
| 1389 | return -EINVAL; |
| 1390 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1391 | if (send_and_recv_msgs(drv, msg, NULL, NULL)) |
| 1392 | return -EINVAL; |
| 1393 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1394 | } |
| 1395 | |
| 1396 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1397 | static int nl80211_get_country(struct nl_msg *msg, void *arg) |
| 1398 | { |
| 1399 | char *alpha2 = arg; |
| 1400 | struct nlattr *tb_msg[NL80211_ATTR_MAX + 1]; |
| 1401 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 1402 | |
| 1403 | nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 1404 | genlmsg_attrlen(gnlh, 0), NULL); |
| 1405 | if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) { |
| 1406 | wpa_printf(MSG_DEBUG, "nl80211: No country information available"); |
| 1407 | return NL_SKIP; |
| 1408 | } |
| 1409 | os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3); |
| 1410 | return NL_SKIP; |
| 1411 | } |
| 1412 | |
| 1413 | |
| 1414 | static int wpa_driver_nl80211_get_country(void *priv, char *alpha2) |
| 1415 | { |
| 1416 | struct i802_bss *bss = priv; |
| 1417 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 1418 | struct nl_msg *msg; |
| 1419 | int ret; |
| 1420 | |
| 1421 | msg = nlmsg_alloc(); |
| 1422 | if (!msg) |
| 1423 | return -ENOMEM; |
| 1424 | |
| 1425 | nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG); |
| 1426 | alpha2[0] = '\0'; |
| 1427 | ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2); |
| 1428 | if (!alpha2[0]) |
| 1429 | ret = -1; |
| 1430 | |
| 1431 | return ret; |
| 1432 | } |
| 1433 | |
| 1434 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1435 | static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1436 | { |
| 1437 | int ret; |
| 1438 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1439 | global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1440 | if (global->nl_cb == NULL) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1441 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink " |
| 1442 | "callbacks"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1443 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1446 | global->nl = nl_create_handle(global->nl_cb, "nl"); |
| 1447 | if (global->nl == NULL) |
| 1448 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1449 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1450 | global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211"); |
| 1451 | if (global->nl80211_id < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1452 | wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not " |
| 1453 | "found"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1454 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1455 | } |
| 1456 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1457 | global->nl_event = nl_create_handle(global->nl_cb, "event"); |
| 1458 | if (global->nl_event == NULL) |
| 1459 | goto err; |
| 1460 | |
| 1461 | ret = nl_get_multicast_id(global, "nl80211", "scan"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1462 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1463 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1464 | if (ret < 0) { |
| 1465 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1466 | "membership for scan events: %d (%s)", |
| 1467 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1468 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1471 | ret = nl_get_multicast_id(global, "nl80211", "mlme"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1472 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1473 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1474 | if (ret < 0) { |
| 1475 | wpa_printf(MSG_ERROR, "nl80211: Could not add multicast " |
| 1476 | "membership for mlme events: %d (%s)", |
| 1477 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1478 | goto err; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1479 | } |
| 1480 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1481 | ret = nl_get_multicast_id(global, "nl80211", "regulatory"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1482 | if (ret >= 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1483 | ret = nl_socket_add_membership(global->nl_event, ret); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1484 | if (ret < 0) { |
| 1485 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1486 | "membership for regulatory events: %d (%s)", |
| 1487 | ret, strerror(-ret)); |
| 1488 | /* Continue without regulatory events */ |
| 1489 | } |
| 1490 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1491 | ret = nl_get_multicast_id(global, "nl80211", "vendor"); |
| 1492 | if (ret >= 0) |
| 1493 | ret = nl_socket_add_membership(global->nl_event, ret); |
| 1494 | if (ret < 0) { |
| 1495 | wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast " |
| 1496 | "membership for vendor events: %d (%s)", |
| 1497 | ret, strerror(-ret)); |
| 1498 | /* Continue without vendor events */ |
| 1499 | } |
| 1500 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1501 | nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1502 | no_seq_check, NULL); |
| 1503 | nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1504 | process_global_event, global); |
| 1505 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1506 | nl80211_register_eloop_read(&global->nl_event, |
| 1507 | wpa_driver_nl80211_event_receive, |
| 1508 | global->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1509 | |
| 1510 | return 0; |
| 1511 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1512 | err: |
| 1513 | nl_destroy_handles(&global->nl_event); |
| 1514 | nl_destroy_handles(&global->nl); |
| 1515 | nl_cb_put(global->nl_cb); |
| 1516 | global->nl_cb = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1517 | return -1; |
| 1518 | } |
| 1519 | |
| 1520 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1521 | static void nl80211_check_global(struct nl80211_global *global) |
| 1522 | { |
| 1523 | struct nl_handle *handle; |
| 1524 | const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL }; |
| 1525 | int ret; |
| 1526 | unsigned int i; |
| 1527 | |
| 1528 | /* |
| 1529 | * Try to re-add memberships to handle case of cfg80211 getting reloaded |
| 1530 | * and all registration having been cleared. |
| 1531 | */ |
| 1532 | handle = (void *) (((intptr_t) global->nl_event) ^ |
| 1533 | ELOOP_SOCKET_INVALID); |
| 1534 | |
| 1535 | for (i = 0; groups[i]; i++) { |
| 1536 | ret = nl_get_multicast_id(global, "nl80211", groups[i]); |
| 1537 | if (ret >= 0) |
| 1538 | ret = nl_socket_add_membership(handle, ret); |
| 1539 | if (ret < 0) { |
| 1540 | wpa_printf(MSG_INFO, |
| 1541 | "nl80211: Could not re-add multicast membership for %s events: %d (%s)", |
| 1542 | groups[i], ret, strerror(-ret)); |
| 1543 | } |
| 1544 | } |
| 1545 | } |
| 1546 | |
| 1547 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1548 | static void wpa_driver_nl80211_rfkill_blocked(void *ctx) |
| 1549 | { |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1550 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1551 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1552 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked"); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1553 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1554 | /* |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1555 | * rtnetlink ifdown handler will report interfaces other than the P2P |
| 1556 | * Device interface as disabled. |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1557 | */ |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1558 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 1559 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | |
| 1563 | static void wpa_driver_nl80211_rfkill_unblocked(void *ctx) |
| 1564 | { |
| 1565 | struct wpa_driver_nl80211_data *drv = ctx; |
| 1566 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked"); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1567 | if (i802_set_iface_flags(drv->first_bss, 1)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1568 | wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP " |
| 1569 | "after rfkill unblock"); |
| 1570 | return; |
| 1571 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1572 | |
| 1573 | if (is_p2p_net_interface(drv->nlmode)) |
| 1574 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
| 1575 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1576 | /* |
| 1577 | * rtnetlink ifup handler will report interfaces other than the P2P |
| 1578 | * Device interface as enabled. |
| 1579 | */ |
| 1580 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 1581 | wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1585 | static void wpa_driver_nl80211_handle_eapol_tx_status(int sock, |
| 1586 | void *eloop_ctx, |
| 1587 | void *handle) |
| 1588 | { |
| 1589 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 1590 | u8 data[2048]; |
| 1591 | struct msghdr msg; |
| 1592 | struct iovec entry; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 1593 | u8 control[512]; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1594 | struct cmsghdr *cmsg; |
| 1595 | int res, found_ee = 0, found_wifi = 0, acked = 0; |
| 1596 | union wpa_event_data event; |
| 1597 | |
| 1598 | memset(&msg, 0, sizeof(msg)); |
| 1599 | msg.msg_iov = &entry; |
| 1600 | msg.msg_iovlen = 1; |
| 1601 | entry.iov_base = data; |
| 1602 | entry.iov_len = sizeof(data); |
| 1603 | msg.msg_control = &control; |
| 1604 | msg.msg_controllen = sizeof(control); |
| 1605 | |
| 1606 | res = recvmsg(sock, &msg, MSG_ERRQUEUE); |
| 1607 | /* if error or not fitting 802.3 header, return */ |
| 1608 | if (res < 14) |
| 1609 | return; |
| 1610 | |
| 1611 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) |
| 1612 | { |
| 1613 | if (cmsg->cmsg_level == SOL_SOCKET && |
| 1614 | cmsg->cmsg_type == SCM_WIFI_STATUS) { |
| 1615 | int *ack; |
| 1616 | |
| 1617 | found_wifi = 1; |
| 1618 | ack = (void *)CMSG_DATA(cmsg); |
| 1619 | acked = *ack; |
| 1620 | } |
| 1621 | |
| 1622 | if (cmsg->cmsg_level == SOL_PACKET && |
| 1623 | cmsg->cmsg_type == PACKET_TX_TIMESTAMP) { |
| 1624 | struct sock_extended_err *err = |
| 1625 | (struct sock_extended_err *)CMSG_DATA(cmsg); |
| 1626 | |
| 1627 | if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS) |
| 1628 | found_ee = 1; |
| 1629 | } |
| 1630 | } |
| 1631 | |
| 1632 | if (!found_ee || !found_wifi) |
| 1633 | return; |
| 1634 | |
| 1635 | memset(&event, 0, sizeof(event)); |
| 1636 | event.eapol_tx_status.dst = data; |
| 1637 | event.eapol_tx_status.data = data + 14; |
| 1638 | event.eapol_tx_status.data_len = res - 14; |
| 1639 | event.eapol_tx_status.ack = acked; |
| 1640 | wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event); |
| 1641 | } |
| 1642 | |
| 1643 | |
| 1644 | static int nl80211_init_bss(struct i802_bss *bss) |
| 1645 | { |
| 1646 | bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT); |
| 1647 | if (!bss->nl_cb) |
| 1648 | return -1; |
| 1649 | |
| 1650 | nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, |
| 1651 | no_seq_check, NULL); |
| 1652 | nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, |
| 1653 | process_bss_event, bss); |
| 1654 | |
| 1655 | return 0; |
| 1656 | } |
| 1657 | |
| 1658 | |
| 1659 | static void nl80211_destroy_bss(struct i802_bss *bss) |
| 1660 | { |
| 1661 | nl_cb_put(bss->nl_cb); |
| 1662 | bss->nl_cb = NULL; |
| 1663 | } |
| 1664 | |
| 1665 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 1666 | static void |
| 1667 | wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv) |
| 1668 | { |
| 1669 | struct rfkill_config *rcfg; |
| 1670 | |
| 1671 | if (drv->rfkill) |
| 1672 | return; |
| 1673 | |
| 1674 | rcfg = os_zalloc(sizeof(*rcfg)); |
| 1675 | if (!rcfg) |
| 1676 | return; |
| 1677 | |
| 1678 | rcfg->ctx = drv; |
| 1679 | |
| 1680 | /* rfkill uses netdev sysfs for initialization. However, P2P Device is |
| 1681 | * not associated with a netdev, so use the name of some other interface |
| 1682 | * sharing the same wiphy as the P2P Device interface. |
| 1683 | * |
| 1684 | * Note: This is valid, as a P2P Device interface is always dynamically |
| 1685 | * created and is created only once another wpa_s interface was added. |
| 1686 | */ |
| 1687 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 1688 | struct nl80211_global *global = drv->global; |
| 1689 | struct wpa_driver_nl80211_data *tmp1; |
| 1690 | |
| 1691 | dl_list_for_each(tmp1, &global->interfaces, |
| 1692 | struct wpa_driver_nl80211_data, list) { |
| 1693 | if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx || |
| 1694 | !tmp1->rfkill) |
| 1695 | continue; |
| 1696 | |
| 1697 | wpa_printf(MSG_DEBUG, |
| 1698 | "nl80211: Use (%s) to initialize P2P Device rfkill", |
| 1699 | tmp1->first_bss->ifname); |
| 1700 | os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname, |
| 1701 | sizeof(rcfg->ifname)); |
| 1702 | break; |
| 1703 | } |
| 1704 | } else { |
| 1705 | os_strlcpy(rcfg->ifname, drv->first_bss->ifname, |
| 1706 | sizeof(rcfg->ifname)); |
| 1707 | } |
| 1708 | |
| 1709 | rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked; |
| 1710 | rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked; |
| 1711 | drv->rfkill = rfkill_init(rcfg); |
| 1712 | if (!drv->rfkill) { |
| 1713 | wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available"); |
| 1714 | os_free(rcfg); |
| 1715 | } |
| 1716 | } |
| 1717 | |
| 1718 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1719 | static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname, |
| 1720 | void *global_priv, int hostapd, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1721 | const u8 *set_addr, |
| 1722 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1723 | { |
| 1724 | struct wpa_driver_nl80211_data *drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1725 | struct i802_bss *bss; |
| 1726 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1727 | if (global_priv == NULL) |
| 1728 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1729 | drv = os_zalloc(sizeof(*drv)); |
| 1730 | if (drv == NULL) |
| 1731 | return NULL; |
| 1732 | drv->global = global_priv; |
| 1733 | drv->ctx = ctx; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1734 | drv->hostapd = !!hostapd; |
| 1735 | drv->eapol_sock = -1; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 1736 | |
| 1737 | /* |
| 1738 | * There is no driver capability flag for this, so assume it is |
| 1739 | * supported and disable this on first attempt to use if the driver |
| 1740 | * rejects the command due to missing support. |
| 1741 | */ |
| 1742 | drv->set_rekey_offload = 1; |
| 1743 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1744 | drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int); |
| 1745 | drv->if_indices = drv->default_if_indices; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 1746 | drv->if_indices_reason = drv->default_if_indices_reason; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 1747 | |
| 1748 | drv->first_bss = os_zalloc(sizeof(*drv->first_bss)); |
| 1749 | if (!drv->first_bss) { |
| 1750 | os_free(drv); |
| 1751 | return NULL; |
| 1752 | } |
| 1753 | bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1754 | bss->drv = drv; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1755 | bss->ctx = ctx; |
| 1756 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1757 | os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname)); |
| 1758 | drv->monitor_ifidx = -1; |
| 1759 | drv->monitor_sock = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1760 | drv->eapol_tx_sock = -1; |
| 1761 | drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1762 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1763 | if (nl80211_init_bss(bss)) |
| 1764 | goto failed; |
| 1765 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1766 | 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] | 1767 | goto failed; |
| 1768 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1769 | drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0); |
| 1770 | if (drv->eapol_tx_sock < 0) |
| 1771 | goto failed; |
| 1772 | |
| 1773 | if (drv->data_tx_status) { |
| 1774 | int enabled = 1; |
| 1775 | |
| 1776 | if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS, |
| 1777 | &enabled, sizeof(enabled)) < 0) { |
| 1778 | wpa_printf(MSG_DEBUG, |
| 1779 | "nl80211: wifi status sockopt failed\n"); |
| 1780 | drv->data_tx_status = 0; |
| 1781 | if (!drv->use_monitor) |
| 1782 | drv->capa.flags &= |
| 1783 | ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS; |
| 1784 | } else { |
| 1785 | eloop_register_read_sock(drv->eapol_tx_sock, |
| 1786 | wpa_driver_nl80211_handle_eapol_tx_status, |
| 1787 | drv, NULL); |
| 1788 | } |
| 1789 | } |
| 1790 | |
| 1791 | if (drv->global) { |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 1792 | nl80211_check_global(drv->global); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1793 | dl_list_add(&drv->global->interfaces, &drv->list); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1794 | drv->in_interface_list = 1; |
| 1795 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1796 | |
| 1797 | return bss; |
| 1798 | |
| 1799 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1800 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1801 | return NULL; |
| 1802 | } |
| 1803 | |
| 1804 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1805 | /** |
| 1806 | * wpa_driver_nl80211_init - Initialize nl80211 driver interface |
| 1807 | * @ctx: context to be used when calling wpa_supplicant functions, |
| 1808 | * e.g., wpa_supplicant_event() |
| 1809 | * @ifname: interface name, e.g., wlan0 |
| 1810 | * @global_priv: private driver global data from global_init() |
| 1811 | * Returns: Pointer to private data, %NULL on failure |
| 1812 | */ |
| 1813 | static void * wpa_driver_nl80211_init(void *ctx, const char *ifname, |
| 1814 | void *global_priv) |
| 1815 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1816 | return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL, |
| 1817 | NULL); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 1818 | } |
| 1819 | |
| 1820 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1821 | static int nl80211_register_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1822 | struct nl_handle *nl_handle, |
| 1823 | u16 type, const u8 *match, size_t match_len) |
| 1824 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1825 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1826 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1827 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1828 | char buf[30]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1829 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1830 | buf[0] = '\0'; |
| 1831 | wpa_snprintf_hex(buf, sizeof(buf), match, match_len); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 1832 | wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s", |
| 1833 | type, fc2str(type), nl_handle, buf); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1834 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1835 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) || |
| 1836 | nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) || |
| 1837 | nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) { |
| 1838 | nlmsg_free(msg); |
| 1839 | return -1; |
| 1840 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1841 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1842 | ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1843 | if (ret) { |
| 1844 | wpa_printf(MSG_DEBUG, "nl80211: Register frame command " |
| 1845 | "failed (type=%u): ret=%d (%s)", |
| 1846 | type, ret, strerror(-ret)); |
| 1847 | wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match", |
| 1848 | match, match_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1849 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1850 | return ret; |
| 1851 | } |
| 1852 | |
| 1853 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1854 | static int nl80211_alloc_mgmt_handle(struct i802_bss *bss) |
| 1855 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1856 | if (bss->nl_mgmt) { |
| 1857 | wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting " |
| 1858 | "already on! (nl_mgmt=%p)", bss->nl_mgmt); |
| 1859 | return -1; |
| 1860 | } |
| 1861 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1862 | bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1863 | if (bss->nl_mgmt == NULL) |
| 1864 | return -1; |
| 1865 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1866 | return 0; |
| 1867 | } |
| 1868 | |
| 1869 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1870 | static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss) |
| 1871 | { |
| 1872 | nl80211_register_eloop_read(&bss->nl_mgmt, |
| 1873 | wpa_driver_nl80211_event_receive, |
| 1874 | bss->nl_cb); |
| 1875 | } |
| 1876 | |
| 1877 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1878 | static int nl80211_register_action_frame(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1879 | const u8 *match, size_t match_len) |
| 1880 | { |
| 1881 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1882 | return nl80211_register_frame(bss, bss->nl_mgmt, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1883 | type, match, match_len); |
| 1884 | } |
| 1885 | |
| 1886 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1887 | static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1888 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1889 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1890 | int ret = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1891 | |
| 1892 | if (nl80211_alloc_mgmt_handle(bss)) |
| 1893 | return -1; |
| 1894 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP " |
| 1895 | "handle %p", bss->nl_mgmt); |
| 1896 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 1897 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 1898 | u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4); |
| 1899 | |
| 1900 | /* register for any AUTH message */ |
| 1901 | nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0); |
| 1902 | } |
| 1903 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1904 | #ifdef CONFIG_INTERWORKING |
| 1905 | /* QoS Map Configure */ |
| 1906 | if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1907 | ret = -1; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 1908 | #endif /* CONFIG_INTERWORKING */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1909 | #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1910 | /* GAS Initial Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1911 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1912 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1913 | /* GAS Initial Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1914 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1915 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1916 | /* GAS Comeback Request */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1917 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1918 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1919 | /* GAS Comeback Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1920 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1921 | ret = -1; |
Dmitry Shmidt | 1846323 | 2014-01-24 12:29:41 -0800 | [diff] [blame] | 1922 | /* Protected GAS Initial Request */ |
| 1923 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0) |
| 1924 | ret = -1; |
| 1925 | /* Protected GAS Initial Response */ |
| 1926 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0) |
| 1927 | ret = -1; |
| 1928 | /* Protected GAS Comeback Request */ |
| 1929 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0) |
| 1930 | ret = -1; |
| 1931 | /* Protected GAS Comeback Response */ |
| 1932 | if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0) |
| 1933 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1934 | #endif /* CONFIG_P2P || CONFIG_INTERWORKING */ |
| 1935 | #ifdef CONFIG_P2P |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1936 | /* P2P Public Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1937 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1938 | (u8 *) "\x04\x09\x50\x6f\x9a\x09", |
| 1939 | 6) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1940 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1941 | /* P2P Action */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1942 | if (nl80211_register_action_frame(bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1943 | (u8 *) "\x7f\x50\x6f\x9a\x09", |
| 1944 | 5) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1945 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1946 | #endif /* CONFIG_P2P */ |
| 1947 | #ifdef CONFIG_IEEE80211W |
| 1948 | /* SA Query Response */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1949 | if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1950 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1951 | #endif /* CONFIG_IEEE80211W */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1952 | #ifdef CONFIG_TDLS |
| 1953 | if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) { |
| 1954 | /* TDLS Discovery Response */ |
| 1955 | if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) < |
| 1956 | 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1957 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1958 | } |
| 1959 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 1960 | #ifdef CONFIG_FST |
| 1961 | /* FST Action frames */ |
| 1962 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 1963 | ret = -1; |
| 1964 | #endif /* CONFIG_FST */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1965 | |
| 1966 | /* FT Action frames */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1967 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1968 | ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 1969 | else |
| 1970 | drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT | |
| 1971 | WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK; |
| 1972 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1973 | /* WNM - BSS Transition Management Request */ |
| 1974 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1975 | ret = -1; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 1976 | /* WNM-Sleep Mode Response */ |
| 1977 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 1978 | ret = -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 1979 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1980 | #ifdef CONFIG_HS20 |
| 1981 | /* WNM-Notification */ |
| 1982 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0) |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 1983 | ret = -1; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 1984 | #endif /* CONFIG_HS20 */ |
| 1985 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 1986 | /* WMM-AC ADDTS Response */ |
| 1987 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0) |
| 1988 | ret = -1; |
| 1989 | |
| 1990 | /* WMM-AC DELTS */ |
| 1991 | if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0) |
| 1992 | ret = -1; |
| 1993 | |
| 1994 | /* Radio Measurement - Neighbor Report Response */ |
| 1995 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0) |
| 1996 | ret = -1; |
| 1997 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 1998 | /* Radio Measurement - Radio Measurement Request */ |
| 1999 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x00", 2) < 0) |
| 2000 | ret = -1; |
| 2001 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2002 | /* Radio Measurement - Link Measurement Request */ |
| 2003 | if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) && |
| 2004 | (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0)) |
| 2005 | ret = -1; |
| 2006 | |
| 2007 | nl80211_mgmt_handle_register_eloop(bss); |
| 2008 | |
| 2009 | return ret; |
| 2010 | } |
| 2011 | |
| 2012 | |
| 2013 | static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss) |
| 2014 | { |
| 2015 | int ret = 0; |
| 2016 | |
| 2017 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2018 | return -1; |
| 2019 | |
| 2020 | wpa_printf(MSG_DEBUG, |
| 2021 | "nl80211: Subscribe to mgmt frames with mesh handle %p", |
| 2022 | bss->nl_mgmt); |
| 2023 | |
| 2024 | /* Auth frames for mesh SAE */ |
| 2025 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2026 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2027 | (WLAN_FC_STYPE_AUTH << 4), |
| 2028 | NULL, 0) < 0) |
| 2029 | ret = -1; |
| 2030 | |
| 2031 | /* Mesh peering open */ |
| 2032 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0) |
| 2033 | ret = -1; |
| 2034 | /* Mesh peering confirm */ |
| 2035 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0) |
| 2036 | ret = -1; |
| 2037 | /* Mesh peering close */ |
| 2038 | if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0) |
| 2039 | ret = -1; |
| 2040 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2041 | nl80211_mgmt_handle_register_eloop(bss); |
| 2042 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2043 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2047 | static int nl80211_register_spurious_class3(struct i802_bss *bss) |
| 2048 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2049 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2050 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2051 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2052 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME); |
| 2053 | 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] | 2054 | if (ret) { |
| 2055 | wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 " |
| 2056 | "failed: ret=%d (%s)", |
| 2057 | ret, strerror(-ret)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2058 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2059 | return ret; |
| 2060 | } |
| 2061 | |
| 2062 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2063 | static int nl80211_action_subscribe_ap(struct i802_bss *bss) |
| 2064 | { |
| 2065 | int ret = 0; |
| 2066 | |
| 2067 | /* Public Action frames */ |
| 2068 | if (nl80211_register_action_frame(bss, (u8 *) "\x04", 1) < 0) |
| 2069 | ret = -1; |
| 2070 | /* RRM Measurement Report */ |
| 2071 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x01", 2) < 0) |
| 2072 | ret = -1; |
| 2073 | /* RRM Neighbor Report Request */ |
| 2074 | if (nl80211_register_action_frame(bss, (u8 *) "\x05\x04", 2) < 0) |
| 2075 | ret = -1; |
| 2076 | /* FT Action frames */ |
| 2077 | if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0) |
| 2078 | ret = -1; |
| 2079 | #ifdef CONFIG_IEEE80211W |
| 2080 | /* SA Query */ |
| 2081 | if (nl80211_register_action_frame(bss, (u8 *) "\x08", 1) < 0) |
| 2082 | ret = -1; |
| 2083 | #endif /* CONFIG_IEEE80211W */ |
| 2084 | /* Protected Dual of Public Action */ |
| 2085 | if (nl80211_register_action_frame(bss, (u8 *) "\x09", 1) < 0) |
| 2086 | ret = -1; |
| 2087 | /* WNM */ |
| 2088 | if (nl80211_register_action_frame(bss, (u8 *) "\x0a", 1) < 0) |
| 2089 | ret = -1; |
| 2090 | /* WMM */ |
| 2091 | if (nl80211_register_action_frame(bss, (u8 *) "\x11", 1) < 0) |
| 2092 | ret = -1; |
| 2093 | #ifdef CONFIG_FST |
| 2094 | /* FST Action frames */ |
| 2095 | if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0) |
| 2096 | ret = -1; |
| 2097 | #endif /* CONFIG_FST */ |
| 2098 | /* Vendor-specific */ |
| 2099 | if (nl80211_register_action_frame(bss, (u8 *) "\x7f", 1) < 0) |
| 2100 | ret = -1; |
| 2101 | |
| 2102 | return ret; |
| 2103 | } |
| 2104 | |
| 2105 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2106 | static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss) |
| 2107 | { |
| 2108 | static const int stypes[] = { |
| 2109 | WLAN_FC_STYPE_AUTH, |
| 2110 | WLAN_FC_STYPE_ASSOC_REQ, |
| 2111 | WLAN_FC_STYPE_REASSOC_REQ, |
| 2112 | WLAN_FC_STYPE_DISASSOC, |
| 2113 | WLAN_FC_STYPE_DEAUTH, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2114 | WLAN_FC_STYPE_PROBE_REQ, |
| 2115 | /* Beacon doesn't work as mac80211 doesn't currently allow |
| 2116 | * it, but it wouldn't really be the right thing anyway as |
| 2117 | * it isn't per interface ... maybe just dump the scan |
| 2118 | * results periodically for OLBC? |
| 2119 | */ |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 2120 | /* WLAN_FC_STYPE_BEACON, */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2121 | }; |
| 2122 | unsigned int i; |
| 2123 | |
| 2124 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2125 | return -1; |
| 2126 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2127 | "handle %p", bss->nl_mgmt); |
| 2128 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2129 | for (i = 0; i < ARRAY_SIZE(stypes); i++) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2130 | if (nl80211_register_frame(bss, bss->nl_mgmt, |
| 2131 | (WLAN_FC_TYPE_MGMT << 2) | |
| 2132 | (stypes[i] << 4), |
| 2133 | NULL, 0) < 0) { |
| 2134 | goto out_err; |
| 2135 | } |
| 2136 | } |
| 2137 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2138 | if (nl80211_action_subscribe_ap(bss)) |
| 2139 | goto out_err; |
| 2140 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2141 | if (nl80211_register_spurious_class3(bss)) |
| 2142 | goto out_err; |
| 2143 | |
| 2144 | if (nl80211_get_wiphy_data_ap(bss) == NULL) |
| 2145 | goto out_err; |
| 2146 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2147 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2148 | return 0; |
| 2149 | |
| 2150 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2151 | nl_destroy_handles(&bss->nl_mgmt); |
| 2152 | return -1; |
| 2153 | } |
| 2154 | |
| 2155 | |
| 2156 | static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss) |
| 2157 | { |
| 2158 | if (nl80211_alloc_mgmt_handle(bss)) |
| 2159 | return -1; |
| 2160 | wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP " |
| 2161 | "handle %p (device SME)", bss->nl_mgmt); |
| 2162 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 2163 | if (nl80211_action_subscribe_ap(bss)) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2164 | goto out_err; |
| 2165 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2166 | nl80211_mgmt_handle_register_eloop(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2167 | return 0; |
| 2168 | |
| 2169 | out_err: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2170 | nl_destroy_handles(&bss->nl_mgmt); |
| 2171 | return -1; |
| 2172 | } |
| 2173 | |
| 2174 | |
| 2175 | static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason) |
| 2176 | { |
| 2177 | if (bss->nl_mgmt == NULL) |
| 2178 | return; |
| 2179 | wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p " |
| 2180 | "(%s)", bss->nl_mgmt, reason); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2181 | nl80211_destroy_eloop_handle(&bss->nl_mgmt); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2182 | |
| 2183 | nl80211_put_wiphy_data_ap(bss); |
| 2184 | } |
| 2185 | |
| 2186 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2187 | static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx) |
| 2188 | { |
| 2189 | wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL); |
| 2190 | } |
| 2191 | |
| 2192 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2193 | static void nl80211_del_p2pdev(struct i802_bss *bss) |
| 2194 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2195 | struct nl_msg *msg; |
| 2196 | int ret; |
| 2197 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2198 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE); |
| 2199 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2200 | |
| 2201 | wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s", |
| 2202 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2203 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2204 | } |
| 2205 | |
| 2206 | |
| 2207 | static int nl80211_set_p2pdev(struct i802_bss *bss, int start) |
| 2208 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2209 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2210 | int ret; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2211 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2212 | msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE : |
| 2213 | NL80211_CMD_STOP_P2P_DEVICE); |
| 2214 | ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2215 | |
| 2216 | wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s", |
| 2217 | start ? "Start" : "Stop", |
| 2218 | bss->ifname, (long long unsigned int) bss->wdev_id, |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 2219 | strerror(-ret)); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2220 | return ret; |
| 2221 | } |
| 2222 | |
| 2223 | |
| 2224 | static int i802_set_iface_flags(struct i802_bss *bss, int up) |
| 2225 | { |
| 2226 | enum nl80211_iftype nlmode; |
| 2227 | |
| 2228 | nlmode = nl80211_get_ifmode(bss); |
| 2229 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2230 | return linux_set_iface_flags(bss->drv->global->ioctl_sock, |
| 2231 | bss->ifname, up); |
| 2232 | } |
| 2233 | |
| 2234 | /* P2P Device has start/stop which is equivalent */ |
| 2235 | return nl80211_set_p2pdev(bss, up); |
| 2236 | } |
| 2237 | |
| 2238 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2239 | #ifdef CONFIG_TESTING_OPTIONS |
| 2240 | static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg) |
| 2241 | { |
| 2242 | /* struct wpa_driver_nl80211_data *drv = arg; */ |
| 2243 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 2244 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 2245 | |
| 2246 | |
| 2247 | wpa_printf(MSG_DEBUG, |
| 2248 | "nl80211: QCA vendor test command response received"); |
| 2249 | |
| 2250 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 2251 | genlmsg_attrlen(gnlh, 0), NULL); |
| 2252 | if (!tb[NL80211_ATTR_VENDOR_DATA]) { |
| 2253 | wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute"); |
| 2254 | return NL_SKIP; |
| 2255 | } |
| 2256 | |
| 2257 | wpa_hexdump(MSG_DEBUG, |
| 2258 | "nl80211: Received QCA vendor test command response", |
| 2259 | nla_data(tb[NL80211_ATTR_VENDOR_DATA]), |
| 2260 | nla_len(tb[NL80211_ATTR_VENDOR_DATA])); |
| 2261 | |
| 2262 | return NL_SKIP; |
| 2263 | } |
| 2264 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2265 | |
| 2266 | |
| 2267 | static void qca_vendor_test(struct wpa_driver_nl80211_data *drv) |
| 2268 | { |
| 2269 | #ifdef CONFIG_TESTING_OPTIONS |
| 2270 | struct nl_msg *msg; |
| 2271 | struct nlattr *params; |
| 2272 | int ret; |
| 2273 | |
| 2274 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2275 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2276 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2277 | QCA_NL80211_VENDOR_SUBCMD_TEST) || |
| 2278 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 2279 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) { |
| 2280 | nlmsg_free(msg); |
| 2281 | return; |
| 2282 | } |
| 2283 | nla_nest_end(msg, params); |
| 2284 | |
| 2285 | ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv); |
| 2286 | wpa_printf(MSG_DEBUG, |
| 2287 | "nl80211: QCA vendor test command returned %d (%s)", |
| 2288 | ret, strerror(-ret)); |
| 2289 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 2290 | } |
| 2291 | |
| 2292 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2293 | static int |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2294 | wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2295 | const u8 *set_addr, int first, |
| 2296 | const char *driver_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2297 | { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2298 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2299 | int send_rfkill_event = 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2300 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2301 | |
| 2302 | drv->ifindex = if_nametoindex(bss->ifname); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2303 | bss->ifindex = drv->ifindex; |
| 2304 | bss->wdev_id = drv->global->if_add_wdevid; |
| 2305 | bss->wdev_id_set = drv->global->if_add_wdevid_set; |
| 2306 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2307 | bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex; |
| 2308 | bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2309 | drv->global->if_add_wdevid_set = 0; |
| 2310 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2311 | if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2312 | bss->static_ap = 1; |
| 2313 | |
Dmitry Shmidt | 014a3ff | 2015-12-28 13:27:49 -0800 | [diff] [blame] | 2314 | if (first && |
| 2315 | nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE && |
| 2316 | linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0) |
| 2317 | drv->start_iface_up = 1; |
| 2318 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2319 | if (wpa_driver_nl80211_capa(drv)) |
| 2320 | return -1; |
| 2321 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2322 | if (driver_params && nl80211_set_param(bss, driver_params) < 0) |
| 2323 | return -1; |
| 2324 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2325 | wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s", |
| 2326 | bss->ifname, drv->phyname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2327 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2328 | if (set_addr && |
| 2329 | (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) || |
| 2330 | linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2331 | set_addr))) |
| 2332 | return -1; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2333 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2334 | if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP) |
| 2335 | drv->start_mode_ap = 1; |
| 2336 | |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 2337 | if (drv->hostapd || bss->static_ap) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2338 | nlmode = NL80211_IFTYPE_AP; |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 2339 | else if (bss->if_dynamic || |
| 2340 | nl80211_get_ifmode(bss) == NL80211_IFTYPE_MESH_POINT) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2341 | nlmode = nl80211_get_ifmode(bss); |
| 2342 | else |
| 2343 | nlmode = NL80211_IFTYPE_STATION; |
| 2344 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2345 | if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2346 | wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2347 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2348 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2349 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2350 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2351 | nl80211_get_macaddr(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2352 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2353 | wpa_driver_nl80211_drv_init_rfkill(drv); |
| 2354 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2355 | if (!rfkill_is_blocked(drv->rfkill)) { |
| 2356 | int ret = i802_set_iface_flags(bss, 1); |
| 2357 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2358 | wpa_printf(MSG_ERROR, "nl80211: Could not set " |
| 2359 | "interface '%s' UP", bss->ifname); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2360 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2361 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2362 | |
| 2363 | if (is_p2p_net_interface(nlmode)) |
| 2364 | nl80211_disable_11b_rates(bss->drv, |
| 2365 | bss->drv->ifindex, 1); |
| 2366 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2367 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2368 | return ret; |
| 2369 | } else { |
| 2370 | wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable " |
| 2371 | "interface '%s' due to rfkill", bss->ifname); |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2372 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 2373 | drv->if_disabled = 1; |
| 2374 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2375 | send_rfkill_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2376 | } |
| 2377 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2378 | if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2379 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, |
| 2380 | 1, IF_OPER_DORMANT); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2381 | |
Dmitry Shmidt | 7d56b75 | 2015-12-22 10:59:44 -0800 | [diff] [blame] | 2382 | if (nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
| 2383 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2384 | bss->addr)) |
| 2385 | return -1; |
| 2386 | os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN); |
| 2387 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2388 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2389 | if (send_rfkill_event) { |
| 2390 | eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill, |
| 2391 | drv, drv->ctx); |
| 2392 | } |
| 2393 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 2394 | if (drv->vendor_cmd_test_avail) |
| 2395 | qca_vendor_test(drv); |
| 2396 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2397 | return 0; |
| 2398 | } |
| 2399 | |
| 2400 | |
| 2401 | static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv) |
| 2402 | { |
| 2403 | struct nl_msg *msg; |
| 2404 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2405 | wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)", |
| 2406 | drv->ifindex); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2407 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2408 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2409 | } |
| 2410 | |
| 2411 | |
| 2412 | /** |
| 2413 | * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2414 | * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init() |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2415 | * |
| 2416 | * Shut down driver interface and processing of driver events. Free |
| 2417 | * private data buffer if one was allocated in wpa_driver_nl80211_init(). |
| 2418 | */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2419 | static void wpa_driver_nl80211_deinit(struct i802_bss *bss) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2420 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2421 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2422 | unsigned int i; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2423 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2424 | wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d", |
| 2425 | bss->ifname, drv->disabled_11b_rates); |
| 2426 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 2427 | bss->in_deinit = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2428 | if (drv->data_tx_status) |
| 2429 | eloop_unregister_read_sock(drv->eapol_tx_sock); |
| 2430 | if (drv->eapol_tx_sock >= 0) |
| 2431 | close(drv->eapol_tx_sock); |
| 2432 | |
| 2433 | if (bss->nl_preq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2434 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 2435 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2436 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 2437 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2438 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2439 | "interface %s from bridge %s: %s", |
| 2440 | bss->ifname, bss->brname, strerror(errno)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2441 | if (drv->rtnl_sk) |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 2442 | nl80211_handle_destroy(drv->rtnl_sk); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2443 | } |
| 2444 | if (bss->added_bridge) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2445 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname, |
| 2446 | 0) < 0) |
| 2447 | wpa_printf(MSG_INFO, |
| 2448 | "nl80211: Could not set bridge %s down", |
| 2449 | bss->brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2450 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2451 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 2452 | "bridge %s: %s", |
| 2453 | bss->brname, strerror(errno)); |
| 2454 | } |
| 2455 | |
| 2456 | nl80211_remove_monitor_interface(drv); |
| 2457 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2458 | if (is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2459 | wpa_driver_nl80211_del_beacon(drv); |
| 2460 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2461 | if (drv->eapol_sock >= 0) { |
| 2462 | eloop_unregister_read_sock(drv->eapol_sock); |
| 2463 | close(drv->eapol_sock); |
| 2464 | } |
| 2465 | |
| 2466 | if (drv->if_indices != drv->default_if_indices) |
| 2467 | os_free(drv->if_indices); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2468 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 2469 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
| 2470 | os_free(drv->if_indices_reason); |
| 2471 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2472 | if (drv->disabled_11b_rates) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2473 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 2474 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2475 | netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0, |
| 2476 | IF_OPER_UP); |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 2477 | eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2478 | rfkill_deinit(drv->rfkill); |
| 2479 | |
| 2480 | eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx); |
| 2481 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2482 | if (!drv->start_iface_up) |
| 2483 | (void) i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2484 | |
| 2485 | if (drv->addr_changed) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2486 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 2487 | 0) < 0) { |
| 2488 | wpa_printf(MSG_DEBUG, |
| 2489 | "nl80211: Could not set interface down to restore permanent MAC address"); |
| 2490 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 2491 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 2492 | drv->perm_addr) < 0) { |
| 2493 | wpa_printf(MSG_DEBUG, |
| 2494 | "nl80211: Could not restore permanent MAC address"); |
| 2495 | } |
| 2496 | } |
| 2497 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2498 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 2499 | if (!drv->hostapd || !drv->start_mode_ap) |
| 2500 | wpa_driver_nl80211_set_mode(bss, |
| 2501 | NL80211_IFTYPE_STATION); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 2502 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2503 | } else { |
| 2504 | nl80211_mgmt_unsubscribe(bss, "deinit"); |
| 2505 | nl80211_del_p2pdev(bss); |
| 2506 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2507 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2508 | nl80211_destroy_bss(drv->first_bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2509 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2510 | os_free(drv->filter_ssids); |
| 2511 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2512 | os_free(drv->auth_ie); |
| 2513 | |
| 2514 | if (drv->in_interface_list) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2515 | dl_list_del(&drv->list); |
| 2516 | |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 2517 | os_free(drv->extended_capa); |
| 2518 | os_free(drv->extended_capa_mask); |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 2519 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 2520 | os_free(drv->iface_ext_capa[i].ext_capa); |
| 2521 | os_free(drv->iface_ext_capa[i].ext_capa_mask); |
| 2522 | } |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 2523 | os_free(drv->first_bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2524 | os_free(drv); |
| 2525 | } |
| 2526 | |
| 2527 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2528 | static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len) |
| 2529 | { |
| 2530 | switch (alg) { |
| 2531 | case WPA_ALG_WEP: |
| 2532 | if (key_len == 5) |
| 2533 | return WLAN_CIPHER_SUITE_WEP40; |
| 2534 | return WLAN_CIPHER_SUITE_WEP104; |
| 2535 | case WPA_ALG_TKIP: |
| 2536 | return WLAN_CIPHER_SUITE_TKIP; |
| 2537 | case WPA_ALG_CCMP: |
| 2538 | return WLAN_CIPHER_SUITE_CCMP; |
| 2539 | case WPA_ALG_GCMP: |
| 2540 | return WLAN_CIPHER_SUITE_GCMP; |
| 2541 | case WPA_ALG_CCMP_256: |
| 2542 | return WLAN_CIPHER_SUITE_CCMP_256; |
| 2543 | case WPA_ALG_GCMP_256: |
| 2544 | return WLAN_CIPHER_SUITE_GCMP_256; |
| 2545 | case WPA_ALG_IGTK: |
| 2546 | return WLAN_CIPHER_SUITE_AES_CMAC; |
| 2547 | case WPA_ALG_BIP_GMAC_128: |
| 2548 | return WLAN_CIPHER_SUITE_BIP_GMAC_128; |
| 2549 | case WPA_ALG_BIP_GMAC_256: |
| 2550 | return WLAN_CIPHER_SUITE_BIP_GMAC_256; |
| 2551 | case WPA_ALG_BIP_CMAC_256: |
| 2552 | return WLAN_CIPHER_SUITE_BIP_CMAC_256; |
| 2553 | case WPA_ALG_SMS4: |
| 2554 | return WLAN_CIPHER_SUITE_SMS4; |
| 2555 | case WPA_ALG_KRK: |
| 2556 | return WLAN_CIPHER_SUITE_KRK; |
| 2557 | case WPA_ALG_NONE: |
| 2558 | case WPA_ALG_PMK: |
| 2559 | wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d", |
| 2560 | alg); |
| 2561 | return 0; |
| 2562 | } |
| 2563 | |
| 2564 | wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d", |
| 2565 | alg); |
| 2566 | return 0; |
| 2567 | } |
| 2568 | |
| 2569 | |
| 2570 | static u32 wpa_cipher_to_cipher_suite(unsigned int cipher) |
| 2571 | { |
| 2572 | switch (cipher) { |
| 2573 | case WPA_CIPHER_CCMP_256: |
| 2574 | return WLAN_CIPHER_SUITE_CCMP_256; |
| 2575 | case WPA_CIPHER_GCMP_256: |
| 2576 | return WLAN_CIPHER_SUITE_GCMP_256; |
| 2577 | case WPA_CIPHER_CCMP: |
| 2578 | return WLAN_CIPHER_SUITE_CCMP; |
| 2579 | case WPA_CIPHER_GCMP: |
| 2580 | return WLAN_CIPHER_SUITE_GCMP; |
| 2581 | case WPA_CIPHER_TKIP: |
| 2582 | return WLAN_CIPHER_SUITE_TKIP; |
| 2583 | case WPA_CIPHER_WEP104: |
| 2584 | return WLAN_CIPHER_SUITE_WEP104; |
| 2585 | case WPA_CIPHER_WEP40: |
| 2586 | return WLAN_CIPHER_SUITE_WEP40; |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 2587 | case WPA_CIPHER_GTK_NOT_USED: |
| 2588 | return WLAN_CIPHER_SUITE_NO_GROUP_ADDR; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 2589 | } |
| 2590 | |
| 2591 | return 0; |
| 2592 | } |
| 2593 | |
| 2594 | |
| 2595 | static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[], |
| 2596 | int max_suites) |
| 2597 | { |
| 2598 | int num_suites = 0; |
| 2599 | |
| 2600 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256) |
| 2601 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP_256; |
| 2602 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256) |
| 2603 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP_256; |
| 2604 | if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP) |
| 2605 | suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP; |
| 2606 | if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP) |
| 2607 | suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP; |
| 2608 | if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP) |
| 2609 | suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP; |
| 2610 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104) |
| 2611 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104; |
| 2612 | if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40) |
| 2613 | suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40; |
| 2614 | |
| 2615 | return num_suites; |
| 2616 | } |
| 2617 | |
| 2618 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2619 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2620 | static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv, |
| 2621 | const u8 *key, size_t key_len) |
| 2622 | { |
| 2623 | struct nl_msg *msg; |
| 2624 | int ret; |
| 2625 | |
| 2626 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) |
| 2627 | return 0; |
| 2628 | |
| 2629 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 2630 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 2631 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 2632 | QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) || |
| 2633 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) { |
| 2634 | nl80211_nlmsg_clear(msg); |
| 2635 | nlmsg_free(msg); |
| 2636 | return -1; |
| 2637 | } |
| 2638 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 2639 | if (ret) { |
| 2640 | wpa_printf(MSG_DEBUG, |
| 2641 | "nl80211: Key management set key failed: ret=%d (%s)", |
| 2642 | ret, strerror(-ret)); |
| 2643 | } |
| 2644 | |
| 2645 | return ret; |
| 2646 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2647 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2648 | |
| 2649 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2650 | 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] | 2651 | enum wpa_alg alg, const u8 *addr, |
| 2652 | int key_idx, int set_tx, |
| 2653 | const u8 *seq, size_t seq_len, |
| 2654 | const u8 *key, size_t key_len) |
| 2655 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2656 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2657 | int ifindex; |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2658 | struct nl_msg *msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2659 | int ret; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2660 | int tdls = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2661 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2662 | /* Ignore for P2P Device */ |
| 2663 | if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) |
| 2664 | return 0; |
| 2665 | |
| 2666 | ifindex = if_nametoindex(ifname); |
| 2667 | 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] | 2668 | "set_tx=%d seq_len=%lu key_len=%lu", |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 2669 | __func__, ifindex, ifname, alg, addr, key_idx, set_tx, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2670 | (unsigned long) seq_len, (unsigned long) key_len); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2671 | #ifdef CONFIG_TDLS |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2672 | if (key_idx == -1) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2673 | key_idx = 0; |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2674 | tdls = 1; |
| 2675 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2676 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2677 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2678 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2679 | if (alg == WPA_ALG_PMK && |
| 2680 | (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) { |
| 2681 | wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key", |
| 2682 | __func__); |
| 2683 | ret = issue_key_mgmt_set_key(drv, key, key_len); |
| 2684 | return ret; |
| 2685 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 2686 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2687 | |
| 2688 | if (alg == WPA_ALG_NONE) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2689 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY); |
| 2690 | if (!msg) |
| 2691 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2692 | } else { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2693 | u32 suite; |
| 2694 | |
| 2695 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 2696 | if (!suite) |
| 2697 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2698 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY); |
| 2699 | if (!msg || |
| 2700 | nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2701 | nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, suite)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2702 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2703 | wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2704 | } |
| 2705 | |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2706 | if (seq && seq_len) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2707 | if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq)) |
| 2708 | goto fail; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 2709 | wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len); |
| 2710 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2711 | |
| 2712 | if (addr && !is_broadcast_ether_addr(addr)) { |
| 2713 | wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2714 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 2715 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2716 | |
| 2717 | if (alg != WPA_ALG_WEP && key_idx && !set_tx) { |
| 2718 | wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2719 | if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE, |
| 2720 | NL80211_KEYTYPE_GROUP)) |
| 2721 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2722 | } |
| 2723 | } else if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2724 | struct nlattr *types; |
| 2725 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2726 | wpa_printf(MSG_DEBUG, " broadcast key"); |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2727 | |
| 2728 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2729 | if (!types || |
| 2730 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 2731 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2732 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2733 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2734 | if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx)) |
| 2735 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2736 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2737 | ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2738 | if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE) |
| 2739 | ret = 0; |
| 2740 | if (ret) |
| 2741 | wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)", |
| 2742 | ret, strerror(-ret)); |
| 2743 | |
| 2744 | /* |
| 2745 | * If we failed or don't need to set the default TX key (below), |
| 2746 | * we're done here. |
| 2747 | */ |
Dmitry Shmidt | d5c075b | 2013-08-05 14:36:10 -0700 | [diff] [blame] | 2748 | if (ret || !set_tx || alg == WPA_ALG_NONE || tdls) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2749 | return ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2750 | if (is_ap_interface(drv->nlmode) && addr && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2751 | !is_broadcast_ether_addr(addr)) |
| 2752 | return ret; |
| 2753 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2754 | msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY); |
| 2755 | if (!msg || |
| 2756 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 2757 | nla_put_flag(msg, (alg == WPA_ALG_IGTK || |
| 2758 | alg == WPA_ALG_BIP_GMAC_128 || |
| 2759 | alg == WPA_ALG_BIP_GMAC_256 || |
| 2760 | alg == WPA_ALG_BIP_CMAC_256) ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2761 | NL80211_ATTR_KEY_DEFAULT_MGMT : |
| 2762 | NL80211_ATTR_KEY_DEFAULT)) |
| 2763 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2764 | if (addr && is_broadcast_ether_addr(addr)) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2765 | struct nlattr *types; |
| 2766 | |
| 2767 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2768 | if (!types || |
| 2769 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST)) |
| 2770 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2771 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2772 | } else if (addr) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2773 | struct nlattr *types; |
| 2774 | |
| 2775 | types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2776 | if (!types || |
| 2777 | nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST)) |
| 2778 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 2779 | nla_nest_end(msg, types); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2780 | } |
| 2781 | |
| 2782 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 2783 | if (ret == -ENOENT) |
| 2784 | ret = 0; |
| 2785 | if (ret) |
| 2786 | wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; " |
| 2787 | "err=%d %s)", ret, strerror(-ret)); |
| 2788 | return ret; |
| 2789 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2790 | fail: |
| 2791 | nl80211_nlmsg_clear(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2792 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2793 | return -ENOBUFS; |
| 2794 | } |
| 2795 | |
| 2796 | |
| 2797 | static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg, |
| 2798 | int key_idx, int defkey, |
| 2799 | const u8 *seq, size_t seq_len, |
| 2800 | const u8 *key, size_t key_len) |
| 2801 | { |
| 2802 | struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY); |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2803 | u32 suite; |
| 2804 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2805 | if (!key_attr) |
| 2806 | return -1; |
| 2807 | |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2808 | suite = wpa_alg_to_cipher_suite(alg, key_len); |
| 2809 | if (!suite) |
| 2810 | return -1; |
| 2811 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2812 | if (defkey && alg == WPA_ALG_IGTK) { |
| 2813 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT)) |
| 2814 | return -1; |
| 2815 | } else if (defkey) { |
| 2816 | if (nla_put_flag(msg, NL80211_KEY_DEFAULT)) |
| 2817 | return -1; |
| 2818 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2819 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2820 | if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 2821 | nla_put_u32(msg, NL80211_KEY_CIPHER, suite) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2822 | (seq && seq_len && |
| 2823 | nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) || |
| 2824 | nla_put(msg, NL80211_KEY_DATA, key_len, key)) |
| 2825 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2826 | |
| 2827 | nla_nest_end(msg, key_attr); |
| 2828 | |
| 2829 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2830 | } |
| 2831 | |
| 2832 | |
| 2833 | static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params, |
| 2834 | struct nl_msg *msg) |
| 2835 | { |
| 2836 | int i, privacy = 0; |
| 2837 | struct nlattr *nl_keys, *nl_key; |
| 2838 | |
| 2839 | for (i = 0; i < 4; i++) { |
| 2840 | if (!params->wep_key[i]) |
| 2841 | continue; |
| 2842 | privacy = 1; |
| 2843 | break; |
| 2844 | } |
| 2845 | if (params->wps == WPS_MODE_PRIVACY) |
| 2846 | privacy = 1; |
| 2847 | if (params->pairwise_suite && |
| 2848 | params->pairwise_suite != WPA_CIPHER_NONE) |
| 2849 | privacy = 1; |
| 2850 | |
| 2851 | if (!privacy) |
| 2852 | return 0; |
| 2853 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2854 | if (nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 2855 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2856 | |
| 2857 | nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS); |
| 2858 | if (!nl_keys) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2859 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2860 | |
| 2861 | for (i = 0; i < 4; i++) { |
| 2862 | if (!params->wep_key[i]) |
| 2863 | continue; |
| 2864 | |
| 2865 | nl_key = nla_nest_start(msg, i); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2866 | if (!nl_key || |
| 2867 | nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i], |
| 2868 | params->wep_key[i]) || |
| 2869 | nla_put_u32(msg, NL80211_KEY_CIPHER, |
| 2870 | params->wep_key_len[i] == 5 ? |
| 2871 | WLAN_CIPHER_SUITE_WEP40 : |
| 2872 | WLAN_CIPHER_SUITE_WEP104) || |
| 2873 | nla_put_u8(msg, NL80211_KEY_IDX, i) || |
| 2874 | (i == params->wep_tx_keyidx && |
| 2875 | nla_put_flag(msg, NL80211_KEY_DEFAULT))) |
| 2876 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2877 | |
| 2878 | nla_nest_end(msg, nl_key); |
| 2879 | } |
| 2880 | nla_nest_end(msg, nl_keys); |
| 2881 | |
| 2882 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2883 | } |
| 2884 | |
| 2885 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2886 | int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv, |
| 2887 | const u8 *addr, int cmd, u16 reason_code, |
| 2888 | int local_state_change) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2889 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2890 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2891 | struct nl_msg *msg; |
| 2892 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2893 | if (!(msg = nl80211_drv_msg(drv, 0, cmd)) || |
| 2894 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) || |
| 2895 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 2896 | (local_state_change && |
| 2897 | nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) { |
| 2898 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2899 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2900 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2901 | |
| 2902 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2903 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2904 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 2905 | "nl80211: MLME command failed: reason=%u ret=%d (%s)", |
| 2906 | reason_code, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2907 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2908 | return ret; |
| 2909 | } |
| 2910 | |
| 2911 | |
| 2912 | static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2913 | int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2914 | { |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2915 | int ret; |
| 2916 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2917 | wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2918 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2919 | /* Disconnect command doesn't need BSSID - it uses cached value */ |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 2920 | ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT, |
| 2921 | reason_code, 0); |
| 2922 | /* |
| 2923 | * For locally generated disconnect, supplicant already generates a |
| 2924 | * DEAUTH event, so ignore the event from NL80211. |
| 2925 | */ |
| 2926 | drv->ignore_next_local_disconnect = ret == 0; |
| 2927 | |
| 2928 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2929 | } |
| 2930 | |
| 2931 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 2932 | static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss, |
| 2933 | const u8 *addr, int reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2934 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2935 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2936 | int ret; |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 2937 | |
| 2938 | if (drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 2939 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 2940 | return nl80211_leave_ibss(drv, 1); |
Dmitry Shmidt | 413dde7 | 2014-04-11 10:23:22 -0700 | [diff] [blame] | 2941 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2942 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 2943 | return wpa_driver_nl80211_disconnect(drv, reason_code); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2944 | wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)", |
| 2945 | __func__, MAC2STR(addr), reason_code); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 2946 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 2947 | ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE, |
| 2948 | reason_code, 0); |
| 2949 | /* |
| 2950 | * For locally generated deauthenticate, supplicant already generates a |
| 2951 | * DEAUTH event, so ignore the event from NL80211. |
| 2952 | */ |
| 2953 | drv->ignore_next_local_deauth = ret == 0; |
| 2954 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 2955 | } |
| 2956 | |
| 2957 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 2958 | static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv, |
| 2959 | struct wpa_driver_auth_params *params) |
| 2960 | { |
| 2961 | int i; |
| 2962 | |
| 2963 | drv->auth_freq = params->freq; |
| 2964 | drv->auth_alg = params->auth_alg; |
| 2965 | drv->auth_wep_tx_keyidx = params->wep_tx_keyidx; |
| 2966 | drv->auth_local_state_change = params->local_state_change; |
| 2967 | drv->auth_p2p = params->p2p; |
| 2968 | |
| 2969 | if (params->bssid) |
| 2970 | os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN); |
| 2971 | else |
| 2972 | os_memset(drv->auth_bssid_, 0, ETH_ALEN); |
| 2973 | |
| 2974 | if (params->ssid) { |
| 2975 | os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len); |
| 2976 | drv->auth_ssid_len = params->ssid_len; |
| 2977 | } else |
| 2978 | drv->auth_ssid_len = 0; |
| 2979 | |
| 2980 | |
| 2981 | os_free(drv->auth_ie); |
| 2982 | drv->auth_ie = NULL; |
| 2983 | drv->auth_ie_len = 0; |
| 2984 | if (params->ie) { |
| 2985 | drv->auth_ie = os_malloc(params->ie_len); |
| 2986 | if (drv->auth_ie) { |
| 2987 | os_memcpy(drv->auth_ie, params->ie, params->ie_len); |
| 2988 | drv->auth_ie_len = params->ie_len; |
| 2989 | } |
| 2990 | } |
| 2991 | |
| 2992 | for (i = 0; i < 4; i++) { |
| 2993 | if (params->wep_key[i] && params->wep_key_len[i] && |
| 2994 | params->wep_key_len[i] <= 16) { |
| 2995 | os_memcpy(drv->auth_wep_key[i], params->wep_key[i], |
| 2996 | params->wep_key_len[i]); |
| 2997 | drv->auth_wep_key_len[i] = params->wep_key_len[i]; |
| 2998 | } else |
| 2999 | drv->auth_wep_key_len[i] = 0; |
| 3000 | } |
| 3001 | } |
| 3002 | |
| 3003 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3004 | static void nl80211_unmask_11b_rates(struct i802_bss *bss) |
| 3005 | { |
| 3006 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3007 | |
| 3008 | if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates) |
| 3009 | return; |
| 3010 | |
| 3011 | /* |
| 3012 | * Looks like we failed to unmask 11b rates previously. This could |
| 3013 | * happen, e.g., if the interface was down at the point in time when a |
| 3014 | * P2P group was terminated. |
| 3015 | */ |
| 3016 | wpa_printf(MSG_DEBUG, |
| 3017 | "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them", |
| 3018 | bss->ifname); |
| 3019 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
| 3020 | } |
| 3021 | |
| 3022 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3023 | static int wpa_driver_nl80211_authenticate( |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3024 | struct i802_bss *bss, struct wpa_driver_auth_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3025 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3026 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3027 | int ret = -1, i; |
| 3028 | struct nl_msg *msg; |
| 3029 | enum nl80211_auth_type type; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3030 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3031 | int count = 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3032 | int is_retry; |
| 3033 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3034 | nl80211_unmask_11b_rates(bss); |
| 3035 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3036 | is_retry = drv->retry_auth; |
| 3037 | drv->retry_auth = 0; |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3038 | drv->ignore_deauth_event = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3039 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3040 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3041 | os_memset(drv->auth_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3042 | if (params->bssid) |
| 3043 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 3044 | else |
| 3045 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3046 | /* FIX: IBSS mode */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3047 | nlmode = params->p2p ? |
| 3048 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 3049 | if (drv->nlmode != nlmode && |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3050 | wpa_driver_nl80211_set_mode(bss, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3051 | return -1; |
| 3052 | |
| 3053 | retry: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3054 | wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)", |
| 3055 | drv->ifindex); |
| 3056 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3057 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE); |
| 3058 | if (!msg) |
| 3059 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3060 | |
| 3061 | for (i = 0; i < 4; i++) { |
| 3062 | if (!params->wep_key[i]) |
| 3063 | continue; |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3064 | wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3065 | NULL, i, |
| 3066 | i == params->wep_tx_keyidx, NULL, 0, |
| 3067 | params->wep_key[i], |
| 3068 | params->wep_key_len[i]); |
| 3069 | if (params->wep_tx_keyidx != i) |
| 3070 | continue; |
| 3071 | if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3072 | params->wep_key[i], params->wep_key_len[i])) |
| 3073 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3074 | } |
| 3075 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3076 | if (params->bssid) { |
| 3077 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 3078 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3079 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 3080 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3081 | } |
| 3082 | if (params->freq) { |
| 3083 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3084 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq)) |
| 3085 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3086 | } |
| 3087 | if (params->ssid) { |
| 3088 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 3089 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3090 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 3091 | params->ssid)) |
| 3092 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3093 | } |
| 3094 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3095 | if (params->ie && |
| 3096 | nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie)) |
| 3097 | goto fail; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame^] | 3098 | if (params->auth_data) { |
| 3099 | wpa_hexdump(MSG_DEBUG, " * auth_data", params->auth_data, |
| 3100 | params->auth_data_len); |
| 3101 | if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->auth_data_len, |
| 3102 | params->auth_data)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3103 | goto fail; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3104 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3105 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 3106 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 3107 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 3108 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 3109 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 3110 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 3111 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 3112 | type = NL80211_AUTHTYPE_FT; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 3113 | else if (params->auth_alg & WPA_AUTH_ALG_SAE) |
| 3114 | type = NL80211_AUTHTYPE_SAE; |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame^] | 3115 | else if (params->auth_alg & WPA_AUTH_ALG_FILS) |
| 3116 | type = NL80211_AUTHTYPE_FILS_SK; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3117 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3118 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3119 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3120 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 3121 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3122 | if (params->local_state_change) { |
| 3123 | wpa_printf(MSG_DEBUG, " * Local state change only"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3124 | if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE)) |
| 3125 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3126 | } |
| 3127 | |
| 3128 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3129 | msg = NULL; |
| 3130 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3131 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 3132 | "nl80211: MLME command failed (auth): ret=%d (%s)", |
| 3133 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3134 | count++; |
| 3135 | if (ret == -EALREADY && count == 1 && params->bssid && |
| 3136 | !params->local_state_change) { |
| 3137 | /* |
| 3138 | * mac80211 does not currently accept new |
| 3139 | * authentication if we are already authenticated. As a |
| 3140 | * workaround, force deauthentication and try again. |
| 3141 | */ |
| 3142 | wpa_printf(MSG_DEBUG, "nl80211: Retry authentication " |
| 3143 | "after forced deauthentication"); |
Dmitry Shmidt | 9866086 | 2014-03-11 17:26:21 -0700 | [diff] [blame] | 3144 | drv->ignore_deauth_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3145 | wpa_driver_nl80211_deauthenticate( |
| 3146 | bss, params->bssid, |
| 3147 | WLAN_REASON_PREV_AUTH_NOT_VALID); |
| 3148 | nlmsg_free(msg); |
| 3149 | goto retry; |
| 3150 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3151 | |
| 3152 | if (ret == -ENOENT && params->freq && !is_retry) { |
| 3153 | /* |
| 3154 | * cfg80211 has likely expired the BSS entry even |
| 3155 | * though it was previously available in our internal |
| 3156 | * BSS table. To recover quickly, start a single |
| 3157 | * channel scan on the specified channel. |
| 3158 | */ |
| 3159 | struct wpa_driver_scan_params scan; |
| 3160 | int freqs[2]; |
| 3161 | |
| 3162 | os_memset(&scan, 0, sizeof(scan)); |
| 3163 | scan.num_ssids = 1; |
| 3164 | if (params->ssid) { |
| 3165 | scan.ssids[0].ssid = params->ssid; |
| 3166 | scan.ssids[0].ssid_len = params->ssid_len; |
| 3167 | } |
| 3168 | freqs[0] = params->freq; |
| 3169 | freqs[1] = 0; |
| 3170 | scan.freqs = freqs; |
| 3171 | wpa_printf(MSG_DEBUG, "nl80211: Trigger single " |
| 3172 | "channel scan to refresh cfg80211 BSS " |
| 3173 | "entry"); |
| 3174 | ret = wpa_driver_nl80211_scan(bss, &scan); |
| 3175 | if (ret == 0) { |
| 3176 | nl80211_copy_auth_params(drv, params); |
| 3177 | drv->scan_for_auth = 1; |
| 3178 | } |
| 3179 | } else if (is_retry) { |
| 3180 | /* |
| 3181 | * Need to indicate this with an event since the return |
| 3182 | * value from the retry is not delivered to core code. |
| 3183 | */ |
| 3184 | union wpa_event_data event; |
| 3185 | wpa_printf(MSG_DEBUG, "nl80211: Authentication retry " |
| 3186 | "failed"); |
| 3187 | os_memset(&event, 0, sizeof(event)); |
| 3188 | os_memcpy(event.timeout_event.addr, drv->auth_bssid_, |
| 3189 | ETH_ALEN); |
| 3190 | wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT, |
| 3191 | &event); |
| 3192 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3193 | } else { |
| 3194 | wpa_printf(MSG_DEBUG, |
| 3195 | "nl80211: Authentication request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3196 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3197 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3198 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3199 | nlmsg_free(msg); |
| 3200 | return ret; |
| 3201 | } |
| 3202 | |
| 3203 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3204 | int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3205 | { |
| 3206 | struct wpa_driver_auth_params params; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 3207 | struct i802_bss *bss = drv->first_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3208 | int i; |
| 3209 | |
| 3210 | wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again"); |
| 3211 | |
| 3212 | os_memset(¶ms, 0, sizeof(params)); |
| 3213 | params.freq = drv->auth_freq; |
| 3214 | params.auth_alg = drv->auth_alg; |
| 3215 | params.wep_tx_keyidx = drv->auth_wep_tx_keyidx; |
| 3216 | params.local_state_change = drv->auth_local_state_change; |
| 3217 | params.p2p = drv->auth_p2p; |
| 3218 | |
| 3219 | if (!is_zero_ether_addr(drv->auth_bssid_)) |
| 3220 | params.bssid = drv->auth_bssid_; |
| 3221 | |
| 3222 | if (drv->auth_ssid_len) { |
| 3223 | params.ssid = drv->auth_ssid; |
| 3224 | params.ssid_len = drv->auth_ssid_len; |
| 3225 | } |
| 3226 | |
| 3227 | params.ie = drv->auth_ie; |
| 3228 | params.ie_len = drv->auth_ie_len; |
| 3229 | |
| 3230 | for (i = 0; i < 4; i++) { |
| 3231 | if (drv->auth_wep_key_len[i]) { |
| 3232 | params.wep_key[i] = drv->auth_wep_key[i]; |
| 3233 | params.wep_key_len[i] = drv->auth_wep_key_len[i]; |
| 3234 | } |
| 3235 | } |
| 3236 | |
| 3237 | drv->retry_auth = 1; |
| 3238 | return wpa_driver_nl80211_authenticate(bss, ¶ms); |
| 3239 | } |
| 3240 | |
| 3241 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3242 | static int wpa_driver_nl80211_send_frame(struct i802_bss *bss, |
| 3243 | const void *data, size_t len, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3244 | int encrypt, int noack, |
| 3245 | unsigned int freq, int no_cck, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3246 | int offchanok, unsigned int wait_time, |
| 3247 | const u16 *csa_offs, |
| 3248 | size_t csa_offs_len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3249 | { |
| 3250 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3251 | u64 cookie; |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3252 | int res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3253 | |
Dmitry Shmidt | 6dc03bd | 2014-05-16 10:40:13 -0700 | [diff] [blame] | 3254 | if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) { |
| 3255 | freq = nl80211_get_assoc_freq(drv); |
| 3256 | wpa_printf(MSG_DEBUG, |
| 3257 | "nl80211: send_frame - Use assoc_freq=%u for IBSS", |
| 3258 | freq); |
| 3259 | } |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3260 | if (freq == 0) { |
| 3261 | wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u", |
| 3262 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3263 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3264 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3265 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3266 | if (drv->use_monitor) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3267 | 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] | 3268 | freq, bss->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3269 | return nl80211_send_monitor(drv, data, len, encrypt, noack); |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3270 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3271 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3272 | wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd"); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3273 | res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3274 | &cookie, no_cck, noack, offchanok, |
| 3275 | csa_offs, csa_offs_len); |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 3276 | if (res == 0 && !noack) { |
| 3277 | const struct ieee80211_mgmt *mgmt; |
| 3278 | u16 fc; |
| 3279 | |
| 3280 | mgmt = (const struct ieee80211_mgmt *) data; |
| 3281 | fc = le_to_host16(mgmt->frame_control); |
| 3282 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3283 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) { |
| 3284 | wpa_printf(MSG_MSGDUMP, |
| 3285 | "nl80211: Update send_action_cookie from 0x%llx to 0x%llx", |
| 3286 | (long long unsigned int) |
| 3287 | drv->send_action_cookie, |
| 3288 | (long long unsigned int) cookie); |
| 3289 | drv->send_action_cookie = cookie; |
| 3290 | } |
| 3291 | } |
| 3292 | |
| 3293 | return res; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3294 | } |
| 3295 | |
| 3296 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 3297 | static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data, |
| 3298 | size_t data_len, int noack, |
| 3299 | unsigned int freq, int no_cck, |
| 3300 | int offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3301 | unsigned int wait_time, |
| 3302 | const u16 *csa_offs, |
| 3303 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3304 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3305 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3306 | struct ieee80211_mgmt *mgmt; |
| 3307 | int encrypt = 1; |
| 3308 | u16 fc; |
| 3309 | |
| 3310 | mgmt = (struct ieee80211_mgmt *) data; |
| 3311 | fc = le_to_host16(mgmt->frame_control); |
Dmitry Shmidt | 2271d3f | 2014-06-23 12:16:31 -0700 | [diff] [blame] | 3312 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR |
| 3313 | " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d", |
| 3314 | MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time, |
| 3315 | fc, fc2str(fc), drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3316 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 3317 | if ((is_sta_interface(drv->nlmode) || |
| 3318 | drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) && |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3319 | WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3320 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) { |
| 3321 | /* |
| 3322 | * The use of last_mgmt_freq is a bit of a hack, |
| 3323 | * but it works due to the single-threaded nature |
| 3324 | * of wpa_supplicant. |
| 3325 | */ |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3326 | if (freq == 0) { |
| 3327 | wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d", |
| 3328 | drv->last_mgmt_freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3329 | freq = drv->last_mgmt_freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3330 | } |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3331 | return nl80211_send_frame_cmd(bss, freq, 0, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3332 | data, data_len, NULL, 1, noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3333 | 1, csa_offs, csa_offs_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3334 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3335 | |
| 3336 | if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) { |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3337 | if (freq == 0) { |
| 3338 | wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d", |
| 3339 | bss->freq); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3340 | freq = bss->freq; |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3341 | } |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3342 | return nl80211_send_frame_cmd(bss, freq, |
| 3343 | (int) freq == bss->freq ? 0 : |
| 3344 | wait_time, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3345 | data, data_len, |
| 3346 | &drv->send_action_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3347 | no_cck, noack, offchanok, |
| 3348 | csa_offs, csa_offs_len); |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 3349 | } |
Dmitry Shmidt | b638fe7 | 2012-03-20 12:51:25 -0700 | [diff] [blame] | 3350 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3351 | if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT && |
| 3352 | WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) { |
| 3353 | /* |
| 3354 | * Only one of the authentication frame types is encrypted. |
| 3355 | * In order for static WEP encryption to work properly (i.e., |
| 3356 | * to not encrypt the frame), we need to tell mac80211 about |
| 3357 | * the frames that must not be encrypted. |
| 3358 | */ |
| 3359 | u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg); |
| 3360 | u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction); |
| 3361 | if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3) |
| 3362 | encrypt = 0; |
| 3363 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3364 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 3365 | wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3366 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3367 | noack, freq, no_cck, offchanok, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3368 | wait_time, csa_offs, |
| 3369 | csa_offs_len); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 3370 | } |
| 3371 | |
| 3372 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3373 | static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates) |
| 3374 | { |
| 3375 | u8 rates[NL80211_MAX_SUPP_RATES]; |
| 3376 | u8 rates_len = 0; |
| 3377 | int i; |
| 3378 | |
| 3379 | if (!basic_rates) |
| 3380 | return 0; |
| 3381 | |
| 3382 | for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++) |
| 3383 | rates[rates_len++] = basic_rates[i] / 5; |
| 3384 | |
| 3385 | return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates); |
| 3386 | } |
| 3387 | |
| 3388 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3389 | static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble, |
| 3390 | int slot, int ht_opmode, int ap_isolate, |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3391 | const int *basic_rates) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3392 | { |
| 3393 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3394 | struct nl_msg *msg; |
| 3395 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3396 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) || |
| 3397 | (cts >= 0 && |
| 3398 | nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) || |
| 3399 | (preamble >= 0 && |
| 3400 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) || |
| 3401 | (slot >= 0 && |
| 3402 | nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) || |
| 3403 | (ht_opmode >= 0 && |
| 3404 | nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) || |
| 3405 | (ap_isolate >= 0 && |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3406 | nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) || |
| 3407 | nl80211_put_basic_rates(msg, basic_rates)) { |
| 3408 | nlmsg_free(msg); |
| 3409 | return -ENOBUFS; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3410 | } |
| 3411 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3412 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3413 | } |
| 3414 | |
| 3415 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3416 | static int wpa_driver_nl80211_set_acl(void *priv, |
| 3417 | struct hostapd_acl_params *params) |
| 3418 | { |
| 3419 | struct i802_bss *bss = priv; |
| 3420 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3421 | struct nl_msg *msg; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3422 | struct nl_msg *acl; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3423 | unsigned int i; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3424 | int ret; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3425 | |
| 3426 | if (!(drv->capa.max_acl_mac_addrs)) |
| 3427 | return -ENOTSUP; |
| 3428 | |
| 3429 | if (params->num_mac_acl > drv->capa.max_acl_mac_addrs) |
| 3430 | return -ENOTSUP; |
| 3431 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3432 | wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)", |
| 3433 | params->acl_policy ? "Accept" : "Deny", params->num_mac_acl); |
| 3434 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3435 | acl = nlmsg_alloc(); |
| 3436 | if (!acl) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3437 | return -ENOMEM; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3438 | for (i = 0; i < params->num_mac_acl; i++) { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3439 | if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) { |
| 3440 | nlmsg_free(acl); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3441 | return -ENOMEM; |
| 3442 | } |
| 3443 | } |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3444 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 3445 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) || |
| 3446 | nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ? |
| 3447 | NL80211_ACL_POLICY_DENY_UNLESS_LISTED : |
| 3448 | NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) || |
| 3449 | nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) { |
| 3450 | nlmsg_free(msg); |
| 3451 | nlmsg_free(acl); |
| 3452 | return -ENOMEM; |
| 3453 | } |
| 3454 | nlmsg_free(acl); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3455 | |
| 3456 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3457 | if (ret) { |
| 3458 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)", |
| 3459 | ret, strerror(-ret)); |
| 3460 | } |
| 3461 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 3462 | return ret; |
| 3463 | } |
| 3464 | |
| 3465 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3466 | static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int) |
| 3467 | { |
| 3468 | if (beacon_int > 0) { |
| 3469 | wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int); |
| 3470 | return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL, |
| 3471 | beacon_int); |
| 3472 | } |
| 3473 | |
| 3474 | return 0; |
| 3475 | } |
| 3476 | |
| 3477 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3478 | static int nl80211_put_dtim_period(struct nl_msg *msg, int dtim_period) |
| 3479 | { |
| 3480 | if (dtim_period > 0) { |
| 3481 | wpa_printf(MSG_DEBUG, " * dtim_period=%d", dtim_period); |
| 3482 | return nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, dtim_period); |
| 3483 | } |
| 3484 | |
| 3485 | return 0; |
| 3486 | } |
| 3487 | |
| 3488 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3489 | #ifdef CONFIG_MESH |
| 3490 | static int nl80211_set_mesh_config(void *priv, |
| 3491 | struct wpa_driver_mesh_bss_params *params) |
| 3492 | { |
| 3493 | struct i802_bss *bss = priv; |
| 3494 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3495 | struct nl_msg *msg; |
| 3496 | int ret; |
| 3497 | |
| 3498 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MESH_CONFIG); |
| 3499 | if (!msg) |
| 3500 | return -1; |
| 3501 | |
| 3502 | ret = nl80211_put_mesh_config(msg, params); |
| 3503 | if (ret < 0) { |
| 3504 | nlmsg_free(msg); |
| 3505 | return ret; |
| 3506 | } |
| 3507 | |
| 3508 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3509 | if (ret) { |
| 3510 | wpa_printf(MSG_ERROR, |
| 3511 | "nl80211: Mesh config set failed: %d (%s)", |
| 3512 | ret, strerror(-ret)); |
| 3513 | return ret; |
| 3514 | } |
| 3515 | return 0; |
| 3516 | } |
| 3517 | #endif /* CONFIG_MESH */ |
| 3518 | |
| 3519 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3520 | static int wpa_driver_nl80211_set_ap(void *priv, |
| 3521 | struct wpa_driver_ap_params *params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3522 | { |
| 3523 | struct i802_bss *bss = priv; |
| 3524 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3525 | struct nl_msg *msg; |
| 3526 | u8 cmd = NL80211_CMD_NEW_BEACON; |
| 3527 | int ret; |
| 3528 | int beacon_set; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3529 | int num_suites; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3530 | int smps_mode; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3531 | u32 suites[10], suite; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3532 | u32 ver; |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3533 | #ifdef CONFIG_MESH |
| 3534 | struct wpa_driver_mesh_bss_params mesh_params; |
| 3535 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3536 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3537 | beacon_set = params->reenable ? 0 : bss->beacon_set; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3538 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3539 | wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)", |
| 3540 | beacon_set); |
| 3541 | if (beacon_set) |
| 3542 | cmd = NL80211_CMD_SET_BEACON; |
| 3543 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3544 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head", |
| 3545 | params->head, params->head_len); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3546 | wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail", |
| 3547 | params->tail, params->tail_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3548 | wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3549 | wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3550 | wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period); |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3551 | wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid", |
| 3552 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3553 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 3554 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len, |
| 3555 | params->head) || |
| 3556 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len, |
| 3557 | params->tail) || |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3558 | nl80211_put_beacon_int(msg, params->beacon_int) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3559 | nl80211_put_dtim_period(msg, params->dtim_period) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3560 | nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 3561 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3562 | if (params->proberesp && params->proberesp_len) { |
| 3563 | wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)", |
| 3564 | params->proberesp, params->proberesp_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3565 | if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len, |
| 3566 | params->proberesp)) |
| 3567 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3568 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3569 | switch (params->hide_ssid) { |
| 3570 | case NO_SSID_HIDING: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3571 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3572 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3573 | NL80211_HIDDEN_SSID_NOT_IN_USE)) |
| 3574 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3575 | break; |
| 3576 | case HIDDEN_SSID_ZERO_LEN: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3577 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3578 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3579 | NL80211_HIDDEN_SSID_ZERO_LEN)) |
| 3580 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3581 | break; |
| 3582 | case HIDDEN_SSID_ZERO_CONTENTS: |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3583 | wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3584 | if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID, |
| 3585 | NL80211_HIDDEN_SSID_ZERO_CONTENTS)) |
| 3586 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3587 | break; |
| 3588 | } |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3589 | wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3590 | if (params->privacy && |
| 3591 | nla_put_flag(msg, NL80211_ATTR_PRIVACY)) |
| 3592 | goto fail; |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3593 | wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3594 | if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) == |
| 3595 | (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) { |
| 3596 | /* Leave out the attribute */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3597 | } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) { |
| 3598 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 3599 | NL80211_AUTHTYPE_SHARED_KEY)) |
| 3600 | goto fail; |
| 3601 | } else { |
| 3602 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, |
| 3603 | NL80211_AUTHTYPE_OPEN_SYSTEM)) |
| 3604 | goto fail; |
| 3605 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3606 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3607 | wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3608 | ver = 0; |
| 3609 | if (params->wpa_version & WPA_PROTO_WPA) |
| 3610 | ver |= NL80211_WPA_VERSION_1; |
| 3611 | if (params->wpa_version & WPA_PROTO_RSN) |
| 3612 | ver |= NL80211_WPA_VERSION_2; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3613 | if (ver && |
| 3614 | nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 3615 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3616 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3617 | wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x", |
| 3618 | params->key_mgmt_suites); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3619 | num_suites = 0; |
| 3620 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X) |
| 3621 | suites[num_suites++] = WLAN_AKM_SUITE_8021X; |
| 3622 | if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK) |
| 3623 | suites[num_suites++] = WLAN_AKM_SUITE_PSK; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3624 | if (num_suites && |
| 3625 | nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32), |
| 3626 | suites)) |
| 3627 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3628 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3629 | if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3630 | (!params->pairwise_ciphers || |
| 3631 | params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) && |
| 3632 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 3633 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3634 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3635 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3636 | wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x", |
| 3637 | params->pairwise_ciphers); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3638 | num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers, |
| 3639 | suites, ARRAY_SIZE(suites)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3640 | if (num_suites && |
| 3641 | nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 3642 | num_suites * sizeof(u32), suites)) |
| 3643 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3644 | |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3645 | wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x", |
| 3646 | params->group_cipher); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 3647 | suite = wpa_cipher_to_cipher_suite(params->group_cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3648 | if (suite && |
| 3649 | nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite)) |
| 3650 | goto fail; |
| 3651 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 3652 | if (params->ht_opmode != -1) { |
| 3653 | switch (params->smps_mode) { |
| 3654 | case HT_CAP_INFO_SMPS_DYNAMIC: |
| 3655 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic"); |
| 3656 | smps_mode = NL80211_SMPS_DYNAMIC; |
| 3657 | break; |
| 3658 | case HT_CAP_INFO_SMPS_STATIC: |
| 3659 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static"); |
| 3660 | smps_mode = NL80211_SMPS_STATIC; |
| 3661 | break; |
| 3662 | default: |
| 3663 | /* invalid - fallback to smps off */ |
| 3664 | case HT_CAP_INFO_SMPS_DISABLED: |
| 3665 | wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off"); |
| 3666 | smps_mode = NL80211_SMPS_OFF; |
| 3667 | break; |
| 3668 | } |
| 3669 | if (nla_put_u32(msg, NL80211_ATTR_SMPS_MODE, smps_mode)) |
| 3670 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3671 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3672 | |
| 3673 | if (params->beacon_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3674 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies", |
| 3675 | params->beacon_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3676 | if (nla_put(msg, NL80211_ATTR_IE, |
| 3677 | wpabuf_len(params->beacon_ies), |
| 3678 | wpabuf_head(params->beacon_ies))) |
| 3679 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3680 | } |
| 3681 | if (params->proberesp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3682 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies", |
| 3683 | params->proberesp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3684 | if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 3685 | wpabuf_len(params->proberesp_ies), |
| 3686 | wpabuf_head(params->proberesp_ies))) |
| 3687 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3688 | } |
| 3689 | if (params->assocresp_ies) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3690 | wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies", |
| 3691 | params->assocresp_ies); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3692 | if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 3693 | wpabuf_len(params->assocresp_ies), |
| 3694 | wpabuf_head(params->assocresp_ies))) |
| 3695 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3696 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3697 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3698 | if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) { |
Dmitry Shmidt | 0ccb66e | 2013-03-29 16:41:28 -0700 | [diff] [blame] | 3699 | wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d", |
| 3700 | params->ap_max_inactivity); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3701 | if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT, |
| 3702 | params->ap_max_inactivity)) |
| 3703 | goto fail; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 3704 | } |
| 3705 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 3706 | #ifdef CONFIG_P2P |
| 3707 | if (params->p2p_go_ctwindow > 0) { |
| 3708 | if (drv->p2p_go_ctwindow_supported) { |
| 3709 | wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d", |
| 3710 | params->p2p_go_ctwindow); |
| 3711 | if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW, |
| 3712 | params->p2p_go_ctwindow)) |
| 3713 | goto fail; |
| 3714 | } else { |
| 3715 | wpa_printf(MSG_INFO, |
| 3716 | "nl80211: Driver does not support CTWindow configuration - ignore this parameter"); |
| 3717 | } |
| 3718 | } |
| 3719 | #endif /* CONFIG_P2P */ |
| 3720 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3721 | if (params->pbss) { |
| 3722 | wpa_printf(MSG_DEBUG, "nl80211: PBSS"); |
| 3723 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 3724 | goto fail; |
| 3725 | } |
| 3726 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3727 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 3728 | if (ret) { |
| 3729 | wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)", |
| 3730 | ret, strerror(-ret)); |
| 3731 | } else { |
| 3732 | bss->beacon_set = 1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3733 | nl80211_set_bss(bss, params->cts_protect, params->preamble, |
| 3734 | params->short_slot_time, params->ht_opmode, |
| 3735 | params->isolate, params->basic_rates); |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3736 | if (beacon_set && params->freq && |
| 3737 | params->freq->bandwidth != bss->bandwidth) { |
| 3738 | wpa_printf(MSG_DEBUG, |
| 3739 | "nl80211: Update BSS %s bandwidth: %d -> %d", |
| 3740 | bss->ifname, bss->bandwidth, |
| 3741 | params->freq->bandwidth); |
| 3742 | ret = nl80211_set_channel(bss, params->freq, 1); |
| 3743 | if (ret) { |
| 3744 | wpa_printf(MSG_DEBUG, |
| 3745 | "nl80211: Frequency set failed: %d (%s)", |
| 3746 | ret, strerror(-ret)); |
| 3747 | } else { |
| 3748 | wpa_printf(MSG_DEBUG, |
| 3749 | "nl80211: Frequency set succeeded for ht2040 coex"); |
| 3750 | bss->bandwidth = params->freq->bandwidth; |
| 3751 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3752 | } else if (!beacon_set && params->freq) { |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3753 | /* |
| 3754 | * cfg80211 updates the driver on frequence change in AP |
| 3755 | * mode only at the point when beaconing is started, so |
| 3756 | * set the initial value here. |
| 3757 | */ |
| 3758 | bss->bandwidth = params->freq->bandwidth; |
| 3759 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3760 | } |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 3761 | |
| 3762 | #ifdef CONFIG_MESH |
| 3763 | if (is_mesh_interface(drv->nlmode) && params->ht_opmode != -1) { |
| 3764 | os_memset(&mesh_params, 0, sizeof(mesh_params)); |
| 3765 | mesh_params.flags |= WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE; |
| 3766 | mesh_params.ht_opmode = params->ht_opmode; |
| 3767 | ret = nl80211_set_mesh_config(priv, &mesh_params); |
| 3768 | if (ret < 0) |
| 3769 | return ret; |
| 3770 | } |
| 3771 | #endif /* CONFIG_MESH */ |
| 3772 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3773 | return ret; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3774 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3775 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3776 | return -ENOBUFS; |
| 3777 | } |
| 3778 | |
| 3779 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3780 | static int nl80211_put_freq_params(struct nl_msg *msg, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3781 | const struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3782 | { |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3783 | wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3784 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq)) |
| 3785 | return -ENOBUFS; |
| 3786 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3787 | wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled); |
| 3788 | wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled); |
| 3789 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3790 | if (freq->vht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3791 | enum nl80211_chan_width cw; |
| 3792 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3793 | wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3794 | switch (freq->bandwidth) { |
| 3795 | case 20: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3796 | cw = NL80211_CHAN_WIDTH_20; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3797 | break; |
| 3798 | case 40: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3799 | cw = NL80211_CHAN_WIDTH_40; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3800 | break; |
| 3801 | case 80: |
| 3802 | if (freq->center_freq2) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3803 | cw = NL80211_CHAN_WIDTH_80P80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3804 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3805 | cw = NL80211_CHAN_WIDTH_80; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3806 | break; |
| 3807 | case 160: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3808 | cw = NL80211_CHAN_WIDTH_160; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3809 | break; |
| 3810 | default: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3811 | return -EINVAL; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3812 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3813 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3814 | wpa_printf(MSG_DEBUG, " * channel_width=%d", cw); |
| 3815 | wpa_printf(MSG_DEBUG, " * center_freq1=%d", |
| 3816 | freq->center_freq1); |
| 3817 | wpa_printf(MSG_DEBUG, " * center_freq2=%d", |
| 3818 | freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3819 | if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) || |
| 3820 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1, |
| 3821 | freq->center_freq1) || |
| 3822 | (freq->center_freq2 && |
| 3823 | nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2, |
| 3824 | freq->center_freq2))) |
| 3825 | return -ENOBUFS; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3826 | } else if (freq->ht_enabled) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3827 | enum nl80211_channel_type ct; |
| 3828 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3829 | wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d", |
| 3830 | freq->sec_channel_offset); |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3831 | switch (freq->sec_channel_offset) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3832 | case -1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3833 | ct = NL80211_CHAN_HT40MINUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3834 | break; |
| 3835 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3836 | ct = NL80211_CHAN_HT40PLUS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3837 | break; |
| 3838 | default: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3839 | ct = NL80211_CHAN_HT20; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3840 | break; |
| 3841 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3842 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 3843 | wpa_printf(MSG_DEBUG, " * channel_type=%d", ct); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3844 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct)) |
| 3845 | return -ENOBUFS; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3846 | } else { |
| 3847 | wpa_printf(MSG_DEBUG, " * channel_type=%d", |
| 3848 | NL80211_CHAN_NO_HT); |
| 3849 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, |
| 3850 | NL80211_CHAN_NO_HT)) |
| 3851 | return -ENOBUFS; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3852 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3853 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3854 | } |
| 3855 | |
| 3856 | |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 3857 | static int nl80211_set_channel(struct i802_bss *bss, |
| 3858 | struct hostapd_freq_params *freq, int set_chan) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3859 | { |
| 3860 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 3861 | struct nl_msg *msg; |
| 3862 | int ret; |
| 3863 | |
| 3864 | wpa_printf(MSG_DEBUG, |
| 3865 | "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)", |
| 3866 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 3867 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3868 | |
| 3869 | msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL : |
| 3870 | NL80211_CMD_SET_WIPHY); |
| 3871 | if (!msg || nl80211_put_freq_params(msg, freq) < 0) { |
| 3872 | nlmsg_free(msg); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 3873 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3874 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3875 | |
| 3876 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3877 | if (ret == 0) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3878 | bss->freq = freq->freq; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3879 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3880 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3881 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): " |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 3882 | "%d (%s)", freq->freq, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3883 | return -1; |
| 3884 | } |
| 3885 | |
| 3886 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3887 | static u32 sta_flags_nl80211(int flags) |
| 3888 | { |
| 3889 | u32 f = 0; |
| 3890 | |
| 3891 | if (flags & WPA_STA_AUTHORIZED) |
| 3892 | f |= BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 3893 | if (flags & WPA_STA_WMM) |
| 3894 | f |= BIT(NL80211_STA_FLAG_WME); |
| 3895 | if (flags & WPA_STA_SHORT_PREAMBLE) |
| 3896 | f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE); |
| 3897 | if (flags & WPA_STA_MFP) |
| 3898 | f |= BIT(NL80211_STA_FLAG_MFP); |
| 3899 | if (flags & WPA_STA_TDLS_PEER) |
| 3900 | f |= BIT(NL80211_STA_FLAG_TDLS_PEER); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3901 | if (flags & WPA_STA_AUTHENTICATED) |
| 3902 | f |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3903 | if (flags & WPA_STA_ASSOCIATED) |
| 3904 | f |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3905 | |
| 3906 | return f; |
| 3907 | } |
| 3908 | |
| 3909 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3910 | #ifdef CONFIG_MESH |
| 3911 | static u32 sta_plink_state_nl80211(enum mesh_plink_state state) |
| 3912 | { |
| 3913 | switch (state) { |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3914 | case PLINK_IDLE: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3915 | return NL80211_PLINK_LISTEN; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3916 | case PLINK_OPN_SNT: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3917 | return NL80211_PLINK_OPN_SNT; |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 3918 | case PLINK_OPN_RCVD: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3919 | return NL80211_PLINK_OPN_RCVD; |
| 3920 | case PLINK_CNF_RCVD: |
| 3921 | return NL80211_PLINK_CNF_RCVD; |
| 3922 | case PLINK_ESTAB: |
| 3923 | return NL80211_PLINK_ESTAB; |
| 3924 | case PLINK_HOLDING: |
| 3925 | return NL80211_PLINK_HOLDING; |
| 3926 | case PLINK_BLOCKED: |
| 3927 | return NL80211_PLINK_BLOCKED; |
| 3928 | default: |
| 3929 | wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d", |
| 3930 | state); |
| 3931 | } |
| 3932 | return -1; |
| 3933 | } |
| 3934 | #endif /* CONFIG_MESH */ |
| 3935 | |
| 3936 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3937 | static int wpa_driver_nl80211_sta_add(void *priv, |
| 3938 | struct hostapd_sta_add_params *params) |
| 3939 | { |
| 3940 | struct i802_bss *bss = priv; |
| 3941 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 3942 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3943 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3944 | int ret = -ENOBUFS; |
| 3945 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 3946 | if ((params->flags & WPA_STA_TDLS_PEER) && |
| 3947 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 3948 | return -EOPNOTSUPP; |
| 3949 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 3950 | wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR, |
| 3951 | params->set ? "Set" : "Add", MAC2STR(params->addr)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3952 | msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION : |
| 3953 | NL80211_CMD_NEW_STATION); |
| 3954 | if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr)) |
| 3955 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 3956 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 3957 | /* |
| 3958 | * Set the below properties only in one of the following cases: |
| 3959 | * 1. New station is added, already associated. |
| 3960 | * 2. Set WPA_STA_TDLS_PEER station. |
| 3961 | * 3. Set an already added unassociated station, if driver supports |
| 3962 | * full AP client state. (Set these properties after station became |
| 3963 | * associated will be rejected by the driver). |
| 3964 | */ |
| 3965 | if (!params->set || (params->flags & WPA_STA_TDLS_PEER) || |
| 3966 | (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 3967 | (params->flags & WPA_STA_ASSOCIATED))) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 3968 | wpa_hexdump(MSG_DEBUG, " * supported rates", |
| 3969 | params->supp_rates, params->supp_rates_len); |
| 3970 | wpa_printf(MSG_DEBUG, " * capability=0x%x", |
| 3971 | params->capability); |
| 3972 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES, |
| 3973 | params->supp_rates_len, params->supp_rates) || |
| 3974 | nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY, |
| 3975 | params->capability)) |
| 3976 | goto fail; |
| 3977 | |
| 3978 | if (params->ht_capabilities) { |
| 3979 | wpa_hexdump(MSG_DEBUG, " * ht_capabilities", |
| 3980 | (u8 *) params->ht_capabilities, |
| 3981 | sizeof(*params->ht_capabilities)); |
| 3982 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, |
| 3983 | sizeof(*params->ht_capabilities), |
| 3984 | params->ht_capabilities)) |
| 3985 | goto fail; |
| 3986 | } |
| 3987 | |
| 3988 | if (params->vht_capabilities) { |
| 3989 | wpa_hexdump(MSG_DEBUG, " * vht_capabilities", |
| 3990 | (u8 *) params->vht_capabilities, |
| 3991 | sizeof(*params->vht_capabilities)); |
| 3992 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, |
| 3993 | sizeof(*params->vht_capabilities), |
| 3994 | params->vht_capabilities)) |
| 3995 | goto fail; |
| 3996 | } |
| 3997 | |
| 3998 | if (params->ext_capab) { |
| 3999 | wpa_hexdump(MSG_DEBUG, " * ext_capab", |
| 4000 | params->ext_capab, params->ext_capab_len); |
| 4001 | if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY, |
| 4002 | params->ext_capab_len, params->ext_capab)) |
| 4003 | goto fail; |
| 4004 | } |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4005 | |
| 4006 | if (is_ap_interface(drv->nlmode) && |
| 4007 | nla_put_u8(msg, NL80211_ATTR_STA_SUPPORT_P2P_PS, |
| 4008 | params->support_p2p_ps ? |
| 4009 | NL80211_P2P_PS_SUPPORTED : |
| 4010 | NL80211_P2P_PS_UNSUPPORTED)) |
| 4011 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4012 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4013 | if (!params->set) { |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4014 | if (params->aid) { |
| 4015 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4016 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid)) |
| 4017 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4018 | } else { |
| 4019 | /* |
| 4020 | * cfg80211 validates that AID is non-zero, so we have |
| 4021 | * to make this a non-zero value for the TDLS case where |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4022 | * a dummy STA entry is used for now and for a station |
| 4023 | * that is still not associated. |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4024 | */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4025 | wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)", |
| 4026 | (params->flags & WPA_STA_TDLS_PEER) ? |
| 4027 | "TDLS" : "UNASSOC_STA"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4028 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1)) |
| 4029 | goto fail; |
Dmitry Shmidt | 51b6ea8 | 2013-05-08 10:42:09 -0700 | [diff] [blame] | 4030 | } |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4031 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 4032 | params->listen_interval); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4033 | if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 4034 | params->listen_interval)) |
| 4035 | goto fail; |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 4036 | } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) { |
| 4037 | wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4038 | if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid)) |
| 4039 | goto fail; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4040 | } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) && |
| 4041 | (params->flags & WPA_STA_ASSOCIATED)) { |
| 4042 | wpa_printf(MSG_DEBUG, " * aid=%u", params->aid); |
| 4043 | wpa_printf(MSG_DEBUG, " * listen_interval=%u", |
| 4044 | params->listen_interval); |
| 4045 | if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) || |
| 4046 | nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL, |
| 4047 | params->listen_interval)) |
| 4048 | goto fail; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4049 | } |
| 4050 | |
Dmitry Shmidt | bd14a57 | 2014-02-18 10:33:49 -0800 | [diff] [blame] | 4051 | if (params->vht_opmode_enabled) { |
| 4052 | wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4053 | if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF, |
| 4054 | params->vht_opmode)) |
| 4055 | goto fail; |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4056 | } |
| 4057 | |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4058 | if (params->supp_channels) { |
| 4059 | wpa_hexdump(MSG_DEBUG, " * supported channels", |
| 4060 | params->supp_channels, params->supp_channels_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4061 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS, |
| 4062 | params->supp_channels_len, params->supp_channels)) |
| 4063 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4064 | } |
| 4065 | |
| 4066 | if (params->supp_oper_classes) { |
| 4067 | wpa_hexdump(MSG_DEBUG, " * supported operating classes", |
| 4068 | params->supp_oper_classes, |
| 4069 | params->supp_oper_classes_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4070 | if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES, |
| 4071 | params->supp_oper_classes_len, |
| 4072 | params->supp_oper_classes)) |
| 4073 | goto fail; |
Dmitry Shmidt | 344abd3 | 2014-01-14 13:17:00 -0800 | [diff] [blame] | 4074 | } |
| 4075 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4076 | os_memset(&upd, 0, sizeof(upd)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4077 | upd.set = sta_flags_nl80211(params->flags); |
| 4078 | upd.mask = upd.set | sta_flags_nl80211(params->flags_mask); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4079 | |
| 4080 | /* |
| 4081 | * If the driver doesn't support full AP client state, ignore ASSOC/AUTH |
| 4082 | * flags, as nl80211 driver moves a new station, by default, into |
| 4083 | * associated state. |
| 4084 | * |
| 4085 | * On the other hand, if the driver supports that feature and the |
| 4086 | * station is added in unauthenticated state, set the |
| 4087 | * authenticated/associated bits in the mask to prevent moving this |
| 4088 | * station to associated state before it is actually associated. |
| 4089 | * |
| 4090 | * This is irrelevant for mesh mode where the station is added to the |
| 4091 | * driver as authenticated already, and ASSOCIATED isn't part of the |
| 4092 | * nl80211 API. |
| 4093 | */ |
| 4094 | if (!is_mesh_interface(drv->nlmode)) { |
| 4095 | if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) { |
| 4096 | wpa_printf(MSG_DEBUG, |
| 4097 | "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state"); |
| 4098 | upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) | |
| 4099 | BIT(NL80211_STA_FLAG_AUTHENTICATED)); |
| 4100 | } else if (!params->set && |
| 4101 | !(params->flags & WPA_STA_TDLS_PEER)) { |
| 4102 | if (!(params->flags & WPA_STA_AUTHENTICATED)) |
| 4103 | upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED); |
| 4104 | if (!(params->flags & WPA_STA_ASSOCIATED)) |
| 4105 | upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED); |
| 4106 | } |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 4107 | #ifdef CONFIG_MESH |
| 4108 | } else { |
| 4109 | if (params->plink_state == PLINK_ESTAB && params->peer_aid) { |
| 4110 | ret = nla_put_u16(msg, NL80211_ATTR_MESH_PEER_AID, |
| 4111 | params->peer_aid); |
| 4112 | if (ret) |
| 4113 | goto fail; |
| 4114 | } |
| 4115 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4116 | } |
| 4117 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4118 | wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x", |
| 4119 | upd.set, upd.mask); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4120 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 4121 | goto fail; |
| 4122 | |
| 4123 | #ifdef CONFIG_MESH |
| 4124 | if (params->plink_state && |
| 4125 | nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE, |
| 4126 | sta_plink_state_nl80211(params->plink_state))) |
| 4127 | goto fail; |
| 4128 | #endif /* CONFIG_MESH */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4129 | |
| 4130 | if (params->flags & WPA_STA_WMM) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4131 | struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME); |
| 4132 | |
Dmitry Shmidt | f862328 | 2013-02-20 14:34:59 -0800 | [diff] [blame] | 4133 | wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4134 | if (!wme || |
| 4135 | nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES, |
| 4136 | params->qosinfo & WMM_QOSINFO_STA_AC_MASK) || |
| 4137 | nla_put_u8(msg, NL80211_STA_WME_MAX_SP, |
| 4138 | (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) & |
| 4139 | WMM_QOSINFO_STA_SP_MASK)) |
| 4140 | goto fail; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4141 | nla_nest_end(msg, wme); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4142 | } |
| 4143 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4144 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4145 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4146 | if (ret) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4147 | wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION " |
| 4148 | "result: %d (%s)", params->set ? "SET" : "NEW", ret, |
| 4149 | strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4150 | if (ret == -EEXIST) |
| 4151 | ret = 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4152 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4153 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4154 | return ret; |
| 4155 | } |
| 4156 | |
| 4157 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4158 | static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr) |
| 4159 | { |
| 4160 | #ifdef CONFIG_LIBNL3_ROUTE |
| 4161 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4162 | struct rtnl_neigh *rn; |
| 4163 | struct nl_addr *nl_addr; |
| 4164 | int err; |
| 4165 | |
| 4166 | rn = rtnl_neigh_alloc(); |
| 4167 | if (!rn) |
| 4168 | return; |
| 4169 | |
| 4170 | rtnl_neigh_set_family(rn, AF_BRIDGE); |
| 4171 | rtnl_neigh_set_ifindex(rn, bss->ifindex); |
| 4172 | nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN); |
| 4173 | if (!nl_addr) { |
| 4174 | rtnl_neigh_put(rn); |
| 4175 | return; |
| 4176 | } |
| 4177 | rtnl_neigh_set_lladdr(rn, nl_addr); |
| 4178 | |
| 4179 | err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 4180 | if (err < 0) { |
| 4181 | wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for " |
| 4182 | MACSTR " ifindex=%d failed: %s", MAC2STR(addr), |
| 4183 | bss->ifindex, nl_geterror(err)); |
| 4184 | } else { |
| 4185 | wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for " |
| 4186 | MACSTR, MAC2STR(addr)); |
| 4187 | } |
| 4188 | |
| 4189 | nl_addr_put(nl_addr); |
| 4190 | rtnl_neigh_put(rn); |
| 4191 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 4192 | } |
| 4193 | |
| 4194 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4195 | static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr, |
| 4196 | int deauth, u16 reason_code) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4197 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4198 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4199 | struct nl_msg *msg; |
| 4200 | int ret; |
| 4201 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4202 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) || |
| 4203 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 4204 | (deauth == 0 && |
| 4205 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 4206 | WLAN_FC_STYPE_DISASSOC)) || |
| 4207 | (deauth == 1 && |
| 4208 | nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE, |
| 4209 | WLAN_FC_STYPE_DEAUTH)) || |
| 4210 | (reason_code && |
| 4211 | nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) { |
| 4212 | nlmsg_free(msg); |
| 4213 | return -ENOBUFS; |
| 4214 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4215 | |
| 4216 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 4217 | wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR |
| 4218 | " --> %d (%s)", |
| 4219 | bss->ifname, MAC2STR(addr), ret, strerror(-ret)); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4220 | |
| 4221 | if (drv->rtnl_sk) |
| 4222 | rtnl_neigh_delete_fdb_entry(bss, addr); |
| 4223 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4224 | if (ret == -ENOENT) |
| 4225 | return 0; |
| 4226 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4227 | } |
| 4228 | |
| 4229 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4230 | void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4231 | { |
| 4232 | struct nl_msg *msg; |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4233 | struct wpa_driver_nl80211_data *drv2; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4234 | |
| 4235 | wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx); |
| 4236 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4237 | /* stop listening for EAPOL on this interface */ |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4238 | dl_list_for_each(drv2, &drv->global->interfaces, |
| 4239 | struct wpa_driver_nl80211_data, list) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4240 | { |
| 4241 | del_ifidx(drv2, ifidx, IFIDX_ANY); |
| 4242 | /* Remove all bridges learned for this iface */ |
| 4243 | del_ifidx(drv2, IFIDX_ANY, ifidx); |
| 4244 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4245 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4246 | msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4247 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 4248 | return; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4249 | wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx); |
| 4250 | } |
| 4251 | |
| 4252 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 4253 | const char * nl80211_iftype_str(enum nl80211_iftype mode) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4254 | { |
| 4255 | switch (mode) { |
| 4256 | case NL80211_IFTYPE_ADHOC: |
| 4257 | return "ADHOC"; |
| 4258 | case NL80211_IFTYPE_STATION: |
| 4259 | return "STATION"; |
| 4260 | case NL80211_IFTYPE_AP: |
| 4261 | return "AP"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 4262 | case NL80211_IFTYPE_AP_VLAN: |
| 4263 | return "AP_VLAN"; |
| 4264 | case NL80211_IFTYPE_WDS: |
| 4265 | return "WDS"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4266 | case NL80211_IFTYPE_MONITOR: |
| 4267 | return "MONITOR"; |
Dmitry Shmidt | f7e0a99 | 2013-05-23 11:03:10 -0700 | [diff] [blame] | 4268 | case NL80211_IFTYPE_MESH_POINT: |
| 4269 | return "MESH_POINT"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4270 | case NL80211_IFTYPE_P2P_CLIENT: |
| 4271 | return "P2P_CLIENT"; |
| 4272 | case NL80211_IFTYPE_P2P_GO: |
| 4273 | return "P2P_GO"; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4274 | case NL80211_IFTYPE_P2P_DEVICE: |
| 4275 | return "P2P_DEVICE"; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4276 | default: |
| 4277 | return "unknown"; |
| 4278 | } |
| 4279 | } |
| 4280 | |
| 4281 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4282 | static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv, |
| 4283 | const char *ifname, |
| 4284 | enum nl80211_iftype iftype, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4285 | const u8 *addr, int wds, |
| 4286 | int (*handler)(struct nl_msg *, void *), |
| 4287 | void *arg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4288 | { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4289 | struct nl_msg *msg; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4290 | int ifidx; |
| 4291 | int ret = -ENOBUFS; |
| 4292 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4293 | wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)", |
| 4294 | iftype, nl80211_iftype_str(iftype)); |
| 4295 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4296 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE); |
| 4297 | if (!msg || |
| 4298 | nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) || |
| 4299 | nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype)) |
| 4300 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4301 | |
| 4302 | if (iftype == NL80211_IFTYPE_MONITOR) { |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4303 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4304 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4305 | flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4306 | if (!flags || |
| 4307 | nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES)) |
| 4308 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4309 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4310 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4311 | } else if (wds) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4312 | if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds)) |
| 4313 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4314 | } |
| 4315 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4316 | /* |
| 4317 | * Tell cfg80211 that the interface belongs to the socket that created |
| 4318 | * it, and the interface should be deleted when the socket is closed. |
| 4319 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4320 | if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER)) |
| 4321 | goto fail; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 4322 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4323 | ret = send_and_recv_msgs(drv, msg, handler, arg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4324 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4325 | if (ret) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4326 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4327 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4328 | wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)", |
| 4329 | ifname, ret, strerror(-ret)); |
| 4330 | return ret; |
| 4331 | } |
| 4332 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4333 | if (iftype == NL80211_IFTYPE_P2P_DEVICE) |
| 4334 | return 0; |
| 4335 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4336 | ifidx = if_nametoindex(ifname); |
| 4337 | wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d", |
| 4338 | ifname, ifidx); |
| 4339 | |
| 4340 | if (ifidx <= 0) |
| 4341 | return -1; |
| 4342 | |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4343 | /* |
| 4344 | * Some virtual interfaces need to process EAPOL packets and events on |
| 4345 | * the parent interface. This is used mainly with hostapd. |
| 4346 | */ |
| 4347 | if (drv->hostapd || |
| 4348 | iftype == NL80211_IFTYPE_AP_VLAN || |
| 4349 | iftype == NL80211_IFTYPE_WDS || |
| 4350 | iftype == NL80211_IFTYPE_MONITOR) { |
| 4351 | /* start listening for EAPOL on this interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 4352 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 4353 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4354 | |
| 4355 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4356 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4357 | nl80211_remove_iface(drv, ifidx); |
| 4358 | return -1; |
| 4359 | } |
| 4360 | |
| 4361 | return ifidx; |
| 4362 | } |
| 4363 | |
| 4364 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4365 | int nl80211_create_iface(struct wpa_driver_nl80211_data *drv, |
| 4366 | const char *ifname, enum nl80211_iftype iftype, |
| 4367 | const u8 *addr, int wds, |
| 4368 | int (*handler)(struct nl_msg *, void *), |
| 4369 | void *arg, int use_existing) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4370 | { |
| 4371 | int ret; |
| 4372 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4373 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler, |
| 4374 | arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4375 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4376 | /* if error occurred and interface exists already */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4377 | if (ret == -ENFILE && if_nametoindex(ifname)) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4378 | if (use_existing) { |
| 4379 | wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s", |
| 4380 | ifname); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 4381 | if (addr && iftype != NL80211_IFTYPE_MONITOR && |
| 4382 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4383 | addr) < 0 && |
| 4384 | (linux_set_iface_flags(drv->global->ioctl_sock, |
| 4385 | ifname, 0) < 0 || |
| 4386 | linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
| 4387 | addr) < 0 || |
| 4388 | linux_set_iface_flags(drv->global->ioctl_sock, |
| 4389 | ifname, 1) < 0)) |
| 4390 | return -1; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4391 | return -ENFILE; |
| 4392 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4393 | wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname); |
| 4394 | |
| 4395 | /* Try to remove the interface that was already there. */ |
| 4396 | nl80211_remove_iface(drv, if_nametoindex(ifname)); |
| 4397 | |
| 4398 | /* Try to create the interface again */ |
| 4399 | ret = nl80211_create_iface_once(drv, ifname, iftype, addr, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 4400 | wds, handler, arg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4401 | } |
| 4402 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4403 | if (ret >= 0 && is_p2p_net_interface(iftype)) { |
| 4404 | wpa_printf(MSG_DEBUG, |
| 4405 | "nl80211: Interface %s created for P2P - disable 11b rates", |
| 4406 | ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4407 | nl80211_disable_11b_rates(drv, ret, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4408 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4409 | |
| 4410 | return ret; |
| 4411 | } |
| 4412 | |
| 4413 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4414 | static int nl80211_setup_ap(struct i802_bss *bss) |
| 4415 | { |
| 4416 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4417 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4418 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 4419 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4420 | |
| 4421 | /* |
| 4422 | * Disable Probe Request reporting unless we need it in this way for |
| 4423 | * devices that include the AP SME, in the other case (unless using |
| 4424 | * monitor iface) we'll get it through the nl_mgmt socket instead. |
| 4425 | */ |
| 4426 | if (!drv->device_ap_sme) |
| 4427 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4428 | |
| 4429 | if (!drv->device_ap_sme && !drv->use_monitor) |
| 4430 | if (nl80211_mgmt_subscribe_ap(bss)) |
| 4431 | return -1; |
| 4432 | |
| 4433 | if (drv->device_ap_sme && !drv->use_monitor) |
| 4434 | if (nl80211_mgmt_subscribe_ap_dev_sme(bss)) |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4435 | wpa_printf(MSG_DEBUG, |
| 4436 | "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] | 4437 | |
| 4438 | if (!drv->device_ap_sme && drv->use_monitor && |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 4439 | nl80211_create_monitor_interface(drv) && |
| 4440 | !drv->device_ap_sme) |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4441 | return -1; |
| 4442 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4443 | if (drv->device_ap_sme && |
| 4444 | wpa_driver_nl80211_probe_req_report(bss, 1) < 0) { |
| 4445 | wpa_printf(MSG_DEBUG, "nl80211: Failed to enable " |
| 4446 | "Probe Request frame reporting in AP mode"); |
| 4447 | /* Try to survive without this */ |
| 4448 | } |
| 4449 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4450 | return 0; |
| 4451 | } |
| 4452 | |
| 4453 | |
| 4454 | static void nl80211_teardown_ap(struct i802_bss *bss) |
| 4455 | { |
| 4456 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4457 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4458 | wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d", |
| 4459 | bss->ifname, drv->device_ap_sme, drv->use_monitor); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4460 | if (drv->device_ap_sme) { |
| 4461 | wpa_driver_nl80211_probe_req_report(bss, 0); |
| 4462 | if (!drv->use_monitor) |
| 4463 | nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)"); |
| 4464 | } else if (drv->use_monitor) |
| 4465 | nl80211_remove_monitor_interface(drv); |
| 4466 | else |
| 4467 | nl80211_mgmt_unsubscribe(bss, "AP teardown"); |
| 4468 | |
| 4469 | bss->beacon_set = 0; |
| 4470 | } |
| 4471 | |
| 4472 | |
| 4473 | static int nl80211_send_eapol_data(struct i802_bss *bss, |
| 4474 | const u8 *addr, const u8 *data, |
| 4475 | size_t data_len) |
| 4476 | { |
| 4477 | struct sockaddr_ll ll; |
| 4478 | int ret; |
| 4479 | |
| 4480 | if (bss->drv->eapol_tx_sock < 0) { |
| 4481 | wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL"); |
| 4482 | return -1; |
| 4483 | } |
| 4484 | |
| 4485 | os_memset(&ll, 0, sizeof(ll)); |
| 4486 | ll.sll_family = AF_PACKET; |
| 4487 | ll.sll_ifindex = bss->ifindex; |
| 4488 | ll.sll_protocol = htons(ETH_P_PAE); |
| 4489 | ll.sll_halen = ETH_ALEN; |
| 4490 | os_memcpy(ll.sll_addr, addr, ETH_ALEN); |
| 4491 | ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0, |
| 4492 | (struct sockaddr *) &ll, sizeof(ll)); |
| 4493 | if (ret < 0) |
| 4494 | wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s", |
| 4495 | strerror(errno)); |
| 4496 | |
| 4497 | return ret; |
| 4498 | } |
| 4499 | |
| 4500 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4501 | static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 }; |
| 4502 | |
| 4503 | static int wpa_driver_nl80211_hapd_send_eapol( |
| 4504 | void *priv, const u8 *addr, const u8 *data, |
| 4505 | size_t data_len, int encrypt, const u8 *own_addr, u32 flags) |
| 4506 | { |
| 4507 | struct i802_bss *bss = priv; |
| 4508 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 4509 | struct ieee80211_hdr *hdr; |
| 4510 | size_t len; |
| 4511 | u8 *pos; |
| 4512 | int res; |
| 4513 | int qos = flags & WPA_STA_WMM; |
Dmitry Shmidt | 641185e | 2013-11-06 15:17:13 -0800 | [diff] [blame] | 4514 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4515 | if (drv->device_ap_sme || !drv->use_monitor) |
| 4516 | return nl80211_send_eapol_data(bss, addr, data, data_len); |
| 4517 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4518 | len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 + |
| 4519 | data_len; |
| 4520 | hdr = os_zalloc(len); |
| 4521 | if (hdr == NULL) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 4522 | wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)", |
| 4523 | (unsigned long) len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4524 | return -1; |
| 4525 | } |
| 4526 | |
| 4527 | hdr->frame_control = |
| 4528 | IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA); |
| 4529 | hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 4530 | if (encrypt) |
| 4531 | hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP); |
| 4532 | if (qos) { |
| 4533 | hdr->frame_control |= |
| 4534 | host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4); |
| 4535 | } |
| 4536 | |
| 4537 | memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 4538 | memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 4539 | memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 4540 | pos = (u8 *) (hdr + 1); |
| 4541 | |
| 4542 | if (qos) { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 4543 | /* Set highest priority in QoS header */ |
| 4544 | pos[0] = 7; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4545 | pos[1] = 0; |
| 4546 | pos += 2; |
| 4547 | } |
| 4548 | |
| 4549 | memcpy(pos, rfc1042_header, sizeof(rfc1042_header)); |
| 4550 | pos += sizeof(rfc1042_header); |
| 4551 | WPA_PUT_BE16(pos, ETH_P_PAE); |
| 4552 | pos += 2; |
| 4553 | memcpy(pos, data, data_len); |
| 4554 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4555 | res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 4556 | 0, 0, 0, 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4557 | if (res < 0) { |
| 4558 | wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - " |
| 4559 | "failed: %d (%s)", |
| 4560 | (unsigned long) len, errno, strerror(errno)); |
| 4561 | } |
| 4562 | os_free(hdr); |
| 4563 | |
| 4564 | return res; |
| 4565 | } |
| 4566 | |
| 4567 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4568 | 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] | 4569 | unsigned int total_flags, |
| 4570 | unsigned int flags_or, |
| 4571 | unsigned int flags_and) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4572 | { |
| 4573 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4574 | struct nl_msg *msg; |
| 4575 | struct nlattr *flags; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4576 | struct nl80211_sta_flag_update upd; |
| 4577 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 4578 | wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR |
| 4579 | " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d", |
| 4580 | bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and, |
| 4581 | !!(total_flags & WPA_STA_AUTHORIZED)); |
| 4582 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4583 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 4584 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) |
| 4585 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4586 | |
| 4587 | /* |
| 4588 | * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This |
| 4589 | * can be removed eventually. |
| 4590 | */ |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4591 | flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4592 | if (!flags || |
| 4593 | ((total_flags & WPA_STA_AUTHORIZED) && |
| 4594 | nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) || |
| 4595 | ((total_flags & WPA_STA_WMM) && |
| 4596 | nla_put_flag(msg, NL80211_STA_FLAG_WME)) || |
| 4597 | ((total_flags & WPA_STA_SHORT_PREAMBLE) && |
| 4598 | nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) || |
| 4599 | ((total_flags & WPA_STA_MFP) && |
| 4600 | nla_put_flag(msg, NL80211_STA_FLAG_MFP)) || |
| 4601 | ((total_flags & WPA_STA_TDLS_PEER) && |
| 4602 | nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER))) |
| 4603 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4604 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 4605 | nla_nest_end(msg, flags); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4606 | |
| 4607 | os_memset(&upd, 0, sizeof(upd)); |
| 4608 | upd.mask = sta_flags_nl80211(flags_or | ~flags_and); |
| 4609 | upd.set = sta_flags_nl80211(flags_or); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4610 | if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) |
| 4611 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4612 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4613 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
| 4614 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4615 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4616 | return -ENOBUFS; |
| 4617 | } |
| 4618 | |
| 4619 | |
| 4620 | static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv, |
| 4621 | struct wpa_driver_associate_params *params) |
| 4622 | { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4623 | enum nl80211_iftype nlmode, old_mode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4624 | |
| 4625 | if (params->p2p) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4626 | wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P " |
| 4627 | "group (GO)"); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 4628 | nlmode = NL80211_IFTYPE_P2P_GO; |
| 4629 | } else |
| 4630 | nlmode = NL80211_IFTYPE_AP; |
| 4631 | |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4632 | old_mode = drv->nlmode; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4633 | if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4634 | nl80211_remove_monitor_interface(drv); |
| 4635 | return -1; |
| 4636 | } |
| 4637 | |
Dmitry Shmidt | 203eadb | 2015-03-05 14:16:04 -0800 | [diff] [blame] | 4638 | if (params->freq.freq && |
| 4639 | nl80211_set_channel(drv->first_bss, ¶ms->freq, 0)) { |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 4640 | if (old_mode != nlmode) |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 4641 | wpa_driver_nl80211_set_mode(drv->first_bss, old_mode); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4642 | nl80211_remove_monitor_interface(drv); |
| 4643 | return -1; |
| 4644 | } |
| 4645 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4646 | return 0; |
| 4647 | } |
| 4648 | |
| 4649 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4650 | static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv, |
| 4651 | int reset_mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4652 | { |
| 4653 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4654 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4655 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4656 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4657 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4658 | if (ret) { |
| 4659 | wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d " |
| 4660 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4661 | } else { |
| 4662 | wpa_printf(MSG_DEBUG, |
| 4663 | "nl80211: Leave IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4664 | } |
| 4665 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4666 | if (reset_mode && |
| 4667 | wpa_driver_nl80211_set_mode(drv->first_bss, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 4668 | NL80211_IFTYPE_STATION)) { |
| 4669 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 4670 | "station mode"); |
| 4671 | } |
| 4672 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4673 | return ret; |
| 4674 | } |
| 4675 | |
| 4676 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4677 | static int nl80211_ht_vht_overrides(struct nl_msg *msg, |
| 4678 | struct wpa_driver_associate_params *params) |
| 4679 | { |
| 4680 | if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT)) |
| 4681 | return -1; |
| 4682 | |
| 4683 | if (params->htcaps && params->htcaps_mask) { |
| 4684 | int sz = sizeof(struct ieee80211_ht_capabilities); |
| 4685 | wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz); |
| 4686 | wpa_hexdump(MSG_DEBUG, " * htcaps_mask", |
| 4687 | params->htcaps_mask, sz); |
| 4688 | if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz, |
| 4689 | params->htcaps) || |
| 4690 | nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz, |
| 4691 | params->htcaps_mask)) |
| 4692 | return -1; |
| 4693 | } |
| 4694 | |
| 4695 | #ifdef CONFIG_VHT_OVERRIDES |
| 4696 | if (params->disable_vht) { |
| 4697 | wpa_printf(MSG_DEBUG, " * VHT disabled"); |
| 4698 | if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT)) |
| 4699 | return -1; |
| 4700 | } |
| 4701 | |
| 4702 | if (params->vhtcaps && params->vhtcaps_mask) { |
| 4703 | int sz = sizeof(struct ieee80211_vht_capabilities); |
| 4704 | wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz); |
| 4705 | wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask", |
| 4706 | params->vhtcaps_mask, sz); |
| 4707 | if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz, |
| 4708 | params->vhtcaps) || |
| 4709 | nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz, |
| 4710 | params->vhtcaps_mask)) |
| 4711 | return -1; |
| 4712 | } |
| 4713 | #endif /* CONFIG_VHT_OVERRIDES */ |
| 4714 | |
| 4715 | return 0; |
| 4716 | } |
| 4717 | |
| 4718 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4719 | static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv, |
| 4720 | struct wpa_driver_associate_params *params) |
| 4721 | { |
| 4722 | struct nl_msg *msg; |
| 4723 | int ret = -1; |
| 4724 | int count = 0; |
| 4725 | |
| 4726 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex); |
| 4727 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4728 | if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, ¶ms->freq)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4729 | wpa_printf(MSG_INFO, "nl80211: Failed to set interface into " |
| 4730 | "IBSS mode"); |
| 4731 | return -1; |
| 4732 | } |
| 4733 | |
| 4734 | retry: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4735 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) || |
| 4736 | params->ssid == NULL || params->ssid_len > sizeof(drv->ssid)) |
| 4737 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4738 | |
| 4739 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 4740 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4741 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid)) |
| 4742 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4743 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 4744 | drv->ssid_len = params->ssid_len; |
| 4745 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 4746 | if (nl80211_put_freq_params(msg, ¶ms->freq) < 0 || |
| 4747 | nl80211_put_beacon_int(msg, params->beacon_int)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4748 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4749 | |
| 4750 | ret = nl80211_set_conn_keys(params, msg); |
| 4751 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4752 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4753 | |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4754 | if (params->bssid && params->fixed_bssid) { |
| 4755 | wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR, |
| 4756 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4757 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 4758 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4759 | } |
| 4760 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 4761 | if (params->fixed_freq) { |
| 4762 | wpa_printf(MSG_DEBUG, " * fixed_freq"); |
| 4763 | if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED)) |
| 4764 | goto fail; |
| 4765 | } |
| 4766 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4767 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 4768 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 4769 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
| 4770 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4771 | wpa_printf(MSG_DEBUG, " * control port"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4772 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 4773 | goto fail; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 4774 | } |
| 4775 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4776 | if (params->wpa_ie) { |
| 4777 | wpa_hexdump(MSG_DEBUG, |
| 4778 | " * Extra IEs for Beacon/Probe Response frames", |
| 4779 | params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4780 | if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, |
| 4781 | params->wpa_ie)) |
| 4782 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4783 | } |
| 4784 | |
Dmitry Shmidt | 1d6bf42 | 2016-01-19 15:51:35 -0800 | [diff] [blame] | 4785 | ret = nl80211_ht_vht_overrides(msg, params); |
| 4786 | if (ret < 0) |
| 4787 | goto fail; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4788 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4789 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 4790 | msg = NULL; |
| 4791 | if (ret) { |
| 4792 | wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)", |
| 4793 | ret, strerror(-ret)); |
| 4794 | count++; |
| 4795 | if (ret == -EALREADY && count == 1) { |
| 4796 | wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after " |
| 4797 | "forced leave"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4798 | nl80211_leave_ibss(drv, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4799 | nlmsg_free(msg); |
| 4800 | goto retry; |
| 4801 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4802 | } else { |
| 4803 | wpa_printf(MSG_DEBUG, |
| 4804 | "nl80211: Join IBSS request sent successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4805 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4806 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4807 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4808 | nlmsg_free(msg); |
| 4809 | return ret; |
| 4810 | } |
| 4811 | |
| 4812 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4813 | static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv, |
| 4814 | struct wpa_driver_associate_params *params, |
| 4815 | struct nl_msg *msg) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4816 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4817 | if (params->bssid) { |
| 4818 | wpa_printf(MSG_DEBUG, " * bssid=" MACSTR, |
| 4819 | MAC2STR(params->bssid)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4820 | if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid)) |
| 4821 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4822 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4823 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4824 | if (params->bssid_hint) { |
| 4825 | wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR, |
| 4826 | MAC2STR(params->bssid_hint)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4827 | if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN, |
| 4828 | params->bssid_hint)) |
| 4829 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4830 | } |
| 4831 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4832 | if (params->freq.freq) { |
| 4833 | wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4834 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, |
| 4835 | params->freq.freq)) |
| 4836 | return -1; |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 4837 | drv->assoc_freq = params->freq.freq; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 4838 | } else |
| 4839 | drv->assoc_freq = 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4840 | |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4841 | if (params->freq_hint) { |
| 4842 | wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4843 | if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT, |
| 4844 | params->freq_hint)) |
| 4845 | return -1; |
Dmitry Shmidt | 96be622 | 2014-02-13 10:16:51 -0800 | [diff] [blame] | 4846 | } |
| 4847 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4848 | if (params->bg_scan_period >= 0) { |
| 4849 | wpa_printf(MSG_DEBUG, " * bg scan period=%d", |
| 4850 | params->bg_scan_period); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4851 | if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD, |
| 4852 | params->bg_scan_period)) |
| 4853 | return -1; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 4854 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4855 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4856 | if (params->ssid) { |
| 4857 | wpa_hexdump_ascii(MSG_DEBUG, " * SSID", |
| 4858 | params->ssid, params->ssid_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4859 | if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, |
| 4860 | params->ssid)) |
| 4861 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4862 | if (params->ssid_len > sizeof(drv->ssid)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4863 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4864 | os_memcpy(drv->ssid, params->ssid, params->ssid_len); |
| 4865 | drv->ssid_len = params->ssid_len; |
| 4866 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4867 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4868 | wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4869 | if (params->wpa_ie && |
| 4870 | nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie)) |
| 4871 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 4872 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4873 | if (params->wpa_proto) { |
| 4874 | enum nl80211_wpa_versions ver = 0; |
| 4875 | |
| 4876 | if (params->wpa_proto & WPA_PROTO_WPA) |
| 4877 | ver |= NL80211_WPA_VERSION_1; |
| 4878 | if (params->wpa_proto & WPA_PROTO_RSN) |
| 4879 | ver |= NL80211_WPA_VERSION_2; |
| 4880 | |
| 4881 | wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4882 | if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver)) |
| 4883 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4884 | } |
| 4885 | |
| 4886 | if (params->pairwise_suite != WPA_CIPHER_NONE) { |
| 4887 | u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite); |
| 4888 | wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4889 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE, |
| 4890 | cipher)) |
| 4891 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4892 | } |
| 4893 | |
Dmitry Shmidt | f21452a | 2014-02-26 10:55:25 -0800 | [diff] [blame] | 4894 | if (params->group_suite == WPA_CIPHER_GTK_NOT_USED && |
| 4895 | !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) { |
| 4896 | /* |
| 4897 | * This is likely to work even though many drivers do not |
| 4898 | * advertise support for operations without GTK. |
| 4899 | */ |
| 4900 | wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement"); |
| 4901 | } else if (params->group_suite != WPA_CIPHER_NONE) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4902 | u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite); |
| 4903 | wpa_printf(MSG_DEBUG, " * group=0x%x", cipher); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4904 | if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher)) |
| 4905 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4906 | } |
| 4907 | |
| 4908 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X || |
| 4909 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 4910 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X || |
| 4911 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK || |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4912 | params->key_mgmt_suite == WPA_KEY_MGMT_CCKM || |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 4913 | params->key_mgmt_suite == WPA_KEY_MGMT_OSEN || |
| 4914 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4915 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4916 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B || |
| 4917 | params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4918 | int mgmt = WLAN_AKM_SUITE_PSK; |
| 4919 | |
| 4920 | switch (params->key_mgmt_suite) { |
| 4921 | case WPA_KEY_MGMT_CCKM: |
| 4922 | mgmt = WLAN_AKM_SUITE_CCKM; |
| 4923 | break; |
| 4924 | case WPA_KEY_MGMT_IEEE8021X: |
| 4925 | mgmt = WLAN_AKM_SUITE_8021X; |
| 4926 | break; |
| 4927 | case WPA_KEY_MGMT_FT_IEEE8021X: |
| 4928 | mgmt = WLAN_AKM_SUITE_FT_8021X; |
| 4929 | break; |
| 4930 | case WPA_KEY_MGMT_FT_PSK: |
| 4931 | mgmt = WLAN_AKM_SUITE_FT_PSK; |
| 4932 | break; |
Dmitry Shmidt | 3c57b3f | 2014-05-22 15:13:07 -0700 | [diff] [blame] | 4933 | case WPA_KEY_MGMT_IEEE8021X_SHA256: |
| 4934 | mgmt = WLAN_AKM_SUITE_8021X_SHA256; |
| 4935 | break; |
| 4936 | case WPA_KEY_MGMT_PSK_SHA256: |
| 4937 | mgmt = WLAN_AKM_SUITE_PSK_SHA256; |
| 4938 | break; |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4939 | case WPA_KEY_MGMT_OSEN: |
| 4940 | mgmt = WLAN_AKM_SUITE_OSEN; |
| 4941 | break; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4942 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B: |
| 4943 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B; |
| 4944 | break; |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 4945 | case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192: |
| 4946 | mgmt = WLAN_AKM_SUITE_8021X_SUITE_B_192; |
| 4947 | break; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4948 | case WPA_KEY_MGMT_PSK: |
| 4949 | default: |
| 4950 | mgmt = WLAN_AKM_SUITE_PSK; |
| 4951 | break; |
| 4952 | } |
Dmitry Shmidt | 1590709 | 2014-03-25 10:42:57 -0700 | [diff] [blame] | 4953 | wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4954 | if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt)) |
| 4955 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4956 | } |
| 4957 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4958 | if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT)) |
| 4959 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4960 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 4961 | if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA && |
| 4962 | (params->pairwise_suite == WPA_CIPHER_NONE || |
| 4963 | params->pairwise_suite == WPA_CIPHER_WEP104 || |
| 4964 | params->pairwise_suite == WPA_CIPHER_WEP40) && |
| 4965 | (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) || |
| 4966 | nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))) |
| 4967 | return -1; |
| 4968 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4969 | if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED && |
| 4970 | nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED)) |
| 4971 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4972 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4973 | if (params->rrm_used) { |
| 4974 | u32 drv_rrm_flags = drv->capa.rrm_flags; |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 4975 | if ((!((drv_rrm_flags & |
| 4976 | WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) && |
| 4977 | (drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET)) && |
| 4978 | !(drv_rrm_flags & WPA_DRIVER_FLAGS_SUPPORT_RRM)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4979 | nla_put_flag(msg, NL80211_ATTR_USE_RRM)) |
| 4980 | return -1; |
| 4981 | } |
| 4982 | |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 4983 | if (nl80211_ht_vht_overrides(msg, params) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 4984 | return -1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4985 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 4986 | if (params->p2p) |
| 4987 | wpa_printf(MSG_DEBUG, " * P2P group"); |
| 4988 | |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 4989 | if (params->pbss) { |
| 4990 | wpa_printf(MSG_DEBUG, " * PBSS"); |
| 4991 | if (nla_put_flag(msg, NL80211_ATTR_PBSS)) |
| 4992 | return -1; |
| 4993 | } |
| 4994 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 4995 | drv->connect_reassoc = 0; |
| 4996 | if (params->prev_bssid) { |
| 4997 | wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR, |
| 4998 | MAC2STR(params->prev_bssid)); |
| 4999 | if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN, |
| 5000 | params->prev_bssid)) |
| 5001 | return -1; |
| 5002 | drv->connect_reassoc = 1; |
| 5003 | } |
| 5004 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5005 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5006 | } |
| 5007 | |
| 5008 | |
| 5009 | static int wpa_driver_nl80211_try_connect( |
| 5010 | struct wpa_driver_nl80211_data *drv, |
| 5011 | struct wpa_driver_associate_params *params) |
| 5012 | { |
| 5013 | struct nl_msg *msg; |
| 5014 | enum nl80211_auth_type type; |
| 5015 | int ret; |
| 5016 | int algs; |
| 5017 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5018 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5019 | if (params->req_key_mgmt_offload && params->psk && |
| 5020 | (params->key_mgmt_suite == WPA_KEY_MGMT_PSK || |
| 5021 | params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 || |
| 5022 | params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) { |
| 5023 | wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK"); |
| 5024 | ret = issue_key_mgmt_set_key(drv, params->psk, 32); |
| 5025 | if (ret) |
| 5026 | return ret; |
| 5027 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5028 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5029 | |
| 5030 | wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex); |
| 5031 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5032 | if (!msg) |
| 5033 | return -1; |
| 5034 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5035 | ret = nl80211_connect_common(drv, params, msg); |
| 5036 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5037 | goto fail; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5038 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5039 | algs = 0; |
| 5040 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 5041 | algs++; |
| 5042 | if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 5043 | algs++; |
| 5044 | if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 5045 | algs++; |
| 5046 | if (algs > 1) { |
| 5047 | wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic " |
| 5048 | "selection"); |
| 5049 | goto skip_auth_type; |
| 5050 | } |
| 5051 | |
| 5052 | if (params->auth_alg & WPA_AUTH_ALG_OPEN) |
| 5053 | type = NL80211_AUTHTYPE_OPEN_SYSTEM; |
| 5054 | else if (params->auth_alg & WPA_AUTH_ALG_SHARED) |
| 5055 | type = NL80211_AUTHTYPE_SHARED_KEY; |
| 5056 | else if (params->auth_alg & WPA_AUTH_ALG_LEAP) |
| 5057 | type = NL80211_AUTHTYPE_NETWORK_EAP; |
| 5058 | else if (params->auth_alg & WPA_AUTH_ALG_FT) |
| 5059 | type = NL80211_AUTHTYPE_FT; |
| 5060 | else |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5061 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5062 | |
| 5063 | wpa_printf(MSG_DEBUG, " * Auth Type %d", type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5064 | if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type)) |
| 5065 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5066 | |
| 5067 | skip_auth_type: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5068 | ret = nl80211_set_conn_keys(params, msg); |
| 5069 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5070 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5071 | |
| 5072 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5073 | msg = NULL; |
| 5074 | if (ret) { |
| 5075 | wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d " |
| 5076 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5077 | } else { |
| 5078 | wpa_printf(MSG_DEBUG, |
| 5079 | "nl80211: Connect request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5080 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5081 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5082 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5083 | nlmsg_free(msg); |
| 5084 | return ret; |
| 5085 | |
| 5086 | } |
| 5087 | |
| 5088 | |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5089 | static int wpa_driver_nl80211_connect( |
| 5090 | struct wpa_driver_nl80211_data *drv, |
| 5091 | struct wpa_driver_associate_params *params) |
| 5092 | { |
Jithu Jance | a7c60b4 | 2014-12-03 18:54:40 +0530 | [diff] [blame] | 5093 | int ret; |
| 5094 | |
| 5095 | /* Store the connection attempted bssid for future use */ |
| 5096 | if (params->bssid) |
| 5097 | os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN); |
| 5098 | else |
| 5099 | os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN); |
| 5100 | |
| 5101 | ret = wpa_driver_nl80211_try_connect(drv, params); |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5102 | if (ret == -EALREADY) { |
| 5103 | /* |
| 5104 | * cfg80211 does not currently accept new connections if |
| 5105 | * we are already connected. As a workaround, force |
| 5106 | * disconnection and try again. |
| 5107 | */ |
| 5108 | wpa_printf(MSG_DEBUG, "nl80211: Explicitly " |
| 5109 | "disconnecting before reassociation " |
| 5110 | "attempt"); |
| 5111 | if (wpa_driver_nl80211_disconnect( |
| 5112 | drv, WLAN_REASON_PREV_AUTH_NOT_VALID)) |
| 5113 | return -1; |
Dmitry Shmidt | d5e4923 | 2012-12-03 15:08:10 -0800 | [diff] [blame] | 5114 | ret = wpa_driver_nl80211_try_connect(drv, params); |
| 5115 | } |
| 5116 | return ret; |
| 5117 | } |
| 5118 | |
| 5119 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5120 | static int wpa_driver_nl80211_associate( |
| 5121 | void *priv, struct wpa_driver_associate_params *params) |
| 5122 | { |
| 5123 | struct i802_bss *bss = priv; |
| 5124 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5125 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5126 | struct nl_msg *msg; |
| 5127 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5128 | nl80211_unmask_11b_rates(bss); |
| 5129 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5130 | if (params->mode == IEEE80211_MODE_AP) |
| 5131 | return wpa_driver_nl80211_ap(drv, params); |
| 5132 | |
| 5133 | if (params->mode == IEEE80211_MODE_IBSS) |
| 5134 | return wpa_driver_nl80211_ibss(drv, params); |
| 5135 | |
| 5136 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5137 | enum nl80211_iftype nlmode = params->p2p ? |
| 5138 | NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION; |
| 5139 | |
| 5140 | if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5141 | return -1; |
| 5142 | return wpa_driver_nl80211_connect(drv, params); |
| 5143 | } |
| 5144 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5145 | nl80211_mark_disconnected(drv); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5146 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5147 | wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)", |
| 5148 | drv->ifindex); |
| 5149 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5150 | if (!msg) |
| 5151 | return -1; |
| 5152 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5153 | ret = nl80211_connect_common(drv, params, msg); |
| 5154 | if (ret) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5155 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5156 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame^] | 5157 | if (params->fils_kek) { |
| 5158 | wpa_printf(MSG_DEBUG, " * FILS KEK (len=%u)", |
| 5159 | (unsigned int) params->fils_kek_len); |
| 5160 | if (nla_put(msg, NL80211_ATTR_FILS_KEK, params->fils_kek_len, |
| 5161 | params->fils_kek)) |
| 5162 | goto fail; |
| 5163 | } |
| 5164 | if (params->fils_nonces) { |
| 5165 | wpa_hexdump(MSG_DEBUG, " * FILS nonces (for AAD)", |
| 5166 | params->fils_nonces, |
| 5167 | params->fils_nonces_len); |
| 5168 | if (nla_put(msg, NL80211_ATTR_FILS_NONCES, |
| 5169 | params->fils_nonces_len, params->fils_nonces)) |
| 5170 | goto fail; |
| 5171 | } |
| 5172 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5173 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5174 | msg = NULL; |
| 5175 | if (ret) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5176 | wpa_dbg(drv->ctx, MSG_DEBUG, |
| 5177 | "nl80211: MLME command failed (assoc): ret=%d (%s)", |
| 5178 | ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5179 | nl80211_dump_scan(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5180 | } else { |
| 5181 | wpa_printf(MSG_DEBUG, |
| 5182 | "nl80211: Association request send successfully"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5183 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5184 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5185 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5186 | nlmsg_free(msg); |
| 5187 | return ret; |
| 5188 | } |
| 5189 | |
| 5190 | |
| 5191 | static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5192 | int ifindex, enum nl80211_iftype mode) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5193 | { |
| 5194 | struct nl_msg *msg; |
| 5195 | int ret = -ENOBUFS; |
| 5196 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5197 | wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)", |
| 5198 | ifindex, mode, nl80211_iftype_str(mode)); |
| 5199 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5200 | msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE); |
| 5201 | if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode)) |
| 5202 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5203 | |
| 5204 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5205 | msg = NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5206 | if (!ret) |
| 5207 | return 0; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5208 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5209 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5210 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:" |
| 5211 | " %d (%s)", ifindex, mode, ret, strerror(-ret)); |
| 5212 | return ret; |
| 5213 | } |
| 5214 | |
| 5215 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5216 | static int wpa_driver_nl80211_set_mode_impl( |
| 5217 | struct i802_bss *bss, |
| 5218 | enum nl80211_iftype nlmode, |
| 5219 | struct hostapd_freq_params *desired_freq_params) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5220 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5221 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5222 | int ret = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5223 | int i; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5224 | int was_ap = is_ap_interface(drv->nlmode); |
| 5225 | int res; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5226 | int mode_switch_res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5227 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 5228 | if (TEST_FAIL()) |
| 5229 | return -1; |
| 5230 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5231 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 5232 | if (mode_switch_res && nlmode == nl80211_get_ifmode(bss)) |
| 5233 | mode_switch_res = 0; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5234 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5235 | if (mode_switch_res == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5236 | drv->nlmode = nlmode; |
| 5237 | ret = 0; |
| 5238 | goto done; |
| 5239 | } |
| 5240 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5241 | if (mode_switch_res == -ENODEV) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5242 | return -1; |
| 5243 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5244 | if (nlmode == drv->nlmode) { |
| 5245 | wpa_printf(MSG_DEBUG, "nl80211: Interface already in " |
| 5246 | "requested mode - ignore error"); |
| 5247 | ret = 0; |
| 5248 | goto done; /* Already in the requested mode */ |
| 5249 | } |
| 5250 | |
| 5251 | /* mac80211 doesn't allow mode changes while the device is up, so |
| 5252 | * take the device down, try to set the mode again, and bring the |
| 5253 | * device back up. |
| 5254 | */ |
| 5255 | wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting " |
| 5256 | "interface down"); |
| 5257 | for (i = 0; i < 10; i++) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5258 | res = i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5259 | if (res == -EACCES || res == -ENODEV) |
| 5260 | break; |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5261 | if (res != 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5262 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set " |
| 5263 | "interface down"); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5264 | os_sleep(0, 100000); |
| 5265 | continue; |
| 5266 | } |
| 5267 | |
| 5268 | /* |
| 5269 | * Setting the mode will fail for some drivers if the phy is |
| 5270 | * on a frequency that the mode is disallowed in. |
| 5271 | */ |
| 5272 | if (desired_freq_params) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5273 | res = nl80211_set_channel(bss, desired_freq_params, 0); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5274 | if (res) { |
| 5275 | wpa_printf(MSG_DEBUG, |
| 5276 | "nl80211: Failed to set frequency on interface"); |
| 5277 | } |
| 5278 | } |
| 5279 | |
| 5280 | /* Try to set the mode again while the interface is down */ |
| 5281 | mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode); |
| 5282 | if (mode_switch_res == -EBUSY) { |
| 5283 | wpa_printf(MSG_DEBUG, |
| 5284 | "nl80211: Delaying mode set while interface going down"); |
| 5285 | os_sleep(0, 100000); |
| 5286 | continue; |
| 5287 | } |
| 5288 | ret = mode_switch_res; |
| 5289 | break; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5290 | } |
| 5291 | |
| 5292 | if (!ret) { |
| 5293 | wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while " |
| 5294 | "interface is down"); |
| 5295 | drv->nlmode = nlmode; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5296 | drv->ignore_if_down_event = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5297 | } |
| 5298 | |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5299 | /* Bring the interface back up */ |
| 5300 | res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1); |
| 5301 | if (res != 0) { |
| 5302 | wpa_printf(MSG_DEBUG, |
| 5303 | "nl80211: Failed to set interface up after switching mode"); |
| 5304 | ret = -1; |
| 5305 | } |
| 5306 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5307 | done: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5308 | if (ret) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5309 | wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d " |
| 5310 | "from %d failed", nlmode, drv->nlmode); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5311 | return ret; |
| 5312 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5313 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5314 | if (is_p2p_net_interface(nlmode)) { |
| 5315 | wpa_printf(MSG_DEBUG, |
| 5316 | "nl80211: Interface %s mode change to P2P - disable 11b rates", |
| 5317 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5318 | nl80211_disable_11b_rates(drv, drv->ifindex, 1); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5319 | } else if (drv->disabled_11b_rates) { |
| 5320 | wpa_printf(MSG_DEBUG, |
| 5321 | "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates", |
| 5322 | bss->ifname); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5323 | nl80211_disable_11b_rates(drv, drv->ifindex, 0); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5324 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5325 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5326 | if (is_ap_interface(nlmode)) { |
| 5327 | nl80211_mgmt_unsubscribe(bss, "start AP"); |
| 5328 | /* Setup additional AP mode functionality if needed */ |
| 5329 | if (nl80211_setup_ap(bss)) |
| 5330 | return -1; |
| 5331 | } else if (was_ap) { |
| 5332 | /* Remove additional AP mode functionality */ |
| 5333 | nl80211_teardown_ap(bss); |
| 5334 | } else { |
| 5335 | nl80211_mgmt_unsubscribe(bss, "mode change"); |
| 5336 | } |
| 5337 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5338 | if (is_mesh_interface(nlmode) && |
| 5339 | nl80211_mgmt_subscribe_mesh(bss)) |
| 5340 | return -1; |
| 5341 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5342 | if (!bss->in_deinit && !is_ap_interface(nlmode) && |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5343 | !is_mesh_interface(nlmode) && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5344 | nl80211_mgmt_subscribe_non_ap(bss) < 0) |
| 5345 | wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action " |
| 5346 | "frame processing - ignore for now"); |
| 5347 | |
| 5348 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5349 | } |
| 5350 | |
| 5351 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5352 | int wpa_driver_nl80211_set_mode(struct i802_bss *bss, |
| 5353 | enum nl80211_iftype nlmode) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5354 | { |
| 5355 | return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL); |
| 5356 | } |
| 5357 | |
| 5358 | |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5359 | static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss, |
| 5360 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5361 | { |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5362 | return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 5363 | freq); |
Dmitry Shmidt | d30ac60 | 2014-06-30 09:54:22 -0700 | [diff] [blame] | 5364 | } |
| 5365 | |
| 5366 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5367 | static int wpa_driver_nl80211_get_capa(void *priv, |
| 5368 | struct wpa_driver_capa *capa) |
| 5369 | { |
| 5370 | struct i802_bss *bss = priv; |
| 5371 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | d11f019 | 2014-03-24 12:09:47 -0700 | [diff] [blame] | 5372 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5373 | if (!drv->has_capability) |
| 5374 | return -1; |
| 5375 | os_memcpy(capa, &drv->capa, sizeof(*capa)); |
Dmitry Shmidt | 444d567 | 2013-04-01 13:08:44 -0700 | [diff] [blame] | 5376 | if (drv->extended_capa && drv->extended_capa_mask) { |
| 5377 | capa->extended_capa = drv->extended_capa; |
| 5378 | capa->extended_capa_mask = drv->extended_capa_mask; |
| 5379 | capa->extended_capa_len = drv->extended_capa_len; |
| 5380 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 5381 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5382 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5383 | } |
| 5384 | |
| 5385 | |
| 5386 | static int wpa_driver_nl80211_set_operstate(void *priv, int state) |
| 5387 | { |
| 5388 | struct i802_bss *bss = priv; |
| 5389 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5390 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5391 | wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)", |
| 5392 | bss->ifname, drv->operstate, state, |
| 5393 | state ? "UP" : "DORMANT"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5394 | drv->operstate = state; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5395 | return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5396 | state ? IF_OPER_UP : IF_OPER_DORMANT); |
| 5397 | } |
| 5398 | |
| 5399 | |
| 5400 | static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized) |
| 5401 | { |
| 5402 | struct i802_bss *bss = priv; |
| 5403 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5404 | struct nl_msg *msg; |
| 5405 | struct nl80211_sta_flag_update upd; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5406 | int ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5407 | |
| 5408 | if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) { |
| 5409 | wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated"); |
| 5410 | return 0; |
| 5411 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5412 | |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 5413 | wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for " |
| 5414 | MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid)); |
| 5415 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5416 | os_memset(&upd, 0, sizeof(upd)); |
| 5417 | upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED); |
| 5418 | if (authorized) |
| 5419 | upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5420 | |
| 5421 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5422 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) || |
| 5423 | nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) { |
| 5424 | nlmsg_free(msg); |
| 5425 | return -ENOBUFS; |
| 5426 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5427 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5428 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5429 | if (!ret) |
| 5430 | return 0; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 5431 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)", |
| 5432 | ret, strerror(-ret)); |
| 5433 | return ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5434 | } |
| 5435 | |
| 5436 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5437 | /* Set kernel driver on given frequency (MHz) */ |
| 5438 | static int i802_set_freq(void *priv, struct hostapd_freq_params *freq) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5439 | { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5440 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 7832adb | 2014-04-29 10:53:02 -0700 | [diff] [blame] | 5441 | return nl80211_set_channel(bss, freq, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5442 | } |
| 5443 | |
| 5444 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5445 | static inline int min_int(int a, int b) |
| 5446 | { |
| 5447 | if (a < b) |
| 5448 | return a; |
| 5449 | return b; |
| 5450 | } |
| 5451 | |
| 5452 | |
| 5453 | static int get_key_handler(struct nl_msg *msg, void *arg) |
| 5454 | { |
| 5455 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5456 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5457 | |
| 5458 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5459 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5460 | |
| 5461 | /* |
| 5462 | * TODO: validate the key index and mac address! |
| 5463 | * Otherwise, there's a race condition as soon as |
| 5464 | * the kernel starts sending key notifications. |
| 5465 | */ |
| 5466 | |
| 5467 | if (tb[NL80211_ATTR_KEY_SEQ]) |
| 5468 | memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]), |
| 5469 | min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6)); |
| 5470 | return NL_SKIP; |
| 5471 | } |
| 5472 | |
| 5473 | |
| 5474 | static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr, |
| 5475 | int idx, u8 *seq) |
| 5476 | { |
| 5477 | struct i802_bss *bss = priv; |
| 5478 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5479 | struct nl_msg *msg; |
| 5480 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5481 | msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0, |
| 5482 | NL80211_CMD_GET_KEY); |
| 5483 | if (!msg || |
| 5484 | (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) || |
| 5485 | nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) { |
| 5486 | nlmsg_free(msg); |
| 5487 | return -ENOBUFS; |
| 5488 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5489 | |
| 5490 | memset(seq, 0, 6); |
| 5491 | |
| 5492 | return send_and_recv_msgs(drv, msg, get_key_handler, seq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5493 | } |
| 5494 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5495 | |
| 5496 | static int i802_set_rts(void *priv, int rts) |
| 5497 | { |
| 5498 | struct i802_bss *bss = priv; |
| 5499 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5500 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5501 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5502 | u32 val; |
| 5503 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5504 | if (rts >= 2347) |
| 5505 | val = (u32) -1; |
| 5506 | else |
| 5507 | val = rts; |
| 5508 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5509 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 5510 | nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) { |
| 5511 | nlmsg_free(msg); |
| 5512 | return -ENOBUFS; |
| 5513 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5514 | |
| 5515 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5516 | if (!ret) |
| 5517 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5518 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: " |
| 5519 | "%d (%s)", rts, ret, strerror(-ret)); |
| 5520 | return ret; |
| 5521 | } |
| 5522 | |
| 5523 | |
| 5524 | static int i802_set_frag(void *priv, int frag) |
| 5525 | { |
| 5526 | struct i802_bss *bss = priv; |
| 5527 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5528 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5529 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5530 | u32 val; |
| 5531 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5532 | if (frag >= 2346) |
| 5533 | val = (u32) -1; |
| 5534 | else |
| 5535 | val = frag; |
| 5536 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5537 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) || |
| 5538 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) { |
| 5539 | nlmsg_free(msg); |
| 5540 | return -ENOBUFS; |
| 5541 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5542 | |
| 5543 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5544 | if (!ret) |
| 5545 | return 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5546 | wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold " |
| 5547 | "%d: %d (%s)", frag, ret, strerror(-ret)); |
| 5548 | return ret; |
| 5549 | } |
| 5550 | |
| 5551 | |
| 5552 | static int i802_flush(void *priv) |
| 5553 | { |
| 5554 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5555 | struct nl_msg *msg; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5556 | int res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5557 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 5558 | wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)", |
| 5559 | bss->ifname); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5560 | |
| 5561 | /* |
| 5562 | * XXX: FIX! this needs to flush all VLANs too |
| 5563 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5564 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION); |
| 5565 | res = send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5566 | if (res) { |
| 5567 | wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d " |
| 5568 | "(%s)", res, strerror(-res)); |
| 5569 | } |
| 5570 | return res; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5571 | } |
| 5572 | |
| 5573 | |
| 5574 | static int get_sta_handler(struct nl_msg *msg, void *arg) |
| 5575 | { |
| 5576 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 5577 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 5578 | struct hostap_sta_driver_data *data = arg; |
| 5579 | struct nlattr *stats[NL80211_STA_INFO_MAX + 1]; |
| 5580 | static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = { |
| 5581 | [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 }, |
| 5582 | [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 }, |
| 5583 | [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 }, |
| 5584 | [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 }, |
| 5585 | [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 }, |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 5586 | [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 }, |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5587 | [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 }, |
| 5588 | [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 }, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5589 | }; |
| 5590 | |
| 5591 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 5592 | genlmsg_attrlen(gnlh, 0), NULL); |
| 5593 | |
| 5594 | /* |
| 5595 | * TODO: validate the interface and mac address! |
| 5596 | * Otherwise, there's a race condition as soon as |
| 5597 | * the kernel starts sending station notifications. |
| 5598 | */ |
| 5599 | |
| 5600 | if (!tb[NL80211_ATTR_STA_INFO]) { |
| 5601 | wpa_printf(MSG_DEBUG, "sta stats missing!"); |
| 5602 | return NL_SKIP; |
| 5603 | } |
| 5604 | if (nla_parse_nested(stats, NL80211_STA_INFO_MAX, |
| 5605 | tb[NL80211_ATTR_STA_INFO], |
| 5606 | stats_policy)) { |
| 5607 | wpa_printf(MSG_DEBUG, "failed to parse nested attributes!"); |
| 5608 | return NL_SKIP; |
| 5609 | } |
| 5610 | |
| 5611 | if (stats[NL80211_STA_INFO_INACTIVE_TIME]) |
| 5612 | data->inactive_msec = |
| 5613 | nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5614 | /* For backwards compatibility, fetch the 32-bit counters first. */ |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5615 | if (stats[NL80211_STA_INFO_RX_BYTES]) |
| 5616 | data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]); |
| 5617 | if (stats[NL80211_STA_INFO_TX_BYTES]) |
| 5618 | data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]); |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 5619 | if (stats[NL80211_STA_INFO_RX_BYTES64] && |
| 5620 | stats[NL80211_STA_INFO_TX_BYTES64]) { |
| 5621 | /* |
| 5622 | * The driver supports 64-bit counters, so use them to override |
| 5623 | * the 32-bit values. |
| 5624 | */ |
| 5625 | data->rx_bytes = |
| 5626 | nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]); |
| 5627 | data->tx_bytes = |
| 5628 | nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]); |
| 5629 | data->bytes_64bit = 1; |
| 5630 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5631 | if (stats[NL80211_STA_INFO_RX_PACKETS]) |
| 5632 | data->rx_packets = |
| 5633 | nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]); |
| 5634 | if (stats[NL80211_STA_INFO_TX_PACKETS]) |
| 5635 | data->tx_packets = |
| 5636 | nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]); |
Jouni Malinen | 1e6c57f | 2012-09-05 17:07:03 +0300 | [diff] [blame] | 5637 | if (stats[NL80211_STA_INFO_TX_FAILED]) |
| 5638 | data->tx_retry_failed = |
| 5639 | nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5640 | |
| 5641 | return NL_SKIP; |
| 5642 | } |
| 5643 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5644 | static int i802_read_sta_data(struct i802_bss *bss, |
| 5645 | struct hostap_sta_driver_data *data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5646 | const u8 *addr) |
| 5647 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5648 | struct nl_msg *msg; |
| 5649 | |
| 5650 | os_memset(data, 0, sizeof(*data)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5651 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5652 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) || |
| 5653 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 5654 | nlmsg_free(msg); |
| 5655 | return -ENOBUFS; |
| 5656 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5657 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5658 | return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5659 | } |
| 5660 | |
| 5661 | |
| 5662 | static int i802_set_tx_queue_params(void *priv, int queue, int aifs, |
| 5663 | int cw_min, int cw_max, int burst_time) |
| 5664 | { |
| 5665 | struct i802_bss *bss = priv; |
| 5666 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5667 | struct nl_msg *msg; |
| 5668 | struct nlattr *txq, *params; |
| 5669 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5670 | msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5671 | if (!msg) |
| 5672 | return -1; |
| 5673 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5674 | txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS); |
| 5675 | if (!txq) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5676 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5677 | |
| 5678 | /* We are only sending parameters for a single TXQ at a time */ |
| 5679 | params = nla_nest_start(msg, 1); |
| 5680 | if (!params) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5681 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5682 | |
| 5683 | switch (queue) { |
| 5684 | case 0: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5685 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO)) |
| 5686 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5687 | break; |
| 5688 | case 1: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5689 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI)) |
| 5690 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5691 | break; |
| 5692 | case 2: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5693 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE)) |
| 5694 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5695 | break; |
| 5696 | case 3: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5697 | if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK)) |
| 5698 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5699 | break; |
| 5700 | } |
| 5701 | /* Burst time is configured in units of 0.1 msec and TXOP parameter in |
| 5702 | * 32 usec, so need to convert the value here. */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5703 | if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP, |
| 5704 | (burst_time * 100 + 16) / 32) || |
| 5705 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) || |
| 5706 | nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) || |
| 5707 | nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs)) |
| 5708 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5709 | |
| 5710 | nla_nest_end(msg, params); |
| 5711 | |
| 5712 | nla_nest_end(msg, txq); |
| 5713 | |
| 5714 | if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0) |
| 5715 | return 0; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5716 | msg = NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5717 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5718 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5719 | return -1; |
| 5720 | } |
| 5721 | |
| 5722 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5723 | 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] | 5724 | const char *ifname, int vlan_id) |
| 5725 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5726 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5727 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5728 | int ret; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5729 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5730 | wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR |
| 5731 | ", ifname=%s[%d], vlan_id=%d)", |
| 5732 | bss->ifname, if_nametoindex(bss->ifname), |
| 5733 | MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5734 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) || |
| 5735 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 5736 | nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) { |
| 5737 | nlmsg_free(msg); |
| 5738 | return -ENOBUFS; |
| 5739 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5740 | |
| 5741 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 5742 | if (ret < 0) { |
| 5743 | wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr=" |
| 5744 | MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)", |
| 5745 | MAC2STR(addr), ifname, vlan_id, ret, |
| 5746 | strerror(-ret)); |
| 5747 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5748 | return ret; |
| 5749 | } |
| 5750 | |
| 5751 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5752 | static int i802_get_inact_sec(void *priv, const u8 *addr) |
| 5753 | { |
| 5754 | struct hostap_sta_driver_data data; |
| 5755 | int ret; |
| 5756 | |
| 5757 | data.inactive_msec = (unsigned long) -1; |
| 5758 | ret = i802_read_sta_data(priv, &data, addr); |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 5759 | if (ret == -ENOENT) |
| 5760 | return -ENOENT; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5761 | if (ret || data.inactive_msec == (unsigned long) -1) |
| 5762 | return -1; |
| 5763 | return data.inactive_msec / 1000; |
| 5764 | } |
| 5765 | |
| 5766 | |
| 5767 | static int i802_sta_clear_stats(void *priv, const u8 *addr) |
| 5768 | { |
| 5769 | #if 0 |
| 5770 | /* TODO */ |
| 5771 | #endif |
| 5772 | return 0; |
| 5773 | } |
| 5774 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5775 | |
| 5776 | static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr, |
| 5777 | int reason) |
| 5778 | { |
| 5779 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5780 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5781 | struct ieee80211_mgmt mgmt; |
| 5782 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5783 | if (is_mesh_interface(drv->nlmode)) |
| 5784 | return -1; |
| 5785 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5786 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5787 | return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5788 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5789 | memset(&mgmt, 0, sizeof(mgmt)); |
| 5790 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 5791 | WLAN_FC_STYPE_DEAUTH); |
| 5792 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 5793 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 5794 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 5795 | mgmt.u.deauth.reason_code = host_to_le16(reason); |
| 5796 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 5797 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5798 | sizeof(mgmt.u.deauth), 0, 0, 0, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5799 | 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5800 | } |
| 5801 | |
| 5802 | |
| 5803 | static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr, |
| 5804 | int reason) |
| 5805 | { |
| 5806 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5807 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5808 | struct ieee80211_mgmt mgmt; |
| 5809 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5810 | if (is_mesh_interface(drv->nlmode)) |
| 5811 | return -1; |
| 5812 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5813 | if (drv->device_ap_sme) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5814 | return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason); |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 5815 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5816 | memset(&mgmt, 0, sizeof(mgmt)); |
| 5817 | mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT, |
| 5818 | WLAN_FC_STYPE_DISASSOC); |
| 5819 | memcpy(mgmt.da, addr, ETH_ALEN); |
| 5820 | memcpy(mgmt.sa, own_addr, ETH_ALEN); |
| 5821 | memcpy(mgmt.bssid, own_addr, ETH_ALEN); |
| 5822 | mgmt.u.disassoc.reason_code = host_to_le16(reason); |
| 5823 | return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt, |
| 5824 | IEEE80211_HDRLEN + |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 5825 | sizeof(mgmt.u.disassoc), 0, 0, 0, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 5826 | 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5827 | } |
| 5828 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 5829 | |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5830 | static void dump_ifidx(struct wpa_driver_nl80211_data *drv) |
| 5831 | { |
| 5832 | char buf[200], *pos, *end; |
| 5833 | int i, res; |
| 5834 | |
| 5835 | pos = buf; |
| 5836 | end = pos + sizeof(buf); |
| 5837 | |
| 5838 | for (i = 0; i < drv->num_if_indices; i++) { |
| 5839 | if (!drv->if_indices[i]) |
| 5840 | continue; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5841 | res = os_snprintf(pos, end - pos, " %d(%d)", |
| 5842 | drv->if_indices[i], |
| 5843 | drv->if_indices_reason[i]); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 5844 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5845 | break; |
| 5846 | pos += res; |
| 5847 | } |
| 5848 | *pos = '\0'; |
| 5849 | |
| 5850 | wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s", |
| 5851 | drv->num_if_indices, buf); |
| 5852 | } |
| 5853 | |
| 5854 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5855 | static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 5856 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5857 | { |
| 5858 | int i; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5859 | int *old, *old_reason; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5860 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5861 | wpa_printf(MSG_DEBUG, |
| 5862 | "nl80211: Add own interface ifindex %d (ifidx_reason %d)", |
| 5863 | ifidx, ifidx_reason); |
| 5864 | if (have_ifidx(drv, ifidx, ifidx_reason)) { |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5865 | wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list", |
| 5866 | ifidx); |
| 5867 | return; |
| 5868 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5869 | for (i = 0; i < drv->num_if_indices; i++) { |
| 5870 | if (drv->if_indices[i] == 0) { |
| 5871 | drv->if_indices[i] = ifidx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5872 | drv->if_indices_reason[i] = ifidx_reason; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5873 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5874 | return; |
| 5875 | } |
| 5876 | } |
| 5877 | |
| 5878 | if (drv->if_indices != drv->default_if_indices) |
| 5879 | old = drv->if_indices; |
| 5880 | else |
| 5881 | old = NULL; |
| 5882 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5883 | if (drv->if_indices_reason != drv->default_if_indices_reason) |
| 5884 | old_reason = drv->if_indices_reason; |
| 5885 | else |
| 5886 | old_reason = NULL; |
| 5887 | |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5888 | drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1, |
| 5889 | sizeof(int)); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5890 | drv->if_indices_reason = os_realloc_array(old_reason, |
| 5891 | drv->num_if_indices + 1, |
| 5892 | sizeof(int)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5893 | if (!drv->if_indices) { |
| 5894 | if (!old) |
| 5895 | drv->if_indices = drv->default_if_indices; |
| 5896 | else |
| 5897 | drv->if_indices = old; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5898 | } |
| 5899 | if (!drv->if_indices_reason) { |
| 5900 | if (!old_reason) |
| 5901 | drv->if_indices_reason = drv->default_if_indices_reason; |
| 5902 | else |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 5903 | drv->if_indices_reason = old_reason; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5904 | } |
| 5905 | if (!drv->if_indices || !drv->if_indices_reason) { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5906 | wpa_printf(MSG_ERROR, "Failed to reallocate memory for " |
| 5907 | "interfaces"); |
| 5908 | wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx); |
| 5909 | return; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5910 | } |
| 5911 | if (!old) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5912 | os_memcpy(drv->if_indices, drv->default_if_indices, |
| 5913 | sizeof(drv->default_if_indices)); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5914 | if (!old_reason) |
| 5915 | os_memcpy(drv->if_indices_reason, |
| 5916 | drv->default_if_indices_reason, |
| 5917 | sizeof(drv->default_if_indices_reason)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5918 | drv->if_indices[drv->num_if_indices] = ifidx; |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5919 | drv->if_indices_reason[drv->num_if_indices] = ifidx_reason; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5920 | drv->num_if_indices++; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5921 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5922 | } |
| 5923 | |
| 5924 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5925 | static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 5926 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5927 | { |
| 5928 | int i; |
| 5929 | |
| 5930 | for (i = 0; i < drv->num_if_indices; i++) { |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5931 | if ((drv->if_indices[i] == ifidx || ifidx == IFIDX_ANY) && |
| 5932 | (drv->if_indices_reason[i] == ifidx_reason || |
| 5933 | ifidx_reason == IFIDX_ANY)) { |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5934 | drv->if_indices[i] = 0; |
| 5935 | break; |
| 5936 | } |
| 5937 | } |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 5938 | dump_ifidx(drv); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5939 | } |
| 5940 | |
| 5941 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5942 | static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx, |
| 5943 | int ifidx_reason) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5944 | { |
| 5945 | int i; |
| 5946 | |
| 5947 | for (i = 0; i < drv->num_if_indices; i++) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 5948 | if (drv->if_indices[i] == ifidx && |
| 5949 | (drv->if_indices_reason[i] == ifidx_reason || |
| 5950 | ifidx_reason == IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5951 | return 1; |
| 5952 | |
| 5953 | return 0; |
| 5954 | } |
| 5955 | |
| 5956 | |
| 5957 | 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] | 5958 | const char *bridge_ifname, char *ifname_wds) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5959 | { |
| 5960 | struct i802_bss *bss = priv; |
| 5961 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 5962 | char name[IFNAMSIZ + 1]; |
| 5963 | |
| 5964 | os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 5965 | if (ifname_wds) |
| 5966 | os_strlcpy(ifname_wds, name, IFNAMSIZ + 1); |
| 5967 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5968 | wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR |
| 5969 | " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name); |
| 5970 | if (val) { |
| 5971 | if (!if_nametoindex(name)) { |
| 5972 | if (nl80211_create_iface(drv, name, |
| 5973 | NL80211_IFTYPE_AP_VLAN, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 5974 | bss->addr, 1, NULL, NULL, 0) < |
| 5975 | 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5976 | return -1; |
| 5977 | if (bridge_ifname && |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 5978 | linux_br_add_if(drv->global->ioctl_sock, |
| 5979 | bridge_ifname, name) < 0) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5980 | return -1; |
| 5981 | } |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 5982 | if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) { |
| 5983 | wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA " |
| 5984 | "interface %s up", name); |
| 5985 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5986 | return i802_set_sta_vlan(priv, addr, name, 0); |
| 5987 | } else { |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 5988 | if (bridge_ifname) |
| 5989 | linux_br_del_if(drv->global->ioctl_sock, bridge_ifname, |
| 5990 | name); |
| 5991 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5992 | i802_set_sta_vlan(priv, addr, bss->ifname, 0); |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 5993 | nl80211_remove_iface(drv, if_nametoindex(name)); |
| 5994 | return 0; |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 5995 | } |
| 5996 | } |
| 5997 | |
| 5998 | |
| 5999 | static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx) |
| 6000 | { |
| 6001 | struct wpa_driver_nl80211_data *drv = eloop_ctx; |
| 6002 | struct sockaddr_ll lladdr; |
| 6003 | unsigned char buf[3000]; |
| 6004 | int len; |
| 6005 | socklen_t fromlen = sizeof(lladdr); |
| 6006 | |
| 6007 | len = recvfrom(sock, buf, sizeof(buf), 0, |
| 6008 | (struct sockaddr *)&lladdr, &fromlen); |
| 6009 | if (len < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6010 | wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s", |
| 6011 | strerror(errno)); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6012 | return; |
| 6013 | } |
| 6014 | |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6015 | if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY)) |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 6016 | drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len); |
| 6017 | } |
| 6018 | |
| 6019 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6020 | static int i802_check_bridge(struct wpa_driver_nl80211_data *drv, |
| 6021 | struct i802_bss *bss, |
| 6022 | const char *brname, const char *ifname) |
| 6023 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6024 | int br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6025 | char in_br[IFNAMSIZ]; |
| 6026 | |
| 6027 | os_strlcpy(bss->brname, brname, IFNAMSIZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6028 | br_ifindex = if_nametoindex(brname); |
| 6029 | if (br_ifindex == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6030 | /* |
| 6031 | * Bridge was configured, but the bridge device does |
| 6032 | * not exist. Try to add it now. |
| 6033 | */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6034 | if (linux_br_add(drv->global->ioctl_sock, brname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6035 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the " |
| 6036 | "bridge interface %s: %s", |
| 6037 | brname, strerror(errno)); |
| 6038 | return -1; |
| 6039 | } |
| 6040 | bss->added_bridge = 1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6041 | br_ifindex = if_nametoindex(brname); |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6042 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6043 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6044 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6045 | |
| 6046 | if (linux_br_get(in_br, ifname) == 0) { |
| 6047 | if (os_strcmp(in_br, brname) == 0) |
| 6048 | return 0; /* already in the bridge */ |
| 6049 | |
| 6050 | wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from " |
| 6051 | "bridge %s", ifname, in_br); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6052 | if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) < |
| 6053 | 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6054 | wpa_printf(MSG_ERROR, "nl80211: Failed to " |
| 6055 | "remove interface %s from bridge " |
| 6056 | "%s: %s", |
| 6057 | ifname, brname, strerror(errno)); |
| 6058 | return -1; |
| 6059 | } |
| 6060 | } |
| 6061 | |
| 6062 | wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s", |
| 6063 | ifname, brname); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6064 | if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6065 | wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s " |
| 6066 | "into bridge %s: %s", |
| 6067 | ifname, brname, strerror(errno)); |
| 6068 | return -1; |
| 6069 | } |
| 6070 | bss->added_if_into_bridge = 1; |
| 6071 | |
| 6072 | return 0; |
| 6073 | } |
| 6074 | |
| 6075 | |
| 6076 | static void *i802_init(struct hostapd_data *hapd, |
| 6077 | struct wpa_init_params *params) |
| 6078 | { |
| 6079 | struct wpa_driver_nl80211_data *drv; |
| 6080 | struct i802_bss *bss; |
| 6081 | size_t i; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6082 | char master_ifname[IFNAMSIZ]; |
| 6083 | int ifindex, br_ifindex = 0; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6084 | int br_added = 0; |
| 6085 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 6086 | bss = wpa_driver_nl80211_drv_init(hapd, params->ifname, |
| 6087 | params->global_priv, 1, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6088 | params->bssid, params->driver_params); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6089 | if (bss == NULL) |
| 6090 | return NULL; |
| 6091 | |
| 6092 | drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6093 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6094 | if (linux_br_get(master_ifname, params->ifname) == 0) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6095 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s", |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6096 | params->ifname, master_ifname); |
| 6097 | br_ifindex = if_nametoindex(master_ifname); |
| 6098 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 6099 | } else if ((params->num_bridge == 0 || !params->bridge[0]) && |
| 6100 | linux_master_get(master_ifname, params->ifname) == 0) { |
| 6101 | wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s", |
| 6102 | params->ifname, master_ifname); |
| 6103 | /* start listening for EAPOL on the master interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6104 | add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex); |
Dmitry Shmidt | 31a29cc | 2016-03-09 15:58:17 -0800 | [diff] [blame] | 6105 | |
| 6106 | /* check if master itself is under bridge */ |
| 6107 | if (linux_br_get(master_ifname, master_ifname) == 0) { |
| 6108 | wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s", |
| 6109 | master_ifname); |
| 6110 | br_ifindex = if_nametoindex(master_ifname); |
| 6111 | os_strlcpy(bss->brname, master_ifname, IFNAMSIZ); |
| 6112 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6113 | } else { |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6114 | master_ifname[0] = '\0'; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6115 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6116 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6117 | bss->br_ifindex = br_ifindex; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6118 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6119 | for (i = 0; i < params->num_bridge; i++) { |
| 6120 | if (params->bridge[i]) { |
| 6121 | ifindex = if_nametoindex(params->bridge[i]); |
| 6122 | if (ifindex) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6123 | add_ifidx(drv, ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6124 | if (ifindex == br_ifindex) |
| 6125 | br_added = 1; |
| 6126 | } |
| 6127 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6128 | |
| 6129 | /* start listening for EAPOL on the default AP interface */ |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6130 | add_ifidx(drv, drv->ifindex, IFIDX_ANY); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6131 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6132 | if (params->num_bridge && params->bridge[0]) { |
| 6133 | if (i802_check_bridge(drv, bss, params->bridge[0], |
| 6134 | params->ifname) < 0) |
| 6135 | goto failed; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6136 | if (os_strcmp(params->bridge[0], master_ifname) != 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6137 | br_added = 1; |
| 6138 | } |
| 6139 | |
| 6140 | if (!br_added && br_ifindex && |
| 6141 | (params->num_bridge == 0 || !params->bridge[0])) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6142 | add_ifidx(drv, br_ifindex, drv->ifindex); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6143 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6144 | #ifdef CONFIG_LIBNL3_ROUTE |
| 6145 | if (bss->added_if_into_bridge) { |
| 6146 | drv->rtnl_sk = nl_socket_alloc(); |
| 6147 | if (drv->rtnl_sk == NULL) { |
| 6148 | wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock"); |
| 6149 | goto failed; |
| 6150 | } |
| 6151 | |
| 6152 | if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) { |
| 6153 | wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s", |
| 6154 | strerror(errno)); |
| 6155 | goto failed; |
| 6156 | } |
| 6157 | } |
| 6158 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 6159 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6160 | drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE)); |
| 6161 | if (drv->eapol_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6162 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s", |
| 6163 | strerror(errno)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6164 | goto failed; |
| 6165 | } |
| 6166 | |
| 6167 | if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL)) |
| 6168 | { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6169 | wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol"); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6170 | goto failed; |
| 6171 | } |
| 6172 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6173 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname, |
| 6174 | params->own_addr)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6175 | goto failed; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 6176 | os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6177 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6178 | memcpy(bss->addr, params->own_addr, ETH_ALEN); |
| 6179 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6180 | return bss; |
| 6181 | |
| 6182 | failed: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6183 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6184 | return NULL; |
| 6185 | } |
| 6186 | |
| 6187 | |
| 6188 | static void i802_deinit(void *priv) |
| 6189 | { |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6190 | struct i802_bss *bss = priv; |
| 6191 | wpa_driver_nl80211_deinit(bss); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6192 | } |
| 6193 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6194 | |
| 6195 | static enum nl80211_iftype wpa_driver_nl80211_if_type( |
| 6196 | enum wpa_driver_if_type type) |
| 6197 | { |
| 6198 | switch (type) { |
| 6199 | case WPA_IF_STATION: |
| 6200 | return NL80211_IFTYPE_STATION; |
| 6201 | case WPA_IF_P2P_CLIENT: |
| 6202 | case WPA_IF_P2P_GROUP: |
| 6203 | return NL80211_IFTYPE_P2P_CLIENT; |
| 6204 | case WPA_IF_AP_VLAN: |
| 6205 | return NL80211_IFTYPE_AP_VLAN; |
| 6206 | case WPA_IF_AP_BSS: |
| 6207 | return NL80211_IFTYPE_AP; |
| 6208 | case WPA_IF_P2P_GO: |
| 6209 | return NL80211_IFTYPE_P2P_GO; |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6210 | case WPA_IF_P2P_DEVICE: |
| 6211 | return NL80211_IFTYPE_P2P_DEVICE; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6212 | case WPA_IF_MESH: |
| 6213 | return NL80211_IFTYPE_MESH_POINT; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6214 | default: |
| 6215 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6216 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6217 | } |
| 6218 | |
| 6219 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6220 | static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr) |
| 6221 | { |
| 6222 | struct wpa_driver_nl80211_data *drv; |
| 6223 | dl_list_for_each(drv, &global->interfaces, |
| 6224 | struct wpa_driver_nl80211_data, list) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6225 | if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6226 | return 1; |
| 6227 | } |
| 6228 | return 0; |
| 6229 | } |
| 6230 | |
| 6231 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6232 | 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] | 6233 | { |
| 6234 | unsigned int idx; |
| 6235 | |
| 6236 | if (!drv->global) |
| 6237 | return -1; |
| 6238 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6239 | os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6240 | for (idx = 0; idx < 64; idx++) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6241 | new_addr[0] = drv->first_bss->addr[0] | 0x02; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6242 | new_addr[0] ^= idx << 2; |
| 6243 | if (!nl80211_addr_in_use(drv->global, new_addr)) |
| 6244 | break; |
| 6245 | } |
| 6246 | if (idx == 64) |
| 6247 | return -1; |
| 6248 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6249 | wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address " |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6250 | MACSTR, MAC2STR(new_addr)); |
| 6251 | |
| 6252 | return 0; |
| 6253 | } |
| 6254 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6255 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6256 | struct wdev_info { |
| 6257 | u64 wdev_id; |
| 6258 | int wdev_id_set; |
| 6259 | u8 macaddr[ETH_ALEN]; |
| 6260 | }; |
| 6261 | |
| 6262 | static int nl80211_wdev_handler(struct nl_msg *msg, void *arg) |
| 6263 | { |
| 6264 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6265 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6266 | struct wdev_info *wi = arg; |
| 6267 | |
| 6268 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6269 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6270 | if (tb[NL80211_ATTR_WDEV]) { |
| 6271 | wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]); |
| 6272 | wi->wdev_id_set = 1; |
| 6273 | } |
| 6274 | |
| 6275 | if (tb[NL80211_ATTR_MAC]) |
| 6276 | os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]), |
| 6277 | ETH_ALEN); |
| 6278 | |
| 6279 | return NL_SKIP; |
| 6280 | } |
| 6281 | |
| 6282 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6283 | static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type, |
| 6284 | const char *ifname, const u8 *addr, |
| 6285 | void *bss_ctx, void **drv_priv, |
| 6286 | char *force_ifname, u8 *if_addr, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6287 | const char *bridge, int use_existing, |
| 6288 | int setup_ap) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6289 | { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6290 | enum nl80211_iftype nlmode; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6291 | struct i802_bss *bss = priv; |
| 6292 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6293 | int ifidx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6294 | int added = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6295 | |
| 6296 | if (addr) |
| 6297 | os_memcpy(if_addr, addr, ETH_ALEN); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6298 | nlmode = wpa_driver_nl80211_if_type(type); |
| 6299 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) { |
| 6300 | struct wdev_info p2pdev_info; |
| 6301 | |
| 6302 | os_memset(&p2pdev_info, 0, sizeof(p2pdev_info)); |
| 6303 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
| 6304 | 0, nl80211_wdev_handler, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6305 | &p2pdev_info, use_existing); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6306 | if (!p2pdev_info.wdev_id_set || ifidx != 0) { |
| 6307 | wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s", |
| 6308 | ifname); |
| 6309 | return -1; |
| 6310 | } |
| 6311 | |
| 6312 | drv->global->if_add_wdevid = p2pdev_info.wdev_id; |
| 6313 | drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set; |
| 6314 | if (!is_zero_ether_addr(p2pdev_info.macaddr)) |
| 6315 | os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN); |
| 6316 | wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created", |
| 6317 | ifname, |
| 6318 | (long long unsigned int) p2pdev_info.wdev_id); |
| 6319 | } else { |
| 6320 | ifidx = nl80211_create_iface(drv, ifname, nlmode, addr, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6321 | 0, NULL, NULL, use_existing); |
| 6322 | if (use_existing && ifidx == -ENFILE) { |
| 6323 | added = 0; |
| 6324 | ifidx = if_nametoindex(ifname); |
| 6325 | } else if (ifidx < 0) { |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6326 | return -1; |
| 6327 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6328 | } |
| 6329 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6330 | if (!addr) { |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6331 | if (nlmode == NL80211_IFTYPE_P2P_DEVICE) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6332 | os_memcpy(if_addr, bss->addr, ETH_ALEN); |
| 6333 | else if (linux_get_ifhwaddr(drv->global->ioctl_sock, |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6334 | ifname, if_addr) < 0) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6335 | if (added) |
| 6336 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6337 | return -1; |
| 6338 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6339 | } |
| 6340 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6341 | if (!addr && |
| 6342 | (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP || |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6343 | type == WPA_IF_P2P_GO || type == WPA_IF_MESH || |
| 6344 | type == WPA_IF_STATION)) { |
| 6345 | /* Enforce unique address */ |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6346 | u8 new_addr[ETH_ALEN]; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6347 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6348 | if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6349 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6350 | if (added) |
| 6351 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6352 | return -1; |
| 6353 | } |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6354 | if (nl80211_addr_in_use(drv->global, new_addr)) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6355 | wpa_printf(MSG_DEBUG, "nl80211: Allocate new address " |
Dmitry Shmidt | 1d755d0 | 2015-04-28 10:34:29 -0700 | [diff] [blame] | 6356 | "for interface %s type %d", ifname, type); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6357 | if (nl80211_vif_addr(drv, new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6358 | if (added) |
| 6359 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6360 | return -1; |
| 6361 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6362 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6363 | new_addr) < 0) { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6364 | if (added) |
| 6365 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6366 | return -1; |
| 6367 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6368 | } |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6369 | os_memcpy(if_addr, new_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6370 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6371 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6372 | if (type == WPA_IF_AP_BSS && setup_ap) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6373 | struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss)); |
| 6374 | if (new_bss == NULL) { |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6375 | if (added) |
| 6376 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6377 | return -1; |
| 6378 | } |
| 6379 | |
| 6380 | if (bridge && |
| 6381 | i802_check_bridge(drv, new_bss, bridge, ifname) < 0) { |
| 6382 | wpa_printf(MSG_ERROR, "nl80211: Failed to add the new " |
| 6383 | "interface %s to a bridge %s", |
| 6384 | ifname, bridge); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6385 | if (added) |
| 6386 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6387 | os_free(new_bss); |
| 6388 | return -1; |
| 6389 | } |
| 6390 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6391 | if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1)) |
| 6392 | { |
Dmitry Shmidt | 7175743 | 2014-06-02 13:50:35 -0700 | [diff] [blame] | 6393 | if (added) |
| 6394 | nl80211_remove_iface(drv, ifidx); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6395 | os_free(new_bss); |
| 6396 | return -1; |
| 6397 | } |
| 6398 | os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6399 | os_memcpy(new_bss->addr, if_addr, ETH_ALEN); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6400 | new_bss->ifindex = ifidx; |
| 6401 | new_bss->drv = drv; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6402 | new_bss->next = drv->first_bss->next; |
| 6403 | new_bss->freq = drv->first_bss->freq; |
Dmitry Shmidt | a54fa5f | 2013-01-15 13:53:35 -0800 | [diff] [blame] | 6404 | new_bss->ctx = bss_ctx; |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6405 | new_bss->added_if = added; |
| 6406 | drv->first_bss->next = new_bss; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6407 | if (drv_priv) |
| 6408 | *drv_priv = new_bss; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6409 | nl80211_init_bss(new_bss); |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6410 | |
| 6411 | /* Subscribe management frames for this WPA_IF_AP_BSS */ |
| 6412 | if (nl80211_setup_ap(new_bss)) |
| 6413 | return -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6414 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6415 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6416 | if (drv->global) |
| 6417 | drv->global->if_add_ifindex = ifidx; |
| 6418 | |
Dmitry Shmidt | 43cb578 | 2014-06-16 16:23:22 -0700 | [diff] [blame] | 6419 | /* |
| 6420 | * Some virtual interfaces need to process EAPOL packets and events on |
| 6421 | * the parent interface. This is used mainly with hostapd. |
| 6422 | */ |
| 6423 | if (ifidx > 0 && |
| 6424 | (drv->hostapd || |
| 6425 | nlmode == NL80211_IFTYPE_AP_VLAN || |
| 6426 | nlmode == NL80211_IFTYPE_WDS || |
| 6427 | nlmode == NL80211_IFTYPE_MONITOR)) |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6428 | add_ifidx(drv, ifidx, IFIDX_ANY); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6429 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6430 | return 0; |
| 6431 | } |
| 6432 | |
| 6433 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6434 | static int wpa_driver_nl80211_if_remove(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6435 | enum wpa_driver_if_type type, |
| 6436 | const char *ifname) |
| 6437 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6438 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6439 | int ifindex = if_nametoindex(ifname); |
| 6440 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6441 | wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d", |
| 6442 | __func__, type, ifname, ifindex, bss->added_if); |
Dmitry Shmidt | 01904cf | 2013-12-05 11:08:35 -0800 | [diff] [blame] | 6443 | if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex)) |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 6444 | nl80211_remove_iface(drv, ifindex); |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 6445 | else if (ifindex > 0 && !bss->added_if) { |
| 6446 | struct wpa_driver_nl80211_data *drv2; |
| 6447 | dl_list_for_each(drv2, &drv->global->interfaces, |
Dmitry Shmidt | 9c17526 | 2016-03-03 10:20:07 -0800 | [diff] [blame] | 6448 | struct wpa_driver_nl80211_data, list) { |
| 6449 | del_ifidx(drv2, ifindex, IFIDX_ANY); |
| 6450 | del_ifidx(drv2, IFIDX_ANY, ifindex); |
| 6451 | } |
Dmitry Shmidt | 76cd2cc | 2014-05-27 12:56:04 -0700 | [diff] [blame] | 6452 | } |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6453 | |
Dmitry Shmidt | aa53251 | 2012-09-24 10:35:31 -0700 | [diff] [blame] | 6454 | if (type != WPA_IF_AP_BSS) |
| 6455 | return 0; |
| 6456 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6457 | if (bss->added_if_into_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6458 | if (linux_br_del_if(drv->global->ioctl_sock, bss->brname, |
| 6459 | bss->ifname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6460 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 6461 | "interface %s from bridge %s: %s", |
| 6462 | bss->ifname, bss->brname, strerror(errno)); |
| 6463 | } |
| 6464 | if (bss->added_bridge) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6465 | if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6466 | wpa_printf(MSG_INFO, "nl80211: Failed to remove " |
| 6467 | "bridge %s: %s", |
| 6468 | bss->brname, strerror(errno)); |
| 6469 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6470 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6471 | if (bss != drv->first_bss) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6472 | struct i802_bss *tbss; |
| 6473 | |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6474 | wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it"); |
| 6475 | for (tbss = drv->first_bss; tbss; tbss = tbss->next) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6476 | if (tbss->next == bss) { |
| 6477 | tbss->next = bss->next; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6478 | /* Unsubscribe management frames */ |
| 6479 | nl80211_teardown_ap(bss); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6480 | nl80211_destroy_bss(bss); |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 6481 | if (!bss->added_if) |
| 6482 | i802_set_iface_flags(bss, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6483 | os_free(bss); |
| 6484 | bss = NULL; |
| 6485 | break; |
| 6486 | } |
| 6487 | } |
| 6488 | if (bss) |
| 6489 | wpa_printf(MSG_INFO, "nl80211: %s - could not find " |
| 6490 | "BSS %p in the list", __func__, bss); |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 6491 | } else { |
| 6492 | wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context"); |
| 6493 | nl80211_teardown_ap(bss); |
| 6494 | if (!bss->added_if && !drv->first_bss->next) |
| 6495 | wpa_driver_nl80211_del_beacon(drv); |
| 6496 | nl80211_destroy_bss(bss); |
| 6497 | if (!bss->added_if) |
| 6498 | i802_set_iface_flags(bss, 0); |
| 6499 | if (drv->first_bss->next) { |
| 6500 | drv->first_bss = drv->first_bss->next; |
| 6501 | drv->ctx = drv->first_bss->ctx; |
| 6502 | os_free(bss); |
| 6503 | } else { |
| 6504 | wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to"); |
| 6505 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6506 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6507 | |
| 6508 | return 0; |
| 6509 | } |
| 6510 | |
| 6511 | |
| 6512 | static int cookie_handler(struct nl_msg *msg, void *arg) |
| 6513 | { |
| 6514 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6515 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6516 | u64 *cookie = arg; |
| 6517 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6518 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6519 | if (tb[NL80211_ATTR_COOKIE]) |
| 6520 | *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]); |
| 6521 | return NL_SKIP; |
| 6522 | } |
| 6523 | |
| 6524 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6525 | static int nl80211_send_frame_cmd(struct i802_bss *bss, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6526 | unsigned int freq, unsigned int wait, |
| 6527 | const u8 *buf, size_t buf_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6528 | u64 *cookie_out, int no_cck, int no_ack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6529 | int offchanok, const u16 *csa_offs, |
| 6530 | size_t csa_offs_len) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6531 | { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6532 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6533 | struct nl_msg *msg; |
| 6534 | u64 cookie; |
| 6535 | int ret = -1; |
| 6536 | |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6537 | 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] | 6538 | "no_ack=%d offchanok=%d", |
| 6539 | freq, wait, no_cck, no_ack, offchanok); |
Dmitry Shmidt | c2ebb4b | 2013-07-24 12:57:51 -0700 | [diff] [blame] | 6540 | wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6541 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6542 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) || |
| 6543 | (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) || |
| 6544 | (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) || |
| 6545 | (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 6546 | drv->test_use_roc_tx) && |
| 6547 | nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) || |
| 6548 | (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) || |
| 6549 | (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) || |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6550 | (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX, |
| 6551 | csa_offs_len * sizeof(u16), csa_offs)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6552 | nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf)) |
| 6553 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6554 | |
| 6555 | cookie = 0; |
| 6556 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 6557 | msg = NULL; |
| 6558 | if (ret) { |
| 6559 | wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d " |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6560 | "(%s) (freq=%u wait=%u)", ret, strerror(-ret), |
| 6561 | freq, wait); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6562 | } else { |
| 6563 | wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; " |
| 6564 | "cookie 0x%llx", no_ack ? " (no ACK)" : "", |
| 6565 | (long long unsigned int) cookie); |
| 6566 | |
| 6567 | if (cookie_out) |
| 6568 | *cookie_out = no_ack ? (u64) -1 : cookie; |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6569 | |
| 6570 | if (drv->num_send_action_cookies == MAX_SEND_ACTION_COOKIES) { |
| 6571 | wpa_printf(MSG_DEBUG, |
| 6572 | "nl80211: Drop oldest pending send action cookie 0x%llx", |
| 6573 | (long long unsigned int) |
| 6574 | drv->send_action_cookies[0]); |
| 6575 | os_memmove(&drv->send_action_cookies[0], |
| 6576 | &drv->send_action_cookies[1], |
| 6577 | (MAX_SEND_ACTION_COOKIES - 1) * |
| 6578 | sizeof(u64)); |
| 6579 | drv->num_send_action_cookies--; |
| 6580 | } |
| 6581 | drv->send_action_cookies[drv->num_send_action_cookies] = cookie; |
| 6582 | drv->num_send_action_cookies++; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6583 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6584 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6585 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6586 | nlmsg_free(msg); |
| 6587 | return ret; |
| 6588 | } |
| 6589 | |
| 6590 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6591 | static int wpa_driver_nl80211_send_action(struct i802_bss *bss, |
| 6592 | unsigned int freq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6593 | unsigned int wait_time, |
| 6594 | const u8 *dst, const u8 *src, |
| 6595 | const u8 *bssid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6596 | const u8 *data, size_t data_len, |
| 6597 | int no_cck) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6598 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6599 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6600 | int ret = -1; |
| 6601 | u8 *buf; |
| 6602 | struct ieee80211_hdr *hdr; |
| 6603 | |
| 6604 | wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, " |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 6605 | "freq=%u MHz wait=%d ms no_cck=%d)", |
| 6606 | drv->ifindex, freq, wait_time, no_cck); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6607 | |
| 6608 | buf = os_zalloc(24 + data_len); |
| 6609 | if (buf == NULL) |
| 6610 | return ret; |
| 6611 | os_memcpy(buf + 24, data, data_len); |
| 6612 | hdr = (struct ieee80211_hdr *) buf; |
| 6613 | hdr->frame_control = |
| 6614 | IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION); |
| 6615 | os_memcpy(hdr->addr1, dst, ETH_ALEN); |
| 6616 | os_memcpy(hdr->addr2, src, ETH_ALEN); |
| 6617 | os_memcpy(hdr->addr3, bssid, ETH_ALEN); |
| 6618 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 6619 | if (is_ap_interface(drv->nlmode) && |
| 6620 | (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) || |
| 6621 | (int) freq == bss->freq || drv->device_ap_sme || |
| 6622 | !drv->use_monitor)) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6623 | ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len, |
| 6624 | 0, freq, no_cck, 1, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6625 | wait_time, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6626 | else |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6627 | ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6628 | 24 + data_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6629 | &drv->send_action_cookie, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6630 | no_cck, 0, 1, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6631 | |
| 6632 | os_free(buf); |
| 6633 | return ret; |
| 6634 | } |
| 6635 | |
| 6636 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6637 | static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6638 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6639 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6640 | struct nl_msg *msg; |
| 6641 | int ret; |
| 6642 | |
Dmitry Shmidt | 2f3b8de | 2013-03-01 09:32:50 -0800 | [diff] [blame] | 6643 | wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx", |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6644 | (long long unsigned int) cookie); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6645 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) || |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6646 | nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6647 | nlmsg_free(msg); |
| 6648 | return; |
| 6649 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6650 | |
| 6651 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6652 | if (ret) |
| 6653 | wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d " |
| 6654 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6655 | } |
| 6656 | |
| 6657 | |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6658 | static void wpa_driver_nl80211_send_action_cancel_wait(void *priv) |
| 6659 | { |
| 6660 | struct i802_bss *bss = priv; |
| 6661 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6662 | unsigned int i; |
| 6663 | u64 cookie; |
| 6664 | |
| 6665 | /* Cancel the last pending TX cookie */ |
| 6666 | nl80211_frame_wait_cancel(bss, drv->send_action_cookie); |
| 6667 | |
| 6668 | /* |
| 6669 | * Cancel the other pending TX cookies, if any. This is needed since |
| 6670 | * the driver may keep a list of all pending offchannel TX operations |
| 6671 | * and free up the radio only once they have expired or cancelled. |
| 6672 | */ |
| 6673 | for (i = drv->num_send_action_cookies; i > 0; i--) { |
| 6674 | cookie = drv->send_action_cookies[i - 1]; |
| 6675 | if (cookie != drv->send_action_cookie) |
| 6676 | nl80211_frame_wait_cancel(bss, cookie); |
| 6677 | } |
| 6678 | drv->num_send_action_cookies = 0; |
| 6679 | } |
| 6680 | |
| 6681 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6682 | static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq, |
| 6683 | unsigned int duration) |
| 6684 | { |
| 6685 | struct i802_bss *bss = priv; |
| 6686 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6687 | struct nl_msg *msg; |
| 6688 | int ret; |
| 6689 | u64 cookie; |
| 6690 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6691 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) || |
| 6692 | nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) || |
| 6693 | nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) { |
| 6694 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6695 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6696 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6697 | |
| 6698 | cookie = 0; |
| 6699 | ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie); |
| 6700 | if (ret == 0) { |
| 6701 | wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie " |
| 6702 | "0x%llx for freq=%u MHz duration=%u", |
| 6703 | (long long unsigned int) cookie, freq, duration); |
| 6704 | drv->remain_on_chan_cookie = cookie; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6705 | drv->pending_remain_on_chan = 1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6706 | return 0; |
| 6707 | } |
| 6708 | wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel " |
| 6709 | "(freq=%d duration=%u): %d (%s)", |
| 6710 | freq, duration, ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6711 | return -1; |
| 6712 | } |
| 6713 | |
| 6714 | |
| 6715 | static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv) |
| 6716 | { |
| 6717 | struct i802_bss *bss = priv; |
| 6718 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6719 | struct nl_msg *msg; |
| 6720 | int ret; |
| 6721 | |
| 6722 | if (!drv->pending_remain_on_chan) { |
| 6723 | wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel " |
| 6724 | "to cancel"); |
| 6725 | return -1; |
| 6726 | } |
| 6727 | |
| 6728 | wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie " |
| 6729 | "0x%llx", |
| 6730 | (long long unsigned int) drv->remain_on_chan_cookie); |
| 6731 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6732 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL); |
| 6733 | if (!msg || |
| 6734 | nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) { |
| 6735 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6736 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6737 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6738 | |
| 6739 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 6740 | if (ret == 0) |
| 6741 | return 0; |
| 6742 | wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: " |
| 6743 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6744 | return -1; |
| 6745 | } |
| 6746 | |
| 6747 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 6748 | 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] | 6749 | { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6750 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 6751 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6752 | if (!report) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6753 | if (bss->nl_preq && drv->device_ap_sme && |
Dmitry Shmidt | 0365883 | 2014-08-13 11:03:49 -0700 | [diff] [blame] | 6754 | is_ap_interface(drv->nlmode) && !bss->in_deinit && |
| 6755 | !bss->static_ap) { |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6756 | /* |
| 6757 | * Do not disable Probe Request reporting that was |
| 6758 | * enabled in nl80211_setup_ap(). |
| 6759 | */ |
| 6760 | wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of " |
| 6761 | "Probe Request reporting nl_preq=%p while " |
| 6762 | "in AP mode", bss->nl_preq); |
| 6763 | } else if (bss->nl_preq) { |
| 6764 | wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request " |
| 6765 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6766 | nl80211_destroy_eloop_handle(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6767 | } |
| 6768 | return 0; |
| 6769 | } |
| 6770 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6771 | if (bss->nl_preq) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6772 | wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting " |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6773 | "already on! nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6774 | return 0; |
| 6775 | } |
| 6776 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6777 | bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq"); |
| 6778 | if (bss->nl_preq == NULL) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6779 | return -1; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6780 | wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request " |
| 6781 | "reporting nl_preq=%p", bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6782 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6783 | if (nl80211_register_frame(bss, bss->nl_preq, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6784 | (WLAN_FC_TYPE_MGMT << 2) | |
| 6785 | (WLAN_FC_STYPE_PROBE_REQ << 4), |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6786 | NULL, 0) < 0) |
| 6787 | goto out_err; |
Dmitry Shmidt | 497c1d5 | 2011-07-21 15:19:46 -0700 | [diff] [blame] | 6788 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 6789 | nl80211_register_eloop_read(&bss->nl_preq, |
| 6790 | wpa_driver_nl80211_event_receive, |
| 6791 | bss->nl_cb); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6792 | |
| 6793 | return 0; |
| 6794 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6795 | out_err: |
| 6796 | nl_destroy_handles(&bss->nl_preq); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6797 | return -1; |
| 6798 | } |
| 6799 | |
| 6800 | |
| 6801 | static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv, |
| 6802 | int ifindex, int disabled) |
| 6803 | { |
| 6804 | struct nl_msg *msg; |
| 6805 | struct nlattr *bands, *band; |
| 6806 | int ret; |
| 6807 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6808 | wpa_printf(MSG_DEBUG, |
| 6809 | "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)", |
| 6810 | ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" : |
| 6811 | "no NL80211_TXRATE_LEGACY constraint"); |
| 6812 | |
| 6813 | msg = nl80211_ifindex_msg(drv, ifindex, 0, |
| 6814 | NL80211_CMD_SET_TX_BITRATE_MASK); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6815 | if (!msg) |
| 6816 | return -1; |
| 6817 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6818 | bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES); |
| 6819 | if (!bands) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6820 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6821 | |
| 6822 | /* |
| 6823 | * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything |
| 6824 | * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS |
| 6825 | * rates. All 5 GHz rates are left enabled. |
| 6826 | */ |
| 6827 | band = nla_nest_start(msg, NL80211_BAND_2GHZ); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6828 | if (!band || |
| 6829 | (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8, |
| 6830 | "\x0c\x12\x18\x24\x30\x48\x60\x6c"))) |
| 6831 | goto fail; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6832 | nla_nest_end(msg, band); |
| 6833 | |
| 6834 | nla_nest_end(msg, bands); |
| 6835 | |
| 6836 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6837 | if (ret) { |
| 6838 | wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d " |
| 6839 | "(%s)", ret, strerror(-ret)); |
Dmitry Shmidt | 61d9df3 | 2012-08-29 16:22:06 -0700 | [diff] [blame] | 6840 | } else |
| 6841 | drv->disabled_11b_rates = disabled; |
| 6842 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6843 | return ret; |
| 6844 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6845 | fail: |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6846 | nlmsg_free(msg); |
| 6847 | return -1; |
| 6848 | } |
| 6849 | |
| 6850 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6851 | static int wpa_driver_nl80211_deinit_ap(void *priv) |
| 6852 | { |
| 6853 | struct i802_bss *bss = priv; |
| 6854 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6855 | if (!is_ap_interface(drv->nlmode)) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6856 | return -1; |
| 6857 | wpa_driver_nl80211_del_beacon(drv); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6858 | bss->beacon_set = 0; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6859 | |
| 6860 | /* |
| 6861 | * If the P2P GO interface was dynamically added, then it is |
| 6862 | * possible that the interface change to station is not possible. |
| 6863 | */ |
| 6864 | if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic) |
| 6865 | return 0; |
| 6866 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 6867 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6868 | } |
| 6869 | |
| 6870 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 6871 | static int wpa_driver_nl80211_stop_ap(void *priv) |
| 6872 | { |
| 6873 | struct i802_bss *bss = priv; |
| 6874 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6875 | if (!is_ap_interface(drv->nlmode)) |
| 6876 | return -1; |
| 6877 | wpa_driver_nl80211_del_beacon(drv); |
| 6878 | bss->beacon_set = 0; |
| 6879 | return 0; |
| 6880 | } |
| 6881 | |
| 6882 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6883 | static int wpa_driver_nl80211_deinit_p2p_cli(void *priv) |
| 6884 | { |
| 6885 | struct i802_bss *bss = priv; |
| 6886 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6887 | if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT) |
| 6888 | return -1; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 6889 | |
| 6890 | /* |
| 6891 | * If the P2P Client interface was dynamically added, then it is |
| 6892 | * possible that the interface change to station is not possible. |
| 6893 | */ |
| 6894 | if (bss->if_dynamic) |
| 6895 | return 0; |
| 6896 | |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 6897 | return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION); |
| 6898 | } |
| 6899 | |
| 6900 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6901 | static void wpa_driver_nl80211_resume(void *priv) |
| 6902 | { |
| 6903 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 6904 | enum nl80211_iftype nlmode = nl80211_get_ifmode(bss); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6905 | |
| 6906 | if (i802_set_iface_flags(bss, 1)) |
| 6907 | 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] | 6908 | |
| 6909 | if (is_p2p_net_interface(nlmode)) |
| 6910 | nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6911 | } |
| 6912 | |
| 6913 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6914 | static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis) |
| 6915 | { |
| 6916 | struct i802_bss *bss = priv; |
| 6917 | struct wpa_driver_nl80211_data *drv = bss->drv; |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6918 | struct nl_msg *msg; |
| 6919 | struct nlattr *cqm; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6920 | |
| 6921 | wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d " |
| 6922 | "hysteresis=%d", threshold, hysteresis); |
| 6923 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6924 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) || |
| 6925 | !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) || |
| 6926 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) || |
| 6927 | nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) { |
| 6928 | nlmsg_free(msg); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6929 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6930 | } |
Dmitry Shmidt | 8da800a | 2013-04-24 12:57:01 -0700 | [diff] [blame] | 6931 | nla_nest_end(msg, cqm); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6932 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6933 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6934 | } |
| 6935 | |
| 6936 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6937 | static int get_channel_width(struct nl_msg *msg, void *arg) |
| 6938 | { |
| 6939 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 6940 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 6941 | struct wpa_signal_info *sig_change = arg; |
| 6942 | |
| 6943 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 6944 | genlmsg_attrlen(gnlh, 0), NULL); |
| 6945 | |
| 6946 | sig_change->center_frq1 = -1; |
| 6947 | sig_change->center_frq2 = -1; |
| 6948 | sig_change->chanwidth = CHAN_WIDTH_UNKNOWN; |
| 6949 | |
| 6950 | if (tb[NL80211_ATTR_CHANNEL_WIDTH]) { |
| 6951 | sig_change->chanwidth = convert2width( |
| 6952 | nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH])); |
| 6953 | if (tb[NL80211_ATTR_CENTER_FREQ1]) |
| 6954 | sig_change->center_frq1 = |
| 6955 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]); |
| 6956 | if (tb[NL80211_ATTR_CENTER_FREQ2]) |
| 6957 | sig_change->center_frq2 = |
| 6958 | nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]); |
| 6959 | } |
| 6960 | |
| 6961 | return NL_SKIP; |
| 6962 | } |
| 6963 | |
| 6964 | |
| 6965 | static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv, |
| 6966 | struct wpa_signal_info *sig) |
| 6967 | { |
| 6968 | struct nl_msg *msg; |
| 6969 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 6970 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6971 | return send_and_recv_msgs(drv, msg, get_channel_width, sig); |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6972 | } |
| 6973 | |
| 6974 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6975 | static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si) |
| 6976 | { |
| 6977 | struct i802_bss *bss = priv; |
| 6978 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 6979 | int res; |
| 6980 | |
| 6981 | os_memset(si, 0, sizeof(*si)); |
| 6982 | res = nl80211_get_link_signal(drv, si); |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 6983 | if (res) { |
| 6984 | if (drv->nlmode != NL80211_IFTYPE_ADHOC && |
| 6985 | drv->nlmode != NL80211_IFTYPE_MESH_POINT) |
| 6986 | return res; |
| 6987 | si->current_signal = 0; |
| 6988 | } |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6989 | |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 6990 | res = nl80211_get_channel_width(drv, si); |
| 6991 | if (res != 0) |
| 6992 | return res; |
| 6993 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 6994 | return nl80211_get_link_noise(drv, si); |
| 6995 | } |
| 6996 | |
| 6997 | |
| 6998 | static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len, |
| 6999 | int encrypt) |
| 7000 | { |
| 7001 | struct i802_bss *bss = priv; |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7002 | return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7003 | 0, 0, 0, 0, NULL, 0); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7004 | } |
| 7005 | |
| 7006 | |
| 7007 | static int nl80211_set_param(void *priv, const char *param) |
| 7008 | { |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 7009 | struct i802_bss *bss = priv; |
| 7010 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7011 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7012 | if (param == NULL) |
| 7013 | return 0; |
Dmitry Shmidt | 57c2d39 | 2016-02-23 13:40:19 -0800 | [diff] [blame] | 7014 | wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param); |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7015 | |
| 7016 | #ifdef CONFIG_P2P |
| 7017 | if (os_strstr(param, "use_p2p_group_interface=1")) { |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7018 | wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group " |
| 7019 | "interface"); |
| 7020 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT; |
| 7021 | drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P; |
| 7022 | } |
| 7023 | #endif /* CONFIG_P2P */ |
| 7024 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 7025 | if (os_strstr(param, "use_monitor=1")) |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7026 | drv->use_monitor = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7027 | |
| 7028 | if (os_strstr(param, "force_connect_cmd=1")) { |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7029 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME; |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7030 | drv->force_connect_cmd = 1; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 7031 | } |
| 7032 | |
Dmitry Shmidt | aca489e | 2016-09-28 15:44:14 -0700 | [diff] [blame] | 7033 | if (os_strstr(param, "force_bss_selection=1")) |
| 7034 | drv->capa.flags |= WPA_DRIVER_FLAGS_BSS_SELECTION; |
| 7035 | |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 7036 | if (os_strstr(param, "no_offchannel_tx=1")) { |
Dmitry Shmidt | 7d5c8f2 | 2014-03-03 13:53:28 -0800 | [diff] [blame] | 7037 | drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX; |
| 7038 | drv->test_use_roc_tx = 1; |
| 7039 | } |
| 7040 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7041 | return 0; |
| 7042 | } |
| 7043 | |
| 7044 | |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7045 | static void * nl80211_global_init(void *ctx) |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7046 | { |
| 7047 | struct nl80211_global *global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7048 | struct netlink_config *cfg; |
| 7049 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7050 | global = os_zalloc(sizeof(*global)); |
| 7051 | if (global == NULL) |
| 7052 | return NULL; |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 7053 | global->ctx = ctx; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7054 | global->ioctl_sock = -1; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7055 | dl_list_init(&global->interfaces); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7056 | global->if_add_ifindex = -1; |
| 7057 | |
| 7058 | cfg = os_zalloc(sizeof(*cfg)); |
| 7059 | if (cfg == NULL) |
| 7060 | goto err; |
| 7061 | |
| 7062 | cfg->ctx = global; |
| 7063 | cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink; |
| 7064 | cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink; |
| 7065 | global->netlink = netlink_init(cfg); |
| 7066 | if (global->netlink == NULL) { |
| 7067 | os_free(cfg); |
| 7068 | goto err; |
| 7069 | } |
| 7070 | |
| 7071 | if (wpa_driver_nl80211_init_nl_global(global) < 0) |
| 7072 | goto err; |
| 7073 | |
| 7074 | global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0); |
| 7075 | if (global->ioctl_sock < 0) { |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7076 | wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s", |
| 7077 | strerror(errno)); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7078 | goto err; |
| 7079 | } |
| 7080 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7081 | return global; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7082 | |
| 7083 | err: |
| 7084 | nl80211_global_deinit(global); |
| 7085 | return NULL; |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7086 | } |
| 7087 | |
| 7088 | |
| 7089 | static void nl80211_global_deinit(void *priv) |
| 7090 | { |
| 7091 | struct nl80211_global *global = priv; |
| 7092 | if (global == NULL) |
| 7093 | return; |
| 7094 | if (!dl_list_empty(&global->interfaces)) { |
| 7095 | wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at " |
| 7096 | "nl80211_global_deinit", |
| 7097 | dl_list_len(&global->interfaces)); |
| 7098 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7099 | |
| 7100 | if (global->netlink) |
| 7101 | netlink_deinit(global->netlink); |
| 7102 | |
| 7103 | nl_destroy_handles(&global->nl); |
| 7104 | |
Dmitry Shmidt | 68d0e3e | 2013-10-28 17:59:21 -0700 | [diff] [blame] | 7105 | if (global->nl_event) |
| 7106 | nl80211_destroy_eloop_handle(&global->nl_event); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7107 | |
| 7108 | nl_cb_put(global->nl_cb); |
| 7109 | |
| 7110 | if (global->ioctl_sock >= 0) |
| 7111 | close(global->ioctl_sock); |
| 7112 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 7113 | os_free(global); |
| 7114 | } |
| 7115 | |
| 7116 | |
| 7117 | static const char * nl80211_get_radio_name(void *priv) |
| 7118 | { |
| 7119 | struct i802_bss *bss = priv; |
| 7120 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7121 | return drv->phyname; |
| 7122 | } |
| 7123 | |
| 7124 | |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7125 | static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid, |
| 7126 | const u8 *pmkid) |
| 7127 | { |
| 7128 | struct nl_msg *msg; |
| 7129 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7130 | if (!(msg = nl80211_bss_msg(bss, 0, cmd)) || |
| 7131 | (pmkid && nla_put(msg, NL80211_ATTR_PMKID, 16, pmkid)) || |
| 7132 | (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))) { |
| 7133 | nlmsg_free(msg); |
| 7134 | return -ENOBUFS; |
| 7135 | } |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7136 | |
| 7137 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 7138 | } |
| 7139 | |
| 7140 | |
| 7141 | static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 7142 | { |
| 7143 | struct i802_bss *bss = priv; |
| 7144 | wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid)); |
| 7145 | return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid); |
| 7146 | } |
| 7147 | |
| 7148 | |
| 7149 | static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid) |
| 7150 | { |
| 7151 | struct i802_bss *bss = priv; |
| 7152 | wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR, |
| 7153 | MAC2STR(bssid)); |
| 7154 | return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid); |
| 7155 | } |
| 7156 | |
| 7157 | |
| 7158 | static int nl80211_flush_pmkid(void *priv) |
| 7159 | { |
| 7160 | struct i802_bss *bss = priv; |
| 7161 | wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs"); |
| 7162 | return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL); |
| 7163 | } |
| 7164 | |
| 7165 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7166 | static void clean_survey_results(struct survey_results *survey_results) |
| 7167 | { |
| 7168 | struct freq_survey *survey, *tmp; |
| 7169 | |
| 7170 | if (dl_list_empty(&survey_results->survey_list)) |
| 7171 | return; |
| 7172 | |
| 7173 | dl_list_for_each_safe(survey, tmp, &survey_results->survey_list, |
| 7174 | struct freq_survey, list) { |
| 7175 | dl_list_del(&survey->list); |
| 7176 | os_free(survey); |
| 7177 | } |
| 7178 | } |
| 7179 | |
| 7180 | |
| 7181 | static void add_survey(struct nlattr **sinfo, u32 ifidx, |
| 7182 | struct dl_list *survey_list) |
| 7183 | { |
| 7184 | struct freq_survey *survey; |
| 7185 | |
| 7186 | survey = os_zalloc(sizeof(struct freq_survey)); |
| 7187 | if (!survey) |
| 7188 | return; |
| 7189 | |
| 7190 | survey->ifidx = ifidx; |
| 7191 | survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 7192 | survey->filled = 0; |
| 7193 | |
| 7194 | if (sinfo[NL80211_SURVEY_INFO_NOISE]) { |
| 7195 | survey->nf = (int8_t) |
| 7196 | nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]); |
| 7197 | survey->filled |= SURVEY_HAS_NF; |
| 7198 | } |
| 7199 | |
| 7200 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) { |
| 7201 | survey->channel_time = |
| 7202 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]); |
| 7203 | survey->filled |= SURVEY_HAS_CHAN_TIME; |
| 7204 | } |
| 7205 | |
| 7206 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) { |
| 7207 | survey->channel_time_busy = |
| 7208 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]); |
| 7209 | survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY; |
| 7210 | } |
| 7211 | |
| 7212 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) { |
| 7213 | survey->channel_time_rx = |
| 7214 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]); |
| 7215 | survey->filled |= SURVEY_HAS_CHAN_TIME_RX; |
| 7216 | } |
| 7217 | |
| 7218 | if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) { |
| 7219 | survey->channel_time_tx = |
| 7220 | nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]); |
| 7221 | survey->filled |= SURVEY_HAS_CHAN_TIME_TX; |
| 7222 | } |
| 7223 | |
| 7224 | 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)", |
| 7225 | survey->freq, |
| 7226 | survey->nf, |
| 7227 | (unsigned long int) survey->channel_time, |
| 7228 | (unsigned long int) survey->channel_time_busy, |
| 7229 | (unsigned long int) survey->channel_time_tx, |
| 7230 | (unsigned long int) survey->channel_time_rx, |
| 7231 | survey->filled); |
| 7232 | |
| 7233 | dl_list_add_tail(survey_list, &survey->list); |
| 7234 | } |
| 7235 | |
| 7236 | |
| 7237 | static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq, |
| 7238 | unsigned int freq_filter) |
| 7239 | { |
| 7240 | if (!freq_filter) |
| 7241 | return 1; |
| 7242 | |
| 7243 | return freq_filter == surveyed_freq; |
| 7244 | } |
| 7245 | |
| 7246 | |
| 7247 | static int survey_handler(struct nl_msg *msg, void *arg) |
| 7248 | { |
| 7249 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 7250 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 7251 | struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1]; |
| 7252 | struct survey_results *survey_results; |
| 7253 | u32 surveyed_freq = 0; |
| 7254 | u32 ifidx; |
| 7255 | |
| 7256 | static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = { |
| 7257 | [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 }, |
| 7258 | [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 }, |
| 7259 | }; |
| 7260 | |
| 7261 | survey_results = (struct survey_results *) arg; |
| 7262 | |
| 7263 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 7264 | genlmsg_attrlen(gnlh, 0), NULL); |
| 7265 | |
Dmitry Shmidt | 9767226 | 2014-02-03 13:02:54 -0800 | [diff] [blame] | 7266 | if (!tb[NL80211_ATTR_IFINDEX]) |
| 7267 | return NL_SKIP; |
| 7268 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7269 | ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]); |
| 7270 | |
| 7271 | if (!tb[NL80211_ATTR_SURVEY_INFO]) |
| 7272 | return NL_SKIP; |
| 7273 | |
| 7274 | if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX, |
| 7275 | tb[NL80211_ATTR_SURVEY_INFO], |
| 7276 | survey_policy)) |
| 7277 | return NL_SKIP; |
| 7278 | |
| 7279 | if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) { |
| 7280 | wpa_printf(MSG_ERROR, "nl80211: Invalid survey data"); |
| 7281 | return NL_SKIP; |
| 7282 | } |
| 7283 | |
| 7284 | surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]); |
| 7285 | |
| 7286 | if (!check_survey_ok(sinfo, surveyed_freq, |
| 7287 | survey_results->freq_filter)) |
| 7288 | return NL_SKIP; |
| 7289 | |
| 7290 | if (survey_results->freq_filter && |
| 7291 | survey_results->freq_filter != surveyed_freq) { |
| 7292 | wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz", |
| 7293 | surveyed_freq); |
| 7294 | return NL_SKIP; |
| 7295 | } |
| 7296 | |
| 7297 | add_survey(sinfo, ifidx, &survey_results->survey_list); |
| 7298 | |
| 7299 | return NL_SKIP; |
| 7300 | } |
| 7301 | |
| 7302 | |
| 7303 | static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq) |
| 7304 | { |
| 7305 | struct i802_bss *bss = priv; |
| 7306 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7307 | struct nl_msg *msg; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7308 | int err; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7309 | union wpa_event_data data; |
| 7310 | struct survey_results *survey_results; |
| 7311 | |
| 7312 | os_memset(&data, 0, sizeof(data)); |
| 7313 | survey_results = &data.survey_results; |
| 7314 | |
| 7315 | dl_list_init(&survey_results->survey_list); |
| 7316 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7317 | msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7318 | if (!msg) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7319 | return -ENOBUFS; |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7320 | |
| 7321 | if (freq) |
| 7322 | data.survey_results.freq_filter = freq; |
| 7323 | |
| 7324 | do { |
| 7325 | wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data"); |
| 7326 | err = send_and_recv_msgs(drv, msg, survey_handler, |
| 7327 | survey_results); |
| 7328 | } while (err > 0); |
| 7329 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7330 | if (err) |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7331 | wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7332 | else |
| 7333 | wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7334 | |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7335 | clean_survey_results(survey_results); |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 7336 | return err; |
| 7337 | } |
| 7338 | |
| 7339 | |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 7340 | static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len, |
| 7341 | const u8 *kck, size_t kck_len, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7342 | const u8 *replay_ctr) |
| 7343 | { |
| 7344 | struct i802_bss *bss = priv; |
| 7345 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7346 | struct nlattr *replay_nested; |
| 7347 | struct nl_msg *msg; |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 7348 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7349 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 7350 | if (!drv->set_rekey_offload) |
| 7351 | return; |
| 7352 | |
| 7353 | wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7354 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) || |
| 7355 | !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) || |
Dmitry Shmidt | 807291d | 2015-01-27 13:40:23 -0800 | [diff] [blame] | 7356 | nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) || |
| 7357 | nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7358 | nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN, |
| 7359 | replay_ctr)) { |
| 7360 | nl80211_nlmsg_clear(msg); |
| 7361 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7362 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7363 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7364 | |
| 7365 | nla_nest_end(msg, replay_nested); |
| 7366 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 7367 | ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1); |
| 7368 | if (ret == -EOPNOTSUPP) { |
| 7369 | wpa_printf(MSG_DEBUG, |
| 7370 | "nl80211: Driver does not support rekey offload"); |
| 7371 | drv->set_rekey_offload = 0; |
| 7372 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7373 | } |
| 7374 | |
| 7375 | |
| 7376 | static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr, |
| 7377 | const u8 *addr, int qos) |
| 7378 | { |
| 7379 | /* send data frame to poll STA and check whether |
| 7380 | * this frame is ACKed */ |
| 7381 | struct { |
| 7382 | struct ieee80211_hdr hdr; |
| 7383 | u16 qos_ctl; |
| 7384 | } STRUCT_PACKED nulldata; |
| 7385 | size_t size; |
| 7386 | |
| 7387 | /* Send data frame to poll STA and check whether this frame is ACKed */ |
| 7388 | |
| 7389 | os_memset(&nulldata, 0, sizeof(nulldata)); |
| 7390 | |
| 7391 | if (qos) { |
| 7392 | nulldata.hdr.frame_control = |
| 7393 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 7394 | WLAN_FC_STYPE_QOS_NULL); |
| 7395 | size = sizeof(nulldata); |
| 7396 | } else { |
| 7397 | nulldata.hdr.frame_control = |
| 7398 | IEEE80211_FC(WLAN_FC_TYPE_DATA, |
| 7399 | WLAN_FC_STYPE_NULLFUNC); |
| 7400 | size = sizeof(struct ieee80211_hdr); |
| 7401 | } |
| 7402 | |
| 7403 | nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS); |
| 7404 | os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN); |
| 7405 | os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN); |
| 7406 | os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN); |
| 7407 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7408 | 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] | 7409 | 0, 0, NULL, 0) < 0) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7410 | wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to " |
| 7411 | "send poll frame"); |
| 7412 | } |
| 7413 | |
| 7414 | static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr, |
| 7415 | int qos) |
| 7416 | { |
| 7417 | struct i802_bss *bss = priv; |
| 7418 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7419 | struct nl_msg *msg; |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 7420 | int ret; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7421 | |
| 7422 | if (!drv->poll_command_supported) { |
| 7423 | nl80211_send_null_frame(bss, own_addr, addr, qos); |
| 7424 | return; |
| 7425 | } |
| 7426 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7427 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) || |
| 7428 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 7429 | nlmsg_free(msg); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7430 | return; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7431 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7432 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 7433 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7434 | if (ret < 0) { |
| 7435 | wpa_printf(MSG_DEBUG, "nl80211: Client probe request for " |
| 7436 | MACSTR " failed: ret=%d (%s)", |
| 7437 | MAC2STR(addr), ret, strerror(-ret)); |
| 7438 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7439 | } |
| 7440 | |
| 7441 | |
| 7442 | static int nl80211_set_power_save(struct i802_bss *bss, int enabled) |
| 7443 | { |
| 7444 | struct nl_msg *msg; |
| 7445 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7446 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) || |
| 7447 | nla_put_u32(msg, NL80211_ATTR_PS_STATE, |
| 7448 | enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) { |
| 7449 | nlmsg_free(msg); |
| 7450 | return -ENOBUFS; |
| 7451 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7452 | return send_and_recv_msgs(bss->drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7453 | } |
| 7454 | |
| 7455 | |
| 7456 | static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps, |
| 7457 | int ctwindow) |
| 7458 | { |
| 7459 | struct i802_bss *bss = priv; |
| 7460 | |
| 7461 | wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d " |
| 7462 | "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow); |
| 7463 | |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 7464 | if (opp_ps != -1 || ctwindow != -1) { |
Dmitry Shmidt | c5ec7f5 | 2012-03-06 16:33:24 -0800 | [diff] [blame] | 7465 | #ifdef ANDROID_P2P |
| 7466 | wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow); |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 7467 | #else /* ANDROID_P2P */ |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7468 | return -1; /* Not yet supported */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 7469 | #endif /* ANDROID_P2P */ |
| 7470 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7471 | |
| 7472 | if (legacy_ps == -1) |
| 7473 | return 0; |
| 7474 | if (legacy_ps != 0 && legacy_ps != 1) |
| 7475 | return -1; /* Not yet supported */ |
| 7476 | |
| 7477 | return nl80211_set_power_save(bss, legacy_ps); |
| 7478 | } |
| 7479 | |
| 7480 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7481 | static int nl80211_start_radar_detection(void *priv, |
| 7482 | struct hostapd_freq_params *freq) |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7483 | { |
| 7484 | struct i802_bss *bss = priv; |
| 7485 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7486 | struct nl_msg *msg; |
| 7487 | int ret; |
| 7488 | |
Dmitry Shmidt | 051af73 | 2013-10-22 13:52:46 -0700 | [diff] [blame] | 7489 | 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)", |
| 7490 | freq->freq, freq->ht_enabled, freq->vht_enabled, |
| 7491 | freq->bandwidth, freq->center_freq1, freq->center_freq2); |
| 7492 | |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7493 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) { |
| 7494 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar " |
| 7495 | "detection"); |
| 7496 | return -1; |
| 7497 | } |
| 7498 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7499 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) || |
| 7500 | nl80211_put_freq_params(msg, freq) < 0) { |
| 7501 | nlmsg_free(msg); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7502 | return -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7503 | } |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7504 | |
| 7505 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7506 | if (ret == 0) |
| 7507 | return 0; |
| 7508 | wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: " |
| 7509 | "%d (%s)", ret, strerror(-ret)); |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 7510 | return -1; |
| 7511 | } |
| 7512 | |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7513 | #ifdef CONFIG_TDLS |
| 7514 | |
| 7515 | static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code, |
| 7516 | u8 dialog_token, u16 status_code, |
Dmitry Shmidt | 9ead16e | 2014-10-07 13:15:23 -0700 | [diff] [blame] | 7517 | u32 peer_capab, int initiator, const u8 *buf, |
| 7518 | size_t len) |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7519 | { |
| 7520 | struct i802_bss *bss = priv; |
| 7521 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7522 | struct nl_msg *msg; |
| 7523 | |
| 7524 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 7525 | return -EOPNOTSUPP; |
| 7526 | |
| 7527 | if (!dst) |
| 7528 | return -EINVAL; |
| 7529 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7530 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) || |
| 7531 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) || |
| 7532 | nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) || |
| 7533 | nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) || |
| 7534 | nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code)) |
| 7535 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7536 | if (peer_capab) { |
| 7537 | /* |
| 7538 | * The internal enum tdls_peer_capability definition is |
| 7539 | * currently identical with the nl80211 enum |
| 7540 | * nl80211_tdls_peer_capability, so no conversion is needed |
| 7541 | * here. |
| 7542 | */ |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7543 | if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY, |
| 7544 | peer_capab)) |
| 7545 | goto fail; |
Dmitry Shmidt | df5a7e4 | 2014-04-02 12:59:59 -0700 | [diff] [blame] | 7546 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7547 | if ((initiator && |
| 7548 | nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) || |
| 7549 | nla_put(msg, NL80211_ATTR_IE, len, buf)) |
| 7550 | goto fail; |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7551 | |
| 7552 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7553 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7554 | fail: |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7555 | nlmsg_free(msg); |
| 7556 | return -ENOBUFS; |
| 7557 | } |
| 7558 | |
| 7559 | |
| 7560 | static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer) |
| 7561 | { |
| 7562 | struct i802_bss *bss = priv; |
| 7563 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7564 | struct nl_msg *msg; |
| 7565 | enum nl80211_tdls_operation nl80211_oper; |
| 7566 | |
| 7567 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) |
| 7568 | return -EOPNOTSUPP; |
| 7569 | |
| 7570 | switch (oper) { |
| 7571 | case TDLS_DISCOVERY_REQ: |
| 7572 | nl80211_oper = NL80211_TDLS_DISCOVERY_REQ; |
| 7573 | break; |
| 7574 | case TDLS_SETUP: |
| 7575 | nl80211_oper = NL80211_TDLS_SETUP; |
| 7576 | break; |
| 7577 | case TDLS_TEARDOWN: |
| 7578 | nl80211_oper = NL80211_TDLS_TEARDOWN; |
| 7579 | break; |
| 7580 | case TDLS_ENABLE_LINK: |
| 7581 | nl80211_oper = NL80211_TDLS_ENABLE_LINK; |
| 7582 | break; |
| 7583 | case TDLS_DISABLE_LINK: |
| 7584 | nl80211_oper = NL80211_TDLS_DISABLE_LINK; |
| 7585 | break; |
| 7586 | case TDLS_ENABLE: |
| 7587 | return 0; |
| 7588 | case TDLS_DISABLE: |
| 7589 | return 0; |
| 7590 | default: |
| 7591 | return -EINVAL; |
| 7592 | } |
| 7593 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7594 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) || |
| 7595 | nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) || |
| 7596 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) { |
| 7597 | nlmsg_free(msg); |
| 7598 | return -ENOBUFS; |
| 7599 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7600 | |
| 7601 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7602 | } |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7603 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7604 | |
| 7605 | static int |
| 7606 | nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class, |
| 7607 | const struct hostapd_freq_params *params) |
| 7608 | { |
| 7609 | struct i802_bss *bss = priv; |
| 7610 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7611 | struct nl_msg *msg; |
| 7612 | int ret = -ENOBUFS; |
| 7613 | |
| 7614 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 7615 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 7616 | return -EOPNOTSUPP; |
| 7617 | |
| 7618 | wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR |
| 7619 | " oper_class=%u freq=%u", |
| 7620 | MAC2STR(addr), oper_class, params->freq); |
| 7621 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH); |
| 7622 | if (!msg || |
| 7623 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 7624 | nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) || |
| 7625 | (ret = nl80211_put_freq_params(msg, params))) { |
| 7626 | nlmsg_free(msg); |
| 7627 | wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch"); |
| 7628 | return ret; |
| 7629 | } |
| 7630 | |
| 7631 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7632 | } |
| 7633 | |
| 7634 | |
| 7635 | static int |
| 7636 | nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr) |
| 7637 | { |
| 7638 | struct i802_bss *bss = priv; |
| 7639 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7640 | struct nl_msg *msg; |
| 7641 | |
| 7642 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) || |
| 7643 | !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH)) |
| 7644 | return -EOPNOTSUPP; |
| 7645 | |
| 7646 | wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR, |
| 7647 | MAC2STR(addr)); |
| 7648 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH); |
| 7649 | if (!msg || |
| 7650 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 7651 | nlmsg_free(msg); |
| 7652 | wpa_printf(MSG_DEBUG, |
| 7653 | "nl80211: Could not build TDLS cancel chan switch"); |
| 7654 | return -ENOBUFS; |
| 7655 | } |
| 7656 | |
| 7657 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 7658 | } |
| 7659 | |
| 7660 | #endif /* CONFIG TDLS */ |
| 7661 | |
| 7662 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7663 | static int driver_nl80211_set_key(const char *ifname, void *priv, |
| 7664 | enum wpa_alg alg, const u8 *addr, |
| 7665 | int key_idx, int set_tx, |
| 7666 | const u8 *seq, size_t seq_len, |
| 7667 | const u8 *key, size_t key_len) |
| 7668 | { |
| 7669 | struct i802_bss *bss = priv; |
| 7670 | return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx, |
| 7671 | set_tx, seq, seq_len, key, key_len); |
| 7672 | } |
| 7673 | |
| 7674 | |
| 7675 | static int driver_nl80211_scan2(void *priv, |
| 7676 | struct wpa_driver_scan_params *params) |
| 7677 | { |
| 7678 | struct i802_bss *bss = priv; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7679 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 7680 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7681 | |
| 7682 | /* |
| 7683 | * Do a vendor specific scan if possible. If only_new_results is |
| 7684 | * set, do a normal scan since a kernel (cfg80211) BSS cache flush |
| 7685 | * cannot be achieved through a vendor scan. The below condition may |
| 7686 | * need to be modified if new scan flags are added in the future whose |
| 7687 | * functionality can only be achieved through a normal scan. |
| 7688 | */ |
| 7689 | if (drv->scan_vendor_cmd_avail && !params->only_new_results) |
| 7690 | return wpa_driver_nl80211_vendor_scan(bss, params); |
| 7691 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7692 | return wpa_driver_nl80211_scan(bss, params); |
| 7693 | } |
| 7694 | |
| 7695 | |
| 7696 | static int driver_nl80211_deauthenticate(void *priv, const u8 *addr, |
| 7697 | int reason_code) |
| 7698 | { |
| 7699 | struct i802_bss *bss = priv; |
| 7700 | return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code); |
| 7701 | } |
| 7702 | |
| 7703 | |
| 7704 | static int driver_nl80211_authenticate(void *priv, |
| 7705 | struct wpa_driver_auth_params *params) |
| 7706 | { |
| 7707 | struct i802_bss *bss = priv; |
| 7708 | return wpa_driver_nl80211_authenticate(bss, params); |
| 7709 | } |
| 7710 | |
| 7711 | |
| 7712 | static void driver_nl80211_deinit(void *priv) |
| 7713 | { |
| 7714 | struct i802_bss *bss = priv; |
| 7715 | wpa_driver_nl80211_deinit(bss); |
| 7716 | } |
| 7717 | |
| 7718 | |
| 7719 | static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type, |
| 7720 | const char *ifname) |
| 7721 | { |
| 7722 | struct i802_bss *bss = priv; |
| 7723 | return wpa_driver_nl80211_if_remove(bss, type, ifname); |
| 7724 | } |
| 7725 | |
| 7726 | |
| 7727 | static int driver_nl80211_send_mlme(void *priv, const u8 *data, |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 7728 | size_t data_len, int noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7729 | unsigned int freq, |
| 7730 | const u16 *csa_offs, size_t csa_offs_len) |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7731 | { |
| 7732 | struct i802_bss *bss = priv; |
| 7733 | return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7734 | freq, 0, 0, 0, csa_offs, |
| 7735 | csa_offs_len); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7736 | } |
| 7737 | |
| 7738 | |
| 7739 | static int driver_nl80211_sta_remove(void *priv, const u8 *addr) |
| 7740 | { |
| 7741 | struct i802_bss *bss = priv; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7742 | return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0); |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7743 | } |
| 7744 | |
| 7745 | |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7746 | static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr, |
| 7747 | const char *ifname, int vlan_id) |
| 7748 | { |
| 7749 | struct i802_bss *bss = priv; |
| 7750 | return i802_set_sta_vlan(bss, addr, ifname, vlan_id); |
| 7751 | } |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 7752 | |
| 7753 | |
| 7754 | static int driver_nl80211_read_sta_data(void *priv, |
| 7755 | struct hostap_sta_driver_data *data, |
| 7756 | const u8 *addr) |
| 7757 | { |
| 7758 | struct i802_bss *bss = priv; |
| 7759 | return i802_read_sta_data(bss, data, addr); |
| 7760 | } |
| 7761 | |
| 7762 | |
| 7763 | static int driver_nl80211_send_action(void *priv, unsigned int freq, |
| 7764 | unsigned int wait_time, |
| 7765 | const u8 *dst, const u8 *src, |
| 7766 | const u8 *bssid, |
| 7767 | const u8 *data, size_t data_len, |
| 7768 | int no_cck) |
| 7769 | { |
| 7770 | struct i802_bss *bss = priv; |
| 7771 | return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src, |
| 7772 | bssid, data, data_len, no_cck); |
| 7773 | } |
| 7774 | |
| 7775 | |
| 7776 | static int driver_nl80211_probe_req_report(void *priv, int report) |
| 7777 | { |
| 7778 | struct i802_bss *bss = priv; |
| 7779 | return wpa_driver_nl80211_probe_req_report(bss, report); |
| 7780 | } |
| 7781 | |
| 7782 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7783 | static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md, |
| 7784 | const u8 *ies, size_t ies_len) |
| 7785 | { |
| 7786 | int ret; |
| 7787 | struct nl_msg *msg; |
| 7788 | struct i802_bss *bss = priv; |
| 7789 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7790 | u16 mdid = WPA_GET_LE16(md); |
| 7791 | |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7792 | wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs"); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7793 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) || |
| 7794 | nla_put(msg, NL80211_ATTR_IE, ies_len, ies) || |
| 7795 | nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) { |
| 7796 | nlmsg_free(msg); |
| 7797 | return -ENOBUFS; |
| 7798 | } |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7799 | |
| 7800 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 7801 | if (ret) { |
| 7802 | wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed " |
| 7803 | "err=%d (%s)", ret, strerror(-ret)); |
| 7804 | } |
| 7805 | |
| 7806 | return ret; |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 7807 | } |
| 7808 | |
| 7809 | |
Dmitry Shmidt | 4ae50e6 | 2016-06-27 13:48:39 -0700 | [diff] [blame] | 7810 | static const u8 * wpa_driver_nl80211_get_macaddr(void *priv) |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 7811 | { |
| 7812 | struct i802_bss *bss = priv; |
| 7813 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7814 | |
| 7815 | if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) |
| 7816 | return NULL; |
| 7817 | |
| 7818 | return bss->addr; |
| 7819 | } |
| 7820 | |
| 7821 | |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7822 | static const char * scan_state_str(enum scan_states scan_state) |
| 7823 | { |
| 7824 | switch (scan_state) { |
| 7825 | case NO_SCAN: |
| 7826 | return "NO_SCAN"; |
| 7827 | case SCAN_REQUESTED: |
| 7828 | return "SCAN_REQUESTED"; |
| 7829 | case SCAN_STARTED: |
| 7830 | return "SCAN_STARTED"; |
| 7831 | case SCAN_COMPLETED: |
| 7832 | return "SCAN_COMPLETED"; |
| 7833 | case SCAN_ABORTED: |
| 7834 | return "SCAN_ABORTED"; |
| 7835 | case SCHED_SCAN_STARTED: |
| 7836 | return "SCHED_SCAN_STARTED"; |
| 7837 | case SCHED_SCAN_STOPPED: |
| 7838 | return "SCHED_SCAN_STOPPED"; |
| 7839 | case SCHED_SCAN_RESULTS: |
| 7840 | return "SCHED_SCAN_RESULTS"; |
| 7841 | } |
| 7842 | |
| 7843 | return "??"; |
| 7844 | } |
| 7845 | |
| 7846 | |
| 7847 | static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen) |
| 7848 | { |
| 7849 | struct i802_bss *bss = priv; |
| 7850 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 7851 | int res; |
| 7852 | char *pos, *end; |
| 7853 | |
| 7854 | pos = buf; |
| 7855 | end = buf + buflen; |
| 7856 | |
| 7857 | res = os_snprintf(pos, end - pos, |
| 7858 | "ifindex=%d\n" |
| 7859 | "ifname=%s\n" |
| 7860 | "brname=%s\n" |
| 7861 | "addr=" MACSTR "\n" |
| 7862 | "freq=%d\n" |
| 7863 | "%s%s%s%s%s", |
| 7864 | bss->ifindex, |
| 7865 | bss->ifname, |
| 7866 | bss->brname, |
| 7867 | MAC2STR(bss->addr), |
| 7868 | bss->freq, |
| 7869 | bss->beacon_set ? "beacon_set=1\n" : "", |
| 7870 | bss->added_if_into_bridge ? |
| 7871 | "added_if_into_bridge=1\n" : "", |
| 7872 | bss->added_bridge ? "added_bridge=1\n" : "", |
| 7873 | bss->in_deinit ? "in_deinit=1\n" : "", |
| 7874 | bss->if_dynamic ? "if_dynamic=1\n" : ""); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7875 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7876 | return pos - buf; |
| 7877 | pos += res; |
| 7878 | |
| 7879 | if (bss->wdev_id_set) { |
| 7880 | res = os_snprintf(pos, end - pos, "wdev_id=%llu\n", |
| 7881 | (unsigned long long) bss->wdev_id); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7882 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7883 | return pos - buf; |
| 7884 | pos += res; |
| 7885 | } |
| 7886 | |
| 7887 | res = os_snprintf(pos, end - pos, |
| 7888 | "phyname=%s\n" |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7889 | "perm_addr=" MACSTR "\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7890 | "drv_ifindex=%d\n" |
| 7891 | "operstate=%d\n" |
| 7892 | "scan_state=%s\n" |
| 7893 | "auth_bssid=" MACSTR "\n" |
| 7894 | "auth_attempt_bssid=" MACSTR "\n" |
| 7895 | "bssid=" MACSTR "\n" |
| 7896 | "prev_bssid=" MACSTR "\n" |
| 7897 | "associated=%d\n" |
| 7898 | "assoc_freq=%u\n" |
| 7899 | "monitor_sock=%d\n" |
| 7900 | "monitor_ifidx=%d\n" |
| 7901 | "monitor_refcount=%d\n" |
| 7902 | "last_mgmt_freq=%u\n" |
| 7903 | "eapol_tx_sock=%d\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7904 | "%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] | 7905 | drv->phyname, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 7906 | MAC2STR(drv->perm_addr), |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7907 | drv->ifindex, |
| 7908 | drv->operstate, |
| 7909 | scan_state_str(drv->scan_state), |
| 7910 | MAC2STR(drv->auth_bssid), |
| 7911 | MAC2STR(drv->auth_attempt_bssid), |
| 7912 | MAC2STR(drv->bssid), |
| 7913 | MAC2STR(drv->prev_bssid), |
| 7914 | drv->associated, |
| 7915 | drv->assoc_freq, |
| 7916 | drv->monitor_sock, |
| 7917 | drv->monitor_ifidx, |
| 7918 | drv->monitor_refcount, |
| 7919 | drv->last_mgmt_freq, |
| 7920 | drv->eapol_tx_sock, |
| 7921 | drv->ignore_if_down_event ? |
| 7922 | "ignore_if_down_event=1\n" : "", |
| 7923 | drv->scan_complete_events ? |
| 7924 | "scan_complete_events=1\n" : "", |
| 7925 | drv->disabled_11b_rates ? |
| 7926 | "disabled_11b_rates=1\n" : "", |
| 7927 | drv->pending_remain_on_chan ? |
| 7928 | "pending_remain_on_chan=1\n" : "", |
| 7929 | drv->in_interface_list ? "in_interface_list=1\n" : "", |
| 7930 | drv->device_ap_sme ? "device_ap_sme=1\n" : "", |
| 7931 | drv->poll_command_supported ? |
| 7932 | "poll_command_supported=1\n" : "", |
| 7933 | drv->data_tx_status ? "data_tx_status=1\n" : "", |
| 7934 | drv->scan_for_auth ? "scan_for_auth=1\n" : "", |
| 7935 | drv->retry_auth ? "retry_auth=1\n" : "", |
| 7936 | drv->use_monitor ? "use_monitor=1\n" : "", |
| 7937 | drv->ignore_next_local_disconnect ? |
| 7938 | "ignore_next_local_disconnect=1\n" : "", |
Dmitry Shmidt | 7dba0e5 | 2014-04-14 10:49:15 -0700 | [diff] [blame] | 7939 | drv->ignore_next_local_deauth ? |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7940 | "ignore_next_local_deauth=1\n" : ""); |
| 7941 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7942 | return pos - buf; |
| 7943 | pos += res; |
| 7944 | |
| 7945 | if (drv->has_capability) { |
| 7946 | res = os_snprintf(pos, end - pos, |
| 7947 | "capa.key_mgmt=0x%x\n" |
| 7948 | "capa.enc=0x%x\n" |
| 7949 | "capa.auth=0x%x\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7950 | "capa.flags=0x%llx\n" |
| 7951 | "capa.rrm_flags=0x%x\n" |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7952 | "capa.max_scan_ssids=%d\n" |
| 7953 | "capa.max_sched_scan_ssids=%d\n" |
| 7954 | "capa.sched_scan_supported=%d\n" |
| 7955 | "capa.max_match_sets=%d\n" |
| 7956 | "capa.max_remain_on_chan=%u\n" |
| 7957 | "capa.max_stations=%u\n" |
| 7958 | "capa.probe_resp_offloads=0x%x\n" |
| 7959 | "capa.max_acl_mac_addrs=%u\n" |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7960 | "capa.num_multichan_concurrent=%u\n" |
| 7961 | "capa.mac_addr_rand_sched_scan_supported=%d\n" |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7962 | "capa.mac_addr_rand_scan_supported=%d\n" |
| 7963 | "capa.conc_capab=%u\n" |
| 7964 | "capa.max_conc_chan_2_4=%u\n" |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7965 | "capa.max_conc_chan_5_0=%u\n" |
| 7966 | "capa.max_sched_scan_plans=%u\n" |
| 7967 | "capa.max_sched_scan_plan_interval=%u\n" |
| 7968 | "capa.max_sched_scan_plan_iterations=%u\n", |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7969 | drv->capa.key_mgmt, |
| 7970 | drv->capa.enc, |
| 7971 | drv->capa.auth, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7972 | (unsigned long long) drv->capa.flags, |
| 7973 | drv->capa.rrm_flags, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7974 | drv->capa.max_scan_ssids, |
| 7975 | drv->capa.max_sched_scan_ssids, |
| 7976 | drv->capa.sched_scan_supported, |
| 7977 | drv->capa.max_match_sets, |
| 7978 | drv->capa.max_remain_on_chan, |
| 7979 | drv->capa.max_stations, |
| 7980 | drv->capa.probe_resp_offloads, |
| 7981 | drv->capa.max_acl_mac_addrs, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7982 | drv->capa.num_multichan_concurrent, |
| 7983 | drv->capa.mac_addr_rand_sched_scan_supported, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 7984 | drv->capa.mac_addr_rand_scan_supported, |
| 7985 | drv->capa.conc_capab, |
| 7986 | drv->capa.max_conc_chan_2_4, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 7987 | drv->capa.max_conc_chan_5_0, |
| 7988 | drv->capa.max_sched_scan_plans, |
| 7989 | drv->capa.max_sched_scan_plan_interval, |
| 7990 | drv->capa.max_sched_scan_plan_iterations); |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 7991 | if (os_snprintf_error(end - pos, res)) |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 7992 | return pos - buf; |
| 7993 | pos += res; |
| 7994 | } |
| 7995 | |
| 7996 | return pos - buf; |
| 7997 | } |
| 7998 | |
| 7999 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8000 | static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings) |
| 8001 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8002 | if ((settings->head && |
| 8003 | nla_put(msg, NL80211_ATTR_BEACON_HEAD, |
| 8004 | settings->head_len, settings->head)) || |
| 8005 | (settings->tail && |
| 8006 | nla_put(msg, NL80211_ATTR_BEACON_TAIL, |
| 8007 | settings->tail_len, settings->tail)) || |
| 8008 | (settings->beacon_ies && |
| 8009 | nla_put(msg, NL80211_ATTR_IE, |
| 8010 | settings->beacon_ies_len, settings->beacon_ies)) || |
| 8011 | (settings->proberesp_ies && |
| 8012 | nla_put(msg, NL80211_ATTR_IE_PROBE_RESP, |
| 8013 | settings->proberesp_ies_len, settings->proberesp_ies)) || |
| 8014 | (settings->assocresp_ies && |
| 8015 | nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP, |
| 8016 | settings->assocresp_ies_len, settings->assocresp_ies)) || |
| 8017 | (settings->probe_resp && |
| 8018 | nla_put(msg, NL80211_ATTR_PROBE_RESP, |
| 8019 | settings->probe_resp_len, settings->probe_resp))) |
| 8020 | return -ENOBUFS; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8021 | |
| 8022 | return 0; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8023 | } |
| 8024 | |
| 8025 | |
| 8026 | static int nl80211_switch_channel(void *priv, struct csa_settings *settings) |
| 8027 | { |
| 8028 | struct nl_msg *msg; |
| 8029 | struct i802_bss *bss = priv; |
| 8030 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8031 | struct nlattr *beacon_csa; |
| 8032 | int ret = -ENOBUFS; |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8033 | int csa_off_len = 0; |
| 8034 | int i; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8035 | |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 8036 | 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] | 8037 | settings->cs_count, settings->block_tx, |
Dmitry Shmidt | 04f534e | 2013-12-09 15:50:16 -0800 | [diff] [blame] | 8038 | settings->freq_params.freq, settings->freq_params.bandwidth, |
| 8039 | settings->freq_params.center_freq1, |
| 8040 | settings->freq_params.center_freq2); |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8041 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8042 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) { |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8043 | wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command"); |
| 8044 | return -EOPNOTSUPP; |
| 8045 | } |
| 8046 | |
| 8047 | if ((drv->nlmode != NL80211_IFTYPE_AP) && |
| 8048 | (drv->nlmode != NL80211_IFTYPE_P2P_GO)) |
| 8049 | return -EOPNOTSUPP; |
| 8050 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8051 | /* |
| 8052 | * Remove empty counters, assuming Probe Response and Beacon frame |
| 8053 | * counters match. This implementation assumes that there are only two |
| 8054 | * counters. |
| 8055 | */ |
| 8056 | if (settings->counter_offset_beacon[0] && |
| 8057 | !settings->counter_offset_beacon[1]) { |
| 8058 | csa_off_len = 1; |
| 8059 | } else if (settings->counter_offset_beacon[1] && |
| 8060 | !settings->counter_offset_beacon[0]) { |
| 8061 | csa_off_len = 1; |
| 8062 | settings->counter_offset_beacon[0] = |
| 8063 | settings->counter_offset_beacon[1]; |
| 8064 | settings->counter_offset_presp[0] = |
| 8065 | settings->counter_offset_presp[1]; |
| 8066 | } else if (settings->counter_offset_beacon[1] && |
| 8067 | settings->counter_offset_beacon[0]) { |
| 8068 | csa_off_len = 2; |
| 8069 | } else { |
| 8070 | wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided"); |
| 8071 | return -EINVAL; |
| 8072 | } |
| 8073 | |
| 8074 | /* Check CSA counters validity */ |
| 8075 | if (drv->capa.max_csa_counters && |
| 8076 | csa_off_len > drv->capa.max_csa_counters) { |
| 8077 | wpa_printf(MSG_ERROR, |
| 8078 | "nl80211: Too many CSA counters provided"); |
| 8079 | return -EINVAL; |
| 8080 | } |
| 8081 | |
| 8082 | if (!settings->beacon_csa.tail) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8083 | return -EINVAL; |
| 8084 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8085 | for (i = 0; i < csa_off_len; i++) { |
| 8086 | u16 csa_c_off_bcn = settings->counter_offset_beacon[i]; |
| 8087 | u16 csa_c_off_presp = settings->counter_offset_presp[i]; |
| 8088 | |
| 8089 | if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) || |
| 8090 | (settings->beacon_csa.tail[csa_c_off_bcn] != |
| 8091 | settings->cs_count)) |
| 8092 | return -EINVAL; |
| 8093 | |
| 8094 | if (settings->beacon_csa.probe_resp && |
| 8095 | ((settings->beacon_csa.probe_resp_len <= |
| 8096 | csa_c_off_presp) || |
| 8097 | (settings->beacon_csa.probe_resp[csa_c_off_presp] != |
| 8098 | settings->cs_count))) |
| 8099 | return -EINVAL; |
| 8100 | } |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8101 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8102 | if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) || |
| 8103 | nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT, |
| 8104 | settings->cs_count) || |
| 8105 | (ret = nl80211_put_freq_params(msg, &settings->freq_params)) || |
| 8106 | (settings->block_tx && |
| 8107 | nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX))) |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8108 | goto error; |
| 8109 | |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8110 | /* beacon_after params */ |
| 8111 | ret = set_beacon_data(msg, &settings->beacon_after); |
| 8112 | if (ret) |
| 8113 | goto error; |
| 8114 | |
| 8115 | /* beacon_csa params */ |
| 8116 | beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES); |
| 8117 | if (!beacon_csa) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8118 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8119 | |
| 8120 | ret = set_beacon_data(msg, &settings->beacon_csa); |
| 8121 | if (ret) |
| 8122 | goto error; |
| 8123 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8124 | if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON, |
| 8125 | csa_off_len * sizeof(u16), |
| 8126 | settings->counter_offset_beacon) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8127 | (settings->beacon_csa.probe_resp && |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8128 | nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP, |
| 8129 | csa_off_len * sizeof(u16), |
| 8130 | settings->counter_offset_presp))) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8131 | goto fail; |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8132 | |
| 8133 | nla_nest_end(msg, beacon_csa); |
| 8134 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8135 | if (ret) { |
| 8136 | wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)", |
| 8137 | ret, strerror(-ret)); |
| 8138 | } |
| 8139 | return ret; |
| 8140 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8141 | fail: |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 8142 | ret = -ENOBUFS; |
| 8143 | error: |
| 8144 | nlmsg_free(msg); |
| 8145 | wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request"); |
| 8146 | return ret; |
| 8147 | } |
| 8148 | |
| 8149 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8150 | static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr, |
| 8151 | u8 user_priority, u16 admitted_time) |
| 8152 | { |
| 8153 | struct i802_bss *bss = priv; |
| 8154 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8155 | struct nl_msg *msg; |
| 8156 | int ret; |
| 8157 | |
| 8158 | wpa_printf(MSG_DEBUG, |
| 8159 | "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d", |
| 8160 | tsid, admitted_time, user_priority); |
| 8161 | |
| 8162 | if (!is_sta_interface(drv->nlmode)) |
| 8163 | return -ENOTSUP; |
| 8164 | |
| 8165 | msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS); |
| 8166 | if (!msg || |
| 8167 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 8168 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) || |
| 8169 | nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) || |
| 8170 | nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) { |
| 8171 | nlmsg_free(msg); |
| 8172 | return -ENOBUFS; |
| 8173 | } |
| 8174 | |
| 8175 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8176 | if (ret) |
| 8177 | wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)", |
| 8178 | ret, strerror(-ret)); |
| 8179 | return ret; |
| 8180 | } |
| 8181 | |
| 8182 | |
| 8183 | static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr) |
| 8184 | { |
| 8185 | struct i802_bss *bss = priv; |
| 8186 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8187 | struct nl_msg *msg; |
| 8188 | int ret; |
| 8189 | |
| 8190 | wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid); |
| 8191 | |
| 8192 | if (!is_sta_interface(drv->nlmode)) |
| 8193 | return -ENOTSUP; |
| 8194 | |
| 8195 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) || |
| 8196 | nla_put_u8(msg, NL80211_ATTR_TSID, tsid) || |
| 8197 | nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) { |
| 8198 | nlmsg_free(msg); |
| 8199 | return -ENOBUFS; |
| 8200 | } |
| 8201 | |
| 8202 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8203 | if (ret) |
| 8204 | wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)", |
| 8205 | ret, strerror(-ret)); |
| 8206 | return ret; |
| 8207 | } |
| 8208 | |
| 8209 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8210 | #ifdef CONFIG_TESTING_OPTIONS |
| 8211 | static int cmd_reply_handler(struct nl_msg *msg, void *arg) |
| 8212 | { |
| 8213 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8214 | struct wpabuf *buf = arg; |
| 8215 | |
| 8216 | if (!buf) |
| 8217 | return NL_SKIP; |
| 8218 | |
| 8219 | if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) { |
| 8220 | wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply"); |
| 8221 | return NL_SKIP; |
| 8222 | } |
| 8223 | |
| 8224 | wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0), |
| 8225 | genlmsg_attrlen(gnlh, 0)); |
| 8226 | |
| 8227 | return NL_SKIP; |
| 8228 | } |
| 8229 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 8230 | |
| 8231 | |
| 8232 | static int vendor_reply_handler(struct nl_msg *msg, void *arg) |
| 8233 | { |
| 8234 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 8235 | struct nlattr *nl_vendor_reply, *nl; |
| 8236 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 8237 | struct wpabuf *buf = arg; |
| 8238 | int rem; |
| 8239 | |
| 8240 | if (!buf) |
| 8241 | return NL_SKIP; |
| 8242 | |
| 8243 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 8244 | genlmsg_attrlen(gnlh, 0), NULL); |
| 8245 | nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA]; |
| 8246 | |
| 8247 | if (!nl_vendor_reply) |
| 8248 | return NL_SKIP; |
| 8249 | |
| 8250 | if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) { |
| 8251 | wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply"); |
| 8252 | return NL_SKIP; |
| 8253 | } |
| 8254 | |
| 8255 | nla_for_each_nested(nl, nl_vendor_reply, rem) { |
| 8256 | wpabuf_put_data(buf, nla_data(nl), nla_len(nl)); |
| 8257 | } |
| 8258 | |
| 8259 | return NL_SKIP; |
| 8260 | } |
| 8261 | |
| 8262 | |
| 8263 | static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id, |
| 8264 | unsigned int subcmd, const u8 *data, |
| 8265 | size_t data_len, struct wpabuf *buf) |
| 8266 | { |
| 8267 | struct i802_bss *bss = priv; |
| 8268 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8269 | struct nl_msg *msg; |
| 8270 | int ret; |
| 8271 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8272 | #ifdef CONFIG_TESTING_OPTIONS |
| 8273 | if (vendor_id == 0xffffffff) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8274 | msg = nlmsg_alloc(); |
| 8275 | if (!msg) |
| 8276 | return -ENOMEM; |
| 8277 | |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8278 | nl80211_cmd(drv, msg, 0, subcmd); |
| 8279 | if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) < |
| 8280 | 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8281 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8282 | ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf); |
| 8283 | if (ret) |
| 8284 | wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d", |
| 8285 | ret); |
| 8286 | return ret; |
| 8287 | } |
| 8288 | #endif /* CONFIG_TESTING_OPTIONS */ |
| 8289 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8290 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) || |
| 8291 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) || |
| 8292 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) || |
| 8293 | (data && |
| 8294 | nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data))) |
| 8295 | goto fail; |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8296 | |
| 8297 | ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf); |
| 8298 | if (ret) |
| 8299 | wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d", |
| 8300 | ret); |
| 8301 | return ret; |
| 8302 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8303 | fail: |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 8304 | nlmsg_free(msg); |
| 8305 | return -ENOBUFS; |
| 8306 | } |
| 8307 | |
| 8308 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8309 | static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set, |
| 8310 | u8 qos_map_set_len) |
| 8311 | { |
| 8312 | struct i802_bss *bss = priv; |
| 8313 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8314 | struct nl_msg *msg; |
| 8315 | int ret; |
| 8316 | |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8317 | wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map", |
| 8318 | qos_map_set, qos_map_set_len); |
| 8319 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8320 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) || |
| 8321 | nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) { |
| 8322 | nlmsg_free(msg); |
| 8323 | return -ENOBUFS; |
| 8324 | } |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8325 | |
| 8326 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8327 | if (ret) |
| 8328 | wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed"); |
| 8329 | |
| 8330 | return ret; |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 8331 | } |
| 8332 | |
| 8333 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8334 | static int nl80211_set_wowlan(void *priv, |
| 8335 | const struct wowlan_triggers *triggers) |
| 8336 | { |
| 8337 | struct i802_bss *bss = priv; |
| 8338 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8339 | struct nl_msg *msg; |
| 8340 | struct nlattr *wowlan_triggers; |
| 8341 | int ret; |
| 8342 | |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8343 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan"); |
| 8344 | |
Dmitry Shmidt | a3dc309 | 2015-06-23 11:21:28 -0700 | [diff] [blame] | 8345 | if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) || |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8346 | !(wowlan_triggers = nla_nest_start(msg, |
| 8347 | NL80211_ATTR_WOWLAN_TRIGGERS)) || |
| 8348 | (triggers->any && |
| 8349 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) || |
| 8350 | (triggers->disconnect && |
| 8351 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) || |
| 8352 | (triggers->magic_pkt && |
| 8353 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) || |
| 8354 | (triggers->gtk_rekey_failure && |
| 8355 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) || |
| 8356 | (triggers->eap_identity_req && |
| 8357 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) || |
| 8358 | (triggers->four_way_handshake && |
| 8359 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) || |
| 8360 | (triggers->rfkill_release && |
| 8361 | nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) { |
| 8362 | nlmsg_free(msg); |
| 8363 | return -ENOBUFS; |
| 8364 | } |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8365 | |
| 8366 | nla_nest_end(msg, wowlan_triggers); |
| 8367 | |
| 8368 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8369 | if (ret) |
| 8370 | wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed"); |
| 8371 | |
| 8372 | return ret; |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 8373 | } |
| 8374 | |
| 8375 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8376 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8377 | static int nl80211_roaming(void *priv, int allowed, const u8 *bssid) |
| 8378 | { |
| 8379 | struct i802_bss *bss = priv; |
| 8380 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8381 | struct nl_msg *msg; |
| 8382 | struct nlattr *params; |
| 8383 | |
| 8384 | wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed); |
| 8385 | |
| 8386 | if (!drv->roaming_vendor_cmd_avail) { |
| 8387 | wpa_printf(MSG_DEBUG, |
| 8388 | "nl80211: Ignore roaming policy change since driver does not provide command for setting it"); |
| 8389 | return -1; |
| 8390 | } |
| 8391 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8392 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 8393 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8394 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8395 | QCA_NL80211_VENDOR_SUBCMD_ROAMING) || |
| 8396 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8397 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY, |
| 8398 | allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS : |
| 8399 | QCA_ROAMING_NOT_ALLOWED) || |
| 8400 | (bssid && |
| 8401 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) { |
| 8402 | nlmsg_free(msg); |
| 8403 | return -1; |
| 8404 | } |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8405 | nla_nest_end(msg, params); |
| 8406 | |
| 8407 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8408 | } |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8409 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8410 | |
| 8411 | |
| 8412 | static int nl80211_set_mac_addr(void *priv, const u8 *addr) |
| 8413 | { |
| 8414 | struct i802_bss *bss = priv; |
| 8415 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8416 | int new_addr = addr != NULL; |
| 8417 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 8418 | if (TEST_FAIL()) |
| 8419 | return -1; |
| 8420 | |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 8421 | if (!addr) |
| 8422 | addr = drv->perm_addr; |
| 8423 | |
| 8424 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0) |
| 8425 | return -1; |
| 8426 | |
| 8427 | if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0) |
| 8428 | { |
| 8429 | wpa_printf(MSG_DEBUG, |
| 8430 | "nl80211: failed to set_mac_addr for %s to " MACSTR, |
| 8431 | bss->ifname, MAC2STR(addr)); |
| 8432 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, |
| 8433 | 1) < 0) { |
| 8434 | wpa_printf(MSG_DEBUG, |
| 8435 | "nl80211: Could not restore interface UP after failed set_mac_addr"); |
| 8436 | } |
| 8437 | return -1; |
| 8438 | } |
| 8439 | |
| 8440 | wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR, |
| 8441 | bss->ifname, MAC2STR(addr)); |
| 8442 | drv->addr_changed = new_addr; |
| 8443 | os_memcpy(bss->addr, addr, ETH_ALEN); |
| 8444 | |
| 8445 | if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0) |
| 8446 | { |
| 8447 | wpa_printf(MSG_DEBUG, |
| 8448 | "nl80211: Could not restore interface UP after set_mac_addr"); |
| 8449 | } |
| 8450 | |
| 8451 | return 0; |
| 8452 | } |
| 8453 | |
| 8454 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8455 | #ifdef CONFIG_MESH |
| 8456 | |
| 8457 | static int wpa_driver_nl80211_init_mesh(void *priv) |
| 8458 | { |
| 8459 | if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) { |
| 8460 | wpa_printf(MSG_INFO, |
| 8461 | "nl80211: Failed to set interface into mesh mode"); |
| 8462 | return -1; |
| 8463 | } |
| 8464 | return 0; |
| 8465 | } |
| 8466 | |
| 8467 | |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8468 | static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id, |
| 8469 | size_t mesh_id_len) |
| 8470 | { |
| 8471 | if (mesh_id) { |
| 8472 | wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)", |
| 8473 | mesh_id, mesh_id_len); |
| 8474 | return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id); |
| 8475 | } |
| 8476 | |
| 8477 | return 0; |
| 8478 | } |
| 8479 | |
| 8480 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 8481 | static int nl80211_put_mesh_config(struct nl_msg *msg, |
| 8482 | struct wpa_driver_mesh_bss_params *params) |
| 8483 | { |
| 8484 | struct nlattr *container; |
| 8485 | |
| 8486 | container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG); |
| 8487 | if (!container) |
| 8488 | return -1; |
| 8489 | |
| 8490 | if (((params->flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) && |
| 8491 | nla_put_u32(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, |
| 8492 | params->auto_plinks)) || |
| 8493 | ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS) && |
| 8494 | nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS, |
| 8495 | params->max_peer_links))) |
| 8496 | return -1; |
| 8497 | |
| 8498 | /* |
| 8499 | * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because |
| 8500 | * the timer could disconnect stations even in that case. |
| 8501 | */ |
| 8502 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT) && |
| 8503 | nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT, |
| 8504 | params->peer_link_timeout)) { |
| 8505 | wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT"); |
| 8506 | return -1; |
| 8507 | } |
| 8508 | |
| 8509 | if ((params->flags & WPA_DRIVER_MESH_CONF_FLAG_HT_OP_MODE) && |
| 8510 | nla_put_u16(msg, NL80211_MESHCONF_HT_OPMODE, params->ht_opmode)) { |
| 8511 | wpa_printf(MSG_ERROR, "nl80211: Failed to set HT_OP_MODE"); |
| 8512 | return -1; |
| 8513 | } |
| 8514 | |
| 8515 | nla_nest_end(msg, container); |
| 8516 | |
| 8517 | return 0; |
| 8518 | } |
| 8519 | |
| 8520 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8521 | static int nl80211_join_mesh(struct i802_bss *bss, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8522 | struct wpa_driver_mesh_join_params *params) |
| 8523 | { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8524 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8525 | struct nl_msg *msg; |
| 8526 | struct nlattr *container; |
Dmitry Shmidt | 2f74e36 | 2015-01-21 13:19:05 -0800 | [diff] [blame] | 8527 | int ret = -1; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8528 | |
| 8529 | wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex); |
| 8530 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH); |
Dmitry Shmidt | ff787d5 | 2015-01-12 13:01:47 -0800 | [diff] [blame] | 8531 | if (!msg || |
| 8532 | nl80211_put_freq_params(msg, ¶ms->freq) || |
| 8533 | nl80211_put_basic_rates(msg, params->basic_rates) || |
| 8534 | nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) || |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 8535 | nl80211_put_beacon_int(msg, params->beacon_int) || |
| 8536 | nl80211_put_dtim_period(msg, params->dtim_period)) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8537 | goto fail; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8538 | |
| 8539 | wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags); |
| 8540 | |
| 8541 | container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP); |
| 8542 | if (!container) |
| 8543 | goto fail; |
| 8544 | |
| 8545 | if (params->ies) { |
| 8546 | wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len); |
| 8547 | if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len, |
| 8548 | params->ies)) |
| 8549 | goto fail; |
| 8550 | } |
| 8551 | /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */ |
| 8552 | if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) { |
| 8553 | if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) || |
| 8554 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH)) |
| 8555 | goto fail; |
| 8556 | } |
| 8557 | if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) && |
| 8558 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE)) |
| 8559 | goto fail; |
| 8560 | if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) && |
| 8561 | nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM)) |
| 8562 | goto fail; |
| 8563 | nla_nest_end(msg, container); |
| 8564 | |
Dmitry Shmidt | d13095b | 2016-08-22 14:02:19 -0700 | [diff] [blame] | 8565 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS; |
| 8566 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_PEER_LINK_TIMEOUT; |
| 8567 | params->conf.flags |= WPA_DRIVER_MESH_CONF_FLAG_MAX_PEER_LINKS; |
| 8568 | if (nl80211_put_mesh_config(msg, ¶ms->conf) < 0) |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8569 | goto fail; |
| 8570 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8571 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8572 | msg = NULL; |
| 8573 | if (ret) { |
| 8574 | wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)", |
| 8575 | ret, strerror(-ret)); |
| 8576 | goto fail; |
| 8577 | } |
| 8578 | ret = 0; |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 8579 | drv->assoc_freq = bss->freq = params->freq.freq; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8580 | wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully"); |
| 8581 | |
| 8582 | fail: |
| 8583 | nlmsg_free(msg); |
| 8584 | return ret; |
| 8585 | } |
| 8586 | |
| 8587 | |
Dmitry Shmidt | 7f65602 | 2015-02-25 14:36:37 -0800 | [diff] [blame] | 8588 | static int |
| 8589 | wpa_driver_nl80211_join_mesh(void *priv, |
| 8590 | struct wpa_driver_mesh_join_params *params) |
| 8591 | { |
| 8592 | struct i802_bss *bss = priv; |
| 8593 | int ret, timeout; |
| 8594 | |
| 8595 | timeout = params->conf.peer_link_timeout; |
| 8596 | |
| 8597 | /* Disable kernel inactivity timer */ |
| 8598 | if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) |
| 8599 | params->conf.peer_link_timeout = 0; |
| 8600 | |
| 8601 | ret = nl80211_join_mesh(bss, params); |
| 8602 | if (ret == -EINVAL && params->conf.peer_link_timeout == 0) { |
| 8603 | wpa_printf(MSG_DEBUG, |
| 8604 | "nl80211: Mesh join retry for peer_link_timeout"); |
| 8605 | /* |
| 8606 | * Old kernel does not support setting |
| 8607 | * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds |
| 8608 | * into future from peer_link_timeout. |
| 8609 | */ |
| 8610 | params->conf.peer_link_timeout = timeout + 60; |
| 8611 | ret = nl80211_join_mesh(priv, params); |
| 8612 | } |
| 8613 | |
| 8614 | params->conf.peer_link_timeout = timeout; |
| 8615 | return ret; |
| 8616 | } |
| 8617 | |
| 8618 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8619 | static int wpa_driver_nl80211_leave_mesh(void *priv) |
| 8620 | { |
| 8621 | struct i802_bss *bss = priv; |
| 8622 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8623 | struct nl_msg *msg; |
| 8624 | int ret; |
| 8625 | |
| 8626 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex); |
| 8627 | msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH); |
| 8628 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 8629 | if (ret) { |
| 8630 | wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)", |
| 8631 | ret, strerror(-ret)); |
| 8632 | } else { |
| 8633 | wpa_printf(MSG_DEBUG, |
| 8634 | "nl80211: mesh leave request send successfully"); |
| 8635 | } |
| 8636 | |
| 8637 | if (wpa_driver_nl80211_set_mode(drv->first_bss, |
| 8638 | NL80211_IFTYPE_STATION)) { |
| 8639 | wpa_printf(MSG_INFO, |
| 8640 | "nl80211: Failed to set interface into station mode"); |
| 8641 | } |
| 8642 | return ret; |
| 8643 | } |
| 8644 | |
| 8645 | #endif /* CONFIG_MESH */ |
| 8646 | |
| 8647 | |
| 8648 | static int wpa_driver_br_add_ip_neigh(void *priv, u8 version, |
| 8649 | const u8 *ipaddr, int prefixlen, |
| 8650 | const u8 *addr) |
| 8651 | { |
| 8652 | #ifdef CONFIG_LIBNL3_ROUTE |
| 8653 | struct i802_bss *bss = priv; |
| 8654 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8655 | struct rtnl_neigh *rn; |
| 8656 | struct nl_addr *nl_ipaddr = NULL; |
| 8657 | struct nl_addr *nl_lladdr = NULL; |
| 8658 | int family, addrsize; |
| 8659 | int res; |
| 8660 | |
| 8661 | if (!ipaddr || prefixlen == 0 || !addr) |
| 8662 | return -EINVAL; |
| 8663 | |
| 8664 | if (bss->br_ifindex == 0) { |
| 8665 | wpa_printf(MSG_DEBUG, |
| 8666 | "nl80211: bridge must be set before adding an ip neigh to it"); |
| 8667 | return -1; |
| 8668 | } |
| 8669 | |
| 8670 | if (!drv->rtnl_sk) { |
| 8671 | wpa_printf(MSG_DEBUG, |
| 8672 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 8673 | return -1; |
| 8674 | } |
| 8675 | |
| 8676 | if (version == 4) { |
| 8677 | family = AF_INET; |
| 8678 | addrsize = 4; |
| 8679 | } else if (version == 6) { |
| 8680 | family = AF_INET6; |
| 8681 | addrsize = 16; |
| 8682 | } else { |
| 8683 | return -EINVAL; |
| 8684 | } |
| 8685 | |
| 8686 | rn = rtnl_neigh_alloc(); |
| 8687 | if (rn == NULL) |
| 8688 | return -ENOMEM; |
| 8689 | |
| 8690 | /* set the destination ip address for neigh */ |
| 8691 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 8692 | if (nl_ipaddr == NULL) { |
| 8693 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 8694 | res = -ENOMEM; |
| 8695 | goto errout; |
| 8696 | } |
| 8697 | nl_addr_set_prefixlen(nl_ipaddr, prefixlen); |
| 8698 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 8699 | if (res) { |
| 8700 | wpa_printf(MSG_DEBUG, |
| 8701 | "nl80211: neigh set destination addr failed"); |
| 8702 | goto errout; |
| 8703 | } |
| 8704 | |
| 8705 | /* set the corresponding lladdr for neigh */ |
| 8706 | nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN); |
| 8707 | if (nl_lladdr == NULL) { |
| 8708 | wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed"); |
| 8709 | res = -ENOMEM; |
| 8710 | goto errout; |
| 8711 | } |
| 8712 | rtnl_neigh_set_lladdr(rn, nl_lladdr); |
| 8713 | |
| 8714 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 8715 | rtnl_neigh_set_state(rn, NUD_PERMANENT); |
| 8716 | |
| 8717 | res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE); |
| 8718 | if (res) { |
| 8719 | wpa_printf(MSG_DEBUG, |
| 8720 | "nl80211: Adding bridge ip neigh failed: %s", |
| 8721 | strerror(errno)); |
| 8722 | } |
| 8723 | errout: |
| 8724 | if (nl_lladdr) |
| 8725 | nl_addr_put(nl_lladdr); |
| 8726 | if (nl_ipaddr) |
| 8727 | nl_addr_put(nl_ipaddr); |
| 8728 | if (rn) |
| 8729 | rtnl_neigh_put(rn); |
| 8730 | return res; |
| 8731 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 8732 | return -1; |
| 8733 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 8734 | } |
| 8735 | |
| 8736 | |
| 8737 | static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version, |
| 8738 | const u8 *ipaddr) |
| 8739 | { |
| 8740 | #ifdef CONFIG_LIBNL3_ROUTE |
| 8741 | struct i802_bss *bss = priv; |
| 8742 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8743 | struct rtnl_neigh *rn; |
| 8744 | struct nl_addr *nl_ipaddr; |
| 8745 | int family, addrsize; |
| 8746 | int res; |
| 8747 | |
| 8748 | if (!ipaddr) |
| 8749 | return -EINVAL; |
| 8750 | |
| 8751 | if (version == 4) { |
| 8752 | family = AF_INET; |
| 8753 | addrsize = 4; |
| 8754 | } else if (version == 6) { |
| 8755 | family = AF_INET6; |
| 8756 | addrsize = 16; |
| 8757 | } else { |
| 8758 | return -EINVAL; |
| 8759 | } |
| 8760 | |
| 8761 | if (bss->br_ifindex == 0) { |
| 8762 | wpa_printf(MSG_DEBUG, |
| 8763 | "nl80211: bridge must be set to delete an ip neigh"); |
| 8764 | return -1; |
| 8765 | } |
| 8766 | |
| 8767 | if (!drv->rtnl_sk) { |
| 8768 | wpa_printf(MSG_DEBUG, |
| 8769 | "nl80211: nl_sock for NETLINK_ROUTE is not initialized"); |
| 8770 | return -1; |
| 8771 | } |
| 8772 | |
| 8773 | rn = rtnl_neigh_alloc(); |
| 8774 | if (rn == NULL) |
| 8775 | return -ENOMEM; |
| 8776 | |
| 8777 | /* set the destination ip address for neigh */ |
| 8778 | nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize); |
| 8779 | if (nl_ipaddr == NULL) { |
| 8780 | wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed"); |
| 8781 | res = -ENOMEM; |
| 8782 | goto errout; |
| 8783 | } |
| 8784 | res = rtnl_neigh_set_dst(rn, nl_ipaddr); |
| 8785 | if (res) { |
| 8786 | wpa_printf(MSG_DEBUG, |
| 8787 | "nl80211: neigh set destination addr failed"); |
| 8788 | goto errout; |
| 8789 | } |
| 8790 | |
| 8791 | rtnl_neigh_set_ifindex(rn, bss->br_ifindex); |
| 8792 | |
| 8793 | res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0); |
| 8794 | if (res) { |
| 8795 | wpa_printf(MSG_DEBUG, |
| 8796 | "nl80211: Deleting bridge ip neigh failed: %s", |
| 8797 | strerror(errno)); |
| 8798 | } |
| 8799 | errout: |
| 8800 | if (nl_ipaddr) |
| 8801 | nl_addr_put(nl_ipaddr); |
| 8802 | if (rn) |
| 8803 | rtnl_neigh_put(rn); |
| 8804 | return res; |
| 8805 | #else /* CONFIG_LIBNL3_ROUTE */ |
| 8806 | return -1; |
| 8807 | #endif /* CONFIG_LIBNL3_ROUTE */ |
| 8808 | } |
| 8809 | |
| 8810 | |
| 8811 | static int linux_write_system_file(const char *path, unsigned int val) |
| 8812 | { |
| 8813 | char buf[50]; |
| 8814 | int fd, len; |
| 8815 | |
| 8816 | len = os_snprintf(buf, sizeof(buf), "%u\n", val); |
| 8817 | if (os_snprintf_error(sizeof(buf), len)) |
| 8818 | return -1; |
| 8819 | |
| 8820 | fd = open(path, O_WRONLY); |
| 8821 | if (fd < 0) |
| 8822 | return -1; |
| 8823 | |
| 8824 | if (write(fd, buf, len) < 0) { |
| 8825 | wpa_printf(MSG_DEBUG, |
| 8826 | "nl80211: Failed to write Linux system file: %s with the value of %d", |
| 8827 | path, val); |
| 8828 | close(fd); |
| 8829 | return -1; |
| 8830 | } |
| 8831 | close(fd); |
| 8832 | |
| 8833 | return 0; |
| 8834 | } |
| 8835 | |
| 8836 | |
| 8837 | static const char * drv_br_port_attr_str(enum drv_br_port_attr attr) |
| 8838 | { |
| 8839 | switch (attr) { |
| 8840 | case DRV_BR_PORT_ATTR_PROXYARP: |
Dmitry Shmidt | 4dd28dc | 2015-03-10 11:21:43 -0700 | [diff] [blame] | 8841 | return "proxyarp_wifi"; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8842 | case DRV_BR_PORT_ATTR_HAIRPIN_MODE: |
| 8843 | return "hairpin_mode"; |
| 8844 | } |
| 8845 | |
| 8846 | return NULL; |
| 8847 | } |
| 8848 | |
| 8849 | |
| 8850 | static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr, |
| 8851 | unsigned int val) |
| 8852 | { |
| 8853 | struct i802_bss *bss = priv; |
| 8854 | char path[128]; |
| 8855 | const char *attr_txt; |
| 8856 | |
| 8857 | attr_txt = drv_br_port_attr_str(attr); |
| 8858 | if (attr_txt == NULL) |
| 8859 | return -EINVAL; |
| 8860 | |
| 8861 | os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s", |
| 8862 | bss->ifname, attr_txt); |
| 8863 | |
| 8864 | if (linux_write_system_file(path, val)) |
| 8865 | return -1; |
| 8866 | |
| 8867 | return 0; |
| 8868 | } |
| 8869 | |
| 8870 | |
| 8871 | static const char * drv_br_net_param_str(enum drv_br_net_param param) |
| 8872 | { |
| 8873 | switch (param) { |
| 8874 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 8875 | return "arp_accept"; |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 8876 | default: |
| 8877 | return NULL; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8878 | } |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8879 | } |
| 8880 | |
| 8881 | |
| 8882 | static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param, |
| 8883 | unsigned int val) |
| 8884 | { |
| 8885 | struct i802_bss *bss = priv; |
| 8886 | char path[128]; |
| 8887 | const char *param_txt; |
| 8888 | int ip_version = 4; |
| 8889 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 8890 | if (param == DRV_BR_MULTICAST_SNOOPING) { |
| 8891 | os_snprintf(path, sizeof(path), |
| 8892 | "/sys/devices/virtual/net/%s/bridge/multicast_snooping", |
| 8893 | bss->brname); |
| 8894 | goto set_val; |
| 8895 | } |
| 8896 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8897 | param_txt = drv_br_net_param_str(param); |
| 8898 | if (param_txt == NULL) |
| 8899 | return -EINVAL; |
| 8900 | |
| 8901 | switch (param) { |
| 8902 | case DRV_BR_NET_PARAM_GARP_ACCEPT: |
| 8903 | ip_version = 4; |
| 8904 | break; |
| 8905 | default: |
| 8906 | return -EINVAL; |
| 8907 | } |
| 8908 | |
| 8909 | os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s", |
| 8910 | ip_version, bss->brname, param_txt); |
| 8911 | |
Dmitry Shmidt | 8347444 | 2015-04-15 13:47:09 -0700 | [diff] [blame] | 8912 | set_val: |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8913 | if (linux_write_system_file(path, val)) |
| 8914 | return -1; |
| 8915 | |
| 8916 | return 0; |
| 8917 | } |
| 8918 | |
| 8919 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8920 | #ifdef CONFIG_DRIVER_NL80211_QCA |
| 8921 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8922 | static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode) |
| 8923 | { |
| 8924 | switch (hw_mode) { |
| 8925 | case HOSTAPD_MODE_IEEE80211B: |
| 8926 | return QCA_ACS_MODE_IEEE80211B; |
| 8927 | case HOSTAPD_MODE_IEEE80211G: |
| 8928 | return QCA_ACS_MODE_IEEE80211G; |
| 8929 | case HOSTAPD_MODE_IEEE80211A: |
| 8930 | return QCA_ACS_MODE_IEEE80211A; |
| 8931 | case HOSTAPD_MODE_IEEE80211AD: |
| 8932 | return QCA_ACS_MODE_IEEE80211AD; |
Dmitry Shmidt | b1e5210 | 2015-05-29 12:36:29 -0700 | [diff] [blame] | 8933 | case HOSTAPD_MODE_IEEE80211ANY: |
| 8934 | return QCA_ACS_MODE_IEEE80211ANY; |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8935 | default: |
| 8936 | return -1; |
| 8937 | } |
| 8938 | } |
| 8939 | |
| 8940 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 8941 | static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list) |
| 8942 | { |
| 8943 | int i, len, ret; |
| 8944 | u32 *freqs; |
| 8945 | |
| 8946 | if (!freq_list) |
| 8947 | return 0; |
| 8948 | len = int_array_len(freq_list); |
| 8949 | freqs = os_malloc(sizeof(u32) * len); |
| 8950 | if (!freqs) |
| 8951 | return -1; |
| 8952 | for (i = 0; i < len; i++) |
| 8953 | freqs[i] = freq_list[i]; |
| 8954 | ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST, |
| 8955 | sizeof(u32) * len, freqs); |
| 8956 | os_free(freqs); |
| 8957 | return ret; |
| 8958 | } |
| 8959 | |
| 8960 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8961 | static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params) |
| 8962 | { |
| 8963 | struct i802_bss *bss = priv; |
| 8964 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 8965 | struct nl_msg *msg; |
| 8966 | struct nlattr *data; |
| 8967 | int ret; |
| 8968 | int mode; |
| 8969 | |
| 8970 | mode = hw_mode_to_qca_acs(params->hw_mode); |
| 8971 | if (mode < 0) |
| 8972 | return -1; |
| 8973 | |
| 8974 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 8975 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 8976 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 8977 | QCA_NL80211_VENDOR_SUBCMD_DO_ACS) || |
| 8978 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 8979 | nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) || |
| 8980 | (params->ht_enabled && |
| 8981 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) || |
| 8982 | (params->ht40_enabled && |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 8983 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) || |
| 8984 | (params->vht_enabled && |
| 8985 | nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) || |
| 8986 | nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH, |
| 8987 | params->ch_width) || |
| 8988 | (params->ch_list_len && |
| 8989 | 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] | 8990 | params->ch_list)) || |
| 8991 | add_acs_freq_list(msg, params->freq_list)) { |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 8992 | nlmsg_free(msg); |
| 8993 | return -ENOBUFS; |
| 8994 | } |
| 8995 | nla_nest_end(msg, data); |
| 8996 | |
Dmitry Shmidt | dda10c2 | 2015-03-24 16:05:01 -0700 | [diff] [blame] | 8997 | wpa_printf(MSG_DEBUG, |
| 8998 | "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u", |
| 8999 | params->hw_mode, params->ht_enabled, params->ht40_enabled, |
| 9000 | params->vht_enabled, params->ch_width, params->ch_list_len); |
| 9001 | |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9002 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9003 | if (ret) { |
| 9004 | wpa_printf(MSG_DEBUG, |
| 9005 | "nl80211: Failed to invoke driver ACS function: %s", |
| 9006 | strerror(errno)); |
| 9007 | } |
| 9008 | return ret; |
| 9009 | } |
| 9010 | |
| 9011 | |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 9012 | static int nl80211_set_band(void *priv, enum set_band band) |
| 9013 | { |
| 9014 | struct i802_bss *bss = priv; |
| 9015 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9016 | struct nl_msg *msg; |
| 9017 | struct nlattr *data; |
| 9018 | int ret; |
| 9019 | enum qca_set_band qca_band; |
| 9020 | |
| 9021 | if (!drv->setband_vendor_cmd_avail) |
| 9022 | return -1; |
| 9023 | |
| 9024 | switch (band) { |
| 9025 | case WPA_SETBAND_AUTO: |
| 9026 | qca_band = QCA_SETBAND_AUTO; |
| 9027 | break; |
| 9028 | case WPA_SETBAND_5G: |
| 9029 | qca_band = QCA_SETBAND_5G; |
| 9030 | break; |
| 9031 | case WPA_SETBAND_2G: |
| 9032 | qca_band = QCA_SETBAND_2G; |
| 9033 | break; |
| 9034 | default: |
| 9035 | return -1; |
| 9036 | } |
| 9037 | |
| 9038 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9039 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9040 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9041 | QCA_NL80211_VENDOR_SUBCMD_SETBAND) || |
| 9042 | !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9043 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) { |
| 9044 | nlmsg_free(msg); |
| 9045 | return -ENOBUFS; |
| 9046 | } |
| 9047 | nla_nest_end(msg, data); |
| 9048 | |
| 9049 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9050 | if (ret) { |
| 9051 | wpa_printf(MSG_DEBUG, |
| 9052 | "nl80211: Driver setband function failed: %s", |
| 9053 | strerror(errno)); |
| 9054 | } |
| 9055 | return ret; |
| 9056 | } |
| 9057 | |
| 9058 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9059 | struct nl80211_pcl { |
| 9060 | unsigned int num; |
| 9061 | unsigned int *freq_list; |
| 9062 | }; |
| 9063 | |
| 9064 | static int preferred_freq_info_handler(struct nl_msg *msg, void *arg) |
| 9065 | { |
| 9066 | struct nlattr *tb[NL80211_ATTR_MAX + 1]; |
| 9067 | struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 9068 | struct nl80211_pcl *param = arg; |
| 9069 | struct nlattr *nl_vend, *attr; |
| 9070 | enum qca_iface_type iface_type; |
| 9071 | struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1]; |
| 9072 | unsigned int num, max_num; |
| 9073 | u32 *freqs; |
| 9074 | |
| 9075 | nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0), |
| 9076 | genlmsg_attrlen(gnlh, 0), NULL); |
| 9077 | |
| 9078 | nl_vend = tb[NL80211_ATTR_VENDOR_DATA]; |
| 9079 | if (!nl_vend) |
| 9080 | return NL_SKIP; |
| 9081 | |
| 9082 | nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX, |
| 9083 | nla_data(nl_vend), nla_len(nl_vend), NULL); |
| 9084 | |
| 9085 | attr = tb_vendor[ |
| 9086 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE]; |
| 9087 | if (!attr) { |
| 9088 | wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found"); |
| 9089 | param->num = 0; |
| 9090 | return NL_SKIP; |
| 9091 | } |
| 9092 | |
| 9093 | iface_type = (enum qca_iface_type) nla_get_u32(attr); |
| 9094 | wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d", |
| 9095 | iface_type); |
| 9096 | |
| 9097 | attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST]; |
| 9098 | if (!attr) { |
| 9099 | wpa_printf(MSG_ERROR, |
| 9100 | "nl80211: preferred_freq_list couldn't be found"); |
| 9101 | param->num = 0; |
| 9102 | return NL_SKIP; |
| 9103 | } |
| 9104 | |
| 9105 | /* |
| 9106 | * param->num has the maximum number of entries for which there |
| 9107 | * is room in the freq_list provided by the caller. |
| 9108 | */ |
| 9109 | freqs = nla_data(attr); |
| 9110 | max_num = nla_len(attr) / sizeof(u32); |
| 9111 | if (max_num > param->num) |
| 9112 | max_num = param->num; |
| 9113 | for (num = 0; num < max_num; num++) |
| 9114 | param->freq_list[num] = freqs[num]; |
| 9115 | param->num = num; |
| 9116 | |
| 9117 | return NL_SKIP; |
| 9118 | } |
| 9119 | |
| 9120 | |
| 9121 | static int nl80211_get_pref_freq_list(void *priv, |
| 9122 | enum wpa_driver_if_type if_type, |
| 9123 | unsigned int *num, |
| 9124 | unsigned int *freq_list) |
| 9125 | { |
| 9126 | struct i802_bss *bss = priv; |
| 9127 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9128 | struct nl_msg *msg; |
| 9129 | int ret; |
| 9130 | unsigned int i; |
| 9131 | struct nlattr *params; |
| 9132 | struct nl80211_pcl param; |
| 9133 | enum qca_iface_type iface_type; |
| 9134 | |
| 9135 | if (!drv->get_pref_freq_list) |
| 9136 | return -1; |
| 9137 | |
| 9138 | switch (if_type) { |
| 9139 | case WPA_IF_STATION: |
| 9140 | iface_type = QCA_IFACE_TYPE_STA; |
| 9141 | break; |
| 9142 | case WPA_IF_AP_BSS: |
| 9143 | iface_type = QCA_IFACE_TYPE_AP; |
| 9144 | break; |
| 9145 | case WPA_IF_P2P_GO: |
| 9146 | iface_type = QCA_IFACE_TYPE_P2P_GO; |
| 9147 | break; |
| 9148 | case WPA_IF_P2P_CLIENT: |
| 9149 | iface_type = QCA_IFACE_TYPE_P2P_CLIENT; |
| 9150 | break; |
| 9151 | case WPA_IF_IBSS: |
| 9152 | iface_type = QCA_IFACE_TYPE_IBSS; |
| 9153 | break; |
| 9154 | case WPA_IF_TDLS: |
| 9155 | iface_type = QCA_IFACE_TYPE_TDLS; |
| 9156 | break; |
| 9157 | default: |
| 9158 | return -1; |
| 9159 | } |
| 9160 | |
| 9161 | param.num = *num; |
| 9162 | param.freq_list = freq_list; |
| 9163 | |
| 9164 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9165 | nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) || |
| 9166 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9167 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9168 | QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) || |
| 9169 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9170 | nla_put_u32(msg, |
| 9171 | QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE, |
| 9172 | iface_type)) { |
| 9173 | wpa_printf(MSG_ERROR, |
| 9174 | "%s: err in adding vendor_cmd and vendor_data", |
| 9175 | __func__); |
| 9176 | nlmsg_free(msg); |
| 9177 | return -1; |
| 9178 | } |
| 9179 | nla_nest_end(msg, params); |
| 9180 | |
| 9181 | os_memset(freq_list, 0, *num * sizeof(freq_list[0])); |
| 9182 | ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, ¶m); |
| 9183 | if (ret) { |
| 9184 | wpa_printf(MSG_ERROR, |
| 9185 | "%s: err in send_and_recv_msgs", __func__); |
| 9186 | return ret; |
| 9187 | } |
| 9188 | |
| 9189 | *num = param.num; |
| 9190 | |
| 9191 | for (i = 0; i < *num; i++) { |
| 9192 | wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d", |
| 9193 | i, freq_list[i]); |
| 9194 | } |
| 9195 | |
| 9196 | return 0; |
| 9197 | } |
| 9198 | |
| 9199 | |
| 9200 | static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq) |
| 9201 | { |
| 9202 | struct i802_bss *bss = priv; |
| 9203 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9204 | struct nl_msg *msg; |
| 9205 | int ret; |
| 9206 | struct nlattr *params; |
| 9207 | |
| 9208 | if (!drv->set_prob_oper_freq) |
| 9209 | return -1; |
| 9210 | |
| 9211 | wpa_printf(MSG_DEBUG, |
| 9212 | "nl80211: Set P2P probable operating freq %u for ifindex %d", |
| 9213 | freq, bss->ifindex); |
| 9214 | |
| 9215 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9216 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9217 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9218 | QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) || |
| 9219 | !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) || |
| 9220 | nla_put_u32(msg, |
| 9221 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE, |
| 9222 | QCA_IFACE_TYPE_P2P_CLIENT) || |
| 9223 | nla_put_u32(msg, |
| 9224 | QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ, |
| 9225 | freq)) { |
| 9226 | wpa_printf(MSG_ERROR, |
| 9227 | "%s: err in adding vendor_cmd and vendor_data", |
| 9228 | __func__); |
| 9229 | nlmsg_free(msg); |
| 9230 | return -1; |
| 9231 | } |
| 9232 | nla_nest_end(msg, params); |
| 9233 | |
| 9234 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9235 | msg = NULL; |
| 9236 | if (ret) { |
| 9237 | wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs", |
| 9238 | __func__); |
| 9239 | return ret; |
| 9240 | } |
| 9241 | nlmsg_free(msg); |
| 9242 | return 0; |
| 9243 | } |
| 9244 | |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 9245 | |
| 9246 | static int nl80211_p2p_lo_start(void *priv, unsigned int freq, |
| 9247 | unsigned int period, unsigned int interval, |
| 9248 | unsigned int count, const u8 *device_types, |
| 9249 | size_t dev_types_len, |
| 9250 | const u8 *ies, size_t ies_len) |
| 9251 | { |
| 9252 | struct i802_bss *bss = priv; |
| 9253 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9254 | struct nl_msg *msg; |
| 9255 | struct nlattr *container; |
| 9256 | int ret; |
| 9257 | |
| 9258 | wpa_printf(MSG_DEBUG, |
| 9259 | "nl80211: Start P2P Listen offload: freq=%u, period=%u, interval=%u, count=%u", |
| 9260 | freq, period, interval, count); |
| 9261 | |
| 9262 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 9263 | return -1; |
| 9264 | |
| 9265 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9266 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9267 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9268 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_START)) |
| 9269 | goto fail; |
| 9270 | |
| 9271 | container = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 9272 | if (!container) |
| 9273 | goto fail; |
| 9274 | |
| 9275 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_CHANNEL, |
| 9276 | freq) || |
| 9277 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_PERIOD, |
| 9278 | period) || |
| 9279 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_INTERVAL, |
| 9280 | interval) || |
| 9281 | nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_COUNT, |
| 9282 | count) || |
| 9283 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_DEVICE_TYPES, |
| 9284 | dev_types_len, device_types) || |
| 9285 | nla_put(msg, QCA_WLAN_VENDOR_ATTR_P2P_LISTEN_OFFLOAD_VENDOR_IE, |
| 9286 | ies_len, ies)) |
| 9287 | goto fail; |
| 9288 | |
| 9289 | nla_nest_end(msg, container); |
| 9290 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9291 | msg = NULL; |
| 9292 | if (ret) { |
| 9293 | wpa_printf(MSG_DEBUG, |
| 9294 | "nl80211: Failed to send P2P Listen offload vendor command"); |
| 9295 | goto fail; |
| 9296 | } |
| 9297 | |
| 9298 | return 0; |
| 9299 | |
| 9300 | fail: |
| 9301 | nlmsg_free(msg); |
| 9302 | return -1; |
| 9303 | } |
| 9304 | |
| 9305 | |
| 9306 | static int nl80211_p2p_lo_stop(void *priv) |
| 9307 | { |
| 9308 | struct i802_bss *bss = priv; |
| 9309 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9310 | struct nl_msg *msg; |
| 9311 | |
| 9312 | wpa_printf(MSG_DEBUG, "nl80211: Stop P2P Listen offload"); |
| 9313 | |
| 9314 | if (!(drv->capa.flags & WPA_DRIVER_FLAGS_P2P_LISTEN_OFFLOAD)) |
| 9315 | return -1; |
| 9316 | |
| 9317 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9318 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9319 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9320 | QCA_NL80211_VENDOR_SUBCMD_P2P_LISTEN_OFFLOAD_STOP)) { |
| 9321 | nlmsg_free(msg); |
| 9322 | return -1; |
| 9323 | } |
| 9324 | |
| 9325 | return send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9326 | } |
| 9327 | |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame^] | 9328 | |
| 9329 | static int nl80211_set_tdls_mode(void *priv, int tdls_external_control) |
| 9330 | { |
| 9331 | struct i802_bss *bss = priv; |
| 9332 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9333 | struct nl_msg *msg; |
| 9334 | struct nlattr *params; |
| 9335 | int ret; |
| 9336 | u32 tdls_mode; |
| 9337 | |
| 9338 | wpa_printf(MSG_DEBUG, |
| 9339 | "nl80211: Set TDKS mode: tdls_external_control=%d", |
| 9340 | tdls_external_control); |
| 9341 | |
| 9342 | if (tdls_external_control == 1) |
| 9343 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_IMPLICIT | |
| 9344 | QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXTERNAL; |
| 9345 | else |
| 9346 | tdls_mode = QCA_WLAN_VENDOR_TDLS_TRIGGER_MODE_EXPLICIT; |
| 9347 | |
| 9348 | if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) || |
| 9349 | nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) || |
| 9350 | nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, |
| 9351 | QCA_NL80211_VENDOR_SUBCMD_CONFIGURE_TDLS)) |
| 9352 | goto fail; |
| 9353 | |
| 9354 | params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA); |
| 9355 | if (!params) |
| 9356 | goto fail; |
| 9357 | |
| 9358 | if (nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TDLS_CONFIG_TRIGGER_MODE, |
| 9359 | tdls_mode)) |
| 9360 | goto fail; |
| 9361 | |
| 9362 | nla_nest_end(msg, params); |
| 9363 | |
| 9364 | ret = send_and_recv_msgs(drv, msg, NULL, NULL); |
| 9365 | msg = NULL; |
| 9366 | if (ret) { |
| 9367 | wpa_printf(MSG_ERROR, |
| 9368 | "nl80211: Set TDLS mode failed: ret=%d (%s)", |
| 9369 | ret, strerror(-ret)); |
| 9370 | goto fail; |
| 9371 | } |
| 9372 | return 0; |
| 9373 | fail: |
| 9374 | nlmsg_free(msg); |
| 9375 | return -1; |
| 9376 | } |
| 9377 | |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9378 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
| 9379 | |
| 9380 | |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9381 | static int nl80211_write_to_file(const char *name, unsigned int val) |
| 9382 | { |
| 9383 | int fd, len; |
| 9384 | char tmp[128]; |
| 9385 | |
| 9386 | fd = open(name, O_RDWR); |
| 9387 | if (fd < 0) { |
| 9388 | wpa_printf(MSG_ERROR, "nl80211: Failed to open %s: %s", |
| 9389 | name, strerror(errno)); |
| 9390 | return fd; |
| 9391 | } |
| 9392 | |
| 9393 | len = os_snprintf(tmp, sizeof(tmp), "%u\n", val); |
| 9394 | len = write(fd, tmp, len); |
| 9395 | if (len < 0) |
| 9396 | wpa_printf(MSG_ERROR, "nl80211: Failed to write to %s: %s", |
| 9397 | name, strerror(errno)); |
| 9398 | close(fd); |
| 9399 | |
| 9400 | return 0; |
| 9401 | } |
| 9402 | |
| 9403 | |
| 9404 | static int nl80211_configure_data_frame_filters(void *priv, u32 filter_flags) |
| 9405 | { |
| 9406 | struct i802_bss *bss = priv; |
| 9407 | char path[128]; |
| 9408 | int ret; |
| 9409 | |
| 9410 | wpa_printf(MSG_DEBUG, "nl80211: Data frame filter flags=0x%x", |
| 9411 | filter_flags); |
| 9412 | |
| 9413 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 9414 | ret = os_snprintf(path, sizeof(path), |
| 9415 | "/proc/sys/net/ipv4/conf/%s/drop_unicast_in_l2_multicast", |
| 9416 | bss->ifname); |
| 9417 | if (os_snprintf_error(sizeof(path), ret)) |
| 9418 | return -1; |
| 9419 | |
| 9420 | ret = nl80211_write_to_file(path, |
| 9421 | !!(filter_flags & |
| 9422 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 9423 | if (ret) { |
| 9424 | wpa_printf(MSG_ERROR, |
| 9425 | "nl80211: Failed to set IPv4 unicast in multicast filter"); |
| 9426 | return ret; |
| 9427 | } |
| 9428 | |
| 9429 | os_snprintf(path, sizeof(path), |
| 9430 | "/proc/sys/net/ipv6/conf/%s/drop_unicast_in_l2_multicast", |
| 9431 | bss->ifname); |
| 9432 | ret = nl80211_write_to_file(path, |
| 9433 | !!(filter_flags & |
| 9434 | WPA_DATA_FRAME_FILTER_FLAG_GTK)); |
| 9435 | |
| 9436 | if (ret) { |
| 9437 | wpa_printf(MSG_ERROR, |
| 9438 | "nl80211: Failed to set IPv6 unicast in multicast filter"); |
| 9439 | return ret; |
| 9440 | } |
| 9441 | |
| 9442 | /* Configure filtering of unicast frame encrypted using GTK */ |
| 9443 | os_snprintf(path, sizeof(path), |
| 9444 | "/proc/sys/net/ipv4/conf/%s/drop_gratuitous_arp", |
| 9445 | bss->ifname); |
| 9446 | ret = nl80211_write_to_file(path, |
| 9447 | !!(filter_flags & |
| 9448 | WPA_DATA_FRAME_FILTER_FLAG_ARP)); |
| 9449 | if (ret) { |
| 9450 | wpa_printf(MSG_ERROR, |
| 9451 | "nl80211: Failed set gratuitous ARP filter"); |
| 9452 | return ret; |
| 9453 | } |
| 9454 | |
| 9455 | /* Configure filtering of IPv6 NA frames */ |
| 9456 | os_snprintf(path, sizeof(path), |
| 9457 | "/proc/sys/net/ipv6/conf/%s/drop_unsolicited_na", |
| 9458 | bss->ifname); |
| 9459 | ret = nl80211_write_to_file(path, |
| 9460 | !!(filter_flags & |
| 9461 | WPA_DATA_FRAME_FILTER_FLAG_NA)); |
| 9462 | if (ret) { |
| 9463 | wpa_printf(MSG_ERROR, |
| 9464 | "nl80211: Failed to set unsolicited NA filter"); |
| 9465 | return ret; |
| 9466 | } |
| 9467 | |
| 9468 | return 0; |
| 9469 | } |
| 9470 | |
| 9471 | |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 9472 | static int nl80211_get_ext_capab(void *priv, enum wpa_driver_if_type type, |
| 9473 | const u8 **ext_capa, const u8 **ext_capa_mask, |
| 9474 | unsigned int *ext_capa_len) |
| 9475 | { |
| 9476 | struct i802_bss *bss = priv; |
| 9477 | struct wpa_driver_nl80211_data *drv = bss->drv; |
| 9478 | enum nl80211_iftype nlmode; |
| 9479 | unsigned int i; |
| 9480 | |
| 9481 | if (!ext_capa || !ext_capa_mask || !ext_capa_len) |
| 9482 | return -1; |
| 9483 | |
| 9484 | nlmode = wpa_driver_nl80211_if_type(type); |
| 9485 | |
| 9486 | /* By default, use the per-radio values */ |
| 9487 | *ext_capa = drv->extended_capa; |
| 9488 | *ext_capa_mask = drv->extended_capa_mask; |
| 9489 | *ext_capa_len = drv->extended_capa_len; |
| 9490 | |
| 9491 | /* Replace the default value if a per-interface type value exists */ |
| 9492 | for (i = 0; i < drv->num_iface_ext_capa; i++) { |
| 9493 | if (nlmode == drv->iface_ext_capa[i].iftype) { |
| 9494 | *ext_capa = drv->iface_ext_capa[i].ext_capa; |
| 9495 | *ext_capa_mask = drv->iface_ext_capa[i].ext_capa_mask; |
| 9496 | *ext_capa_len = drv->iface_ext_capa[i].ext_capa_len; |
| 9497 | break; |
| 9498 | } |
| 9499 | } |
| 9500 | |
| 9501 | return 0; |
| 9502 | } |
| 9503 | |
| 9504 | |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9505 | const struct wpa_driver_ops wpa_driver_nl80211_ops = { |
| 9506 | .name = "nl80211", |
| 9507 | .desc = "Linux nl80211/cfg80211", |
| 9508 | .get_bssid = wpa_driver_nl80211_get_bssid, |
| 9509 | .get_ssid = wpa_driver_nl80211_get_ssid, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9510 | .set_key = driver_nl80211_set_key, |
| 9511 | .scan2 = driver_nl80211_scan2, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9512 | .sched_scan = wpa_driver_nl80211_sched_scan, |
| 9513 | .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9514 | .get_scan_results2 = wpa_driver_nl80211_get_scan_results, |
Dmitry Shmidt | d7ff03d | 2015-12-04 14:49:35 -0800 | [diff] [blame] | 9515 | .abort_scan = wpa_driver_nl80211_abort_scan, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9516 | .deauthenticate = driver_nl80211_deauthenticate, |
| 9517 | .authenticate = driver_nl80211_authenticate, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9518 | .associate = wpa_driver_nl80211_associate, |
| 9519 | .global_init = nl80211_global_init, |
| 9520 | .global_deinit = nl80211_global_deinit, |
| 9521 | .init2 = wpa_driver_nl80211_init, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9522 | .deinit = driver_nl80211_deinit, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9523 | .get_capa = wpa_driver_nl80211_get_capa, |
| 9524 | .set_operstate = wpa_driver_nl80211_set_operstate, |
| 9525 | .set_supp_port = wpa_driver_nl80211_set_supp_port, |
| 9526 | .set_country = wpa_driver_nl80211_set_country, |
Dmitry Shmidt | cce0666 | 2013-11-04 18:44:24 -0800 | [diff] [blame] | 9527 | .get_country = wpa_driver_nl80211_get_country, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9528 | .set_ap = wpa_driver_nl80211_set_ap, |
Dmitry Shmidt | 8bae413 | 2013-06-06 11:25:10 -0700 | [diff] [blame] | 9529 | .set_acl = wpa_driver_nl80211_set_acl, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9530 | .if_add = wpa_driver_nl80211_if_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9531 | .if_remove = driver_nl80211_if_remove, |
| 9532 | .send_mlme = driver_nl80211_send_mlme, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9533 | .get_hw_feature_data = nl80211_get_hw_feature_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9534 | .sta_add = wpa_driver_nl80211_sta_add, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9535 | .sta_remove = driver_nl80211_sta_remove, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9536 | .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol, |
| 9537 | .sta_set_flags = wpa_driver_nl80211_sta_set_flags, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9538 | .hapd_init = i802_init, |
| 9539 | .hapd_deinit = i802_deinit, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9540 | .set_wds_sta = i802_set_wds_sta, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9541 | .get_seqnum = i802_get_seqnum, |
| 9542 | .flush = i802_flush, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9543 | .get_inact_sec = i802_get_inact_sec, |
| 9544 | .sta_clear_stats = i802_sta_clear_stats, |
| 9545 | .set_rts = i802_set_rts, |
| 9546 | .set_frag = i802_set_frag, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9547 | .set_tx_queue_params = i802_set_tx_queue_params, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9548 | .set_sta_vlan = driver_nl80211_set_sta_vlan, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9549 | .sta_deauth = i802_sta_deauth, |
| 9550 | .sta_disassoc = i802_sta_disassoc, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9551 | .read_sta_data = driver_nl80211_read_sta_data, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9552 | .set_freq = i802_set_freq, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9553 | .send_action = driver_nl80211_send_action, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9554 | .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait, |
| 9555 | .remain_on_channel = wpa_driver_nl80211_remain_on_channel, |
| 9556 | .cancel_remain_on_channel = |
| 9557 | wpa_driver_nl80211_cancel_remain_on_channel, |
Dmitry Shmidt | 4b9d52f | 2013-02-05 17:44:43 -0800 | [diff] [blame] | 9558 | .probe_req_report = driver_nl80211_probe_req_report, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9559 | .deinit_ap = wpa_driver_nl80211_deinit_ap, |
Dmitry Shmidt | 0494959 | 2012-07-19 12:16:46 -0700 | [diff] [blame] | 9560 | .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9561 | .resume = wpa_driver_nl80211_resume, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9562 | .signal_monitor = nl80211_signal_monitor, |
| 9563 | .signal_poll = nl80211_signal_poll, |
| 9564 | .send_frame = nl80211_send_frame, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9565 | .set_param = nl80211_set_param, |
| 9566 | .get_radio_name = nl80211_get_radio_name, |
Jouni Malinen | 75ecf52 | 2011-06-27 15:19:46 -0700 | [diff] [blame] | 9567 | .add_pmkid = nl80211_add_pmkid, |
| 9568 | .remove_pmkid = nl80211_remove_pmkid, |
| 9569 | .flush_pmkid = nl80211_flush_pmkid, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9570 | .set_rekey_info = nl80211_set_rekey_info, |
| 9571 | .poll_client = nl80211_poll_client, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9572 | .set_p2p_powersave = nl80211_set_p2p_powersave, |
Dmitry Shmidt | ea69e84 | 2013-05-13 14:52:28 -0700 | [diff] [blame] | 9573 | .start_dfs_cac = nl80211_start_radar_detection, |
| 9574 | .stop_ap = wpa_driver_nl80211_stop_ap, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9575 | #ifdef CONFIG_TDLS |
| 9576 | .send_tdls_mgmt = nl80211_send_tdls_mgmt, |
| 9577 | .tdls_oper = nl80211_tdls_oper, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9578 | .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch, |
| 9579 | .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9580 | #endif /* CONFIG_TDLS */ |
Dmitry Shmidt | 700a137 | 2013-03-15 14:14:44 -0700 | [diff] [blame] | 9581 | .update_ft_ies = wpa_driver_nl80211_update_ft_ies, |
Dmitry Shmidt | 34af306 | 2013-07-11 10:46:32 -0700 | [diff] [blame] | 9582 | .get_mac_addr = wpa_driver_nl80211_get_macaddr, |
Dmitry Shmidt | b7b4d0e | 2013-08-26 12:09:05 -0700 | [diff] [blame] | 9583 | .get_survey = wpa_driver_nl80211_get_survey, |
Dmitry Shmidt | 5605286 | 2013-10-04 10:23:25 -0700 | [diff] [blame] | 9584 | .status = wpa_driver_nl80211_status, |
Dmitry Shmidt | e0e48dc | 2013-11-18 12:00:06 -0800 | [diff] [blame] | 9585 | .switch_channel = nl80211_switch_channel, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9586 | #ifdef ANDROID_P2P |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 9587 | .set_noa = wpa_driver_set_p2p_noa, |
Dmitry Shmidt | 1f69aa5 | 2012-01-24 16:10:04 -0800 | [diff] [blame] | 9588 | .get_noa = wpa_driver_get_p2p_noa, |
Dmitry Shmidt | 6e933c1 | 2011-09-27 12:29:26 -0700 | [diff] [blame] | 9589 | .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie, |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 9590 | #endif /* ANDROID_P2P */ |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 9591 | #ifdef ANDROID |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 9592 | #ifndef ANDROID_LIB_STUB |
Dmitry Shmidt | 738a26e | 2011-07-07 14:22:14 -0700 | [diff] [blame] | 9593 | .driver_cmd = wpa_driver_nl80211_driver_cmd, |
Dmitry Shmidt | 4171258 | 2015-06-29 11:02:15 -0700 | [diff] [blame] | 9594 | #endif /* !ANDROID_LIB_STUB */ |
Dmitry Shmidt | 292b0c3 | 2013-11-22 12:54:42 -0800 | [diff] [blame] | 9595 | #endif /* ANDROID */ |
Dmitry Shmidt | a38abf9 | 2014-03-06 13:38:44 -0800 | [diff] [blame] | 9596 | .vendor_cmd = nl80211_vendor_cmd, |
Dmitry Shmidt | fb79edc | 2014-01-10 10:45:54 -0800 | [diff] [blame] | 9597 | .set_qos_map = nl80211_set_qos_map, |
Dmitry Shmidt | b58836e | 2014-04-29 14:35:56 -0700 | [diff] [blame] | 9598 | .set_wowlan = nl80211_set_wowlan, |
Dmitry Shmidt | 661b4f7 | 2014-09-29 14:58:27 -0700 | [diff] [blame] | 9599 | .set_mac_addr = nl80211_set_mac_addr, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9600 | #ifdef CONFIG_MESH |
| 9601 | .init_mesh = wpa_driver_nl80211_init_mesh, |
| 9602 | .join_mesh = wpa_driver_nl80211_join_mesh, |
| 9603 | .leave_mesh = wpa_driver_nl80211_leave_mesh, |
| 9604 | #endif /* CONFIG_MESH */ |
| 9605 | .br_add_ip_neigh = wpa_driver_br_add_ip_neigh, |
| 9606 | .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh, |
| 9607 | .br_port_set_attr = wpa_driver_br_port_set_attr, |
| 9608 | .br_set_net_param = wpa_driver_br_set_net_param, |
| 9609 | .add_tx_ts = nl80211_add_ts, |
| 9610 | .del_tx_ts = nl80211_del_ts, |
Dmitry Shmidt | e466304 | 2016-04-04 10:07:49 -0700 | [diff] [blame] | 9611 | .get_ifindex = nl80211_get_ifindex, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9612 | #ifdef CONFIG_DRIVER_NL80211_QCA |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 9613 | .roaming = nl80211_roaming, |
Dmitry Shmidt | 6c0da2b | 2015-01-05 13:08:17 -0800 | [diff] [blame] | 9614 | .do_acs = wpa_driver_do_acs, |
Ravi Joshi | e6ccb16 | 2015-07-16 17:45:41 -0700 | [diff] [blame] | 9615 | .set_band = nl80211_set_band, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9616 | .get_pref_freq_list = nl80211_get_pref_freq_list, |
| 9617 | .set_prob_oper_freq = nl80211_set_prob_oper_freq, |
Dmitry Shmidt | 58d12ad | 2016-07-28 10:07:03 -0700 | [diff] [blame] | 9618 | .p2p_lo_start = nl80211_p2p_lo_start, |
| 9619 | .p2p_lo_stop = nl80211_p2p_lo_stop, |
Dmitry Shmidt | 7f2c753 | 2016-08-15 09:48:12 -0700 | [diff] [blame] | 9620 | .set_default_scan_ies = nl80211_set_default_scan_ies, |
Dmitry Shmidt | 9839ecd | 2016-11-07 11:05:47 -0800 | [diff] [blame^] | 9621 | .set_tdls_mode = nl80211_set_tdls_mode, |
Dmitry Shmidt | d80a401 | 2015-11-05 16:35:40 -0800 | [diff] [blame] | 9622 | #endif /* CONFIG_DRIVER_NL80211_QCA */ |
Dmitry Shmidt | 849734c | 2016-05-27 09:59:01 -0700 | [diff] [blame] | 9623 | .configure_data_frame_filters = nl80211_configure_data_frame_filters, |
Dmitry Shmidt | d5ab1b5 | 2016-06-21 12:38:41 -0700 | [diff] [blame] | 9624 | .get_ext_capab = nl80211_get_ext_capab, |
Dmitry Shmidt | 8d520ff | 2011-05-09 14:06:53 -0700 | [diff] [blame] | 9625 | }; |